From: Duncan P. N. Exon Smith Date: Wed, 15 Apr 2015 23:19:27 +0000 (+0000) Subject: DebugInfo: Gut DICompileUnit and DIFile X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ed0e117ff38559aba99eb7a02187e3bf07e55488;p=oota-llvm.git DebugInfo: Gut DICompileUnit and DIFile Continuing gutting `DIDescriptor` subclasses; this edition, `DICompileUnit` and `DIFile`. In the name of PR23080. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235055 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/examples/Kaleidoscope/Chapter8/toy.cpp b/examples/Kaleidoscope/Chapter8/toy.cpp index 2838d6df593..5ffc4ca55b3 100644 --- a/examples/Kaleidoscope/Chapter8/toy.cpp +++ b/examples/Kaleidoscope/Chapter8/toy.cpp @@ -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); diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index cf7b5e0b8da..83fa3fbf228 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -374,59 +374,31 @@ public: MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); } }; -/// \brief This is a wrapper for a file. -class DIFile : public DIScope { -public: - DIFile() = default; - DIFile(const MDFile *N) : DIScope(N) {} +class DIFile { + MDFile *N; - MDFile *get() const { return cast_or_null(DIDescriptor::get()); } - operator MDFile *() const { return get(); } - MDFile *operator->() const { return get(); } - MDFile &operator*() const { return *get(); } +public: + DIFile(const MDFile *N = nullptr) : N(const_cast(N)) {} - /// \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 { -public: - DICompileUnit() = default; - DICompileUnit(const MDCompileUnit *N) : DIScope(N) {} - - MDCompileUnit *get() const { - return cast_or_null(DIDescriptor::get()); - } - operator MDCompileUnit *() const { return get(); } - MDCompileUnit *operator->() const { return get(); } - MDCompileUnit &operator*() const { return *get(); } +class DICompileUnit { + MDCompileUnit *N; - dwarf::SourceLanguage getLanguage() const { - return static_cast(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); - } +public: + DICompileUnit(const MDCompileUnit *N = nullptr) + : N(const_cast(N)) {} - 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 { diff --git a/lib/Analysis/ModuleDebugInfoPrinter.cpp b/lib/Analysis/ModuleDebugInfoPrinter.cpp index 1b50bf02570..c8e5c37ccfd 100644 --- a/lib/Analysis/ModuleDebugInfoPrinter.cpp +++ b/lib/Analysis/ModuleDebugInfoPrinter.cpp @@ -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'; } diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index ee52a6eb1ad..81056cb3a39 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -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 diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 665b9824a2a..3784c851e05 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -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( 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 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; } diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h index 3063f9e246e..a7378738d67 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -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; } diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 654dafca1b9..49358d67d84 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -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(Ty.get()), isLocalToUnit, isDefinition, - ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn, - cast_or_null(TParams), cast_or_null(Decl), + Name, LinkageName, File, LineNo, cast_or_null(Ty.get()), + isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, + Fn, cast_or_null(TParams), cast_or_null(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(Ty.get()), isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn, cast_or_null(TParams), cast_or_null(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(Context)), Name, LinkageName, - F.get(), LineNo, cast_or_null(Ty.get()), isLocalToUnit, + VMContext, MDScopeRef::get(cast(Context)), Name, LinkageName, F, + LineNo, cast_or_null(Ty.get()), isLocalToUnit, isDefinition, LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags, isOptimized, Fn, cast_or_null(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) { diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 3e34572c044..f396721efec 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -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(CU_Nodes->getOperand(CUi)); - DIArray Retain = CU.getRetainedTypes(); + auto *CU = cast(CU_Nodes->getOperand(CUi)); + DIArray Retain = CU->getRetainedTypes(); for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) { if (!isa(Retain[Ti])) continue; diff --git a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index 6c9092ee560..20f5b434bbf 100644 --- a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -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); diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp index 39d8e7619de..ad7c5a08765 100644 --- a/lib/Transforms/IPO/StripSymbols.cpp +++ b/lib/Transforms/IPO/StripSymbols.cpp @@ -305,7 +305,7 @@ bool StripDeadDebugInfo::runOnModule(Module &M) { SmallVector LiveSubprograms; DenseSet 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; } diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 5791ae10e85..368a81d7aba 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -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; diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index f5ca7ac9efd..f200b588194 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -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 diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp index b56d453997f..ca68bb83d6d 100644 --- a/unittests/Transforms/Utils/Cloning.cpp +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -322,8 +322,8 @@ TEST_F(CloneFunc, SubprogramInRightCU) { DICompileUnit CU1 = cast(*Iter); Iter++; DICompileUnit CU2 = cast(*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