]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blobdiff - include/llvm/IR/DIBuilder.h
DIBuilder: Similar to createPointerType, make createMemberPointerType take
[opencl/llvm.git] / include / llvm / IR / DIBuilder.h
index 7d87a69de0e8361768823bbf0df63b3d37c351a3..ae1ac650a9ec4b09857cc1ead6e2f87ac92ed06c 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/TrackingMDRef.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/DataTypes.h"
 
@@ -27,6 +28,7 @@ namespace llvm {
   class Function;
   class Module;
   class Value;
+  class Constant;
   class LLVMContext;
   class MDNode;
   class StringRef;
@@ -38,7 +40,6 @@ namespace llvm {
   class DIFile;
   class DIEnumerator;
   class DIType;
-  class DIArray;
   class DIGlobalVariable;
   class DIImportedEntity;
   class DINameSpace;
@@ -53,7 +54,6 @@ namespace llvm {
   class DIObjCProperty;
 
   class DIBuilder {
-    private:
     Module &M;
     LLVMContext &VMContext;
 
@@ -66,27 +66,34 @@ namespace llvm {
     Function *DeclareFn;     // llvm.dbg.declare
     Function *ValueFn;       // llvm.dbg.value
 
-    SmallVector<Value *, 4> AllEnumTypes;
-    /// Use TrackingVH to collect RetainTypes, since they can be updated
-    /// later on.
-    SmallVector<TrackingVH<MDNode>, 4> AllRetainTypes;
-    SmallVector<Value *, 4> AllSubprograms;
-    SmallVector<Value *, 4> AllGVs;
-    SmallVector<TrackingVH<MDNode>, 4> AllImportedModules;
+    SmallVector<Metadata *, 4> AllEnumTypes;
+    /// Track the RetainTypes, since they can be updated later on.
+    SmallVector<TrackingMDNodeRef, 4> AllRetainTypes;
+    SmallVector<Metadata *, 4> AllSubprograms;
+    SmallVector<Metadata *, 4> AllGVs;
+    SmallVector<TrackingMDNodeRef, 4> AllImportedModules;
 
-    // Private use for multiple types of template parameters.
-    DITemplateValueParameter
-    createTemplateValueParameter(unsigned Tag, DIDescriptor Scope,
-                                 StringRef Name, DIType Ty, Value *Val,
-                                 MDNode *File = 0, unsigned LineNo = 0,
-                                 unsigned ColumnNo = 0);
+    /// \brief Track nodes that may be unresolved.
+    SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes;
+    bool AllowUnresolvedNodes;
+
+    /// Each subprogram's preserved local variables.
+    DenseMap<MDNode *, std::vector<TrackingMDNodeRef>> PreservedVariables;
 
     DIBuilder(const DIBuilder &) LLVM_DELETED_FUNCTION;
     void operator=(const DIBuilder &) LLVM_DELETED_FUNCTION;
 
-    public:
-    explicit DIBuilder(Module &M);
-    enum ComplexAddrKind { OpPlus=1, OpDeref };
+    /// \brief Create a temporary.
+    ///
+    /// Create an \a MDNodeFwdDecl and track it in \a UnresolvedNodes.
+    void trackIfUnresolved(MDNode *N);
+
+  public:
+    /// \brief Construct a builder for a module.
+    ///
+    /// If \c AllowUnresolved, collect unresolved nodes attached to the module
+    /// in order to resolve cycles during \a finalize().
+    explicit DIBuilder(Module &M, bool AllowUnresolved = true);
     enum DebugEmissionKind { FullDebug=1, LineTablesOnly };
 
     /// finalize - Construct any deferred debug info descriptors.
@@ -108,12 +115,23 @@ namespace llvm {
     ///                 Objective-C.
     /// @param SplitName The name of the file that we'll split debug info out
     ///                  into.
+    /// @param Kind     The kind of debug information to generate.
+    /// @param EmitDebugInfo   A boolean flag which indicates whether debug
+    ///                        information should be written to the final
+    ///                        output or not. When this is false, debug
+    ///                        information annotations will be present in
+    ///                        the IL but they are not written to the final
+    ///                        assembly or object file. This supports tracking
+    ///                        source location information in the back end
+    ///                        without actually changing the output (e.g.,
+    ///                        when using optimization remarks).
     DICompileUnit createCompileUnit(unsigned Lang, StringRef File,
                                     StringRef Dir, StringRef Producer,
                                     bool isOptimized, StringRef Flags,
                                     unsigned RV,
                                     StringRef SplitName = StringRef(),
-                                    DebugEmissionKind Kind = FullDebug);
+                                    DebugEmissionKind Kind = FullDebug,
+                                    bool EmitDebugInfo = true);
 
     /// createFile - Create a file descriptor to hold debugging information
     /// for a file.
@@ -154,8 +172,12 @@ namespace llvm {
 
     /// \brief Create debugging information entry for a pointer to member.
     /// @param PointeeTy Type pointed to by this pointer.
+    /// @param SizeInBits  Size.
+    /// @param AlignInBits Alignment. (optional)
     /// @param Class Type for which this pointer points to members of.
-    DIDerivedType createMemberPointerType(DIType PointeeTy, DIType Class);
+    DIDerivedType createMemberPointerType(DIType PointeeTy, DIType Class,
+                                          uint64_t SizeInBits,
+                                          uint64_t AlignInBits = 0);
 
     /// createReferenceType - Create debugging information entry for a c++
     /// style reference or rvalue reference type.
@@ -207,36 +229,10 @@ namespace llvm {
     /// @param Ty         Type of the static member.
     /// @param Flags      Flags to encode member attribute, e.g. private.
     /// @param Val        Const initializer of the member.
-    DIDerivedType
-    createStaticMemberType(DIDescriptor Scope, StringRef Name,
-                           DIFile File, unsigned LineNo, DIType Ty,
-                           unsigned Flags, llvm::Value *Val);
-
-    /// createObjCIVar - Create debugging information entry for Objective-C
-    /// instance variable.
-    /// @param Name         Member name.
-    /// @param File         File where this member is defined.
-    /// @param LineNo       Line number.
-    /// @param SizeInBits   Member size.
-    /// @param AlignInBits  Member alignment.
-    /// @param OffsetInBits Member offset.
-    /// @param Flags        Flags to encode member attribute, e.g. private
-    /// @param Ty           Parent type.
-    /// @param PropertyName Name of the Objective C property associated with
-    ///                     this ivar.
-    /// @param PropertyGetterName Name of the Objective C property getter
-    ///                           selector.
-    /// @param PropertySetterName Name of the Objective C property setter
-    ///                           selector.
-    /// @param PropertyAttributes Objective C property attributes.
-    DIDerivedType createObjCIVar(StringRef Name, DIFile File,
-                                 unsigned LineNo, uint64_t SizeInBits,
-                                 uint64_t AlignInBits, uint64_t OffsetInBits,
-                                 unsigned Flags, DIType Ty,
-                                 StringRef PropertyName = StringRef(),
-                                 StringRef PropertyGetterName = StringRef(),
-                                 StringRef PropertySetterName = StringRef(),
-                                 unsigned PropertyAttributes = 0);
+    DIDerivedType createStaticMemberType(DIDescriptor Scope, StringRef Name,
+                                         DIFile File, unsigned LineNo,
+                                         DIType Ty, unsigned Flags,
+                                         llvm::Constant *Val);
 
     /// createObjCIVar - Create debugging information entry for Objective-C
     /// instance variable.
@@ -293,7 +289,7 @@ namespace llvm {
                                     uint64_t OffsetInBits, unsigned Flags,
                                     DIType DerivedFrom, DIArray Elements,
                                     DIType VTableHolder = DIType(),
-                                    MDNode *TemplateParms = 0,
+                                    MDNode *TemplateParms = nullptr,
                                     StringRef UniqueIdentifier = StringRef());
 
     /// createStructType - Create debugging information entry for a struct.
@@ -342,7 +338,7 @@ namespace llvm {
     /// @param ColumnNo     Column Number.
     DITemplateTypeParameter
     createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
-                                MDNode *File = 0, unsigned LineNo = 0,
+                                MDNode *File = nullptr, unsigned LineNo = 0,
                                 unsigned ColumnNo = 0);
 
     /// createTemplateValueParameter - Create debugging information for template
@@ -355,8 +351,8 @@ namespace llvm {
     /// @param LineNo       Line number.
     /// @param ColumnNo     Column Number.
     DITemplateValueParameter
-    createTemplateValueParameter(DIDescriptor Scope, StringRef Name,
-                                 DIType Ty, Value *Val, MDNode *File = 0,
+    createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
+                                 Constant *Val, MDNode *File = nullptr,
                                  unsigned LineNo = 0, unsigned ColumnNo = 0);
 
     /// \brief Create debugging information for a template template parameter.
@@ -369,8 +365,9 @@ namespace llvm {
     /// @param ColumnNo     Column Number.
     DITemplateValueParameter
     createTemplateTemplateParameter(DIDescriptor Scope, StringRef Name,
-                                    DIType Ty, StringRef Val, MDNode *File = 0,
-                                    unsigned LineNo = 0, unsigned ColumnNo = 0);
+                                    DIType Ty, StringRef Val,
+                                    MDNode *File = nullptr, unsigned LineNo = 0,
+                                    unsigned ColumnNo = 0);
 
     /// \brief Create debugging information for a template parameter pack.
     /// @param Scope        Scope in which this type is defined.
@@ -382,7 +379,7 @@ namespace llvm {
     /// @param ColumnNo     Column Number.
     DITemplateValueParameter
     createTemplateParameterPack(DIDescriptor Scope, StringRef Name,
-                                DIType Ty, DIArray Val, MDNode *File = 0,
+                                DIType Ty, DIArray Val, MDNode *File = nullptr,
                                 unsigned LineNo = 0, unsigned ColumnNo = 0);
 
     /// createArrayType - Create debugging information entry for an array.
@@ -423,8 +420,9 @@ namespace llvm {
     ///                        includes return type at 0th index.
     /// @param Flags           E.g.: LValueReference.
     ///                        These flags are used to emit dwarf attributes.
-    DICompositeType createSubroutineType(DIFile File, DIArray ParameterTypes,
-                                         unsigned Flags = 0);
+    DISubroutineType createSubroutineType(DIFile File,
+                                          DITypeArray ParameterTypes,
+                                          unsigned Flags = 0);
 
     /// createArtificialType - Create a new DIType with "artificial" flag set.
     DIType createArtificialType(DIType Ty);
@@ -433,7 +431,7 @@ namespace llvm {
     /// flag set.
     DIType createObjectPointerType(DIType Ty);
 
-    /// createForwardDecl - Create a temporary forward-declared type.
+    /// \brief Create a permanent forward-declared type.
     DICompositeType createForwardDecl(unsigned Tag, StringRef Name,
                                       DIDescriptor Scope, DIFile F,
                                       unsigned Line, unsigned RuntimeLang = 0,
@@ -441,48 +439,32 @@ namespace llvm {
                                       uint64_t AlignInBits = 0,
                                       StringRef UniqueIdentifier = StringRef());
 
+    /// \brief Create a temporary forward-declared type.
+    DICompositeType createReplaceableForwardDecl(
+        unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F,
+        unsigned Line, unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
+        uint64_t AlignInBits = 0, StringRef UniqueIdentifier = StringRef());
+
     /// retainType - Retain DIType in a module even if it is not referenced
     /// through debug info anchors.
     void retainType(DIType T);
 
-    /// createUnspecifiedParameter - Create unspecified type descriptor
+    /// createUnspecifiedParameter - Create unspecified parameter type
     /// for a subroutine type.
-    DIDescriptor createUnspecifiedParameter();
+    DIBasicType createUnspecifiedParameter();
 
     /// getOrCreateArray - Get a DIArray, create one if required.
-    DIArray getOrCreateArray(ArrayRef<Value *> Elements);
+    DIArray getOrCreateArray(ArrayRef<Metadata *> Elements);
+
+    /// getOrCreateTypeArray - Get a DITypeArray, create one if required.
+    DITypeArray getOrCreateTypeArray(ArrayRef<Metadata *> Elements);
 
     /// getOrCreateSubrange - Create a descriptor for a value range.  This
     /// implicitly uniques the values returned.
     DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
 
-    /// createGlobalVariable - Create a new descriptor for the specified global.
-    /// @param Name        Name of the variable.
-    /// @param File        File where this variable is defined.
-    /// @param LineNo      Line number.
-    /// @param Ty          Variable Type.
-    /// @param isLocalToUnit Boolean flag indicate whether this variable is
-    ///                      externally visible or not.
-    /// @param Val         llvm::Value of the variable.
-    DIGlobalVariable
-    createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
-                         DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val);
 
-    /// \brief Create a new descriptor for the specified global.
-    /// @param Name        Name of the variable.
-    /// @param LinkageName Mangled variable name.
-    /// @param File        File where this variable is defined.
-    /// @param LineNo      Line number.
-    /// @param Ty          Variable Type.
-    /// @param isLocalToUnit Boolean flag indicate whether this variable is
-    ///                      externally visible or not.
-    /// @param Val         llvm::Value of the variable.
-    DIGlobalVariable
-    createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile File,
-                         unsigned LineNo, DITypeRef Ty, bool isLocalToUnit,
-                         llvm::Value *Val);
-
-    /// createStaticVariable - Create a new descriptor for the specified
+    /// createGlobalVariable - Create a new descriptor for the specified
     /// variable.
     /// @param Context     Variable scope.
     /// @param Name        Name of the variable.
@@ -494,12 +476,19 @@ namespace llvm {
     ///                      externally visible or not.
     /// @param Val         llvm::Value of the variable.
     /// @param Decl        Reference to the corresponding declaration.
-    DIGlobalVariable
-    createStaticVariable(DIDescriptor Context, StringRef Name,
-                         StringRef LinkageName, DIFile File, unsigned LineNo,
-                         DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val,
-                         MDNode *Decl = NULL);
-
+    DIGlobalVariable createGlobalVariable(DIDescriptor Context, StringRef Name,
+                                          StringRef LinkageName, DIFile File,
+                                          unsigned LineNo, DITypeRef Ty,
+                                          bool isLocalToUnit,
+                                          llvm::Constant *Val,
+                                          MDNode *Decl = nullptr);
+
+    /// createTempGlobalVariableFwdDecl - Identical to createGlobalVariable
+    /// except that the resulting DbgNode is temporary and meant to be RAUWed.
+    DIGlobalVariable createTempGlobalVariableFwdDecl(
+        DIDescriptor Context, StringRef Name, StringRef LinkageName,
+        DIFile File, unsigned LineNo, DITypeRef Ty, bool isLocalToUnit,
+        llvm::Constant *Val, MDNode *Decl = nullptr);
 
     /// createLocalVariable - Create a new descriptor for the specified
     /// local variable.
@@ -522,23 +511,18 @@ namespace llvm {
                                    unsigned Flags = 0,
                                    unsigned ArgNo = 0);
 
-
-    /// createComplexVariable - Create a new descriptor for the specified
+    /// createExpression - Create a new descriptor for the specified
     /// variable which has a complex address expression for its address.
-    /// @param Tag         Dwarf TAG. Usually DW_TAG_auto_variable or
-    ///                    DW_TAG_arg_variable.
-    /// @param Scope       Variable scope.
-    /// @param Name        Variable name.
-    /// @param F           File where this variable is defined.
-    /// @param LineNo      Line number.
-    /// @param Ty          Variable Type
     /// @param Addr        An array of complex address operations.
-    /// @param ArgNo       If this variable is an argument then this argument's
-    ///                    number. 1 indicates 1st argument.
-    DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
-                                     StringRef Name, DIFile F, unsigned LineNo,
-                                     DITypeRef Ty, ArrayRef<Value *> Addr,
-                                     unsigned ArgNo = 0);
+    DIExpression createExpression(ArrayRef<int64_t> Addr = None);
+
+    /// createPieceExpression - Create a descriptor to describe one part
+    /// of aggregate variable that is fragmented across multiple Values.
+    ///
+    /// @param OffsetInBytes Offset of the piece in bytes.
+    /// @param SizeInBytes   Size of the piece in bytes.
+    DIExpression createPieceExpression(unsigned OffsetInBytes,
+                                       unsigned SizeInBytes);
 
     /// createFunction - Create a new descriptor for the specified subprogram.
     /// See comments in DISubprogram for descriptions of these fields.
@@ -564,9 +548,24 @@ namespace llvm {
                                 unsigned ScopeLine,
                                 unsigned Flags = 0,
                                 bool isOptimized = false,
-                                Function *Fn = 0,
-                                MDNode *TParam = 0,
-                                MDNode *Decl = 0);
+                                Function *Fn = nullptr,
+                                MDNode *TParam = nullptr,
+                                MDNode *Decl = nullptr);
+
+    /// createTempFunctionFwdDecl - Identical to createFunction,
+    /// except that the resulting DbgNode is meant to be RAUWed.
+    DISubprogram createTempFunctionFwdDecl(DIDescriptor Scope, StringRef Name,
+                                           StringRef LinkageName,
+                                           DIFile File, unsigned LineNo,
+                                           DICompositeType Ty, bool isLocalToUnit,
+                                           bool isDefinition,
+                                           unsigned ScopeLine,
+                                           unsigned Flags = 0,
+                                           bool isOptimized = false,
+                                           Function *Fn = nullptr,
+                                           MDNode *TParam = nullptr,
+                                           MDNode *Decl = nullptr);
+
 
     /// FIXME: this is added for dragonegg. Once we update dragonegg
     /// to call resolve function, this will be removed.
@@ -578,9 +577,9 @@ namespace llvm {
                                 unsigned ScopeLine,
                                 unsigned Flags = 0,
                                 bool isOptimized = false,
-                                Function *Fn = 0,
-                                MDNode *TParam = 0,
-                                MDNode *Decl = 0);
+                                Function *Fn = nullptr,
+                                MDNode *TParam = nullptr,
+                                MDNode *Decl = nullptr);
 
     /// createMethod - Create a new descriptor for the specified C++ method.
     /// See comments in DISubprogram for descriptions of these fields.
@@ -610,8 +609,8 @@ namespace llvm {
                               DIType VTableHolder = DIType(),
                               unsigned Flags = 0,
                               bool isOptimized = false,
-                              Function *Fn = 0,
-                              MDNode *TParam = 0);
+                              Function *Fn = nullptr,
+                              MDNode *TParam = nullptr);
 
     /// createNameSpace - This creates new descriptor for a namespace
     /// with the specified parent scope.
@@ -628,8 +627,9 @@ namespace llvm {
     /// lexical block as it crosses a file.
     /// @param Scope       Lexical block.
     /// @param File        Source file.
-    DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
-                                              DIFile File);
+    /// @param Discriminator DWARF path discriminator value.
+    DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope, DIFile File,
+                                              unsigned Discriminator = 0);
 
     /// createLexicalBlock - This creates a descriptor for a lexical block
     /// with the specified parent context.
@@ -637,68 +637,85 @@ namespace llvm {
     /// @param File          Source file.
     /// @param Line          Line number.
     /// @param Col           Column number.
-    /// @param Discriminator DWARF path discriminator value.
     DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
-                                      unsigned Line, unsigned Col,
-                                      unsigned Discriminator);
+                                      unsigned Line, unsigned Col);
 
     /// \brief Create a descriptor for an imported module.
     /// @param Context The scope this module is imported into
     /// @param NS The namespace being imported here
     /// @param Line Line number
     DIImportedEntity createImportedModule(DIScope Context, DINameSpace NS,
-                                          unsigned Line,
-                                          StringRef Name = StringRef());
+                                          unsigned Line);
 
     /// \brief Create a descriptor for an imported module.
     /// @param Context The scope this module is imported into
     /// @param NS An aliased namespace
     /// @param Line Line number
     DIImportedEntity createImportedModule(DIScope Context, DIImportedEntity NS,
-                                          unsigned Line, StringRef Name);
+                                          unsigned Line);
 
     /// \brief Create a descriptor for an imported function.
     /// @param Context The scope this module is imported into
     /// @param Decl The declaration (or definition) of a function, type, or
     ///             variable
     /// @param Line Line number
+    DIImportedEntity createImportedDeclaration(DIScope Context, DIDescriptor Decl,
+                                               unsigned Line,
+                                               StringRef Name = StringRef());
     DIImportedEntity createImportedDeclaration(DIScope Context,
-                                               DIScope Decl,
-                                               unsigned Line);
+                                               DIImportedEntity NS,
+                                               unsigned Line,
+                                               StringRef Name = StringRef());
 
     /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
     /// @param Storage     llvm::Value of the variable
     /// @param VarInfo     Variable's debug info descriptor.
+    /// @param Expr         A complex location expression.
     /// @param InsertAtEnd Location for the new intrinsic.
     Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
-                               BasicBlock *InsertAtEnd);
+                               DIExpression Expr, BasicBlock *InsertAtEnd);
 
     /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
     /// @param Storage      llvm::Value of the variable
     /// @param VarInfo      Variable's debug info descriptor.
