1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

DebugInfo: Gut DICompileUnit and DIFile

Continuing gutting `DIDescriptor` subclasses; this edition,
`DICompileUnit` and `DIFile`.  In the name of PR23080.

llvm-svn: 235055
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-15 23:19:27 +00:00
parent 17e5601b85
commit d7810b7970
13 changed files with 69 additions and 98 deletions

View File

@ -827,13 +827,13 @@ DIType DebugInfo::getDoubleTy() {
void DebugInfo::emitLocation(ExprAST *AST) {
if (!AST)
return Builder.SetCurrentDebugLocation(DebugLoc());
DIScope *Scope;
MDScope *Scope;
if (LexicalBlocks.empty())
Scope = &TheCU;
Scope = TheCU;
else
Scope = LexicalBlocks.back();
Scope = *LexicalBlocks.back();
Builder.SetCurrentDebugLocation(
DebugLoc::get(AST->getLine(), AST->getCol(), DIScope(*Scope)));
DebugLoc::get(AST->getLine(), AST->getCol(), Scope));
}
static DICompositeType CreateFunctionType(unsigned NumArgs, DIFile Unit) {
@ -1224,9 +1224,9 @@ Function *PrototypeAST::Codegen() {
AI->setName(Args[Idx]);
// Create a subprogram DIE for this function.
DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
KSDbgInfo.TheCU.getDirectory());
DIDescriptor FContext(Unit);
DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
KSDbgInfo.TheCU->getDirectory());
DIDescriptor FContext = Unit;
unsigned LineNo = Line;
unsigned ScopeLine = Line;
DISubprogram SP = DBuilder->createFunction(
@ -1248,15 +1248,15 @@ void PrototypeAST::CreateArgumentAllocas(Function *F) {
// Create a debug descriptor for the variable.
DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
KSDbgInfo.TheCU.getDirectory());
DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
KSDbgInfo.TheCU->getDirectory());
DIVariable D = DBuilder->createLocalVariable(dwarf::DW_TAG_arg_variable,
*Scope, Args[Idx], Unit, Line,
KSDbgInfo.getDoubleTy(), Idx);
Instruction *Call = DBuilder->insertDeclare(
Alloca, D, DBuilder->createExpression(), Builder.GetInsertBlock());
Call->setDebugLoc(DebugLoc::get(Line, 0, *Scope));
DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(),
DebugLoc::get(Line, 0, *Scope),
Builder.GetInsertBlock());
// Store the initial value into the alloca.
Builder.CreateStore(AI, Alloca);

View File

