diff options
author | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
commit | 06210ae42d418d50d8d9365d5c9419308ae9e7ee (patch) | |
tree | ab60b4cdd6e430dda1f292a46a77ddb744723f31 /contrib/llvm/lib/IR/DIBuilder.cpp | |
parent | 2dd166267f53df1c3748b4325d294b9b839de74b (diff) | |
download | FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.zip FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.tar.gz |
MFC r309124:
Upgrade our copies of clang, llvm, lldb, compiler-rt and libc++ to 3.9.0
release, and add lld 3.9.0. Also completely revamp the build system for
clang, llvm, lldb and their related tools.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld are available here:
<http://llvm.org/releases/3.9.0/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/clang/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/lld/docs/ReleaseNotes.html>
Thanks to Ed Maste, Bryan Drewery, Andrew Turner, Antoine Brodin and Jan
Beich for their help.
Relnotes: yes
MFC r309147:
Pull in r282174 from upstream llvm trunk (by Krzysztof Parzyszek):
[PPC] Set SP after loading data from stack frame, if no red zone is
present
Follow-up to r280705: Make sure that the SP is only restored after
all data is loaded from the stack frame, if there is no red zone.
This completes the fix for
https://llvm.org/bugs/show_bug.cgi?id=26519.
Differential Revision: https://reviews.llvm.org/D24466
Reported by: Mark Millard
PR: 214433
MFC r309149:
Pull in r283060 from upstream llvm trunk (by Hal Finkel):
[PowerPC] Refactor soft-float support, and enable PPC64 soft float
This change enables soft-float for PowerPC64, and also makes
soft-float disable all vector instruction sets for both 32-bit and
64-bit modes. This latter part is necessary because the PPC backend
canonicalizes many Altivec vector types to floating-point types, and
so soft-float breaks scalarization support for many operations. Both
for embedded targets and for operating-system kernels desiring
soft-float support, it seems reasonable that disabling hardware
floating-point also disables vector instructions (embedded targets
without hardware floating point support are unlikely to have Altivec,
etc. and operating system kernels desiring not to use floating-point
registers to lower syscall cost are unlikely to want to use vector
registers either). If someone needs this to work, we'll need to
change the fact that we promote many Altivec operations to act on
v4f32. To make it possible to disable Altivec when soft-float is
enabled, hardware floating-point support needs to be expressed as a
positive feature, like the others, and not a negative feature,
because target features cannot have dependencies on the disabling of
some other feature. So +soft-float has now become -hard-float.
Fixes PR26970.
Pull in r283061 from upstream clang trunk (by Hal Finkel):
[PowerPC] Enable soft-float for PPC64, and +soft-float -> -hard-float
Enable soft-float support on PPC64, as the backend now supports it.
Also, the backend now uses -hard-float instead of +soft-float, so set
the target features accordingly.
Fixes PR26970.
Reported by: Mark Millard
PR: 214433
MFC r309212:
Add a few missed clang 3.9.0 files to OptionalObsoleteFiles.
MFC r309262:
Fix packaging for clang, lldb and lld 3.9.0
During the upgrade of clang/llvm etc to 3.9.0 in r309124, the PACKAGE
directive in the usr.bin/clang/*.mk files got dropped accidentally.
Restore it, with a few minor changes and additions:
* Correct license in clang.ucl to NCSA
* Add PACKAGE=clang for clang and most of the "ll" tools
* Put lldb in its own package
* Put lld in its own package
Reviewed by: gjb, jmallett
Differential Revision: https://reviews.freebsd.org/D8666
MFC r309656:
During the bootstrap phase, when building the minimal llvm library on
PowerPC, add lib/Support/Atomic.cpp. This is needed because upstream
llvm revision r271821 disabled the use of std::call_once, which causes
some fallback functions from Atomic.cpp to be used instead.
Reported by: Mark Millard
PR: 214902
MFC r309835:
Tentatively apply https://reviews.llvm.org/D18730 to work around gcc PR
70528 (bogus error: constructor required before non-static data member).
This should fix buildworld with the external gcc package.
Reported by: https://jenkins.freebsd.org/job/FreeBSD_HEAD_amd64_gcc/
MFC r310194:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
3.9.1 release.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld will be available here:
<http://releases.llvm.org/3.9.1/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/lld/docs/ReleaseNotes.html>
Relnotes: yes
Diffstat (limited to 'contrib/llvm/lib/IR/DIBuilder.cpp')
-rw-r--r-- | contrib/llvm/lib/IR/DIBuilder.cpp | 311 |
1 files changed, 128 insertions, 183 deletions
diff --git a/contrib/llvm/lib/IR/DIBuilder.cpp b/contrib/llvm/lib/IR/DIBuilder.cpp index b7841fe..01b47f3 100644 --- a/contrib/llvm/lib/IR/DIBuilder.cpp +++ b/contrib/llvm/lib/IR/DIBuilder.cpp @@ -19,44 +19,11 @@ #include "llvm/IR/Module.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Dwarf.h" +#include "LLVMContextImpl.h" using namespace llvm; using namespace llvm::dwarf; -namespace { -class HeaderBuilder { - /// \brief Whether there are any fields yet. - /// - /// Note that this is not equivalent to \c Chars.empty(), since \a concat() - /// may have been called already with an empty string. - bool IsEmpty; - SmallVector<char, 256> Chars; - -public: - HeaderBuilder() : IsEmpty(true) {} - HeaderBuilder(const HeaderBuilder &X) : IsEmpty(X.IsEmpty), Chars(X.Chars) {} - HeaderBuilder(HeaderBuilder &&X) - : IsEmpty(X.IsEmpty), Chars(std::move(X.Chars)) {} - - template <class Twineable> HeaderBuilder &concat(Twineable &&X) { - if (IsEmpty) - IsEmpty = false; - else - Chars.push_back(0); - Twine(X).toVector(Chars); - return *this; - } - - MDString *get(LLVMContext &Context) const { - return MDString::get(Context, StringRef(Chars.begin(), Chars.size())); - } - - static HeaderBuilder get(unsigned Tag) { - return HeaderBuilder().concat("0x" + Twine::utohexstr(Tag)); - } -}; -} - DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes) : M(m), VMContext(M.getContext()), CUNode(nullptr), DeclareFn(nullptr), ValueFn(nullptr), @@ -95,17 +62,25 @@ void DIBuilder::finalize() { CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); - if (!AllSubprograms.empty()) - CUNode->replaceSubprograms(SPs.get()); - - for (auto *SP : SPs) { - if (MDTuple *Temp = SP->getVariables().get()) { - const auto &PV = PreservedVariables.lookup(SP); - SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end()); - DINodeArray AV = getOrCreateArray(Variables); - TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); - } - } + auto resolveVariables = [&](DISubprogram *SP) { + MDTuple *Temp = SP->getVariables().get(); + if (!Temp) + return; + + SmallVector<Metadata *, 4> Variables; + + auto PV = PreservedVariables.find(SP); + if (PV != PreservedVariables.end()) + Variables.append(PV->second.begin(), PV->second.end()); + + DINodeArray AV = getOrCreateArray(Variables); + TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); + }; + for (auto *SP : SPs) + resolveVariables(SP); + for (auto *N : RetainValues) + if (auto *SP = dyn_cast<DISubprogram>(N)) + resolveVariables(SP); if (!AllGVs.empty()) CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); @@ -136,7 +111,7 @@ static DIScope *getNonCompileUnitScope(DIScope *N) { DICompileUnit *DIBuilder::createCompileUnit( unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer, bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName, - DebugEmissionKind Kind, uint64_t DWOId, bool EmitDebugInfo) { + DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId) { assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && @@ -147,19 +122,12 @@ DICompileUnit *DIBuilder::createCompileUnit( assert(!CUNode && "Can only make one compile unit per DIBuilder instance"); CUNode = DICompileUnit::getDistinct( VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer, - isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr, DWOId); + isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr, nullptr, + nullptr, nullptr, nullptr, DWOId); // Create a named metadata so that it is easier to find cu in a module. - // Note that we only generate this when the caller wants to actually - // emit debug information. When we are only interested in tracking - // source line locations throughout the backend, we prevent codegen from - // emitting debug info in the final output by not generating llvm.dbg.cu. - if (EmitDebugInfo) { - NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); - NMD->addOperand(CUNode); - } - + NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); + NMD->addOperand(CUNode); trackIfUnresolved(CUNode); return CUNode; } @@ -168,8 +136,12 @@ static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, unsigned Line, StringRef Name, SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { + unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); auto *M = DIImportedEntity::get(C, Tag, Context, DINodeRef(NS), Line, Name); - AllImportedModules.emplace_back(M); + if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) + // A new Imported Entity was just added to the context. + // Add it to the Imported Modules list. + AllImportedModules.emplace_back(M); return M; } @@ -200,8 +172,7 @@ DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context, // Make sure to use the unique identifier based metadata reference for // types that have one. return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, - Context, DINodeRef::get(Decl), Line, Name, - AllImportedModules); + Context, Decl, Line, Name, AllImportedModules); } DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory) { @@ -231,8 +202,8 @@ DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, } DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { - return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, - DITypeRef::get(FromTy), 0, 0, 0, 0); + return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0, + 0, 0, 0); } DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy, @@ -241,43 +212,41 @@ DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy, StringRef Name) { // FIXME: Why is there a name here? return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, - nullptr, 0, nullptr, DITypeRef::get(PointeeTy), - SizeInBits, AlignInBits, 0, 0); + nullptr, 0, nullptr, PointeeTy, SizeInBits, + AlignInBits, 0, 0); } DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, DIType *Base, uint64_t SizeInBits, - uint64_t AlignInBits) { + uint64_t AlignInBits, + unsigned Flags) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "", - nullptr, 0, nullptr, DITypeRef::get(PointeeTy), - SizeInBits, AlignInBits, 0, 0, - DITypeRef::get(Base)); + nullptr, 0, nullptr, PointeeTy, SizeInBits, + AlignInBits, 0, Flags, Base); } DIDerivedType *DIBuilder::createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits, uint64_t AlignInBits) { assert(RTy && "Unable to create reference type"); - return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, - DITypeRef::get(RTy), SizeInBits, AlignInBits, 0, 0); + return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy, + SizeInBits, AlignInBits, 0, 0); } DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Context) { return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File, - LineNo, - DIScopeRef::get(getNonCompileUnitScope(Context)), - DITypeRef::get(Ty), 0, 0, 0, 0); + LineNo, getNonCompileUnitScope(Context), Ty, 0, 0, + 0, 0); } DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { assert(Ty && "Invalid type!"); assert(FriendTy && "Invalid friend type!"); - return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, - DITypeRef::get(Ty), DITypeRef::get(FriendTy), 0, 0, - 0, 0); + return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty, + FriendTy, 0, 0, 0, 0); } DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, @@ -285,8 +254,7 @@ DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, unsigned Flags) { assert(Ty && "Unable to create inheritance"); return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, - 0, DITypeRef::get(Ty), DITypeRef::get(BaseTy), 0, 0, - BaseOffset, Flags); + 0, Ty, BaseTy, 0, 0, BaseOffset, Flags); } DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, @@ -295,10 +263,9 @@ DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType *Ty) { - return DIDerivedType::get( - VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, - DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty), - SizeInBits, AlignInBits, OffsetInBits, Flags); + return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, + LineNumber, getNonCompileUnitScope(Scope), Ty, + SizeInBits, AlignInBits, OffsetInBits, Flags); } static ConstantAsMetadata *getConstantOrNull(Constant *C) { @@ -307,16 +274,27 @@ static ConstantAsMetadata *getConstantOrNull(Constant *C) { return nullptr; } +DIDerivedType *DIBuilder::createBitFieldMemberType( + DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, + uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, + uint64_t StorageOffsetInBits, unsigned Flags, DIType *Ty) { + Flags |= DINode::FlagBitField; + return DIDerivedType::get( + VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, + getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits, + Flags, ConstantAsMetadata::get(ConstantInt::get( + IntegerType::get(VMContext, 64), StorageOffsetInBits))); +} + DIDerivedType *DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, DIType *Ty, unsigned Flags, llvm::Constant *Val) { Flags |= DINode::FlagStaticMember; - return DIDerivedType::get( - VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, - DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty), 0, 0, - 0, Flags, getConstantOrNull(Val)); + return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, + LineNumber, getNonCompileUnitScope(Scope), Ty, 0, 0, + 0, Flags, getConstantOrNull(Val)); } DIDerivedType *DIBuilder::createObjCIVar(StringRef Name, DIFile *File, @@ -325,10 +303,10 @@ DIDerivedType *DIBuilder::createObjCIVar(StringRef Name, DIFile *File, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType *Ty, MDNode *PropertyNode) { - return DIDerivedType::get( - VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, - DIScopeRef::get(getNonCompileUnitScope(File)), DITypeRef::get(Ty), - SizeInBits, AlignInBits, OffsetInBits, Flags, PropertyNode); + return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, + LineNumber, getNonCompileUnitScope(File), Ty, + SizeInBits, AlignInBits, OffsetInBits, Flags, + PropertyNode); } DIObjCProperty * @@ -336,15 +314,14 @@ DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, StringRef GetterName, StringRef SetterName, unsigned PropertyAttributes, DIType *Ty) { return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, - SetterName, PropertyAttributes, - DITypeRef::get(Ty)); + SetterName, PropertyAttributes, Ty); } DITemplateTypeParameter * DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name, DIType *Ty) { assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); - return DITemplateTypeParameter::get(VMContext, Name, DITypeRef::get(Ty)); + return DITemplateTypeParameter::get(VMContext, Name, Ty); } static DITemplateValueParameter * @@ -352,8 +329,7 @@ createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, DIScope *Context, StringRef Name, DIType *Ty, Metadata *MD) { assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); - return DITemplateValueParameter::get(VMContext, Tag, Name, DITypeRef::get(Ty), - MD); + return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD); } DITemplateValueParameter * @@ -390,12 +366,9 @@ DICompositeType *DIBuilder::createClassType( auto *R = DICompositeType::get( VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, - DIScopeRef::get(getNonCompileUnitScope(Context)), - DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, OffsetInBits, Flags, - Elements, 0, DITypeRef::get(VTableHolder), + getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, + OffsetInBits, Flags, Elements, 0, VTableHolder, cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier); - if (!UniqueIdentifier.empty()) - retainType(R); trackIfUnresolved(R); return R; } @@ -407,11 +380,8 @@ DICompositeType *DIBuilder::createStructType( DIType *VTableHolder, StringRef UniqueIdentifier) { auto *R = DICompositeType::get( VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, - DIScopeRef::get(getNonCompileUnitScope(Context)), - DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, 0, Flags, Elements, - RunTimeLang, DITypeRef::get(VTableHolder), nullptr, UniqueIdentifier); - if (!UniqueIdentifier.empty()) - retainType(R); + getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0, + Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier); trackIfUnresolved(R); return R; } @@ -422,30 +392,23 @@ DICompositeType *DIBuilder::createUnionType( DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) { auto *R = DICompositeType::get( VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, - DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits, - AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr, - UniqueIdentifier); - if (!UniqueIdentifier.empty()) - retainType(R); + getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, + Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier); trackIfUnresolved(R); return R; } DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes, - unsigned Flags) { - return DISubroutineType::get(VMContext, Flags, ParameterTypes); + unsigned Flags, unsigned CC) { + return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes); } DICompositeType *DIBuilder::createExternalTypeRef(unsigned Tag, DIFile *File, StringRef UniqueIdentifier) { assert(!UniqueIdentifier.empty() && "external type ref without uid"); - auto *CTy = - DICompositeType::get(VMContext, Tag, "", nullptr, 0, nullptr, nullptr, 0, - 0, 0, DINode::FlagExternalTypeRef, nullptr, 0, - nullptr, nullptr, UniqueIdentifier); - // Types with unique IDs need to be in the type map. - retainType(CTy); - return CTy; + return DICompositeType::get(VMContext, Tag, "", nullptr, 0, nullptr, nullptr, + 0, 0, 0, DINode::FlagExternalTypeRef, nullptr, 0, + nullptr, nullptr, UniqueIdentifier); } DICompositeType *DIBuilder::createEnumerationType( @@ -454,12 +417,9 @@ DICompositeType *DIBuilder::createEnumerationType( DIType *UnderlyingType, StringRef UniqueIdentifier) { auto *CTy = DICompositeType::get( VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, - DIScopeRef::get(getNonCompileUnitScope(Scope)), - DITypeRef::get(UnderlyingType), SizeInBits, AlignInBits, 0, 0, Elements, - 0, nullptr, nullptr, UniqueIdentifier); + getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0, + 0, Elements, 0, nullptr, nullptr, UniqueIdentifier); AllEnumTypes.push_back(CTy); - if (!UniqueIdentifier.empty()) - retainType(CTy); trackIfUnresolved(CTy); return CTy; } @@ -468,8 +428,8 @@ DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, DIType *Ty, DINodeArray Subscripts) { auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", - nullptr, 0, nullptr, DITypeRef::get(Ty), Size, - AlignInBits, 0, 0, Subscripts, 0, nullptr); + nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, + 0, Subscripts, 0, nullptr); trackIfUnresolved(R); return R; } @@ -477,10 +437,9 @@ DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits, DICompositeType *DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits, DIType *Ty, DINodeArray Subscripts) { - auto *R = - DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, - nullptr, DITypeRef::get(Ty), Size, AlignInBits, 0, - DINode::FlagVector, Subscripts, 0, nullptr); + auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", + nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, + DINode::FlagVector, Subscripts, 0, nullptr); trackIfUnresolved(R); return R; } @@ -507,8 +466,11 @@ DIType *DIBuilder::createObjectPointerType(DIType *Ty) { return createTypeWithFlags(VMContext, Ty, Flags); } -void DIBuilder::retainType(DIType *T) { +void DIBuilder::retainType(DIScope *T) { assert(T && "Expected non-null type"); + assert((isa<DIType>(T) || (isa<DISubprogram>(T) && + cast<DISubprogram>(T)->isDefinition() == false)) && + "Expected type or subprogram declaration"); AllRetainTypes.emplace_back(T); } @@ -522,12 +484,9 @@ DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, // FIXME: Define in terms of createReplaceableForwardDecl() by calling // replaceWithUniqued(). auto *RetTy = DICompositeType::get( - VMContext, Tag, Name, F, Line, - DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits, - AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, nullptr, - nullptr, UniqueIdentifier); - if (!UniqueIdentifier.empty()) - retainType(RetTy); + VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, + SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, + nullptr, nullptr, UniqueIdentifier); trackIfUnresolved(RetTy); return RetTy; } @@ -536,14 +495,12 @@ DICompositeType *DIBuilder::createReplaceableCompositeType( unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags, StringRef UniqueIdentifier) { - auto *RetTy = DICompositeType::getTemporary( - VMContext, Tag, Name, F, Line, - DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, - SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, - nullptr, nullptr, UniqueIdentifier) - .release(); - if (!UniqueIdentifier.empty()) - retainType(RetTy); + auto *RetTy = + DICompositeType::getTemporary( + VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, + SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr, + nullptr, UniqueIdentifier) + .release(); trackIfUnresolved(RetTy); return RetTy; } @@ -556,7 +513,7 @@ DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { SmallVector<llvm::Metadata *, 16> Elts; for (unsigned i = 0, e = Elements.size(); i != e; ++i) { if (Elements[i] && isa<MDNode>(Elements[i])) - Elts.push_back(DITypeRef::get(cast<DIType>(Elements[i]))); + Elts.push_back(cast<DIType>(Elements[i])); else Elts.push_back(Elements[i]); } @@ -582,10 +539,10 @@ DIGlobalVariable *DIBuilder::createGlobalVariable( MDNode *Decl) { checkGlobalVariableScope(Context); - auto *N = DIGlobalVariable::get(VMContext, cast_or_null<DIScope>(Context), - Name, LinkageName, F, LineNumber, - DITypeRef::get(Ty), isLocalToUnit, true, Val, - cast_or_null<DIDerivedType>(Decl)); + auto *N = DIGlobalVariable::getDistinct( + VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, + LineNumber, Ty, isLocalToUnit, true, Val, + cast_or_null<DIDerivedType>(Decl)); AllGVs.push_back(N); return N; } @@ -598,14 +555,14 @@ DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( return DIGlobalVariable::getTemporary( VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, - LineNumber, DITypeRef::get(Ty), isLocalToUnit, false, Val, + LineNumber, Ty, isLocalToUnit, false, Val, cast_or_null<DIDerivedType>(Decl)) .release(); } static DILocalVariable *createLocalVariable( LLVMContext &VMContext, - DenseMap<MDNode *, std::vector<TrackingMDNodeRef>> &PreservedVariables, + DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) { // FIXME: Why getNonCompileUnitScope()? @@ -616,7 +573,7 @@ static DILocalVariable *createLocalVariable( auto *Node = DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, - File, LineNo, DITypeRef::get(Ty), ArgNo, Flags); + File, LineNo, Ty, ArgNo, Flags); 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 @@ -661,19 +618,6 @@ DIExpression *DIBuilder::createBitPieceExpression(unsigned OffsetInBytes, return DIExpression::get(VMContext, Addr); } -DISubprogram *DIBuilder::createFunction( - DIScopeRef Context, StringRef Name, StringRef LinkageName, DIFile *File, - unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, - bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized, - DITemplateParameterArray TParams, DISubprogram *Decl) { - // dragonegg does not generate identifier for types, so using an empty map - // to resolve the context should be fine. - DITypeIdentifierMap EmptyMap; - return createFunction(Context.resolve(EmptyMap), Name, LinkageName, File, - LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, - Flags, isOptimized, TParams, Decl); -} - template <class... Ts> static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { if (IsDistinct) @@ -686,12 +630,12 @@ DISubprogram *DIBuilder::createFunction( unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl) { - auto *Node = - getSubprogram(/* IsDistinct = */ isDefinition, VMContext, - DIScopeRef::get(getNonCompileUnitScope(Context)), Name, - LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition, - ScopeLine, nullptr, 0, 0, Flags, isOptimized, TParams, Decl, - MDTuple::getTemporary(VMContext, None).release()); + auto *Node = getSubprogram( + /* IsDistinct = */ isDefinition, VMContext, + getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty, + isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, 0, Flags, + isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl, + MDTuple::getTemporary(VMContext, None).release()); if (isDefinition) AllSubprograms.push_back(Node); @@ -705,10 +649,10 @@ DISubprogram *DIBuilder::createTempFunctionFwdDecl( bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized, DITemplateParameterArray TParams, DISubprogram *Decl) { return DISubprogram::getTemporary( - VMContext, DIScopeRef::get(getNonCompileUnitScope(Context)), Name, - LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition, - ScopeLine, nullptr, 0, 0, Flags, isOptimized, TParams, Decl, - nullptr) + VMContext, getNonCompileUnitScope(Context), Name, LinkageName, + File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr, + 0, 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr, + TParams, Decl, nullptr) .release(); } @@ -716,17 +660,18 @@ DISubprogram * DIBuilder::createMethod(DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit, bool isDefinition, unsigned VK, - unsigned VIndex, DIType *VTableHolder, unsigned Flags, - bool isOptimized, DITemplateParameterArray TParams) { + unsigned VIndex, int ThisAdjustment, + DIType *VTableHolder, unsigned Flags, bool isOptimized, + DITemplateParameterArray TParams) { assert(getNonCompileUnitScope(Context) && "Methods should have both a Context and a context that isn't " "the compile unit."); // FIXME: Do we want to use different scope/lines? auto *SP = getSubprogram( - /* IsDistinct = */ isDefinition, VMContext, - DIScopeRef::get(cast<DIScope>(Context)), Name, LinkageName, F, LineNo, Ty, - isLocalToUnit, isDefinition, LineNo, DITypeRef::get(VTableHolder), VK, - VIndex, Flags, isOptimized, TParams, nullptr, nullptr); + /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name, + LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo, + VTableHolder, VK, VIndex, ThisAdjustment, Flags, isOptimized, + isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr); if (isDefinition) AllSubprograms.push_back(SP); @@ -866,7 +811,7 @@ void DIBuilder::replaceVTableHolder(DICompositeType *&T, DICompositeType *VTableHolder) { { TypedTrackingMDRef<DICompositeType> N(T); - N->replaceVTableHolder(DITypeRef::get(VTableHolder)); + N->replaceVTableHolder(VTableHolder); T = N.get(); } |