+    /// @param Expr         A complex location expression.
     /// @param InsertBefore Location for the new intrinsic.
     Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
-                               Instruction *InsertBefore);
-
+                               DIExpression Expr, Instruction *InsertBefore);
 
     /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
     /// @param Val          llvm::Value of the variable
     /// @param Offset       Offset
     /// @param VarInfo      Variable's debug info descriptor.
+    /// @param Expr         A complex location expression.
     /// @param InsertAtEnd Location for the new intrinsic.
     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
-                                         DIVariable VarInfo,
+                                         DIVariable VarInfo, DIExpression Expr,
                                          BasicBlock *InsertAtEnd);
 
     /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
     /// @param Val          llvm::Value of the variable
     /// @param Offset       Offset
     /// @param VarInfo      Variable's debug info descriptor.
+    /// @param Expr         A complex location expression.
     /// @param InsertBefore Location for the new intrinsic.
     Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
-                                         DIVariable VarInfo,
+                                         DIVariable VarInfo, DIExpression Expr,
                                          Instruction *InsertBefore);
 
+    /// \brief Replace the vtable holder in the given composite type.
+    ///
+    /// If this creates a self reference, it may orphan some unresolved cycles
+    /// in the operands of \c T, so \a DIBuilder needs to track that.
+    void replaceVTableHolder(DICompositeType &T, DICompositeType VTableHolder);
+
+    /// \brief Replace arrays on a composite type.
+    ///
+    /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
+    /// has a self-reference -- \a DIBuilder needs to track the array to
+    /// resolve cycles.
+    void replaceArrays(DICompositeType &T, DIArray Elements,
+                       DIArray TParems = DIArray());
   };
 } // end namespace llvm