@ -374,59 +374,31 @@ public:
MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
};
/// \brief This is a wrapper for a file.
class DIFile : public DIScope {
class DIFile {
MDFile *N;
public:
DIFile() = default;
DIFile(const MDFile *N) : DIScope(N) {}
DIFile(const MDFile *N = nullptr) : N(const_cast<MDFile *>(N)) {}
MDFile *get() const { return cast_or_null<MDFile>(DIDescriptor::get()); }
operator MDFile *() const { return get(); }
MDFile *operator->() const { return get(); }
MDFile &operator*() const { return *get(); }
/// \brief Retrieve the MDNode for the directory/file pair.
MDNode *getFileNode() const { return get(); }
operator DIDescriptor() const { return N; }
operator DIScope() const { return N; }
operator MDFile *() const { return N; }
MDFile *operator->() const { return N; }
MDFile &operator*() const { return *N; }
};
/// \brief A wrapper for a compile unit.
class DICompileUnit : public DIScope {
class DICompileUnit {
MDCompileUnit *N;
public:
DICompileUnit() = default;
DICompileUnit(const MDCompileUnit *N) : DIScope(N) {}
DICompileUnit(const MDCompileUnit *N = nullptr)
: N(const_cast<MDCompileUnit *>(N)) {}
MDCompileUnit *get() const {
return cast_or_null<MDCompileUnit>(DIDescriptor::get());
}
operator MDCompileUnit *() const { return get(); }
MDCompileUnit *operator->() const { return get(); }
MDCompileUnit &operator*() const { return *get(); }
dwarf::SourceLanguage getLanguage() const {
return static_cast<dwarf::SourceLanguage>(get()->getSourceLanguage());
}
StringRef getProducer() const { return get()->getProducer(); }
bool isOptimized() const { return get()->isOptimized(); }
StringRef getFlags() const { return get()->getFlags(); }
unsigned getRunTimeVersion() const { return get()->getRuntimeVersion(); }
DIArray getEnumTypes() const { return get()->getEnumTypes(); }
DIArray getRetainedTypes() const { return get()->getRetainedTypes(); }
DIArray getSubprograms() const { return get()->getSubprograms(); }
DIArray getGlobalVariables() const { return get()->getGlobalVariables(); }
DIArray getImportedEntities() const { return get()->getImportedEntities(); }
void replaceSubprograms(MDSubprogramArray Subprograms) const {
get()->replaceSubprograms(Subprograms);
}
void replaceGlobalVariables(MDGlobalVariableArray GlobalVariables) const {
get()->replaceGlobalVariables(GlobalVariables);
}
StringRef getSplitDebugFilename() const {
return get()->getSplitDebugFilename();
}
unsigned getEmissionKind() const { return get()->getEmissionKind(); }
operator DIDescriptor() const { return N; }
operator DIScope() const { return N; }
operator MDCompileUnit *() const { return N; }
MDCompileUnit *operator->() const { return N; }
MDCompileUnit &operator*() const { return *N; }
};
class DISubprogram {

View File

@ -72,13 +72,13 @@ void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
// Printing the nodes directly isn't particularly helpful (since they
// reference other nodes that won't be printed, particularly for the
// filenames), so just print a few useful things.
for (DICompileUnit CU : Finder.compile_units()) {
for (MDCompileUnit *CU : Finder.compile_units()) {
O << "Compile unit: ";
if (const char *Lang = LanguageString(CU.getLanguage()))
if (const char *Lang = dwarf::LanguageString(CU->getSourceLanguage()))
O << Lang;
else
O << "unknown-language(" << CU.getLanguage() << ")";
printFile(O, CU.getFilename(), CU.getDirectory());
O << "unknown-language(" << CU->getSourceLanguage() << ")";
printFile(O, CU->getFilename(), CU->getDirectory());
O << '\n';
}

View File

@ -819,7 +819,7 @@ bool DwarfCompileUnit::isDwoUnit() const {
}
bool DwarfCompileUnit::includeMinimalInlineScopes() const {
return getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly ||
return getCUNode()->getEmissionKind() == DIBuilder::LineTablesOnly ||
(DD->useSplitDwarf() && !Skeleton);
}
} // end llvm namespace

View File

@ -363,8 +363,8 @@ void DwarfDebug::addGnuPubAttributes(DwarfUnit &U, DIE &D) const {
// Create new DwarfCompileUnit for the given metadata node with tag
// DW_TAG_compile_unit.
DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
StringRef FN = DIUnit.getFilename();
CompilationDir = DIUnit.getDirectory();
StringRef FN = DIUnit->getFilename();
CompilationDir = DIUnit->getDirectory();
auto OwnedUnit = make_unique<DwarfCompileUnit>(
InfoHolder.getUnits().size(), DIUnit, Asm, this, &InfoHolder);
@ -382,9 +382,9 @@ DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
NewCU.getUniqueID(), CompilationDir);
NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit->getProducer());
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
DIUnit.getLanguage());
DIUnit->getSourceLanguage());
NewCU.addString(Die, dwarf::DW_AT_name, FN);
if (!useSplitDwarf()) {
@ -398,14 +398,14 @@ DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
addGnuPubAttributes(NewCU, Die);
}
if (DIUnit.isOptimized())
if (DIUnit->isOptimized())
NewCU.addFlag(Die, dwarf::DW_AT_APPLE_optimized);
StringRef Flags = DIUnit.getFlags();
StringRef Flags = DIUnit->getFlags();
if (!Flags.empty())
NewCU.addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
if (unsigned RVer = DIUnit.getRunTimeVersion())
if (unsigned RVer = DIUnit->getRuntimeVersion())
NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
dwarf::DW_FORM_data1, RVer);
@ -1194,7 +1194,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
// Under -gmlt, skip building the subprogram if there are no inlined
// subroutines inside it.
if (TheCU.getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly &&
if (TheCU.getCUNode()->getEmissionKind() == DIBuilder::LineTablesOnly &&
LScopes.getAbstractScopesList().empty() && !IsDarwin) {
assert(InfoHolder.getScopeVariables().empty());
assert(DbgValues.empty());
@ -1824,7 +1824,7 @@ void DwarfDebug::emitDebugRanges() {
void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die,
std::unique_ptr<DwarfUnit> NewU) {
NewU->addString(Die, dwarf::DW_AT_GNU_dwo_name,
U.getCUNode().getSplitDebugFilename());
U.getCUNode()->getSplitDebugFilename());
if (!CompilationDir.empty())
NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
@ -1888,7 +1888,7 @@ MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
if (!useSplitDwarf())
return nullptr;
if (SingleCU)
SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode().getDirectory());
SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode()->getDirectory());
return &SplitTypeUnitFileTable;
}

View File

@ -141,7 +141,7 @@ public:
// Accessors.
AsmPrinter* getAsmPrinter() const { return Asm; }
unsigned getUniqueID() const { return UniqueID; }
uint16_t getLanguage() const { return CUNode.getLanguage(); }
uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
DICompileUnit getCUNode() const { return CUNode; }
DIE &getUnitDie() { return UnitDie; }

View File

