summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/AsmWriter.cpp24
-rw-r--r--llvm/lib/IR/DIBuilder.cpp695
-rw-r--r--llvm/lib/IR/DebugInfo.cpp788
3 files changed, 243 insertions, 1264 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 685a48d538d..0c3e601969e 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2984,29 +2984,6 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
printInfoComment(I);
}
-static void WriteMDNodeComment(const MDNode *Node,
- formatted_raw_ostream &Out) {
- if (Node->getNumOperands() < 1)
- return;
-
- Metadata *Op = Node->getOperand(0);
- if (!Op || !isa<MDString>(Op))
- return;
-
- DIDescriptor Desc(Node);
- if (!Desc.Verify())
- return;
-
- unsigned Tag = Desc.getTag();
- Out.PadToColumn(50);
- if (dwarf::TagString(Tag)) {
- Out << "; ";
- Desc.print(Out);
- } else if (Tag == dwarf::DW_TAG_user_base) {
- Out << "; [ DW_TAG_user_base ]";
- }
-}
-
void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) {
Out << '!' << Slot << " = ";
printMDNodeBody(Node);
@@ -3027,7 +3004,6 @@ void AssemblyWriter::writeAllMDNodes() {
void AssemblyWriter::printMDNodeBody(const MDNode *Node) {
WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine, TheModule);
- WriteMDNodeComment(Node, Out);
}
void AssemblyWriter::writeAllAttributeGroups() {
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 2cb27cae144..981e3fd3062 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -127,14 +127,6 @@ static MDNode *getNonCompileUnitScope(MDNode *N) {
return N;
}
-static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
- StringRef Directory) {
- assert(!Filename.empty() && "Unable to create file without name");
- Metadata *Pair[] = {MDString::get(VMContext, Filename),
- MDString::get(VMContext, Directory)};
- return MDNode::get(VMContext, Pair);
-}
-
DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
StringRef Directory,
StringRef Producer, bool isOptimized,
@@ -157,22 +149,12 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
TempGVs = MDTuple::getTemporary(VMContext, None).release();
TempImportedModules = MDTuple::getTemporary(VMContext, None).release();
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_compile_unit)
- .concat(Lang)
- .concat(Producer)
- .concat(isOptimized)
- .concat(Flags)
- .concat(RunTimeVer)
- .concat(SplitName)
- .concat(Kind)
- .get(VMContext),
- createFilePathPair(VMContext, Filename, Directory),
- TempEnumTypes, TempRetainTypes, TempSubprograms, TempGVs,
- TempImportedModules};
-
// TODO: Switch to getDistinct(). We never want to merge compile units based
// on contents.
- MDNode *CUNode = MDNode::get(VMContext, Elts);
+ MDNode *CUNode = MDCompileUnit::get(
+ VMContext, Lang, MDFile::get(VMContext, Filename, Directory), Producer,
+ isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes,
+ TempRetainTypes, TempSubprograms, TempGVs, TempImportedModules);
// 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
@@ -192,11 +174,7 @@ static DIImportedEntity
createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
Metadata *NS, unsigned Line, StringRef Name,
SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
- const MDNode *R;
- Metadata *Elts[] = {HeaderBuilder::get(Tag).concat(Line).concat(Name).get(C),
- Context, NS};
- R = MDNode::get(C, Elts);
- DIImportedEntity M(R);
+ DIImportedEntity M = MDImportedEntity::get(C, Tag, Context, NS, Line, Name);
assert(M.Verify() && "Imported module should be valid");
AllImportedModules.emplace_back(M.get());
return M;
@@ -236,39 +214,17 @@ DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
}
DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_file_type).get(VMContext),
- createFilePathPair(VMContext, Filename, Directory)};
- return DIFile(MDNode::get(VMContext, Elts));
+ return MDFile::get(VMContext, Filename, Directory);
}
DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
assert(!Name.empty() && "Unable to create enumerator without name");
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_enumerator)
- .concat(Name)
- .concat(Val)
- .get(VMContext)};
- return DIEnumerator(MDNode::get(VMContext, Elts));
+ return MDEnumerator::get(VMContext, Val, Name);
}
DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
assert(!Name.empty() && "Unable to create type without name");
- // Unspecified types are encoded in DIBasicType format. Line number, filename,
- // size, alignment, offset and flags are always empty here.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_unspecified_type)
- .concat(Name)
- .concat(0)
- .concat(0)
- .concat(0)
- .concat(0)
- .concat(0)
- .concat(0)
- .get(VMContext),
- nullptr, // Filename
- nullptr // Unused
- };
- return DIBasicType(MDNode::get(VMContext, Elts));
+ return MDBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
}
DIBasicType DIBuilder::createNullPtrType() {
@@ -279,142 +235,61 @@ DIBasicType
DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
uint64_t AlignInBits, unsigned Encoding) {
assert(!Name.empty() && "Unable to create type without name");
- // Basic types are encoded in DIBasicType format. Line number, filename,
- // offset and flags are always empty here.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_base_type)
- .concat(Name)
- .concat(0) // Line
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(0) // Flags
- .concat(Encoding)
- .get(VMContext),
- nullptr, // Filename
- nullptr // Unused
- };
- return DIBasicType(MDNode::get(VMContext, Elts));
+ return MDBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
+ AlignInBits, Encoding);
}
DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
- // Qualified types are encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(Tag)
- .concat(StringRef()) // Name
- .concat(0) // Line
- .concat(0) // Size
- .concat(0) // Align
- .concat(0) // Offset
- .concat(0) // Flags
- .get(VMContext),
- nullptr, // Filename
- nullptr, // Unused
- FromTy.getRef()};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
+ FromTy.getRef(), 0, 0, 0, 0);
}
DIDerivedType
DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
uint64_t AlignInBits, StringRef Name) {
- // Pointer types are encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_pointer_type)
- .concat(Name)
- .concat(0) // Line
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(0) // Flags
- .get(VMContext),
- nullptr, // Filename
- nullptr, // Unused
- PointeeTy.getRef()};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ // FIXME: Why is there a name here?
+ return MDDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
+ nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits,
+ AlignInBits, 0, 0);
}
DIDerivedType
DIBuilder::createMemberPointerType(DIType PointeeTy, DIType Base,
uint64_t SizeInBits, uint64_t AlignInBits) {
- // Pointer types are encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_ptr_to_member_type)
- .concat(StringRef())
- .concat(0) // Line
- .concat(SizeInBits) // Size
- .concat(AlignInBits) // Align
- .concat(0) // Offset
- .concat(0) // Flags
- .get(VMContext),
- nullptr, // Filename
- nullptr, // Unused
- PointeeTy.getRef(), Base.getRef()};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
+ nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits,
+ AlignInBits, 0, 0, Base.getRef());
}
DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
assert(RTy.isType() && "Unable to create reference type");
- // References are encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(Tag)
- .concat(StringRef()) // Name
- .concat(0) // Line
- .concat(0) // Size
- .concat(0) // Align
- .concat(0) // Offset
- .concat(0) // Flags
- .get(VMContext),
- nullptr, // Filename
- nullptr, // TheCU,
- RTy.getRef()};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
+ RTy.getRef(), 0, 0, 0, 0);
}
DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
unsigned LineNo, DIDescriptor Context) {
- // typedefs are encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_typedef)
- .concat(Name)
- .concat(LineNo)
- .concat(0) // Size
- .concat(0) // Align
- .concat(0) // Offset
- .concat(0) // Flags
- .get(VMContext),
- File.getFileNode(),
- DIScope(getNonCompileUnitScope(Context)).getRef(),
- Ty.getRef()};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name,
+ File.getFileNode(), LineNo,
+ DIScope(getNonCompileUnitScope(Context)).getRef(),
+ Ty.getRef(), 0, 0, 0, 0);
}
DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
// typedefs are encoded in DIDerivedType format.
assert(Ty.isType() && "Invalid type!");
assert(FriendTy.isType() && "Invalid friend type!");
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_friend)
- .concat(StringRef()) // Name
- .concat(0) // Line
- .concat(0) // Size
- .concat(0) // Align
- .concat(0) // Offset
- .concat(0) // Flags
- .get(VMContext),
- nullptr, Ty.getRef(), FriendTy.getRef()};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
+ Ty.getRef(), FriendTy.getRef(), 0, 0, 0, 0);
}
DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
uint64_t BaseOffset,
unsigned Flags) {
assert(Ty.isType() && "Unable to create inheritance");
- // TAG_inheritance is encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_inheritance)
- .concat(StringRef()) // Name
- .concat(0) // Line
- .concat(0) // Size
- .concat(0) // Align
- .concat(BaseOffset)
- .concat(Flags)
- .get(VMContext),
- nullptr, Ty.getRef(), BaseTy.getRef()};
- auto R = DIDerivedType(MDNode::get(VMContext, Elts));
- return R;
+ return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
+ 0, Ty.getRef(), BaseTy.getRef(), 0, 0, BaseOffset,
+ Flags);
}
DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
@@ -423,19 +298,10 @@ DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
DIType Ty) {
- // TAG_member is encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
- .concat(Name)
- .concat(LineNumber)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(OffsetInBits)
- .concat(Flags)
- .get(VMContext),
- File.getFileNode(),
- DIScope(getNonCompileUnitScope(Scope)).getRef(),
- Ty.getRef()};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(
+ VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
+ DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), SizeInBits,
+ AlignInBits, OffsetInBits, Flags);
}
static Metadata *getConstantOrNull(Constant *C) {
@@ -451,18 +317,10 @@ DIDerivedType DIBuilder::createStaticMemberType(DIDescriptor Scope,
llvm::Constant *Val) {
// TAG_member is encoded in DIDerivedType format.
Flags |= DIDescriptor::FlagStaticMember;
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
- .concat(Name)
- .concat(LineNumber)
- .concat(0) // Size
- .concat(0) // Align
- .concat(0) // Offset
- .concat(Flags)
- .get(VMContext),
- File.getFileNode(),
- DIScope(getNonCompileUnitScope(Scope)).getRef(),
- Ty.getRef(), getConstantOrNull(Val)};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(
+ VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
+ DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), 0, 0, 0,
+ Flags, getConstantOrNull(Val));
}
DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
@@ -471,33 +329,18 @@ DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
DIType Ty, MDNode *PropertyNode) {
- // TAG_member is encoded in DIDerivedType format.
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
- .concat(Name)
- .concat(LineNumber)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(OffsetInBits)
- .concat(Flags)
- .get(VMContext),
- File.getFileNode(), getNonCompileUnitScope(File), Ty,
- PropertyNode};
- return DIDerivedType(MDNode::get(VMContext, Elts));
+ return MDDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
+ LineNumber, getNonCompileUnitScope(File),
+ Ty.getRef(), SizeInBits, AlignInBits, OffsetInBits,
+ Flags, PropertyNode);
}
DIObjCProperty
DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
StringRef GetterName, StringRef SetterName,
unsigned PropertyAttributes, DIType Ty) {
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_APPLE_property)
- .concat(Name)
- .concat(LineNumber)
- .concat(GetterName)
- .concat(SetterName)
- .concat(PropertyAttributes)
- .get(VMContext),
- File, Ty};
- return DIObjCProperty(MDNode::get(VMContext, Elts));
+ return MDObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
+ SetterName, PropertyAttributes, Ty);
}
DITemplateTypeParameter
@@ -505,13 +348,7 @@ DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
DIType Ty) {
assert(!DIScope(getNonCompileUnitScope(Context)).getRef() &&
"Expected compile unit");
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_template_type_parameter)
- .concat(Name)
- .concat(0)
- .concat(0)
- .get(VMContext),
- nullptr, Ty.getRef(), nullptr};
- return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
+ return MDTemplateTypeParameter::get(VMContext, Name, Ty.getRef());
}
static DITemplateValueParameter
@@ -520,10 +357,7 @@ createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
DIType Ty, Metadata *MD) {
assert(!DIScope(getNonCompileUnitScope(Context)).getRef() &&
"Expected compile unit");
- Metadata *Elts[] = {
- HeaderBuilder::get(Tag).concat(Name).concat(0).concat(0).get(VMContext),
- nullptr, Ty.getRef(), MD, nullptr};
- return DITemplateValueParameter(MDNode::get(VMContext, Elts));
+ return MDTemplateValueParameter::get(VMContext, Tag, Name, Ty.getRef(), MD);
}
DITemplateValueParameter
@@ -563,23 +397,11 @@ DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
assert((!Context || Context.isScope() || Context.isType()) &&
"createClassType should be called with a valid Context");
// TAG_class_type is encoded in DICompositeType format.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_class_type)
- .concat(Name)
- .concat(LineNumber)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(OffsetInBits)
- .concat(Flags)
- .concat(0)
- .get(VMContext),
- File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(),
- DerivedFrom.getRef(), Elements, VTableHolder.getRef(), TemplateParams,
- UniqueIdentifier.empty() ? nullptr
- : MDString::get(VMContext, UniqueIdentifier)};
- DICompositeType R(MDNode::get(VMContext, Elts));
- assert(R.isCompositeType() &&
- "createClassType should return a DICompositeType");
+ DICompositeType R = MDCompositeType::get(
+ VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
+ DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(),
+ SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, 0,
+ VTableHolder.getRef(), TemplateParams, UniqueIdentifier);
if (!UniqueIdentifier.empty())
retainType(R);
trackIfUnresolved(R);
@@ -596,24 +418,11 @@ DICompositeType DIBuilder::createStructType(DIDescriptor Context,
unsigned RunTimeLang,
DIType VTableHolder,
StringRef UniqueIdentifier) {
- // TAG_structure_type is encoded in DICompositeType format.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_structure_type)
- .concat(Name)
- .concat(LineNumber)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(0)
- .concat(Flags)
- .concat(RunTimeLang)
- .get(VMContext),
- File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(),
- DerivedFrom.getRef(), Elements, VTableHolder.getRef(), nullptr,
- UniqueIdentifier.empty() ? nullptr
- : MDString::get(VMContext, UniqueIdentifier)};
- DICompositeType R(MDNode::get(VMContext, Elts));
- assert(R.isCompositeType() &&
- "createStructType should return a DICompositeType");
+ DICompositeType R = MDCompositeType::get(
+ VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
+ DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(),
+ SizeInBits, AlignInBits, 0, Flags, Elements, RunTimeLang,
+ VTableHolder.getRef(), nullptr, UniqueIdentifier);
if (!UniqueIdentifier.empty())
retainType(R);
trackIfUnresolved(R);
@@ -627,22 +436,11 @@ DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
DIArray Elements,
unsigned RunTimeLang,
StringRef UniqueIdentifier) {
- // TAG_union_type is encoded in DICompositeType format.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_union_type)
- .concat(Name)
- .concat(LineNumber)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(Flags)
- .concat(RunTimeLang)
- .get(VMContext),
- File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(),
- nullptr, Elements, nullptr, nullptr,
- UniqueIdentifier.empty() ? nullptr
- : MDString::get(VMContext, UniqueIdentifier)};
- DICompositeType R(MDNode::get(VMContext, Elts));
+ DICompositeType R = MDCompositeType::get(
+ VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
+ DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
+ AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr,
+ UniqueIdentifier);
if (!UniqueIdentifier.empty())
retainType(R);
trackIfUnresolved(R);
@@ -652,43 +450,18 @@ DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
DISubroutineType DIBuilder::createSubroutineType(DIFile File,
DITypeArray ParameterTypes,
unsigned Flags) {
- // TAG_subroutine_type is encoded in DICompositeType format.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_subroutine_type)
- .concat(StringRef())
- .concat(0) // Line
- .concat(0) // Size
- .concat(0) // Align
- .concat(0) // Offset
- .concat(Flags) // Flags
- .concat(0)
- .get(VMContext),
- nullptr, nullptr, nullptr, ParameterTypes, nullptr, nullptr,
- nullptr // Type Identifer
- };
- return DISubroutineType(MDNode::get(VMContext, Elts));
+ return MDSubroutineType::get(VMContext, Flags, ParameterTypes);
}
DICompositeType DIBuilder::createEnumerationType(
DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
DIType UnderlyingType, StringRef UniqueIdentifier) {
- // TAG_enumeration_type is encoded in DICompositeType format.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_enumeration_type)
- .concat(Name)
- .concat(LineNumber)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(0) // Flags
- .concat(0)
- .get(VMContext),
- File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(),
- UnderlyingType.getRef(), Elements, nullptr, nullptr,
- UniqueIdentifier.empty() ? nullptr
- : MDString::get(VMContext, UniqueIdentifier)};
- DICompositeType CTy(MDNode::get(VMContext, Elts));
+ DICompositeType CTy = MDCompositeType::get(
+ VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
+ DIScope(getNonCompileUnitScope(Scope)).getRef(), UnderlyingType.getRef(),
+ SizeInBits, AlignInBits, 0, 0, Elements, 0, nullptr, nullptr,
+ UniqueIdentifier);
AllEnumTypes.push_back(CTy);
if (!UniqueIdentifier.empty())
retainType(CTy);
@@ -698,85 +471,38 @@ DICompositeType DIBuilder::createEnumerationType(
DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
DIType Ty, DIArray Subscripts) {
- // TAG_array_type is encoded in DICompositeType format.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_array_type)
- .concat(StringRef())
- .concat(0) // Line
- .concat(Size)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(0) // Flags
- .concat(0)
- .get(VMContext),
- nullptr, // Filename/Directory,
- nullptr, // Unused
- Ty.getRef(), Subscripts, nullptr, nullptr,
- nullptr // Type Identifer
- };
- DICompositeType R(MDNode::get(VMContext, Elts));
+ auto *R = MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
+ nullptr, 0, nullptr, Ty.getRef(), Size,
+ AlignInBits, 0, 0, Subscripts, 0, nullptr);
trackIfUnresolved(R);
return R;
}
DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
DIType Ty, DIArray Subscripts) {
- // A vector is an array type with the FlagVector flag applied.
- Metadata *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_array_type)
- .concat("")
- .concat(0) // Line
- .concat(Size)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(DIType::FlagVector)
- .concat(0)
- .get(VMContext),
- nullptr, // Filename/Directory,
- nullptr, // Unused
- Ty.getRef(), Subscripts, nullptr, nullptr,
- nullptr // Type Identifer
- };
- DICompositeType R(MDNode::get(VMContext, Elts));
+ auto *R = MDCompositeType::get(
+ VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty.getRef(),
+ Size, AlignInBits, 0, DIType::FlagVector, Subscripts, 0, nullptr);
trackIfUnresolved(R);
return R;
}
-static HeaderBuilder setTypeFlagsInHeader(StringRef Header,
- unsigned FlagsToSet) {
- DIHeaderFieldIterator I(Header);
- std::advance(I, 6);
-
- unsigned Flags;
- if (I->getAsInteger(0, Flags))
- Flags = 0;
- Flags |= FlagsToSet;
-
- return HeaderBuilder()
- .concat(I.getPrefix())
- .concat(Flags)
- .concat(I.getSuffix());
-}
-
static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty,
unsigned FlagsToSet) {
- SmallVector<Metadata *, 9> Elts;
- MDNode *N = Ty;
- assert(N && "Unexpected input DIType!");
- // Update header field.
- Elts.push_back(setTypeFlagsInHeader(Ty.getHeader(), FlagsToSet).get(Context));
- Elts.append(N->op_begin() + 1, N->op_end());
-
- return DIType(MDNode::get(Context, Elts));
+ TempMDType NewTy = cast<MDType>(static_cast<MDNode *>(Ty))->clone();
+ NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
+ return MDNode::replaceWithUniqued(std::move(NewTy));
}
DIType DIBuilder::createArtificialType(DIType Ty) {
+ // FIXME: Restrict this to the nodes where it's valid.
if (Ty.isArtificial())
return Ty;
return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial);
}
DIType DIBuilder::createObjectPointerType(DIType Ty) {
+ // FIXME: Restrict this to the nodes where it's valid.
if (Ty.isObjectPointer())
return Ty;
unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial;
@@ -794,26 +520,13 @@ DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
DIFile F, unsigned Line, unsigned RuntimeLang,
uint64_t SizeInBits, uint64_t AlignInBits,
StringRef UniqueIdentifier) {
- // Create a temporary MDNode.
- Metadata *Elts[] = {
- HeaderBuilder::get(Tag)
- .concat(Name)
- .concat(Line)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(DIDescriptor::FlagFwdDecl)
- .concat(RuntimeLang)
- .get(VMContext),
- F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr,
- DIArray(), nullptr,
- nullptr, // TemplateParams
- UniqueIdentifier.empty() ? nullptr
- : MDString::get(VMContext, UniqueIdentifier)};
- MDNode *Node = MDNode::get(VMContext, Elts);
- DICompositeType RetTy(Node);
- assert(RetTy.isCompositeType() &&
- "createForwardDecl result should be a DIType");
+ // FIXME: Define in terms of createReplaceableForwardDecl() by calling
+ // replaceWithUniqued().
+ DICompositeType RetTy = MDCompositeType::get(
+ VMContext, Tag, Name, F.getFileNode(), Line,
+ DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
+ AlignInBits, 0, DIDescriptor::FlagFwdDecl, nullptr, RuntimeLang, nullptr,
+ nullptr, UniqueIdentifier);
if (!UniqueIdentifier.empty())
retainType(RetTy);
trackIfUnresolved(RetTy);
@@ -824,25 +537,12 @@ DICompositeType DIBuilder::createReplaceableCompositeType(
unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line,
unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
unsigned Flags, StringRef UniqueIdentifier) {
- // Create a temporary MDNode.
- Metadata *Elts[] = {
- HeaderBuilder::get(Tag)
- .concat(Name)
- .concat(Line)
- .concat(SizeInBits)
- .concat(AlignInBits)
- .concat(0) // Offset
- .concat(Flags)
- .concat(RuntimeLang)
- .get(VMContext),
- F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr,
- DIArray(), nullptr,
- nullptr, // TemplateParams
- UniqueIdentifier.empty() ? nullptr
- : MDString::get(VMContext, UniqueIdentifier)};
- DICompositeType RetTy(MDNode::getTemporary(VMContext, Elts).release());
- assert(RetTy.isCompositeType() &&
- "createReplaceableForwardDecl result should be a DIType");
+ DICompositeType RetTy =
+ MDCompositeType::getTemporary(
+ VMContext, Tag, Name, F.getFileNode(), Line,
+ DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
+ AlignInBits, 0, Flags, nullptr, RuntimeLang,
+ nullptr, nullptr, UniqueIdentifier).release();
if (!UniqueIdentifier.empty())
retainType(RetTy);
trackIfUnresolved(RetTy);
@@ -865,62 +565,39 @@ DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
}
DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subrange_type)
- .concat(Lo)
- .concat(Count)
- .get(VMContext)};
-
- return DISubrange(MDNode::get(VMContext, Elts));
+ return MDSubrange::get(VMContext, Count, Lo);
}
-static DIGlobalVariable createGlobalVariableHelper(
- LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
- StringRef LinkageName, DIFile F, unsigned LineNumber, DITypeRef Ty,
- bool isLocalToUnit, Constant *Val, MDNode *Decl, bool isDefinition,
- std::function<MDNode *(ArrayRef<Metadata *>)> CreateFunc) {
-
+static void checkGlobalVariableScope(DIDescriptor Context) {
MDNode *TheCtx = getNonCompileUnitScope(Context);
if (DIScope(TheCtx).isCompositeType()) {
assert(!DICompositeType(TheCtx).getIdentifier() &&
"Context of a global variable should not be a type with identifier");
}
-
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_variable)
- .concat(Name)
- .concat(Name)
- .concat(LinkageName)
- .concat(LineNumber)
- .concat(isLocalToUnit)
- .concat(isDefinition)
- .get(VMContext),
- TheCtx, F, Ty, getConstantOrNull(Val),
- DIDescriptor(Decl)};
-
- return DIGlobalVariable(CreateFunc(Elts));
}
DIGlobalVariable DIBuilder::createGlobalVariable(
DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val,
MDNode *Decl) {
- return createGlobalVariableHelper(
- VMContext, Context, Name, LinkageName, F, LineNumber, Ty, isLocalToUnit,
- Val, Decl, true, [&](ArrayRef<Metadata *> Elts) -> MDNode *{
- MDNode *Node = MDNode::get(VMContext, Elts);
- AllGVs.push_back(Node);
- return Node;
- });
+ checkGlobalVariableScope(Context);
+
+ auto *N = MDGlobalVariable::get(VMContext, Context, Name, LinkageName, F,
+ LineNumber, Ty, isLocalToUnit, true,
+ getConstantOrNull(Val), Decl);
+ AllGVs.push_back(N);
+ return N;
}
DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl(
DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val,
MDNode *Decl) {
- return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F,
- LineNumber, Ty, isLocalToUnit, Val, Decl,
- false, [&](ArrayRef<Metadata *> Elts) {
- return MDNode::getTemporary(VMContext, Elts).release();
- });
+ checkGlobalVariableScope(Context);
+
+ return MDGlobalVariable::getTemporary(VMContext, Context, Name, LinkageName,
+ F, LineNumber, Ty, isLocalToUnit, false,
+ getConstantOrNull(Val), Decl).release();
}
DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
@@ -928,16 +605,17 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
unsigned LineNo, DITypeRef Ty,
bool AlwaysPreserve, unsigned Flags,
unsigned ArgNo) {
+ // 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)?
DIDescriptor Context(getNonCompileUnitScope(Scope));
assert((!Context || Context.isScope()) &&
"createLocalVariable should be called with a valid Context");
- Metadata *Elts[] = {HeaderBuilder::get(Tag)
- .concat(Name)
- .concat(LineNo | (ArgNo << 24))
- .concat(Flags)
- .get(VMContext),
- getNonCompileUnitScope(Scope), File, Ty};
- MDNode *Node = MDNode::get(VMContext, Elts);
+
+ auto *Node =
+ MDLocalVariable::get(VMContext, Tag, getNonCompileUnitScope(Scope), Name,
+ File, LineNo, Ty, ArgNo, Flags);
if (AlwaysPreserve) {
// The optimizer may remove local variable. If there is an interest
// to preserve variable info in such situation then stash it in a
@@ -946,18 +624,11 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
assert(Fn && "Missing subprogram for local variable");
PreservedVariables[Fn].emplace_back(Node);
}
- DIVariable RetVar(Node);
- assert(RetVar.isVariable() &&
- "createLocalVariable should return a valid DIVariable");
- return RetVar;
+ return Node;
}
DIExpression DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
- auto Header = HeaderBuilder::get(DW_TAG_expression);
- for (uint64_t I : Addr)
- Header.concat(I);
- Metadata *Elts[] = {Header.get(VMContext)};
- return DIExpression(MDNode::get(VMContext, Elts));
+ return MDExpression::get(VMContext, Addr);
}
DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
@@ -966,10 +637,10 @@ DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
return createExpression(Addr);
}
-DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBits,
- unsigned SizeInBits) {
- int64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBits, SizeInBits};
- return createExpression(Addr);
+DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
+ unsigned SizeInBytes) {
+ uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes};
+ return MDExpression::get(VMContext, Addr);
}
DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
@@ -987,38 +658,6 @@ DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
Flags, isOptimized, Fn, TParams, Decl);
}
-static DISubprogram createFunctionHelper(
- LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
- StringRef LinkageName, DIFile File, unsigned LineNo, DICompositeType Ty,
- bool isLocalToUnit, bool isDefinition, unsigned ScopeLine, unsigned Flags,
- bool isOptimized, Function *Fn, MDNode *TParams, MDNode *Decl, MDNode *Vars,
- std::function<MDNode *(ArrayRef<Metadata *>)> CreateFunc) {
- assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
- "function types should be subroutines");
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subprogram)
- .concat(Name)
- .concat(Name)
- .concat(LinkageName)
- .concat(LineNo)
- .concat(isLocalToUnit)
- .concat(isDefinition)
- .concat(0)
- .concat(0)
- .concat(Flags)
- .concat(isOptimized)
- .concat(ScopeLine)
- .get(VMContext),
- File.getFileNode(),
- DIScope(getNonCompileUnitScope(Context)).getRef(), Ty,
- nullptr, getConstantOrNull(Fn), TParams, Decl, Vars};
-
- DISubprogram S(CreateFunc(Elts));
- assert(S.isSubprogram() &&
- "createFunction should return a valid DISubprogram");
- return S;
-}
-
-
DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
StringRef LinkageName, DIFile File,
unsigned LineNo, DICompositeType Ty,
@@ -1026,19 +665,18 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
unsigned ScopeLine, unsigned Flags,
bool isOptimized, Function *Fn,
MDNode *TParams, MDNode *Decl) {
- return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
- LineNo, Ty, isLocalToUnit, isDefinition,
- ScopeLine, Flags, isOptimized, Fn, TParams, Decl,
- MDNode::getTemporary(VMContext, None).release(),
- [&](ArrayRef<Metadata *> Elts) -> MDNode *{
- MDNode *Node = MDNode::get(VMContext, Elts);
- // Create a named metadata so that we
- // do not lose this mdnode.
- if (isDefinition)
- AllSubprograms.push_back(Node);
- trackIfUnresolved(Node);
- return Node;
- });
+ assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
+ "function types should be subroutines");
+ auto *Node = MDSubprogram::get(
+ VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
+ LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit, isDefinition,
+ ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn),
+ TParams, Decl, MDNode::getTemporary(VMContext, None).release());
+
+ if (isDefinition)
+ AllSubprograms.push_back(Node);
+ trackIfUnresolved(Node);
+ return Node;
}
DISubprogram
@@ -1049,12 +687,11 @@ DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
unsigned ScopeLine, unsigned Flags,
bool isOptimized, Function *Fn,
MDNode *TParams, MDNode *Decl) {
- return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
- LineNo, Ty, isLocalToUnit, isDefinition,
- ScopeLine, Flags, isOptimized, Fn, TParams, Decl,
- nullptr, [&](ArrayRef<Metadata *> Elts) {
- return MDNode::getTemporary(VMContext, Elts).release();
- });
+ return MDSubprogram::getTemporary(
+ VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
+ LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit,
+ isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
+ getConstantOrNull(Fn), TParams, Decl, nullptr).release();
}
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
@@ -1070,24 +707,13 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
assert(getNonCompileUnitScope(Context) &&
"Methods should have both a Context and a context that isn't "
"the compile unit.");
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subprogram)
- .concat(Name)
- .concat(Name)
- .concat(LinkageName)
- .concat(LineNo)
- .concat(isLocalToUnit)
- .concat(isDefinition)
- .concat(VK)
- .concat(VIndex)
- .concat(Flags)
- .concat(isOptimized)
- .concat(LineNo)
- // FIXME: Do we want to use different scope/lines?
- .get(VMContext),
- F.getFileNode(), DIScope(Context).getRef(), Ty,
- VTableHolder.getRef(), getConstantOrNull(Fn), TParam,
- nullptr, nullptr};
- MDNode *Node = MDNode::get(VMContext, Elts);
+ // FIXME: Do we want to use different scope/lines?
+ auto *Node = MDSubprogram::get(
+ VMContext, DIScope(Context).getRef(), Name, LinkageName, F.getFileNode(),
+ LineNo, Ty, isLocalToUnit, isDefinition, LineNo, VTableHolder.getRef(),
+ VK, VIndex, Flags, isOptimized, getConstantOrNull(Fn), TParam, nullptr,
+ nullptr);
+
if (isDefinition)
AllSubprograms.push_back(Node);
DISubprogram S(Node);
@@ -1098,12 +724,8 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
DIFile File, unsigned LineNo) {
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_namespace)
- .concat(Name)
- .concat(LineNo)
- .get(VMContext),
- File.getFileNode(), getNonCompileUnitScope(Scope)};
- DINameSpace R(MDNode::get(VMContext, Elts));
+ DINameSpace R = MDNamespace::get(VMContext, getNonCompileUnitScope(Scope),
+ File.getFileNode(), Name, LineNo);
assert(R.Verify() &&
"createNameSpace should return a verifiable DINameSpace");
return R;
@@ -1112,11 +734,8 @@ DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
DIFile File,
unsigned Discriminator) {
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
- .concat(Discriminator)
- .get(VMContext),
- File.getFileNode(), Scope};
- DILexicalBlockFile R(MDNode::get(VMContext, Elts));
+ DILexicalBlockFile R = MDLexicalBlockFile::get(
+ VMContext, Scope, File.getFileNode(), Discriminator);
assert(
R.Verify() &&
"createLexicalBlockFile should return a verifiable DILexicalBlockFile");
@@ -1125,22 +744,10 @@ DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
unsigned Line, unsigned Col) {
- // FIXME: This isn't thread safe nor the right way to defeat MDNode uniquing.
- // I believe the right way is to have a self-referential element in the node.
- // Also: why do we bother with line/column - they're not used and the
- // documentation (SourceLevelDebugging.rst) claims the line/col are necessary
- // for uniquing, yet then we have this other solution (because line/col were
- // inadequate) anyway. Remove all 3 and replace them with a self-reference.
-
- // Defeat MDNode uniquing for lexical blocks by using unique id.
- static unsigned int unique_id = 0;
- Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
- .concat(Line)
- .concat(Col)
- .concat(unique_id++)
- .get(VMContext),
- File.getFileNode(), getNonCompileUnitScope(Scope)};
- DILexicalBlock R(MDNode::get(VMContext, Elts));
+ // Make these distinct, to avoid merging two lexical blocks on the same
+ // file/line/column.
+ DILexicalBlock R = MDLexicalBlock::getDistinct(
+ VMContext, getNonCompileUnitScope(Scope), File.getFileNode(), Line, Col);
assert(R.Verify() &&
"createLexicalBlock should return a verifiable DILexicalBlock");
return R;
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 8e996148955..d44d6c9e15b 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -155,21 +155,6 @@ Function *DIDescriptor::getFunctionField(unsigned Elt) const {
return dyn_cast_or_null<Function>(getConstantField(Elt));
}
-void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) {
- if (!DbgNode)
- return;
-
- if (Elt < DbgNode->getNumOperands()) {
- MDNode *Node = const_cast<MDNode *>(DbgNode);
- Node->replaceOperandWith(Elt, F ? ConstantAsMetadata::get(F) : nullptr);
- }
-}
-
-static unsigned DIVariableInlinedAtIndex = 4;
-MDNode *DIVariable::getInlinedAt() const {
- return getNodeField(DbgNode, DIVariableInlinedAtIndex);
-}
-
/// \brief Return the size reported by the variable's type.
unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
DIType Ty = getType().resolve(Map);
@@ -183,13 +168,6 @@ unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
return Ty.getSizeInBits();
}
-uint64_t DIExpression::getElement(unsigned Idx) const {
- unsigned I = Idx + 1;
- assert(I < getNumHeaderFields() &&
- "non-existing complex address element requested");
- return getHeaderFieldAs<int64_t>(I);
-}
-
bool DIExpression::isBitPiece() const {
unsigned N = getNumElements();
return N >=3 && getElement(N-3) == dwarf::DW_OP_bit_piece;
@@ -205,174 +183,12 @@ uint64_t DIExpression::getBitPieceSize() const {
return getElement(getNumElements()-1);
}
-DIExpression::iterator DIExpression::begin() const {
- return DIExpression::iterator(*this);
-}
-
-DIExpression::iterator DIExpression::end() const {
- return DIExpression::iterator();
-}
-
DIExpression::Operand DIExpression::Operand::getNext() const {
iterator it(I);
return *(++it);
}
//===----------------------------------------------------------------------===//
-// Predicates
-//===----------------------------------------------------------------------===//
-
-bool DIDescriptor::isSubroutineType() const {
- return DbgNode && getTag() == dwarf::DW_TAG_subroutine_type;
-}
-
-bool DIDescriptor::isBasicType() const {
- if (!DbgNode)
- return false;
- switch (getTag()) {
- case dwarf::DW_TAG_base_type:
- case dwarf::DW_TAG_unspecified_type:
- return true;
- default:
- return false;
- }
-}
-
-bool DIDescriptor::isDerivedType() const {
- if (!DbgNode)
- return false;
- switch (getTag()) {
- case dwarf::DW_TAG_typedef:
- case dwarf::DW_TAG_pointer_type:
- case dwarf::DW_TAG_ptr_to_member_type:
- case dwarf::DW_TAG_reference_type:
- case dwarf::DW_TAG_rvalue_reference_type:
- case dwarf::DW_TAG_const_type:
- case dwarf::DW_TAG_volatile_type:
- case dwarf::DW_TAG_restrict_type:
- case dwarf::DW_TAG_member:
- case dwarf::DW_TAG_inheritance:
- case dwarf::DW_TAG_friend:
- return true;
- default:
- // CompositeTypes are currently modelled as DerivedTypes.
- return isCompositeType();
- }
-}
-
-bool DIDescriptor::isCompositeType() const {
- if (!DbgNode)
- return false;
- switch (getTag()) {
- case dwarf::DW_TAG_array_type:
- case dwarf::DW_TAG_structure_type:
- case dwarf::DW_TAG_union_type:
- case dwarf::DW_TAG_enumeration_type:
- case dwarf::DW_TAG_subroutine_type:
- case dwarf::DW_TAG_class_type:
- return true;
- default:
- return false;
- }
-}
-
-bool DIDescriptor::isVariable() const {
- if (!DbgNode)
- return false;
- switch (getTag()) {
- case dwarf::DW_TAG_auto_variable:
- case dwarf::DW_TAG_arg_variable:
- return true;
- default:
- return false;
- }
-}
-
-bool DIDescriptor::isType() const {
- return isBasicType() || isCompositeType() || isDerivedType();
-}
-
-bool DIDescriptor::isSubprogram() const {
- return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
-}
-
-bool DIDescriptor::isGlobalVariable() const {
- return DbgNode && getTag() == dwarf::DW_TAG_variable;
-}
-
-bool DIDescriptor::isScope() const {
- if (!DbgNode)
- return false;
- switch (getTag()) {
- case dwarf::DW_TAG_compile_unit:
- case dwarf::DW_TAG_lexical_block:
- case dwarf::DW_TAG_subprogram:
- case dwarf::DW_TAG_namespace:
- case dwarf::DW_TAG_file_type:
- return true;
- default:
- break;
- }
- return isType();
-}
-
-bool DIDescriptor::isTemplateTypeParameter() const {
- return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
-}
-
-bool DIDescriptor::isTemplateValueParameter() const {
- return DbgNode && (getTag() == dwarf::DW_TAG_template_value_parameter ||
- getTag() == dwarf::DW_TAG_GNU_template_template_param ||
- getTag() == dwarf::DW_TAG_GNU_template_parameter_pack);
-}
-
-bool DIDescriptor::isCompileUnit() const {
- return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
-}
-
-bool DIDescriptor::isFile() const {
- return DbgNode && getTag() == dwarf::DW_TAG_file_type;
-}
-
-bool DIDescriptor::isNameSpace() const {
- return DbgNode && getTag() == dwarf::DW_TAG_namespace;
-}
-
-bool DIDescriptor::isLexicalBlockFile() const {
- return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
- DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 2;
-}
-
-bool DIDescriptor::isLexicalBlock() const {
- // FIXME: There are always exactly 4 header fields in DILexicalBlock, but
- // something relies on this returning true for DILexicalBlockFile.
- return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
- DbgNode->getNumOperands() == 3 &&
- (getNumHeaderFields() == 2 || getNumHeaderFields() == 4);
-}
-
-bool DIDescriptor::isSubrange() const {
- return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
-}
-
-bool DIDescriptor::isEnumerator() const {
- return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
-}
-
-bool DIDescriptor::isObjCProperty() const {
- return DbgNode && getTag() == dwarf::DW_TAG_APPLE_property;
-}
-
-bool DIDescriptor::isImportedEntity() const {
- return DbgNode && (getTag() == dwarf::DW_TAG_imported_module ||
- getTag() == dwarf::DW_TAG_imported_declaration);
-}
-
-bool DIDescriptor::isExpression() const {
- return DbgNode && (getTag() == dwarf::DW_TAG_expression);
-}
-
-//===----------------------------------------------------------------------===//
// Simple Descriptor Constructors and other Methods
//===----------------------------------------------------------------------===//
@@ -409,31 +225,10 @@ bool DICompileUnit::Verify() const {
// Don't bother verifying the compilation directory or producer string
// as those could be empty.
- if (getFilename().empty())
- return false;
-
- return DbgNode->getNumOperands() == 7 && getNumHeaderFields() == 8;
+ return !getFilename().empty();
}
-bool DIObjCProperty::Verify() const {
- if (!isObjCProperty())
- return false;
-
- // Don't worry about the rest of the strings for now.
- return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 6;
-}
-
-/// \brief Check if a field at position Elt of a MDNode is a MDNode.
-static bool fieldIsMDNode(const MDNode *DbgNode, unsigned Elt) {
- Metadata *Fld = getField(DbgNode, Elt);
- return !Fld || isa<MDNode>(Fld);
-}
-
-/// \brief Check if a field at position Elt of a MDNode is a MDString.
-static bool fieldIsMDString(const MDNode *DbgNode, unsigned Elt) {
- Metadata *Fld = getField(DbgNode, Elt);
- return !Fld || isa<MDString>(Fld);
-}
+bool DIObjCProperty::Verify() const { return isObjCProperty(); }
/// \brief Check if a value can be a reference to a type.
static bool isTypeRef(const Metadata *MD) {
@@ -441,14 +236,7 @@ static bool isTypeRef(const Metadata *MD) {
return true;
if (auto *S = dyn_cast<MDString>(MD))
return !S->getString().empty();
- if (auto *N = dyn_cast<MDNode>(MD))
- return DIType(N).isType();
- return false;
-}
-
-/// \brief Check if referenced field might be a type.
-static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) {
- return isTypeRef(dyn_cast_or_null<Metadata>(getField(DbgNode, Elt)));
+ return isa<MDType>(MD);
}
/// \brief Check if a value can be a ScopeRef.
@@ -457,14 +245,7 @@ static bool isScopeRef(const Metadata *MD) {
return true;
if (auto *S = dyn_cast<MDString>(MD))
return !S->getString().empty();
- if (auto *N = dyn_cast<MDNode>(MD))
- return DIScope(N).isScope();
- return false;
-}
-
-/// \brief Check if a field at position Elt of a MDNode can be a ScopeRef.
-static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
- return isScopeRef(dyn_cast_or_null<Metadata>(getField(DbgNode, Elt)));
+ return isa<MDScope>(MD);
}
#ifndef NDEBUG
@@ -479,10 +260,10 @@ static bool isDescriptorRef(const Metadata *MD) {
#endif
bool DIType::Verify() const {
- if (!isType())
+ auto *N = getRaw();
+ if (!N)
return false;
- // Make sure Context @ field 2 is MDNode.
- if (!fieldIsScopeRef(DbgNode, 2))
+ if (!isScopeRef(N->getScope()))
return false;
// FIXME: Sink this into the various subclass verifies.
@@ -511,60 +292,43 @@ bool DIType::Verify() const {
return false;
}
-bool DIBasicType::Verify() const {
- return isBasicType() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 8;
-}
+bool DIBasicType::Verify() const { return getRaw(); }
bool DIDerivedType::Verify() const {
- // Make sure DerivedFrom @ field 3 is TypeRef.
- if (!fieldIsTypeRef(DbgNode, 3))
+ auto *N = getRaw();
+ if (!N)
return false;
- if (getTag() == dwarf::DW_TAG_ptr_to_member_type)
- // Make sure ClassType @ field 4 is a TypeRef.
- if (!fieldIsTypeRef(DbgNode, 4))
+ if (getTag() == dwarf::DW_TAG_ptr_to_member_type) {
+ auto *D = dyn_cast<MDDerivedType>(N);
+ if (!D)
return false;
-
- return isDerivedType() && DbgNode->getNumOperands() >= 4 &&
- DbgNode->getNumOperands() <= 8 && getNumHeaderFields() >= 7 &&
- getNumHeaderFields() <= 8;
+ if (!isTypeRef(D->getExtraData()))
+ return false;
+ }
+ return isTypeRef(N->getBaseType());
}
bool DICompositeType::Verify() const {
- if (!isCompositeType())
- return false;
-
- // Make sure DerivedFrom @ field 3 and ContainingType @ field 5 are TypeRef.
- if (!fieldIsTypeRef(DbgNode, 3))
- return false;
- if (!fieldIsTypeRef(DbgNode, 5))
- return false;
-
- // Make sure the type identifier at field 7 is MDString, it can be null.
- if (!fieldIsMDString(DbgNode, 7))
- return false;
-
- // A subroutine type can't be both & and &&.
- if (isLValueReference() && isRValueReference())
- return false;
-
- return DbgNode->getNumOperands() == 8 && getNumHeaderFields() == 8;
+ auto *N = getRaw();
+ return N && isTypeRef(N->getBaseType()) && isTypeRef(N->getVTableHolder()) &&
+ !(isLValueReference() && isRValueReference());
}
bool DISubprogram::Verify() const {
- if (!isSubprogram())
+ auto *N = getRaw();
+ if (!N)
return false;
- // Make sure context @ field 2 is a ScopeRef and type @ field 3 is a MDNode.
- if (!fieldIsScopeRef(DbgNode, 2))
+ if (!isScopeRef(N->getScope()))
return false;
- if (!fieldIsMDNode(DbgNode, 3))
- return false;
- // Containing type @ field 4.
- if (!fieldIsTypeRef(DbgNode, 4))
+
+ if (auto *Op = N->getType())
+ if (!isa<MDNode>(Op))
+ return false;
+
+ if (!isTypeRef(getContainingType()))
return false;
- // A subprogram can't be both & and &&.
if (isLValueReference() && isRValueReference())
return false;
@@ -599,164 +363,66 @@ bool DISubprogram::Verify() const {
}
}
}
- return DbgNode->getNumOperands() == 9 && getNumHeaderFields() == 12;
+
+ return true;
}
bool DIGlobalVariable::Verify() const {
- if (!isGlobalVariable())
- return false;
+ auto *N = getRaw();
- if (getDisplayName().empty())
- return false;
- // Make sure context @ field 1 is an MDNode.
- if (!fieldIsMDNode(DbgNode, 1))
- return false;
- // Make sure that type @ field 3 is a DITypeRef.
- if (!fieldIsTypeRef(DbgNode, 3))
- return false;
- // Make sure StaticDataMemberDeclaration @ field 5 is MDNode.
- if (!fieldIsMDNode(DbgNode, 5))
- return false;
-
- return DbgNode->getNumOperands() == 6 && getNumHeaderFields() == 7;
-}
-
-bool DIVariable::Verify() const {
- if (!isVariable())
+ if (!N)
return false;
- // Make sure context @ field 1 is an MDNode.
- if (!fieldIsMDNode(DbgNode, 1))
- return false;
- // Make sure that type @ field 3 is a DITypeRef.
- if (!fieldIsTypeRef(DbgNode, 3))
+ if (N->getDisplayName().empty())
return false;
- // Check the number of header fields, which is common between complex and
- // simple variables.
- if (getNumHeaderFields() != 4)
- return false;
+ if (auto *Op = N->getScope())
+ if (!isa<MDNode>(Op))
+ return false;
- // Variable without an inline location.
- if (DbgNode->getNumOperands() == 4)
- return true;
+ if (auto *Op = N->getStaticDataMemberDeclaration())
+ if (!isa<MDNode>(Op))
+ return false;
- // Variable with an inline location.
- return getInlinedAt() != nullptr && DbgNode->getNumOperands() == 5;
+ return isTypeRef(N->getType());
}
-bool DIExpression::Verify() const {
- // Empty DIExpressions may be represented as a nullptr.
- if (!DbgNode)
- return true;
+bool DIVariable::Verify() const {
+ auto *N = getRaw();
- if (!(isExpression() && DbgNode->getNumOperands() == 1))
+ if (!N)
return false;
- for (auto Op : *this)
- switch (Op) {
- case DW_OP_bit_piece:
- // Must be the last element of the expression.
- return std::distance(Op.getBase(), DIHeaderFieldIterator()) == 3;
- case DW_OP_plus:
- if (std::distance(Op.getBase(), DIHeaderFieldIterator()) < 2)
- return false;
- break;
- case DW_OP_deref:
- break;
- default:
- // Other operators are not yet supported by the backend.
+ if (auto *Op = N->getScope())
+ if (!isa<MDNode>(Op))
return false;
- }
- return true;
-}
-
-bool DILocation::Verify() const {
- return DbgNode && isa<MDLocation>(DbgNode);
-}
-
-bool DINameSpace::Verify() const {
- if (!isNameSpace())
- return false;
- return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 3;
-}
-
-MDNode *DIFile::getFileNode() const { return getNodeField(DbgNode, 1); }
-
-bool DIFile::Verify() const {
- return isFile() && DbgNode->getNumOperands() == 2;
-}
-
-bool DIEnumerator::Verify() const {
- return isEnumerator() && DbgNode->getNumOperands() == 1 &&
- getNumHeaderFields() == 3;
-}
-bool DISubrange::Verify() const {
- return isSubrange() && DbgNode->getNumOperands() == 1 &&
- getNumHeaderFields() == 3;
+ return isTypeRef(N->getType());
}
-bool DILexicalBlock::Verify() const {
- return isLexicalBlock() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 4;
-}
-
-bool DILexicalBlockFile::Verify() const {
- return isLexicalBlockFile() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 2;
-}
-
-bool DITemplateTypeParameter::Verify() const {
- return isTemplateTypeParameter() && DbgNode->getNumOperands() == 4 &&
- getNumHeaderFields() == 4;
-}
-
-bool DITemplateValueParameter::Verify() const {
- return isTemplateValueParameter() && DbgNode->getNumOperands() == 5 &&
- getNumHeaderFields() == 4;
-}
-
-bool DIImportedEntity::Verify() const {
- return isImportedEntity() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 3;
-}
-
-MDNode *DIDerivedType::getObjCProperty() const {
- return getNodeField(DbgNode, 4);
-}
-
-MDString *DICompositeType::getIdentifier() const {
- return cast_or_null<MDString>(getField(DbgNode, 7));
-}
-
-#ifndef NDEBUG
-static void VerifySubsetOf(const MDNode *LHS, const MDNode *RHS) {
- for (unsigned i = 0; i != LHS->getNumOperands(); ++i) {
- // Skip the 'empty' list (that's a single i32 0, rather than truly empty).
- if (i == 0 && mdconst::hasa<ConstantInt>(LHS->getOperand(i)))
- continue;
- const MDNode *E = cast<MDNode>(LHS->getOperand(i));
- bool found = false;
- for (unsigned j = 0; !found && j != RHS->getNumOperands(); ++j)
- found = (E == cast<MDNode>(RHS->getOperand(j)));
- assert(found && "Losing a member during member list replacement");
- }
-}
-#endif
+bool DIExpression::Verify() const {
+ // FIXME: This should return false if it's null!
+ auto *N = getRaw();
+ return !N || N->isValid();
+}
+
+bool DILocation::Verify() const { return getRaw(); }
+bool DINameSpace::Verify() const { return getRaw(); }
+bool DIFile::Verify() const { return getRaw(); }
+bool DIEnumerator::Verify() const { return getRaw(); }
+bool DISubrange::Verify() const { return getRaw(); }
+bool DILexicalBlock::Verify() const { return getRaw(); }
+bool DILexicalBlockFile::Verify() const { return getRaw(); }
+bool DITemplateTypeParameter::Verify() const { return getRaw(); }
+bool DITemplateValueParameter::Verify() const { return getRaw(); }
+bool DIImportedEntity::Verify() const { return getRaw(); }
void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
- TrackingMDNodeRef N(*this);
- if (Elements) {
-#ifndef NDEBUG
- // Check that the new list of members contains all the old members as well.
- if (const MDNode *El = cast_or_null<MDNode>(N->getOperand(4)))
- VerifySubsetOf(El, Elements);
-#endif
- N->replaceOperandWith(4, Elements);
- }
+ TypedTrackingMDRef<MDCompositeTypeBase> N(getRaw());
+ if (Elements)
+ N->replaceElements(cast<MDTuple>(Elements));
if (TParams)
- N->replaceOperandWith(6, TParams);
+ N->replaceTemplateParams(cast<MDTuple>(TParams));
DbgNode = N;
}
@@ -770,8 +436,8 @@ DIScopeRef DIScope::getRef() const {
}
void DICompositeType::setContainingType(DICompositeType ContainingType) {
- TrackingMDNodeRef N(*this);
- N->replaceOperandWith(5, ContainingType.getRef());
+ TypedTrackingMDRef<MDCompositeTypeBase> N(getRaw());
+ N->replaceVTableHolder(ContainingType.getRef());
DbgNode = N;
}
@@ -784,6 +450,13 @@ bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
return !DISubprogram(getContext()).describes(CurFn);
}
+Function *DISubprogram::getFunction() const {
+ if (auto *N = getRaw())
+ if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getFunction()))
+ return dyn_cast<Function>(C->getValue());
+ return nullptr;
+}
+
bool DISubprogram::describes(const Function *F) {
assert(F && "Invalid function");
if (F == getFunction())
@@ -796,16 +469,8 @@ bool DISubprogram::describes(const Function *F) {
return false;
}
-MDNode *DISubprogram::getVariablesNodes() const {
- return getNodeField(DbgNode, 8);
-}
-
-DIArray DISubprogram::getVariables() const {
- return DIArray(getNodeField(DbgNode, 8));
-}
-
-Metadata *DITemplateValueParameter::getValue() const {
- return DbgNode->getOperand(3);
+GlobalVariable *DIGlobalVariable::getGlobal() const {
+ return dyn_cast_or_null<GlobalVariable>(getConstant());
}
DIScopeRef DIScope::getContext() const {
@@ -843,66 +508,26 @@ StringRef DIScope::getName() const {
}
StringRef DIScope::getFilename() const {
- if (!DbgNode)
- return StringRef();
- return ::getStringField(getNodeField(DbgNode, 1), 0);
+ if (auto *N = getRaw())
+ return ::getStringField(dyn_cast_or_null<MDNode>(N->getFile()), 0);
+ return "";
}
StringRef DIScope::getDirectory() const {
- if (!DbgNode)
- return StringRef();
- return ::getStringField(getNodeField(DbgNode, 1), 1);
-}
-
-DIArray DICompileUnit::getEnumTypes() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
- return DIArray();
-
- return DIArray(getNodeField(DbgNode, 2));
-}
-
-DIArray DICompileUnit::getRetainedTypes() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
- return DIArray();
-
- return DIArray(getNodeField(DbgNode, 3));
-}
-
-DIArray DICompileUnit::getSubprograms() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
- return DIArray();
-
- return DIArray(getNodeField(DbgNode, 4));
-}
-
-DIArray DICompileUnit::getGlobalVariables() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
- return DIArray();
-
- return DIArray(getNodeField(DbgNode, 5));
-}
-
-DIArray DICompileUnit::getImportedEntities() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
- return DIArray();
-
- return DIArray(getNodeField(DbgNode, 6));
+ if (auto *N = getRaw())
+ return ::getStringField(dyn_cast_or_null<MDNode>(N->getFile()), 1);
+ return "";
}
void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
assert(Verify() && "Expected compile unit");
- if (Subprograms == getSubprograms())
- return;
-
- const_cast<MDNode *>(DbgNode)->replaceOperandWith(4, Subprograms);
+ getRaw()->replaceSubprograms(cast_or_null<MDTuple>(Subprograms.get()));
}
void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
assert(Verify() && "Expected compile unit");
- if (GlobalVariables == getGlobalVariables())
- return;
-
- const_cast<MDNode *>(DbgNode)->replaceOperandWith(5, GlobalVariables);
+ getRaw()->replaceGlobalVariables(
+ cast_or_null<MDTuple>(GlobalVariables.get()));
}
DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
@@ -923,31 +548,13 @@ unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) {
DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
LLVMContext &VMContext) {
assert(DIVariable(DV).Verify() && "Expected a DIVariable");
- if (!InlinedScope)
- return cleanseInlinedVariable(DV, VMContext);
-
- // Insert inlined scope.
- SmallVector<Metadata *, 8> Elts(DV->op_begin(),
- DV->op_begin() + DIVariableInlinedAtIndex);
- Elts.push_back(InlinedScope);
-
- DIVariable Inlined(MDNode::get(VMContext, Elts));
- assert(Inlined.Verify() && "Expected to create a DIVariable");
- return Inlined;
+ return cast<MDLocalVariable>(DV)
+ ->withInline(cast_or_null<MDLocation>(InlinedScope));
}
DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
assert(DIVariable(DV).Verify() && "Expected a DIVariable");
- if (!DIVariable(DV).getInlinedAt())
- return DIVariable(DV);
-
- // Remove inlined scope.
- SmallVector<Metadata *, 8> Elts(DV->op_begin(),
- DV->op_begin() + DIVariableInlinedAtIndex);
-
- DIVariable Cleansed(MDNode::get(VMContext, Elts));
- assert(Cleansed.Verify() && "Expected to create a DIVariable");
- return Cleansed;
+ return cast<MDLocalVariable>(DV)->withoutInline();
}
DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
@@ -1263,220 +870,9 @@ void DIDescriptor::dump() const {
}
void DIDescriptor::print(raw_ostream &OS) const {
- if (!DbgNode)
+ if (!get())
return;
-
- if (const char *Tag = dwarf::TagString(getTag()))
- OS << "[ " << Tag << " ]";
-
- if (this->isSubrange()) {
- DISubrange(DbgNode).printInternal(OS);
- } else if (this->isCompileUnit()) {
- DICompileUnit(DbgNode).printInternal(OS);
- } else if (this->isFile()) {
- DIFile(DbgNode).printInternal(OS);
- } else if (this->isEnumerator()) {
- DIEnumerator(DbgNode).printInternal(OS);
- } else if (this->isBasicType()) {
- DIType(DbgNode).printInternal(OS);
- } else if (this->isDerivedType()) {
- DIDerivedType(DbgNode).printInternal(OS);
- } else if (this->isCompositeType()) {
- DICompositeType(DbgNode).printInternal(OS);
- } else if (this->isSubprogram()) {
- DISubprogram(DbgNode).printInternal(OS);
- } else if (this->isGlobalVariable()) {
- DIGlobalVariable(DbgNode).printInternal(OS);
- } else if (this->isVariable()) {
- DIVariable(DbgNode).printInternal(OS);
- } else if (this->isObjCProperty()) {
- DIObjCProperty(DbgNode).printInternal(OS);
- } else if (this->isNameSpace()) {
- DINameSpace(DbgNode).printInternal(OS);
- } else if (this->isScope()) {
- DIScope(DbgNode).printInternal(OS);
- } else if (this->isExpression()) {
- DIExpression(DbgNode).printInternal(OS);
- }
-}
-
-void DISubrange::printInternal(raw_ostream &OS) const {
- int64_t Count = getCount();
- if (Count != -1)
- OS << " [" << getLo() << ", " << Count - 1 << ']';
- else
- OS << " [unbounded]";
-}
-
-void DIScope::printInternal(raw_ostream &OS) const {
- OS << " [" << getDirectory() << "/" << getFilename() << ']';
-}
-
-void DICompileUnit::printInternal(raw_ostream &OS) const {
- DIScope::printInternal(OS);
- OS << " [";
- unsigned Lang = getLanguage();
- if (const char *LangStr = dwarf::LanguageString(Lang))
- OS << LangStr;
- else
- (OS << "lang 0x").write_hex(Lang);
- OS << ']';
-}
-
-void DIEnumerator::printInternal(raw_ostream &OS) const {
- OS << " [" << getName() << " :: " << getEnumValue() << ']';
-}
-
-void DIType::printInternal(raw_ostream &OS) const {
- if (!DbgNode)
- return;
-
- StringRef Res = getName();
- if (!Res.empty())
- OS << " [" << Res << "]";
-
- // TODO: Print context?
-
- OS << " [line " << getLineNumber() << ", size " << getSizeInBits()
- << ", align " << getAlignInBits() << ", offset " << getOffsetInBits();
- if (isBasicType())
- if (const char *Enc =
- dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding()))
- OS << ", enc " << Enc;
- OS << "]";
-
- if (isPrivate())
- OS << " [private]";
- else if (isProtected())
- OS << " [protected]";
- else if (isPublic())
- OS << " [public]";
-
- if (isArtificial())
- OS << " [artificial]";
-
- if (isForwardDecl())
- OS << " [decl]";
- else if (getTag() == dwarf::DW_TAG_structure_type ||
- getTag() == dwarf::DW_TAG_union_type ||
- getTag() == dwarf::DW_TAG_enumeration_type ||
- getTag() == dwarf::DW_TAG_class_type)
- OS << " [def]";
- if (isVector())
- OS << " [vector]";
- if (isStaticMember())
- OS << " [static]";
-
- if (isLValueReference())
- OS << " [reference]";
-
- if (isRValueReference())
- OS << " [rvalue reference]";
-}
-
-void DIDerivedType::printInternal(raw_ostream &OS) const {
- DIType::printInternal(OS);
- OS << " [from " << getTypeDerivedFrom().getName() << ']';
-}
-
-void DICompositeType::printInternal(raw_ostream &OS) const {
- DIType::printInternal(OS);
- DIArray A = getElements();
- OS << " [" << A.getNumElements() << " elements]";
-}
-
-void DINameSpace::printInternal(raw_ostream &OS) const {
- StringRef Name = getName();
- if (!Name.empty())
- OS << " [" << Name << ']';
-
- OS << " [line " << getLineNumber() << ']';
-}
-
-void DISubprogram::printInternal(raw_ostream &OS) const {
- // TODO : Print context
- OS << " [line " << getLineNumber() << ']';
-
- if (isLocalToUnit())
- OS << " [local]";
-
- if (isDefinition())
- OS << " [def]";
-
- if (getScopeLineNumber() != getLineNumber())
- OS << " [scope " << getScopeLineNumber() << "]";
-
- if (isPrivate())
- OS << " [private]";
- else if (isProtected())
- OS << " [protected]";
- else if (isPublic())
- OS << " [public]";
-
- if (isLValueReference())
- OS << " [reference]";
-
- if (isRValueReference())
- OS << " [rvalue reference]";
-
- StringRef Res = getName();
- if (!Res.empty())
- OS << " [" << Res << ']';
-}
-
-void DIGlobalVariable::printInternal(raw_ostream &OS) const {
- StringRef Res = getName();
- if (!Res.empty())
- OS << " [" << Res << ']';
-
- OS << " [line " << getLineNumber() << ']';
-
- // TODO : Print context
-
- if (isLocalToUnit())
- OS << " [local]";
-
- if (isDefinition())
- OS << " [def]";
-}
-
-void DIVariable::printInternal(raw_ostream &OS) const {
- StringRef Res = getName();
- if (!Res.empty())
- OS << " [" << Res << ']';
-
- OS << " [line " << getLineNumber() << ']';
-}
-
-void DIExpression::printInternal(raw_ostream &OS) const {
- for (auto Op : *this) {
- OS << " [" << OperationEncodingString(Op);
- switch (Op) {
- case DW_OP_plus: {
- OS << " " << Op.getArg(1);
- break;
- }
- case DW_OP_bit_piece: {
- OS << " offset=" << Op.getArg(1) << ", size=" << Op.getArg(2);
- break;
- }
- case DW_OP_deref:
- // No arguments.
- break;
- default:
- llvm_unreachable("unhandled operation");
- }
- OS << "]";
- }
-}
-
-void DIObjCProperty::printInternal(raw_ostream &OS) const {
- StringRef Name = getObjCPropertyName();
- if (!Name.empty())
- OS << " [" << Name << ']';
-
- OS << " [line " << getLineNumber() << ", properties " << getUnsignedField(6)
- << ']';
+ get()->print(OS);
}
static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
OpenPOWER on IntegriCloud