diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2022-06-04 11:58:51 +0000 |
| commit | 4b6eb0e63c698094db5506763df44cc83c19f643 (patch) | |
| tree | f1d30b8c10bc6db323b91538745ae8ab8b593910 /contrib/llvm-project/llvm/lib/IR/DIBuilder.cpp | |
| parent | 76886853f03395abb680824bcc74e98f83bd477a (diff) | |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/DIBuilder.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/IR/DIBuilder.cpp | 200 |
1 files changed, 105 insertions, 95 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/DIBuilder.cpp b/contrib/llvm-project/llvm/lib/IR/DIBuilder.cpp index 61d3b5e69e9e..ca7dafc814ce 100644 --- a/contrib/llvm-project/llvm/lib/IR/DIBuilder.cpp +++ b/contrib/llvm-project/llvm/lib/IR/DIBuilder.cpp @@ -32,8 +32,8 @@ static cl::opt<bool> cl::init(false), cl::Hidden); DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU) - : M(m), VMContext(M.getContext()), CUNode(CU), - DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr), + : M(m), VMContext(M.getContext()), CUNode(CU), DeclareFn(nullptr), + ValueFn(nullptr), LabelFn(nullptr), AllowUnresolvedNodes(AllowUnresolvedNodes) {} void DIBuilder::trackIfUnresolved(MDNode *N) { @@ -73,7 +73,8 @@ void DIBuilder::finalize() { return; } - CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); + if (!AllEnumTypes.empty()) + CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); SmallVector<Metadata *, 16> RetainValues; // Declarations and definitions of the same type may be retained. Some @@ -164,12 +165,13 @@ DICompileUnit *DIBuilder::createCompileUnit( static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, + DINodeArray Elements, SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { if (Line) assert(File && "Source location has line number but no file"); unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null<DINode>(NS), - File, Line, Name); + File, Line, Name, Elements); if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) // A new Imported Entity was just added to the context. // Add it to the Imported Modules list. @@ -179,36 +181,38 @@ createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DINamespace *NS, DIFile *File, - unsigned Line) { + unsigned Line, + DINodeArray Elements) { return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, - Context, NS, File, Line, StringRef(), + Context, NS, File, Line, StringRef(), Elements, AllImportedModules); } DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIImportedEntity *NS, - DIFile *File, unsigned Line) { + DIFile *File, unsigned Line, + DINodeArray Elements) { return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, - Context, NS, File, Line, StringRef(), + Context, NS, File, Line, StringRef(), Elements, AllImportedModules); } DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M, - DIFile *File, unsigned Line) { + DIFile *File, unsigned Line, + DINodeArray Elements) { return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, - Context, M, File, Line, StringRef(), + Context, M, File, Line, StringRef(), Elements, AllImportedModules); } -DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context, - DINode *Decl, - DIFile *File, - unsigned Line, - StringRef Name) { +DIImportedEntity * +DIBuilder::createImportedDeclaration(DIScope *Context, DINode *Decl, + DIFile *File, unsigned Line, + StringRef Name, DINodeArray Elements) { // Make sure to use the unique identifier based metadata reference for // types that have one. return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, - Context, Decl, File, Line, Name, + Context, Decl, File, Line, Name, Elements, AllImportedModules); } @@ -250,7 +254,7 @@ DIEnumerator *DIBuilder::createEnumerator(StringRef Name, uint64_t Val, Name); } -DIEnumerator *DIBuilder::createEnumerator(StringRef Name, APSInt Value) { +DIEnumerator *DIBuilder::createEnumerator(StringRef Name, const APSInt &Value) { assert(!Name.empty() && "Unable to create enumerator without name"); return DIEnumerator::get(VMContext, APInt(Value), Value.isUnsigned(), Name); } @@ -283,17 +287,16 @@ DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { 0, 0, None, DINode::FlagZero); } -DIDerivedType *DIBuilder::createPointerType( - DIType *PointeeTy, - uint64_t SizeInBits, - uint32_t AlignInBits, - Optional<unsigned> DWARFAddressSpace, - StringRef Name) { +DIDerivedType * +DIBuilder::createPointerType(DIType *PointeeTy, uint64_t SizeInBits, + uint32_t AlignInBits, + Optional<unsigned> DWARFAddressSpace, + StringRef Name, DINodeArray Annotations) { // FIXME: Why is there a name here? return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, nullptr, 0, nullptr, PointeeTy, SizeInBits, - AlignInBits, 0, DWARFAddressSpace, - DINode::FlagZero); + AlignInBits, 0, DWARFAddressSpace, DINode::FlagZero, + nullptr, Annotations); } DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, @@ -306,11 +309,10 @@ DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, AlignInBits, 0, None, Flags, Base); } -DIDerivedType *DIBuilder::createReferenceType( - unsigned Tag, DIType *RTy, - uint64_t SizeInBits, - uint32_t AlignInBits, - Optional<unsigned> DWARFAddressSpace) { +DIDerivedType * +DIBuilder::createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits, + uint32_t AlignInBits, + Optional<unsigned> DWARFAddressSpace) { assert(RTy && "Unable to create reference type"); return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy, SizeInBits, AlignInBits, 0, DWARFAddressSpace, @@ -319,11 +321,12 @@ DIDerivedType *DIBuilder::createReferenceType( DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name, DIFile *File, unsigned LineNo, - DIScope *Context, - uint32_t AlignInBits) { + DIScope *Context, uint32_t AlignInBits, + DINodeArray Annotations) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo, getNonCompileUnitScope(Context), Ty, 0, - AlignInBits, 0, None, DINode::FlagZero); + AlignInBits, 0, None, DINode::FlagZero, nullptr, + Annotations); } DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { @@ -341,19 +344,18 @@ DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, Metadata *ExtraData = ConstantAsMetadata::get( ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset)); return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, - 0, Ty, BaseTy, 0, 0, BaseOffset, None, - Flags, ExtraData); + 0, Ty, BaseTy, 0, 0, BaseOffset, None, Flags, + ExtraData); } -DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, - DIFile *File, unsigned LineNumber, - uint64_t SizeInBits, - uint32_t AlignInBits, - uint64_t OffsetInBits, - DINode::DIFlags Flags, DIType *Ty) { +DIDerivedType *DIBuilder::createMemberType( + DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, + uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, + DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, getNonCompileUnitScope(Scope), Ty, - SizeInBits, AlignInBits, OffsetInBits, None, Flags); + SizeInBits, AlignInBits, OffsetInBits, None, Flags, + nullptr, Annotations); } static ConstantAsMetadata *getConstantOrNull(Constant *C) { @@ -375,14 +377,15 @@ DIDerivedType *DIBuilder::createVariantMemberType( DIDerivedType *DIBuilder::createBitFieldMemberType( DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, - DINode::DIFlags Flags, DIType *Ty) { + DINode::DIFlags Flags, DIType *Ty, DINodeArray Annotations) { Flags |= DINode::FlagBitField; return DIDerivedType::get( VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, - getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0, + getNonCompileUnitScope(Scope), Ty, SizeInBits, /*AlignInBits=*/0, OffsetInBits, None, Flags, ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64), - StorageOffsetInBits))); + StorageOffsetInBits)), + Annotations); } DIDerivedType * @@ -498,10 +501,12 @@ DICompositeType *DIBuilder::createUnionType( return R; } -DICompositeType *DIBuilder::createVariantPart( - DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, - uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, - DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) { +DICompositeType * +DIBuilder::createVariantPart(DIScope *Scope, StringRef Name, DIFile *File, + unsigned LineNumber, uint64_t SizeInBits, + uint32_t AlignInBits, DINode::DIFlags Flags, + DIDerivedType *Discriminator, DINodeArray Elements, + StringRef UniqueIdentifier) { auto *R = DICompositeType::get( VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber, getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, @@ -542,16 +547,17 @@ DIDerivedType *DIBuilder::createSetType(DIScope *Scope, StringRef Name, return R; } -DICompositeType *DIBuilder::createArrayType( - uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts, - PointerUnion<DIExpression *, DIVariable *> DL, - PointerUnion<DIExpression *, DIVariable *> AS, - PointerUnion<DIExpression *, DIVariable *> AL, - PointerUnion<DIExpression *, DIVariable *> RK) { +DICompositeType * +DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, + DINodeArray Subscripts, + PointerUnion<DIExpression *, DIVariable *> DL, + PointerUnion<DIExpression *, DIVariable *> AS, + PointerUnion<DIExpression *, DIVariable *> AL, + PointerUnion<DIExpression *, DIVariable *> RK) { auto *R = DICompositeType::get( - VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, - nullptr, Ty, Size, AlignInBits, 0, DINode::FlagZero, - Subscripts, 0, nullptr, nullptr, "", nullptr, + VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty, Size, + AlignInBits, 0, DINode::FlagZero, Subscripts, 0, nullptr, nullptr, "", + nullptr, DL.is<DIExpression *>() ? (Metadata *)DL.get<DIExpression *>() : (Metadata *)DL.get<DIVariable *>(), AS.is<DIExpression *>() ? (Metadata *)AS.get<DIExpression *>() @@ -628,12 +634,14 @@ DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, DICompositeType *DIBuilder::createReplaceableCompositeType( unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, - DINode::DIFlags Flags, StringRef UniqueIdentifier) { + DINode::DIFlags Flags, StringRef UniqueIdentifier, + DINodeArray Annotations) { auto *RetTy = DICompositeType::getTemporary( VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr, - nullptr, UniqueIdentifier) + nullptr, UniqueIdentifier, nullptr, nullptr, nullptr, nullptr, + nullptr, Annotations) .release(); trackIfUnresolved(RetTy); return RetTy; @@ -701,15 +709,16 @@ static void checkGlobalVariableScope(DIScope *Context) { DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression( DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, - unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, - bool isDefined, DIExpression *Expr, - MDNode *Decl, MDTuple *TemplateParams, uint32_t AlignInBits) { + unsigned LineNumber, DIType *Ty, bool IsLocalToUnit, bool isDefined, + DIExpression *Expr, MDNode *Decl, MDTuple *TemplateParams, + uint32_t AlignInBits, DINodeArray Annotations) { checkGlobalVariableScope(Context); auto *GV = DIGlobalVariable::getDistinct( VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, - LineNumber, Ty, IsLocalToUnit, isDefined, cast_or_null<DIDerivedType>(Decl), - TemplateParams, AlignInBits); + LineNumber, Ty, IsLocalToUnit, isDefined, + cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits, + Annotations); if (!Expr) Expr = createExpression(); auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr); @@ -726,7 +735,8 @@ DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( return DIGlobalVariable::getTemporary( VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, LineNumber, Ty, IsLocalToUnit, false, - cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits) + cast_or_null<DIDerivedType>(Decl), TemplateParams, AlignInBits, + nullptr) .release(); } @@ -735,16 +745,16 @@ static DILocalVariable *createLocalVariable( DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, - uint32_t AlignInBits) { + uint32_t AlignInBits, DINodeArray Annotations = nullptr) { // FIXME: Why getNonCompileUnitScope()? // FIXME: Why is "!Context" okay here? // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT // the only valid scopes)? DIScope *Context = getNonCompileUnitScope(Scope); - auto *Node = - DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, - File, LineNo, Ty, ArgNo, Flags, AlignInBits); + auto *Node = DILocalVariable::get( + VMContext, cast_or_null<DILocalScope>(Context), Name, File, LineNo, Ty, + ArgNo, Flags, AlignInBits, Annotations); if (AlwaysPreserve) { // The optimizer may remove local variables. If there is an interest // to preserve variable info in such situation then stash it in a @@ -768,21 +778,20 @@ DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, DILocalVariable *DIBuilder::createParameterVariable( DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, - unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) { + unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, + DINodeArray Annotations) { assert(ArgNo && "Expected non-zero argument number for parameter"); return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, File, LineNo, Ty, AlwaysPreserve, Flags, - /* AlignInBits */0); + /*AlignInBits=*/0, Annotations); } -DILabel *DIBuilder::createLabel( - DIScope *Scope, StringRef Name, DIFile *File, - unsigned LineNo, bool AlwaysPreserve) { +DILabel *DIBuilder::createLabel(DIScope *Scope, StringRef Name, DIFile *File, + unsigned LineNo, bool AlwaysPreserve) { DIScope *Context = getNonCompileUnitScope(Scope); - auto *Node = - DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name, - File, LineNo); + auto *Node = DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), + Name, File, LineNo); if (AlwaysPreserve) { /// The optimizer may remove labels. If there is an interest @@ -806,7 +815,7 @@ DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) { } template <class... Ts> -static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { +static DISubprogram *getSubprogram(bool IsDistinct, Ts &&...Args) { if (IsDistinct) return DISubprogram::getDistinct(std::forward<Ts>(Args)...); return DISubprogram::get(std::forward<Ts>(Args)...); @@ -817,13 +826,14 @@ DISubprogram *DIBuilder::createFunction( unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams, DISubprogram *Decl, - DITypeArray ThrownTypes) { + DITypeArray ThrownTypes, DINodeArray Annotations) { bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition; auto *Node = getSubprogram( /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, - MDTuple::getTemporary(VMContext, None).release(), ThrownTypes); + MDTuple::getTemporary(VMContext, None).release(), ThrownTypes, + Annotations); if (IsDefinition) AllSubprograms.push_back(Node); @@ -869,11 +879,11 @@ DISubprogram *DIBuilder::createMethod( return SP; } -DICommonBlock *DIBuilder::createCommonBlock( - DIScope *Scope, DIGlobalVariable *Decl, StringRef Name, DIFile *File, - unsigned LineNo) { - return DICommonBlock::get( - VMContext, Scope, Decl, Name, File, LineNo); +DICommonBlock *DIBuilder::createCommonBlock(DIScope *Scope, + DIGlobalVariable *Decl, + StringRef Name, DIFile *File, + unsigned LineNo) { + return DICommonBlock::get(VMContext, Scope, Decl, Name, File, LineNo); } DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name, @@ -929,9 +939,9 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, Instruction *InsertBefore) { - return insertLabel( - LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr, - InsertBefore); + return insertLabel(LabelInfo, DL, + InsertBefore ? InsertBefore->getParent() : nullptr, + InsertBefore); } Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, @@ -980,7 +990,8 @@ static Function *getDeclareIntrin(Module &M) { Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, - BasicBlock *InsertBB, Instruction *InsertBefore) { + BasicBlock *InsertBB, + Instruction *InsertBefore) { assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare"); assert(DL && "Expected debug loc"); assert(DL->getScope()->getSubprogram() == @@ -1023,9 +1034,9 @@ Instruction *DIBuilder::insertDbgValueIntrinsic( return B.CreateCall(ValueFn, Args); } -Instruction *DIBuilder::insertLabel( - DILabel *LabelInfo, const DILocation *DL, - BasicBlock *InsertBB, Instruction *InsertBefore) { +Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, + BasicBlock *InsertBB, + Instruction *InsertBefore) { assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label"); assert(DL && "Expected debug loc"); assert(DL->getScope()->getSubprogram() == @@ -1042,8 +1053,7 @@ Instruction *DIBuilder::insertLabel( return B.CreateCall(LabelFn, Args); } -void DIBuilder::replaceVTableHolder(DICompositeType *&T, - DIType *VTableHolder) { +void DIBuilder::replaceVTableHolder(DICompositeType *&T, DIType *VTableHolder) { { TypedTrackingMDRef<DICompositeType> N(T); N->replaceVTableHolder(VTableHolder); |