@ -679,10 +679,9 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
"function types should be subroutines");
auto *Node = MDSubprogram::get(
VMContext, MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
Name, LinkageName, File.get(), LineNo,
cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit, isDefinition,
ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
Name, LinkageName, File, LineNo, cast_or_null<MDSubroutineType>(Ty.get()),
isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
Fn, cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
MDTuple::getTemporary(VMContext, None).release());
if (isDefinition)
@ -702,11 +701,12 @@ DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
return MDSubprogram::getTemporary(
VMContext,
MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), Name,
LinkageName, File.get(), LineNo,
LinkageName, File, LineNo,
cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
nullptr).release();
nullptr)
.release();
}
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
@ -724,8 +724,8 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
"the compile unit.");
// FIXME: Do we want to use different scope/lines?
auto *SP = MDSubprogram::get(
VMContext, MDScopeRef::get(cast<MDScope>(Context)), Name, LinkageName,
F.get(), LineNo, cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
VMContext, MDScopeRef::get(cast<MDScope>(Context)), Name, LinkageName, F,
LineNo, cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
isDefinition, LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags,
isOptimized, Fn, cast_or_null<MDTuple>(TParam), nullptr, nullptr);
@ -744,8 +744,7 @@ DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
DIFile File,
unsigned Discriminator) {
return MDLexicalBlockFile::get(VMContext, Scope, File.getFileNode(),
Discriminator);
return MDLexicalBlockFile::get(VMContext, Scope, File, Discriminator);
}
DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
@ -753,7 +752,7 @@ DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
// Make these distinct, to avoid merging two lexical blocks on the same
// file/line/column.
return MDLexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
File.getFileNode(), Line, Col);
File, Line, Col);
}
static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {

View File

@ -78,8 +78,8 @@ DITypeIdentifierMap
llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
DITypeIdentifierMap Map;
for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(CUi));
DIArray Retain = CU.getRetainedTypes();
auto *CU = cast<MDCompileUnit>(CU_Nodes->getOperand(CUi));
DIArray Retain = CU->getRetainedTypes();
for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) {
if (!isa<MDCompositeType>(Retain[Ti]))
continue;

View File

@ -773,9 +773,9 @@ void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) {
DbgFinder.processModule(M);
unsigned i = 1;
for (DICompileUnit DIUnit : DbgFinder.compile_units()) {
StringRef Filename(DIUnit.getFilename());
StringRef Dirname(DIUnit.getDirectory());
for (const MDCompileUnit *DIUnit : DbgFinder.compile_units()) {
StringRef Filename = DIUnit->getFilename();
StringRef Dirname = DIUnit->getDirectory();
SmallString<128> FullPathName = Dirname;
if (!Dirname.empty() && !sys::path::is_absolute(Filename)) {
sys::path::append(FullPathName, Filename);

View File

@ -305,7 +305,7 @@ bool StripDeadDebugInfo::runOnModule(Module &M) {
SmallVector<Metadata *, 64> LiveSubprograms;
DenseSet<const MDNode *> VisitedSet;
for (DICompileUnit DIC : F.compile_units()) {
for (MDCompileUnit *DIC : F.compile_units()) {
// Create our live subprogram list.
MDSubprogramArray SPs = DIC->getSubprograms();
bool SubprogramChange = false;
@ -345,12 +345,12 @@ bool StripDeadDebugInfo::runOnModule(Module &M) {
// subprogram list/global variable list with our new live subprogram/global
// variable list.
if (SubprogramChange) {
DIC.replaceSubprograms(MDTuple::get(C, LiveSubprograms));
DIC->replaceSubprograms(MDTuple::get(C, LiveSubprograms));
Changed = true;
}
if (GlobalVariableChange) {
DIC.replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables));
DIC->replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables));
Changed = true;
}

View File

@ -437,7 +437,7 @@ std::string GCOVProfiler::mangleName(DICompileUnit CU, const char *NewStem) {
}
}
SmallString<128> Filename = CU.getFilename();
SmallString<128> Filename = CU->getFilename();
sys::path::replace_extension(Filename, NewStem);
StringRef FName = sys::path::filename(Filename);
SmallString<128> CurPath;

View File

@ -171,7 +171,7 @@ static void AddOperand(DICompileUnit CU, MDSubprogramArray SPs, Metadata *NewSP)
for (auto *SP : SPs)
NewSPs.push_back(SP);
NewSPs.push_back(NewSP);
CU.replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs));
CU->replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs));
}
// Clone the module-level debug info associated with OldFunc. The cloned data

View File

@ -322,8 +322,8 @@ TEST_F(CloneFunc, SubprogramInRightCU) {
DICompileUnit CU1 = cast<MDCompileUnit>(*Iter);
Iter++;
DICompileUnit CU2 = cast<MDCompileUnit>(*Iter);
EXPECT_TRUE(CU1.getSubprograms().size() == 0 ||
CU2.getSubprograms().size() == 0);
EXPECT_TRUE(CU1->getSubprograms().size() == 0 ||
CU2->getSubprograms().size() == 0);
}
// Test that instructions in the old function still belong to it in the