summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp2
-rw-r--r--llvm/lib/CodeGen/MachineInstr.cpp10
-rw-r--r--llvm/lib/IR/AsmWriter.cpp2
-rw-r--r--llvm/lib/IR/DIBuilder.cpp899
-rw-r--r--llvm/lib/IR/DebugInfo.cpp196
-rw-r--r--llvm/lib/IR/DebugLoc.cpp10
-rw-r--r--llvm/lib/Transforms/IPO/StripSymbols.cpp17
7 files changed, 608 insertions, 528 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 902dafa6f46..b19b576cdf3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1713,7 +1713,7 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(DIGlobalVariable GV) {
// it is not a static member.
if (!IsStaticMember)
addConstantValue(*VariableDIE, CI, GTy);
- } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV.getConstant())) {
+ } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getOperand(11))) {
addToAccelTable = true;
// GV is a merged global.
DIELoc *Loc = new (DIEValueAllocator) DIELoc();
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 2e59f371826..d33d4a9d26a 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -1643,11 +1643,11 @@ void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM,
if (isDebugValue() && MO.isMetadata()) {
// Pretty print DBG_VALUE instructions.
const MDNode *MD = MO.getMetadata();
- DIDescriptor DI(MD);
- DIVariable DIV(MD);
-
- if (DI.isVariable() && !DIV.getName().empty())
- OS << "!\"" << DIV.getName() << '\"';
+ if (MD->getNumOperands() >= 2)
+ if (const MDString *MDS = dyn_cast<MDString>(MD->getOperand(2)))
+ OS << "!\"" << MDS->getString() << '\"';
+ else
+ MO.print(OS, TM);
else
MO.print(OS, TM);
} else if (TM && (isInsertSubreg() || isRegSequence()) && MO.isImm()) {
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 31d960e96cb..ebc78e0517f 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -2340,7 +2340,7 @@ static void WriteMDNodeComment(const MDNode *Node,
return;
Value *Op = Node->getOperand(0);
- if (!Op || !isa<MDString>(Op))
+ if (!Op || !isa<ConstantInt>(Op) || cast<ConstantInt>(Op)->getBitWidth() < 32)
return;
DIDescriptor Desc(Node);
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index c131b544b5f..d17c1455ff5 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -23,29 +23,10 @@
using namespace llvm;
using namespace llvm::dwarf;
-namespace {
-class HeaderBuilder {
- SmallVector<char, 256> Chars;
-
-public:
- explicit HeaderBuilder(Twine T) { T.toVector(Chars); }
- HeaderBuilder(const HeaderBuilder &X) : Chars(X.Chars) {}
- HeaderBuilder(HeaderBuilder &&X) : Chars(std::move(X.Chars)) {}
-
- template <class Twineable> HeaderBuilder &concat(Twineable &&X) {
- 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("0x" + Twine::utohexstr(Tag));
- }
-};
+static Constant *GetTagConstant(LLVMContext &VMContext, unsigned Tag) {
+ assert((Tag & LLVMDebugVersionMask) == 0 &&
+ "Tag too large for debug encoding!");
+ return ConstantInt::get(Type::getInt32Ty(VMContext), Tag | LLVMDebugVersion);
}
DIBuilder::DIBuilder(Module &m)
@@ -125,7 +106,7 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
"Invalid Language tag");
assert(!Filename.empty() &&
"Unable to create compile unit without filename");
- Value *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)};
+ Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
TempEnumTypes = MDNode::getTemporary(VMContext, TElts);
TempRetainTypes = MDNode::getTemporary(VMContext, TElts);
@@ -136,18 +117,22 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
TempImportedModules = MDNode::getTemporary(VMContext, TElts);
- Value *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};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
+ createFilePathPair(VMContext, Filename, Directory),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
+ MDString::get(VMContext, Producer),
+ ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
+ MDString::get(VMContext, Flags),
+ ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer),
+ TempEnumTypes,
+ TempRetainTypes,
+ TempSubprograms,
+ TempGVs,
+ TempImportedModules,
+ MDString::get(VMContext, SplitName),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Kind)
+ };
MDNode *CUNode = MDNode::get(VMContext, Elts);
@@ -169,9 +154,24 @@ createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
Value *NS, unsigned Line, StringRef Name,
SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
const MDNode *R;
- Value *Elts[] = {HeaderBuilder::get(Tag).concat(Line).concat(Name).get(C),
- Context, NS};
- R = MDNode::get(C, Elts);
+ if (Name.empty()) {
+ Value *Elts[] = {
+ GetTagConstant(C, Tag),
+ Context,
+ NS,
+ ConstantInt::get(Type::getInt32Ty(C), Line),
+ };
+ R = MDNode::get(C, Elts);
+ } else {
+ Value *Elts[] = {
+ GetTagConstant(C, Tag),
+ Context,
+ NS,
+ ConstantInt::get(Type::getInt32Ty(C), Line),
+ MDString::get(C, Name)
+ };
+ R = MDNode::get(C, Elts);
+ }
DIImportedEntity M(R);
assert(M.Verify() && "Imported module should be valid");
AllImportedModules.push_back(TrackingVH<MDNode>(M));
@@ -208,16 +208,20 @@ DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
}
DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_file_type).get(VMContext),
- createFilePathPair(VMContext, Filename, Directory)};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
+ createFilePathPair(VMContext, Filename, Directory)
+ };
return DIFile(MDNode::get(VMContext, Elts));
}
DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
assert(!Name.empty() && "Unable to create enumerator without name");
Value *Elts[] = {
- HeaderBuilder::get(dwarf::DW_TAG_enumerator).concat(Name).concat(Val).get(
- VMContext)};
+ GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt64Ty(VMContext), Val)
+ };
return DIEnumerator(MDNode::get(VMContext, Elts));
}
@@ -226,17 +230,16 @@ DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
// Unspecified types are encoded in DIBasicType format. Line number, filename,
// size, alignment, offset and flags are always empty here.
Value *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
+ GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_type),
+ nullptr, // Filename
+ nullptr, // Unused
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0) // Encoding
};
return DIBasicType(MDNode::get(VMContext, Elts));
}
@@ -252,34 +255,34 @@ DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
// Basic types are encoded in DIBasicType format. Line number, filename,
// offset and flags are always empty here.
Value *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
+ GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
+ nullptr, // File/directory name
+ nullptr, // Unused
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
+ ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
};
return DIBasicType(MDNode::get(VMContext, Elts));
}
DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
// Qualified types are encoded in DIDerivedType format.
- Value *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()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, Tag),
+ nullptr, // Filename
+ nullptr, // Unused
+ MDString::get(VMContext, StringRef()), // Empty name.
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ FromTy.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
@@ -287,68 +290,73 @@ DIDerivedType
DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
uint64_t AlignInBits, StringRef Name) {
// Pointer types are encoded in DIDerivedType format.
- Value *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()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
+ nullptr, // Filename
+ nullptr, // Unused
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ PointeeTy.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
DIDerivedType DIBuilder::createMemberPointerType(DIType PointeeTy,
DIType Base) {
// Pointer types are encoded in DIDerivedType format.
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_ptr_to_member_type)
- .concat(StringRef())
- .concat(0) // Line
- .concat(0) // Size
- .concat(0) // Align
- .concat(0) // Offset
- .concat(0) // Flags
- .get(VMContext),
- nullptr, // Filename
- nullptr, // Unused
- PointeeTy.getRef(), Base.getRef()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_ptr_to_member_type),
+ nullptr, // Filename
+ nullptr, // Unused
+ nullptr,
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ PointeeTy.getRef(),
+ Base.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
assert(RTy.isType() && "Unable to create reference type");
// References are encoded in DIDerivedType format.
- Value *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()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, Tag),
+ nullptr, // Filename
+ nullptr, // TheCU,
+ nullptr, // Name
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ RTy.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
unsigned LineNo, DIDescriptor Context) {
// typedefs are encoded in DIDerivedType format.
- Value *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()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Context)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ Ty.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
@@ -356,15 +364,18 @@ DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
// typedefs are encoded in DIDerivedType format.
assert(Ty.isType() && "Invalid type!");
assert(FriendTy.isType() && "Invalid friend type!");
- Value *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()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_friend),
+ nullptr,
+ Ty.getRef(),
+ nullptr, // Name
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ FriendTy.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
@@ -373,15 +384,18 @@ DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
unsigned Flags) {
assert(Ty.isType() && "Unable to create inheritance");
// TAG_inheritance is encoded in DIDerivedType format.
- Value *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()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
+ nullptr,
+ Ty.getRef(),
+ nullptr, // Name
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ BaseTy.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
@@ -392,17 +406,18 @@ DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
uint64_t OffsetInBits, unsigned Flags,
DIType Ty) {
// TAG_member is encoded in DIDerivedType format.
- Value *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()};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_member),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Scope)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ Ty.getRef()
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
@@ -413,17 +428,19 @@ DIBuilder::createStaticMemberType(DIDescriptor Scope, StringRef Name,
llvm::Value *Val) {
// TAG_member is encoded in DIDerivedType format.
Flags |= DIDescriptor::FlagStaticMember;
- Value *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(),
- Val};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_member),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Scope)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ Ty.getRef(),
+ Val
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
@@ -434,16 +451,19 @@ DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
uint64_t OffsetInBits, unsigned Flags,
DIType Ty, MDNode *PropertyNode) {
// TAG_member is encoded in DIDerivedType format.
- Value *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};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_member),
+ File.getFileNode(),
+ getNonCompileUnitScope(File),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ Ty,
+ PropertyNode
+ };
return DIDerivedType(MDNode::get(VMContext, Elts));
}
@@ -451,14 +471,16 @@ DIObjCProperty
DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
StringRef GetterName, StringRef SetterName,
unsigned PropertyAttributes, DIType Ty) {
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_APPLE_property)
- .concat(Name)
- .concat(LineNumber)
- .concat(GetterName)
- .concat(SetterName)
- .concat(PropertyAttributes)
- .get(VMContext),
- File, Ty};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_APPLE_property),
+ MDString::get(VMContext, Name),
+ File,
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ MDString::get(VMContext, GetterName),
+ MDString::get(VMContext, SetterName),
+ ConstantInt::get(Type::getInt32Ty(VMContext), PropertyAttributes),
+ Ty
+ };
return DIObjCProperty(MDNode::get(VMContext, Elts));
}
@@ -466,13 +488,15 @@ DITemplateTypeParameter
DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
DIType Ty, MDNode *File, unsigned LineNo,
unsigned ColumnNo) {
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_template_type_parameter)
- .concat(Name)
- .concat(LineNo)
- .concat(ColumnNo)
- .get(VMContext),
- DIScope(getNonCompileUnitScope(Context)).getRef(),
- Ty.getRef(), File};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_template_type_parameter),
+ DIScope(getNonCompileUnitScope(Context)).getRef(),
+ MDString::get(VMContext, Name),
+ Ty.getRef(),
+ File,
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
+ ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
+ };
return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
}
@@ -483,10 +507,15 @@ DIBuilder::createTemplateValueParameter(unsigned Tag, DIDescriptor Context,
unsigned LineNo,
unsigned ColumnNo) {
Value *Elts[] = {
- HeaderBuilder::get(Tag).concat(Name).concat(LineNo).concat(ColumnNo).get(
- VMContext),
- DIScope(getNonCompileUnitScope(Context)).getRef(), Ty.getRef(), Val,
- File};
+ GetTagConstant(VMContext, Tag),
+ DIScope(getNonCompileUnitScope(Context)).getRef(),
+ MDString::get(VMContext, Name),
+ Ty.getRef(),
+ Val,
+ File,
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
+ ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo)
+ };
return DITemplateValueParameter(MDNode::get(VMContext, Elts));
}
@@ -534,19 +563,23 @@ DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
"createClassType should be called with a valid Context");
// TAG_class_type is encoded in DICompositeType format.
Value *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)};
+ GetTagConstant(VMContext, dwarf::DW_TAG_class_type),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Context)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ DerivedFrom.getRef(),
+ Elements,
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ VTableHolder.getRef(),
+ TemplateParams,
+ UniqueIdentifier.empty() ? nullptr
+ : MDString::get(VMContext, UniqueIdentifier)
+ };
DICompositeType R(MDNode::get(VMContext, Elts));
assert(R.isCompositeType() &&
"createClassType should return a DICompositeType");
@@ -567,19 +600,23 @@ DICompositeType DIBuilder::createStructType(DIDescriptor Context,
StringRef UniqueIdentifier) {
// TAG_structure_type is encoded in DICompositeType format.
Value *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)};
+ GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Context)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ DerivedFrom.getRef(),
+ Elements,
+ ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
+ VTableHolder.getRef(),
+ nullptr,
+ UniqueIdentifier.empty() ? nullptr
+ : MDString::get(VMContext, UniqueIdentifier)
+ };
DICompositeType R(MDNode::get(VMContext, Elts));
assert(R.isCompositeType() &&
"createStructType should return a DICompositeType");
@@ -597,19 +634,23 @@ DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name,
StringRef UniqueIdentifier) {
// TAG_union_type is encoded in DICompositeType format.
Value *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)};
+ GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Scope)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ nullptr,
+ Elements,
+ ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
+ nullptr,
+ nullptr,
+ UniqueIdentifier.empty() ? nullptr
+ : MDString::get(VMContext, UniqueIdentifier)
+ };
DICompositeType R(MDNode::get(VMContext, Elts));
if (!UniqueIdentifier.empty())
retainType(R);
@@ -621,17 +662,21 @@ DISubroutineType DIBuilder::createSubroutineType(DIFile File,
unsigned Flags) {
// TAG_subroutine_type is encoded in DICompositeType format.
Value *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
+ GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
+ Constant::getNullValue(Type::getInt32Ty(VMContext)),
+ nullptr,
+ MDString::get(VMContext, ""),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
+ ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags), // Flags
+ nullptr,
+ ParameterTypes,
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ nullptr,
+ nullptr,
+ nullptr // Type Identifer
};
return DISubroutineType(MDNode::get(VMContext, Elts));
}
@@ -642,19 +687,23 @@ DICompositeType DIBuilder::createEnumerationType(
DIType UnderlyingType, StringRef UniqueIdentifier) {
// TAG_enumeration_type is encoded in DICompositeType format.
Value *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)};
+ GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Scope)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ UnderlyingType.getRef(),
+ Elements,
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ nullptr,
+ nullptr,
+ UniqueIdentifier.empty() ? nullptr
+ : MDString::get(VMContext, UniqueIdentifier)
+ };
DICompositeType CTy(MDNode::get(VMContext, Elts));
AllEnumTypes.push_back(CTy);
if (!UniqueIdentifier.empty())
@@ -666,19 +715,21 @@ DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
DIType Ty, DIArray Subscripts) {
// TAG_array_type is encoded in DICompositeType format.
Value *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
+ GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
+ nullptr, // Filename/Directory,
+ nullptr, // Unused
+ MDString::get(VMContext, ""),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), Size),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
+ Ty.getRef(),
+ Subscripts,
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ nullptr,
+ nullptr,
+ nullptr // Type Identifer
};
return DICompositeType(MDNode::get(VMContext, Elts));
}
@@ -687,61 +738,63 @@ DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
DIType Ty, DIArray Subscripts) {
// A vector is an array type with the FlagVector flag applied.
Value *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
+ GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
+ nullptr, // Filename/Directory,
+ nullptr, // Unused
+ MDString::get(VMContext, ""),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
+ ConstantInt::get(Type::getInt64Ty(VMContext), Size),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), DIType::FlagVector),
+ Ty.getRef(),
+ Subscripts,
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ nullptr,
+ nullptr,
+ nullptr // Type Identifer
};
return DICompositeType(MDNode::get(VMContext, Elts));
}
-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(Twine(I.getPrefix())).concat(Flags).concat(
- I.getSuffix());
-}
+DIType DIBuilder::createArtificialType(DIType Ty) {
+ if (Ty.isArtificial())
+ return Ty;
-static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty,
- unsigned FlagsToSet) {
SmallVector<Value *, 9> Elts;
MDNode *N = Ty;
- assert(N && "Unexpected input DIType!");
- // Update header field.
- Elts.push_back(setTypeFlagsInHeader(Ty.getHeader(), FlagsToSet).get(Context));
- for (unsigned I = 1, E = N->getNumOperands(); I != E; ++I)
- Elts.push_back(N->getOperand(I));
+ assert (N && "Unexpected input DIType!");
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
+ Elts.push_back(N->getOperand(i));
- return DIType(MDNode::get(Context, Elts));
-}
+ unsigned CurFlags = Ty.getFlags();
+ CurFlags = CurFlags | DIType::FlagArtificial;
-DIType DIBuilder::createArtificialType(DIType Ty) {
- if (Ty.isArtificial())
- return Ty;
- return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial);
+ // Flags are stored at this slot.
+ // FIXME: Add an enum for this magic value.
+ Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
+
+ return DIType(MDNode::get(VMContext, Elts));
}
DIType DIBuilder::createObjectPointerType(DIType Ty) {
if (Ty.isObjectPointer())
return Ty;
- unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial;
- return createTypeWithFlags(VMContext, Ty, Flags);
+
+ SmallVector<Value *, 9> Elts;
+ MDNode *N = Ty;
+ assert (N && "Unexpected input DIType!");
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
+ Elts.push_back(N->getOperand(i));
+
+ unsigned CurFlags = Ty.getFlags();
+ CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
+
+ // Flags are stored at this slot.
+ // FIXME: Add an enum for this magic value.
+ Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
+
+ return DIType(MDNode::get(VMContext, Elts));
}
void DIBuilder::retainType(DIType T) {
@@ -759,20 +812,23 @@ DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
StringRef UniqueIdentifier) {
// Create a temporary MDNode.
Value *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)};
+ GetTagConstant(VMContext, Tag),
+ F.getFileNode(),
+ DIScope(getNonCompileUnitScope(Scope)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Line),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
+ nullptr,
+ DIArray(),
+ ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
+ nullptr,
+ nullptr, //TemplateParams
+ UniqueIdentifier.empty() ? nullptr
+ : MDString::get(VMContext, UniqueIdentifier)
+ };
MDNode *Node = MDNode::get(VMContext, Elts);
DICompositeType RetTy(Node);
assert(RetTy.isCompositeType() &&
@@ -788,20 +844,23 @@ DICompositeType DIBuilder::createReplaceableForwardDecl(
StringRef UniqueIdentifier) {
// Create a temporary MDNode.
Value *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)};
+ GetTagConstant(VMContext, Tag),
+ F.getFileNode(),
+ DIScope(getNonCompileUnitScope(Scope)).getRef(),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Line),
+ ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
+ ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset
+ ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl),
+ nullptr,
+ DIArray(),
+ ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
+ nullptr,
+ nullptr, //TemplateParams
+ UniqueIdentifier.empty() ? nullptr
+ : MDString::get(VMContext, UniqueIdentifier)
+ };
MDNode *Node = MDNode::getTemporary(VMContext, Elts);
DICompositeType RetTy(Node);
assert(RetTy.isCompositeType() &&
@@ -827,10 +886,11 @@ DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef<Value *> Elements) {
}
DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subrange_type)
- .concat(Lo)
- .concat(Count)
- .get(VMContext)};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
+ ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
+ ConstantInt::get(Type::getInt64Ty(VMContext), Count)
+ };
return DISubrange(MDNode::get(VMContext, Elts));
}
@@ -841,16 +901,21 @@ createGlobalVariableHelper(LLVMContext &VMContext, DIDescriptor Context,
unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit,
Value *Val, MDNode *Decl, bool isDefinition,
std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_variable)
- .concat(Name)
- .concat(Name)
- .concat(LinkageName)
- .concat(LineNumber)
- .concat(isLocalToUnit)
- .concat(isDefinition)
- .get(VMContext),
- getNonCompileUnitScope(Context), F, Ty, Val,
- DIDescriptor(Decl)};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_variable),
+ Constant::getNullValue(Type::getInt32Ty(VMContext)),
+ getNonCompileUnitScope(Context),
+ MDString::get(VMContext, Name),
+ MDString::get(VMContext, Name),
+ MDString::get(VMContext, LinkageName),
+ F,
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
+ Ty,
+ ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
+ ConstantInt::get(Type::getInt32Ty(VMContext), isDefinition),
+ Val,
+ DIDescriptor(Decl)
+ };
return DIGlobalVariable(CreateFunc(Elts));
}
@@ -894,12 +959,16 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
DIDescriptor Context(getNonCompileUnitScope(Scope));
assert((!Context || Context.isScope()) &&
"createLocalVariable should be called with a valid Context");
- Value *Elts[] = {HeaderBuilder::get(Tag)
- .concat(Name)
- .concat(LineNo | (ArgNo << 24))
- .concat(Flags)
- .get(VMContext),
- getNonCompileUnitScope(Scope), File, Ty};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, Tag),
+ getNonCompileUnitScope(Scope),
+ MDString::get(VMContext, Name),
+ File,
+ ConstantInt::get(Type::getInt32Ty(VMContext), (LineNo | (ArgNo << 24))),
+ Ty,
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ Constant::getNullValue(Type::getInt32Ty(VMContext))
+ };
MDNode *Node = MDNode::get(VMContext, Elts);
if (AlwaysPreserve) {
// The optimizer may remove local variable. If there is an interest
@@ -916,10 +985,13 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
}
DIExpression DIBuilder::createExpression(ArrayRef<int64_t> Addr) {
- auto Header = HeaderBuilder::get(DW_TAG_expression);
+ SmallVector<llvm::Value *, 16> Elts;
+ Elts.push_back(GetTagConstant(VMContext, DW_TAG_expression));
+
+ llvm::Type *Int64Ty = Type::getInt64Ty(VMContext);
for (int64_t I : Addr)
- Header.concat(I);
- Value *Elts[] = {Header.get(VMContext)};
+ Elts.push_back(ConstantInt::get(Int64Ty, I));
+
return DIExpression(MDNode::get(VMContext, Elts));
}
@@ -953,23 +1025,29 @@ createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Nam
std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
"function types should be subroutines");
- Value *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)};
+ Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
Value *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, Fn, TParams, Decl, MDNode::getTemporary(VMContext, TElts)};
+ GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
+ File.getFileNode(),
+ DIScope(getNonCompileUnitScope(Context)).getRef(),
+ MDString::get(VMContext, Name),
+ MDString::get(VMContext, Name),
+ MDString::get(VMContext, LinkageName),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
+ Ty,
+ ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
+ ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ ConstantInt::get(Type::getInt32Ty(VMContext), 0),
+ nullptr,
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
+ Fn,
+ TParams,
+ Decl,
+ MDNode::getTemporary(VMContext, TElts),
+ ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
+ };
DISubprogram S(CreateFunc(Elts));
assert(S.isSubprogram() &&
@@ -1027,22 +1105,29 @@ 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.");
- Value *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(), Fn, TParam, nullptr, nullptr};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
+ F.getFileNode(),
+ DIScope(Context).getRef(),
+ MDString::get(VMContext, Name),
+ MDString::get(VMContext, Name),
+ MDString::get(VMContext, LinkageName),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
+ Ty,
+ ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
+ ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
+ ConstantInt::get(Type::getInt32Ty(VMContext), VK),
+ ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
+ VTableHolder.getRef(),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
+ ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
+ Fn,
+ TParam,
+ Constant::getNullValue(Type::getInt32Ty(VMContext)),
+ nullptr,
+ // FIXME: Do we want to use different scope/lines?
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
+ };
MDNode *Node = MDNode::get(VMContext, Elts);
if (isDefinition)
AllSubprograms.push_back(Node);
@@ -1053,11 +1138,13 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
DIFile File, unsigned LineNo) {
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_namespace)
- .concat(Name)
- .concat(LineNo)
- .get(VMContext),
- File.getFileNode(), getNonCompileUnitScope(Scope)};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
+ File.getFileNode(),
+ getNonCompileUnitScope(Scope),
+ MDString::get(VMContext, Name),
+ ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
+ };
DINameSpace R(MDNode::get(VMContext, Elts));
assert(R.Verify() &&
"createNameSpace should return a verifiable DINameSpace");
@@ -1067,10 +1154,12 @@ DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
DIFile File,
unsigned Discriminator) {
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
- .concat(Discriminator)
- .get(VMContext),
- File.getFileNode(), Scope};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
+ File.getFileNode(),
+ Scope,
+ ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
+ };
DILexicalBlockFile R(MDNode::get(VMContext, Elts));
assert(
R.Verify() &&
@@ -1089,12 +1178,14 @@ DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
// Defeat MDNode uniquing for lexical blocks by using unique id.
static unsigned int unique_id = 0;
- Value *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
- .concat(Line)
- .concat(Col)
- .concat(unique_id++)
- .get(VMContext),
- File.getFileNode(), getNonCompileUnitScope(Scope)};
+ Value *Elts[] = {
+ GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
+ File.getFileNode(),
+ getNonCompileUnitScope(Scope),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Line),
+ ConstantInt::get(Type::getInt32Ty(VMContext), Col),
+ ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
+ };
DILexicalBlock R(MDNode::get(VMContext, Elts));
assert(R.Verify() &&
"createLexicalBlock should return a verifiable DILexicalBlock");
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index f1060a0fc71..42b0dc0fc27 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -138,10 +138,8 @@ void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) {
}
}
-static unsigned DIVariableInlinedAtIndex = 4;
-MDNode *DIVariable::getInlinedAt() const {
- return getNodeField(DbgNode, DIVariableInlinedAtIndex);
-}
+/// getInlinedAt - If this variable is inlined then return inline location.
+MDNode *DIVariable::getInlinedAt() const { return getNodeField(DbgNode, 7); }
/// Return the size reported by the variable's type.
unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
@@ -158,9 +156,12 @@ unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
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);
+ if (I < DbgNode->getNumOperands())
+ if (auto *CI = dyn_cast_or_null<ConstantInt>(DbgNode->getOperand(I)))
+ return CI->getZExtValue();
+
+ assert(false && "non-existing complex address element requested");
+ return 0;
}
bool DIExpression::isVariablePiece() const {
@@ -322,13 +323,13 @@ bool DIDescriptor::isNameSpace() const {
/// lexical block with an extra file.
bool DIDescriptor::isLexicalBlockFile() const {
return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
- DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 2;
+ (DbgNode->getNumOperands() == 4);
}
/// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
bool DIDescriptor::isLexicalBlock() const {
return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
- DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 4;
+ (DbgNode->getNumOperands() > 3);
}
/// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
@@ -412,7 +413,7 @@ bool DICompileUnit::Verify() const {
if (getFilename().empty())
return false;
- return DbgNode->getNumOperands() == 7 && getNumHeaderFields() == 8;
+ return DbgNode->getNumOperands() == 14;
}
/// Verify - Verify that an ObjC property is well formed.
@@ -421,7 +422,7 @@ bool DIObjCProperty::Verify() const {
return false;
// Don't worry about the rest of the strings for now.
- return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 6;
+ return DbgNode->getNumOperands() == 8;
}
/// Check if a field at position Elt of a MDNode is a MDNode.
@@ -506,23 +507,21 @@ bool DIType::Verify() const {
/// Verify - Verify that a basic type descriptor is well formed.
bool DIBasicType::Verify() const {
- return isBasicType() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 8;
+ return isBasicType() && DbgNode->getNumOperands() == 10;
}
/// Verify - Verify that a derived type descriptor is well formed.
bool DIDerivedType::Verify() const {
- // Make sure DerivedFrom @ field 3 is TypeRef.
- if (!fieldIsTypeRef(DbgNode, 3))
+ // Make sure DerivedFrom @ field 9 is TypeRef.
+ if (!fieldIsTypeRef(DbgNode, 9))
return false;
if (getTag() == dwarf::DW_TAG_ptr_to_member_type)
- // Make sure ClassType @ field 4 is a TypeRef.
- if (!fieldIsTypeRef(DbgNode, 4))
+ // Make sure ClassType @ field 10 is a TypeRef.
+ if (!fieldIsTypeRef(DbgNode, 10))
return false;
- return isDerivedType() && DbgNode->getNumOperands() >= 4 &&
- DbgNode->getNumOperands() <= 8 && getNumHeaderFields() >= 7 &&
- getNumHeaderFields() <= 8;
+ return isDerivedType() && DbgNode->getNumOperands() >= 10 &&
+ DbgNode->getNumOperands() <= 14;
}
/// Verify - Verify that a composite type descriptor is well formed.
@@ -530,21 +529,21 @@ bool DICompositeType::Verify() const {
if (!isCompositeType())
return false;
- // Make sure DerivedFrom @ field 3 and ContainingType @ field 5 are TypeRef.
- if (!fieldIsTypeRef(DbgNode, 3))
+ // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are TypeRef.
+ if (!fieldIsTypeRef(DbgNode, 9))
return false;
- if (!fieldIsTypeRef(DbgNode, 5))
+ if (!fieldIsTypeRef(DbgNode, 12))
return false;
- // Make sure the type identifier at field 7 is MDString, it can be null.
- if (!fieldIsMDString(DbgNode, 7))
+ // Make sure the type identifier at field 14 is MDString, it can be null.
+ if (!fieldIsMDString(DbgNode, 14))
return false;
// A subroutine type can't be both & and &&.
if (isLValueReference() && isRValueReference())
return false;
- return DbgNode->getNumOperands() == 8 && getNumHeaderFields() == 8;
+ return DbgNode->getNumOperands() == 15;
}
/// Verify - Verify that a subprogram descriptor is well formed.
@@ -552,20 +551,20 @@ bool DISubprogram::Verify() const {
if (!isSubprogram())
return false;
- // Make sure context @ field 2 is a ScopeRef and type @ field 3 is a MDNode.
+ // Make sure context @ field 2 is a ScopeRef and type @ field 7 is a MDNode.
if (!fieldIsScopeRef(DbgNode, 2))
return false;
- if (!fieldIsMDNode(DbgNode, 3))
+ if (!fieldIsMDNode(DbgNode, 7))
return false;
- // Containing type @ field 4.
- if (!fieldIsTypeRef(DbgNode, 4))
+ // Containing type @ field 12.
+ if (!fieldIsTypeRef(DbgNode, 12))
return false;
// A subprogram can't be both & and &&.
if (isLValueReference() && isRValueReference())
return false;
- return DbgNode->getNumOperands() == 9 && getNumHeaderFields() == 12;
+ return DbgNode->getNumOperands() == 20;
}
/// Verify - Verify that a global variable descriptor is well formed.
@@ -575,17 +574,17 @@ bool DIGlobalVariable::Verify() const {
if (getDisplayName().empty())
return false;
- // Make sure context @ field 1 is an MDNode.
- if (!fieldIsMDNode(DbgNode, 1))
+ // Make sure context @ field 2 is an MDNode.
+ if (!fieldIsMDNode(DbgNode, 2))
return false;
- // Make sure that type @ field 3 is a DITypeRef.
- if (!fieldIsTypeRef(DbgNode, 3))
+ // Make sure that type @ field 8 is a DITypeRef.
+ if (!fieldIsTypeRef(DbgNode, 8))
return false;
- // Make sure StaticDataMemberDeclaration @ field 5 is MDNode.
- if (!fieldIsMDNode(DbgNode, 5))
+ // Make sure StaticDataMemberDeclaration @ field 12 is MDNode.
+ if (!fieldIsMDNode(DbgNode, 12))
return false;
- return DbgNode->getNumOperands() == 6 && getNumHeaderFields() == 7;
+ return DbgNode->getNumOperands() == 13;
}
/// Verify - Verify that a variable descriptor is well formed.
@@ -596,21 +595,15 @@ bool DIVariable::Verify() const {
// 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;
-
- // Check the number of header fields, which is common between complex and
- // simple variables.
- if (getNumHeaderFields() != 4)
+ // Make sure that type @ field 5 is a DITypeRef.
+ if (!fieldIsTypeRef(DbgNode, 5))
return false;
// Variable without an inline location.
- if (DbgNode->getNumOperands() == 4)
+ if (DbgNode->getNumOperands() == 7)
return true;
- // Variable with an inline location.
- return getInlinedAt() != nullptr && DbgNode->getNumOperands() == 5;
+ return DbgNode->getNumOperands() == 8;
}
/// Verify - Verify that a variable descriptor is well formed.
@@ -619,7 +612,7 @@ bool DIExpression::Verify() const {
if (!DbgNode)
return true;
- return isExpression() && DbgNode->getNumOperands() == 1;
+ return isExpression();
}
/// Verify - Verify that a location descriptor is well formed.
@@ -634,7 +627,7 @@ bool DILocation::Verify() const {
bool DINameSpace::Verify() const {
if (!isNameSpace())
return false;
- return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 3;
+ return DbgNode->getNumOperands() == 5;
}
/// \brief Retrieve the MDNode for the directory/file pair.
@@ -647,53 +640,47 @@ bool DIFile::Verify() const {
/// \brief Verify that the enumerator descriptor is well formed.
bool DIEnumerator::Verify() const {
- return isEnumerator() && DbgNode->getNumOperands() == 1 &&
- getNumHeaderFields() == 3;
+ return isEnumerator() && DbgNode->getNumOperands() == 3;
}
/// \brief Verify that the subrange descriptor is well formed.
bool DISubrange::Verify() const {
- return isSubrange() && DbgNode->getNumOperands() == 1 &&
- getNumHeaderFields() == 3;
+ return isSubrange() && DbgNode->getNumOperands() == 3;
}
/// \brief Verify that the lexical block descriptor is well formed.
bool DILexicalBlock::Verify() const {
- return isLexicalBlock() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 4;
+ return isLexicalBlock() && DbgNode->getNumOperands() == 6;
}
/// \brief Verify that the file-scoped lexical block descriptor is well formed.
bool DILexicalBlockFile::Verify() const {
- return isLexicalBlockFile() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 2;
+ return isLexicalBlockFile() && DbgNode->getNumOperands() == 4;
}
/// \brief Verify that the template type parameter descriptor is well formed.
bool DITemplateTypeParameter::Verify() const {
- return isTemplateTypeParameter() && DbgNode->getNumOperands() == 4 &&
- getNumHeaderFields() == 4;
+ return isTemplateTypeParameter() && DbgNode->getNumOperands() == 7;
}
/// \brief Verify that the template value parameter descriptor is well formed.
bool DITemplateValueParameter::Verify() const {
- return isTemplateValueParameter() && DbgNode->getNumOperands() == 5 &&
- getNumHeaderFields() == 4;
+ return isTemplateValueParameter() && DbgNode->getNumOperands() == 8;
}
/// \brief Verify that the imported module descriptor is well formed.
bool DIImportedEntity::Verify() const {
- return isImportedEntity() && DbgNode->getNumOperands() == 3 &&
- getNumHeaderFields() == 3;
+ return isImportedEntity() &&
+ (DbgNode->getNumOperands() == 4 || DbgNode->getNumOperands() == 5);
}
/// getObjCProperty - Return property node, if this ivar is associated with one.
MDNode *DIDerivedType::getObjCProperty() const {
- return getNodeField(DbgNode, 4);
+ return getNodeField(DbgNode, 10);
}
MDString *DICompositeType::getIdentifier() const {
- return cast_or_null<MDString>(getField(DbgNode, 7));
+ return cast_or_null<MDString>(getField(DbgNode, 14));
}
#ifndef NDEBUG
@@ -717,13 +704,13 @@ void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
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)))
+ if (const MDNode *El = cast_or_null<MDNode>(N->getOperand(10)))
VerifySubsetOf(El, Elements);
#endif
- N->replaceOperandWith(4, Elements);
+ N->replaceOperandWith(10, Elements);
}
if (TParams)
- N->replaceOperandWith(6, TParams);
+ N->replaceOperandWith(13, TParams);
DbgNode = N;
}
@@ -741,7 +728,7 @@ DIScopeRef DIScope::getRef() const {
/// \brief Set the containing type.
void DICompositeType::setContainingType(DICompositeType ContainingType) {
TrackingVH<MDNode> N(*this);
- N->replaceOperandWith(5, ContainingType.getRef());
+ N->replaceOperandWith(12, ContainingType.getRef());
DbgNode = N;
}
@@ -770,16 +757,23 @@ bool DISubprogram::describes(const Function *F) {
return false;
}
+unsigned DISubprogram::isOptimized() const {
+ assert(DbgNode && "Invalid subprogram descriptor!");
+ if (DbgNode->getNumOperands() == 15)
+ return getUnsignedField(14);
+ return 0;
+}
+
MDNode *DISubprogram::getVariablesNodes() const {
- return getNodeField(DbgNode, 8);
+ return getNodeField(DbgNode, 18);
}
DIArray DISubprogram::getVariables() const {
- return DIArray(getNodeField(DbgNode, 8));
+ return DIArray(getNodeField(DbgNode, 18));
}
Value *DITemplateValueParameter::getValue() const {
- return getField(DbgNode, 3);
+ return getField(DbgNode, 4);
}
// If the current node has a parent scope then return that,
@@ -832,38 +826,38 @@ StringRef DIScope::getDirectory() const {
}
DIArray DICompileUnit::getEnumTypes() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
+ if (!DbgNode || DbgNode->getNumOperands() < 13)
return DIArray();
- return DIArray(getNodeField(DbgNode, 2));
+ return DIArray(getNodeField(DbgNode, 7));
}
DIArray DICompileUnit::getRetainedTypes() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
+ if (!DbgNode || DbgNode->getNumOperands() < 13)
return DIArray();
- return DIArray(getNodeField(DbgNode, 3));
+ return DIArray(getNodeField(DbgNode, 8));
}
DIArray DICompileUnit::getSubprograms() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
+ if (!DbgNode || DbgNode->getNumOperands() < 13)
return DIArray();
- return DIArray(getNodeField(DbgNode, 4));
+ return DIArray(getNodeField(DbgNode, 9));
}
DIArray DICompileUnit::getGlobalVariables() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
+ if (!DbgNode || DbgNode->getNumOperands() < 13)
return DIArray();
- return DIArray(getNodeField(DbgNode, 5));
+ return DIArray(getNodeField(DbgNode, 10));
}
DIArray DICompileUnit::getImportedEntities() const {
- if (!DbgNode || DbgNode->getNumOperands() < 7)
+ if (!DbgNode || DbgNode->getNumOperands() < 13)
return DIArray();
- return DIArray(getNodeField(DbgNode, 6));
+ return DIArray(getNodeField(DbgNode, 11));
}
/// copyWithNewScope - Return a copy of this location, replacing the
@@ -936,35 +930,21 @@ NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, DISubprogram Fn) {
/// @param InlinedScope Location at current variable is inlined.
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<Value *, 8> Elts;
- for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I)
- Elts.push_back(DV->getOperand(I));
- Elts.push_back(InlinedScope);
-
- DIVariable Inlined(MDNode::get(VMContext, Elts));
- assert(Inlined.Verify() && "Expected to create a DIVariable");
- return Inlined;
+ SmallVector<Value *, 16> Elts;
+ // Insert inlined scope as 7th element.
+ for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
+ i == 7 ? Elts.push_back(InlinedScope) : Elts.push_back(DV->getOperand(i));
+ return DIVariable(MDNode::get(VMContext, Elts));
}
/// cleanseInlinedVariable - Remove inlined scope from the variable.
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<Value *, 8> Elts;
- for (unsigned I = 0, E = DIVariableInlinedAtIndex; I != E; ++I)
- Elts.push_back(DV->getOperand(I));
-
- DIVariable Cleansed(MDNode::get(VMContext, Elts));
- assert(Cleansed.Verify() && "Expected to create a DIVariable");
- return Cleansed;
+ SmallVector<Value *, 16> Elts;
+ // Insert inlined scope as 7th element.
+ for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
+ i == 7 ? Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)))
+ : Elts.push_back(DV->getOperand(i));
+ return DIVariable(MDNode::get(VMContext, Elts));
}
/// getDISubprogram - Find subprogram that is enclosing this scope.
diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp
index 718da852fec..e8bdccebae9 100644
--- a/llvm/lib/IR/DebugLoc.cpp
+++ b/llvm/lib/IR/DebugLoc.cpp
@@ -79,8 +79,14 @@ MDNode *DebugLoc::getScopeNode(const LLVMContext &Ctx) const {
DebugLoc DebugLoc::getFnDebugLoc(const LLVMContext &Ctx) const {
const MDNode *Scope = getScopeNode(Ctx);
DISubprogram SP = getDISubprogram(Scope);
- if (SP.isSubprogram())
- return DebugLoc::get(SP.getScopeLineNumber(), 0, SP);
+ if (SP.isSubprogram()) {
+ // Check for number of operands since the compatibility is
+ // cheap here. FIXME: Name the magic constant.
+ if (SP->getNumOperands() > 19)
+ return DebugLoc::get(SP.getScopeLineNumber(), 0, SP);
+ else
+ return DebugLoc::get(SP.getLineNumber(), 0, SP);
+ }
return DebugLoc();
}
diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp
index 8a7c87911f6..e459a634dcf 100644
--- a/llvm/lib/Transforms/IPO/StripSymbols.cpp
+++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp
@@ -353,9 +353,11 @@ bool StripDeadDebugInfo::runOnModule(Module &M) {
// sure that an assert is hit if the location of the subprogram array
// changes. This is just to make sure that this is updated if such an
// event occurs.
- assert(DIC->getNumOperands() >= 5 && SPs == DIC->getOperand(4) &&
- "DICompileUnits is expected to store Subprograms in operand 4.");
- DIC->replaceOperandWith(4, MDNode::get(C, LiveSubprograms));
+ assert(DIC->getNumOperands() >= 10 &&
+ SPs == DIC->getOperand(9) &&
+ "DICompileUnits is expected to store Subprograms in operand "
+ "9.");
+ DIC->replaceOperandWith(9, MDNode::get(C, LiveSubprograms));
Changed = true;
}
@@ -364,10 +366,11 @@ bool StripDeadDebugInfo::runOnModule(Module &M) {
// make sure that an assert is hit if the location of the subprogram array
// changes. This is just to make sure that this index is updated if such
// an event occurs.
- assert(
- DIC->getNumOperands() >= 6 && GVs == DIC->getOperand(5) &&
- "DICompileUnits is expected to store Global Variables in operand 5.");
- DIC->replaceOperandWith(5, MDNode::get(C, LiveGlobalVariables));
+ assert(DIC->getNumOperands() >= 11 &&
+ GVs == DIC->getOperand(10) &&
+ "DICompileUnits is expected to store Global Variables in operand "
+ "10.");
+ DIC->replaceOperandWith(10, MDNode::get(C, LiveGlobalVariables));
Changed = true;
}
OpenPOWER on IntegriCloud