llvm.org GIT mirror llvm / ed0e117
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 Duncan P. N. Exon Smith 4 years ago
13 changed file(s) with 75 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
826826 void DebugInfo::emitLocation(ExprAST *AST) {
827827 if (!AST)
828828 return Builder.SetCurrentDebugLocation(DebugLoc());
829 DIScope *Scope;
829 MDScope *Scope;
830830 if (LexicalBlocks.empty())
831 Scope = &TheCU;
831 Scope = TheCU;
832832 else
833 Scope = LexicalBlocks.back();
833 Scope = *LexicalBlocks.back();
834834 Builder.SetCurrentDebugLocation(
835 DebugLoc::get(AST->getLine(), AST->getCol(), DIScope(*Scope)));
835 DebugLoc::get(AST->getLine(), AST->getCol(), Scope));
836836 }
837837
838838 static DICompositeType CreateFunctionType(unsigned NumArgs, DIFile Unit) {
12231223 AI->setName(Args[Idx]);
12241224
12251225 // Create a subprogram DIE for this function.
1226 DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
1227 KSDbgInfo.TheCU.getDirectory());
1228 DIDescriptor FContext(Unit);
1226 DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1227 KSDbgInfo.TheCU->getDirectory());
1228 DIDescriptor FContext = Unit;
12291229 unsigned LineNo = Line;
12301230 unsigned ScopeLine = Line;
12311231 DISubprogram SP = DBuilder->createFunction(
12471247
12481248 // Create a debug descriptor for the variable.
12491249 DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
1250 DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
1251 KSDbgInfo.TheCU.getDirectory());
1250 DIFile Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1251 KSDbgInfo.TheCU->getDirectory());
12521252 DIVariable D = DBuilder->createLocalVariable(dwarf::DW_TAG_arg_variable,
12531253 *Scope, Args[Idx], Unit, Line,
12541254 KSDbgInfo.getDoubleTy(), Idx);
12551255
1256 Instruction *Call = DBuilder->insertDeclare(
1257 Alloca, D, DBuilder->createExpression(), Builder.GetInsertBlock());
1258 Call->setDebugLoc(DebugLoc::get(Line, 0, *Scope));
1256 DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(),
1257 DebugLoc::get(Line, 0, *Scope),
1258 Builder.GetInsertBlock());
12591259
12601260 // Store the initial value into the alloca.
12611261 Builder.CreateStore(AI, Alloca);
373373 MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
374374 };
375375
376 /// \brief This is a wrapper for a file.
377 class DIFile : public DIScope {
378 public:
379 DIFile() = default;
380 DIFile(const MDFile *N) : DIScope(N) {}
381
382 MDFile *get() const { return cast_or_null(DIDescriptor::get()); }
383 operator MDFile *() const { return get(); }
384 MDFile *operator->() const { return get(); }
385 MDFile &operator*() const { return *get(); }
386
387 /// \brief Retrieve the MDNode for the directory/file pair.
388 MDNode *getFileNode() const { return get(); }
389 };
390
391 /// \brief A wrapper for a compile unit.
392 class DICompileUnit : public DIScope {
393 public:
394 DICompileUnit() = default;
395 DICompileUnit(const MDCompileUnit *N) : DIScope(N) {}
396
397 MDCompileUnit *get() const {
398 return cast_or_null(DIDescriptor::get());
399 }
400 operator MDCompileUnit *() const { return get(); }
401 MDCompileUnit *operator->() const { return get(); }
402 MDCompileUnit &operator*() const { return *get(); }
403
404 dwarf::SourceLanguage getLanguage() const {
405 return static_cast(get()->getSourceLanguage());
406 }
407 StringRef getProducer() const { return get()->getProducer(); }
408 bool isOptimized() const { return get()->isOptimized(); }
409 StringRef getFlags() const { return get()->getFlags(); }
410 unsigned getRunTimeVersion() const { return get()->getRuntimeVersion(); }
411
412 DIArray getEnumTypes() const { return get()->getEnumTypes(); }
413 DIArray getRetainedTypes() const { return get()->getRetainedTypes(); }
414 DIArray getSubprograms() const { return get()->getSubprograms(); }
415 DIArray getGlobalVariables() const { return get()->getGlobalVariables(); }
416 DIArray getImportedEntities() const { return get()->getImportedEntities(); }
417
418 void replaceSubprograms(MDSubprogramArray Subprograms) const {
419 get()->replaceSubprograms(Subprograms);
420 }
421 void replaceGlobalVariables(MDGlobalVariableArray GlobalVariables) const {
422 get()->replaceGlobalVariables(GlobalVariables);
423 }
424
425 StringRef getSplitDebugFilename() const {
426 return get()->getSplitDebugFilename();
427 }
428 unsigned getEmissionKind() const { return get()->getEmissionKind(); }
376 class DIFile {
377 MDFile *N;
378
379 public:
380 DIFile(const MDFile *N = nullptr) : N(const_cast(N)) {}
381
382 operator DIDescriptor() const { return N; }
383 operator DIScope() const { return N; }
384 operator MDFile *() const { return N; }
385 MDFile *operator->() const { return N; }
386 MDFile &operator*() const { return *N; }
387 };
388
389 class DICompileUnit {
390 MDCompileUnit *N;
391
392 public:
393 DICompileUnit(const MDCompileUnit *N = nullptr)
394 : N(const_cast(N)) {}
395
396 operator DIDescriptor() const { return N; }
397 operator DIScope() const { return N; }
398 operator MDCompileUnit *() const { return N; }
399 MDCompileUnit *operator->() const { return N; }
400 MDCompileUnit &operator*() const { return *N; }
429401 };
430402
431403 class DISubprogram {
7171 // Printing the nodes directly isn't particularly helpful (since they
7272 // reference other nodes that won't be printed, particularly for the
7373 // filenames), so just print a few useful things.
74 for (DICompileUnit CU : Finder.compile_units()) {
74 for (MDCompileUnit *CU : Finder.compile_units()) {
7575 O << "Compile unit: ";
76 if (const char *Lang = LanguageString(CU.getLanguage()))
76 if (const char *Lang = dwarf::LanguageString(CU->getSourceLanguage()))
7777 O << Lang;
7878 else
79 O << "unknown-language(" << CU.getLanguage() << ")";
80 printFile(O, CU.getFilename(), CU.getDirectory());
79 O << "unknown-language(" << CU->getSourceLanguage() << ")";
80 printFile(O, CU->getFilename(), CU->getDirectory());
8181 O << '\n';
8282 }
8383
818818 }
819819
820820 bool DwarfCompileUnit::includeMinimalInlineScopes() const {
821 return getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly ||
821 return getCUNode()->getEmissionKind() == DIBuilder::LineTablesOnly ||
822822 (DD->useSplitDwarf() && !Skeleton);
823823 }
824824 } // end llvm namespace
362362 // Create new DwarfCompileUnit for the given metadata node with tag
363363 // DW_TAG_compile_unit.
364364 DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
365 StringRef FN = DIUnit.getFilename();
366 CompilationDir = DIUnit.getDirectory();
365 StringRef FN = DIUnit->getFilename();
366 CompilationDir = DIUnit->getDirectory();
367367
368368 auto OwnedUnit = make_unique(
369369 InfoHolder.getUnits().size(), DIUnit, Asm, this, &InfoHolder);
381381 Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
382382 NewCU.getUniqueID(), CompilationDir);
383383
384 NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
384 NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit->getProducer());
385385 NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
386 DIUnit.getLanguage());
386 DIUnit->getSourceLanguage());
387387 NewCU.addString(Die, dwarf::DW_AT_name, FN);
388388
389389 if (!useSplitDwarf()) {
397397 addGnuPubAttributes(NewCU, Die);
398398 }
399399
400 if (DIUnit.isOptimized())
400 if (DIUnit->isOptimized())
401401 NewCU.addFlag(Die, dwarf::DW_AT_APPLE_optimized);
402402
403 StringRef Flags = DIUnit.getFlags();
403 StringRef Flags = DIUnit->getFlags();
404404 if (!Flags.empty())
405405 NewCU.addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
406406
407 if (unsigned RVer = DIUnit.getRunTimeVersion())
407 if (unsigned RVer = DIUnit->getRuntimeVersion())
408408 NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
409409 dwarf::DW_FORM_data1, RVer);
410410
11931193
11941194 // Under -gmlt, skip building the subprogram if there are no inlined
11951195 // subroutines inside it.
1196 if (TheCU.getCUNode().getEmissionKind() == DIBuilder::LineTablesOnly &&
1196 if (TheCU.getCUNode()->getEmissionKind() == DIBuilder::LineTablesOnly &&
11971197 LScopes.getAbstractScopesList().empty() && !IsDarwin) {
11981198 assert(InfoHolder.getScopeVariables().empty());
11991199 assert(DbgValues.empty());
18231823 void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die,
18241824 std::unique_ptr NewU) {
18251825 NewU->addString(Die, dwarf::DW_AT_GNU_dwo_name,
1826 U.getCUNode().getSplitDebugFilename());
1826 U.getCUNode()->getSplitDebugFilename());
18271827
18281828 if (!CompilationDir.empty())
18291829 NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
18871887 if (!useSplitDwarf())
18881888 return nullptr;
18891889 if (SingleCU)
1890 SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode().getDirectory());
1890 SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode()->getDirectory());
18911891 return &SplitTypeUnitFileTable;
18921892 }
18931893
140140 // Accessors.
141141 AsmPrinter* getAsmPrinter() const { return Asm; }
142142 unsigned getUniqueID() const { return UniqueID; }
143 uint16_t getLanguage() const { return CUNode.getLanguage(); }
143 uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
144144 DICompileUnit getCUNode() const { return CUNode; }
145145 DIE &getUnitDie() { return UnitDie; }
146146
678678 "function types should be subroutines");
679679 auto *Node = MDSubprogram::get(
680680 VMContext, MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
681 Name, LinkageName, File.get(), LineNo,
682 cast_or_null(Ty.get()), isLocalToUnit, isDefinition,
683 ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
684 cast_or_null(TParams), cast_or_null(Decl),
681 Name, LinkageName, File, LineNo, cast_or_null(Ty.get()),
682 isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
683 Fn, cast_or_null(TParams), cast_or_null(Decl),
685684 MDTuple::getTemporary(VMContext, None).release());
686685
687686 if (isDefinition)
701700 return MDSubprogram::getTemporary(
702701 VMContext,
703702 MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), Name,
704 LinkageName, File.get(), LineNo,
703 LinkageName, File, LineNo,
705704 cast_or_null(Ty.get()), isLocalToUnit,
706705 isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
707706 cast_or_null(TParams), cast_or_null(Decl),
708 nullptr).release();
707 nullptr)
708 .release();
709709 }
710710
711711 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
723723 "the compile unit.");
724724 // FIXME: Do we want to use different scope/lines?
725725 auto *SP = MDSubprogram::get(
726 VMContext, MDScopeRef::get(cast(Context)), Name, LinkageName,
727 F.get(), LineNo, cast_or_null(Ty.get()), isLocalToUnit,
726 VMContext, MDScopeRef::get(cast(Context)), Name, LinkageName, F,
727 LineNo, cast_or_null(Ty.get()), isLocalToUnit,
728728 isDefinition, LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags,
729729 isOptimized, Fn, cast_or_null(TParam), nullptr, nullptr);
730730
743743 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
744744 DIFile File,
745745 unsigned Discriminator) {
746 return MDLexicalBlockFile::get(VMContext, Scope, File.getFileNode(),
747 Discriminator);
746 return MDLexicalBlockFile::get(VMContext, Scope, File, Discriminator);
748747 }
749748
750749 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
752751 // Make these distinct, to avoid merging two lexical blocks on the same
753752 // file/line/column.
754753 return MDLexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
755 File.getFileNode(), Line, Col);
754 File, Line, Col);
756755 }
757756
758757 static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
7777 llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
7878 DITypeIdentifierMap Map;
7979 for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
80 DICompileUnit CU = cast(CU_Nodes->getOperand(CUi));
81 DIArray Retain = CU.getRetainedTypes();
80 auto *CU = cast(CU_Nodes->getOperand(CUi));
81 DIArray Retain = CU->getRetainedTypes();
8282 for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) {
8383 if (!isa(Retain[Ti]))
8484 continue;
772772 DbgFinder.processModule(M);
773773
774774 unsigned i = 1;
775 for (DICompileUnit DIUnit : DbgFinder.compile_units()) {
776 StringRef Filename(DIUnit.getFilename());
777 StringRef Dirname(DIUnit.getDirectory());
775 for (const MDCompileUnit *DIUnit : DbgFinder.compile_units()) {
776 StringRef Filename = DIUnit->getFilename();
777 StringRef Dirname = DIUnit->getDirectory();
778778 SmallString<128> FullPathName = Dirname;
779779 if (!Dirname.empty() && !sys::path::is_absolute(Filename)) {
780780 sys::path::append(FullPathName, Filename);
304304 SmallVector LiveSubprograms;
305305 DenseSet VisitedSet;
306306
307 for (DICompileUnit DIC : F.compile_units()) {
307 for (MDCompileUnit *DIC : F.compile_units()) {
308308 // Create our live subprogram list.
309309 MDSubprogramArray SPs = DIC->getSubprograms();
310310 bool SubprogramChange = false;
344344 // subprogram list/global variable list with our new live subprogram/global
345345 // variable list.
346346 if (SubprogramChange) {
347 DIC.replaceSubprograms(MDTuple::get(C, LiveSubprograms));
347 DIC->replaceSubprograms(MDTuple::get(C, LiveSubprograms));
348348 Changed = true;
349349 }
350350
351351 if (GlobalVariableChange) {
352 DIC.replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables));
352 DIC->replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables));
353353 Changed = true;
354354 }
355355
436436 }
437437 }
438438
439 SmallString<128> Filename = CU.getFilename();
439 SmallString<128> Filename = CU->getFilename();
440440 sys::path::replace_extension(Filename, NewStem);
441441 StringRef FName = sys::path::filename(Filename);
442442 SmallString<128> CurPath;
170170 for (auto *SP : SPs)
171171 NewSPs.push_back(SP);
172172 NewSPs.push_back(NewSP);
173 CU.replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs));
173 CU->replaceSubprograms(MDTuple::get(CU->getContext(), NewSPs));
174174 }
175175
176176 // Clone the module-level debug info associated with OldFunc. The cloned data
321321 DICompileUnit CU1 = cast(*Iter);
322322 Iter++;
323323 DICompileUnit CU2 = cast(*Iter);
324 EXPECT_TRUE(CU1.getSubprograms().size() == 0 ||
325 CU2.getSubprograms().size() == 0);
324 EXPECT_TRUE(CU1->getSubprograms().size() == 0 ||
325 CU2->getSubprograms().size() == 0);
326326 }
327327
328328 // Test that instructions in the old function still belong to it in the