llvm.org GIT mirror llvm / 1ac3fba
Remove llvm::getDISubprogram in favor of Function::getSubprogram llvm::getDISubprogram walks the instructions in a function, looking for one in the scope of the current function, so that it can find the !dbg entry for the subprogram itself. Now that !dbg is attached to functions, this should not be necessary. This patch changes all uses to just query the subprogram directly on the function. Ideally this should be NFC, but in reality its possible that a function: has no !dbg (in which case there's likely a bug somewhere in an opt pass), or that none of the instructions had a scope referencing the function, so we used to not find the !dbg on the function but now we will Reviewed by Duncan Exon Smith. Differential Revision: http://reviews.llvm.org/D18074 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263184 91177308-0d34-0410-b5e6-96231b3b80d8 Pete Cooper 3 years ago
8 changed file(s) with 9 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
3737
3838 /// \brief Find subprogram that is enclosing this scope.
3939 DISubprogram *getDISubprogram(const MDNode *Scope);
40
41 /// \brief Find debug info for a given function.
42 ///
43 /// \returns a valid subprogram, if found. Otherwise, return \c nullptr.
44 DISubprogram *getDISubprogram(const Function *F);
4540
4641 /// \brief Generate map by visiting all retained types.
4742 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
411411 assert(Fn);
412412
413413 StringRef FuncName;
414 if (auto *SP = getDISubprogram(GV))
414 if (auto *SP = GV->getSubprogram())
415415 FuncName = SP->getDisplayName();
416416
417417 // If our DISubprogram name is empty, use the mangled name.
751751 assert(FnDebugInfo.count(GV));
752752 assert(CurFn == &FnDebugInfo[GV]);
753753
754 collectVariableInfo(getDISubprogram(GV));
754 collectVariableInfo(GV->getSubprogram());
755755
756756 DebugHandlerBase::endFunction(MF);
757757
3434 DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
3535 if (auto *LocalScope = dyn_cast_or_null(Scope))
3636 return LocalScope->getSubprogram();
37 return nullptr;
38 }
39
40 DISubprogram *llvm::getDISubprogram(const Function *F) {
41 // We look for the first instr that has a debug annotation leading back to F.
42 for (auto &BB : *F) {
43 auto Inst = std::find_if(BB.begin(), BB.end(), [](const Instruction &Inst) {
44 return Inst.getDebugLoc();
45 });
46 if (Inst == BB.end())
47 continue;
48 DebugLoc DLoc = Inst->getDebugLoc();
49 const MDNode *Scope = DLoc.getInlinedAtScope();
50 auto *Subprogram = getDISubprogram(Scope);
51 return Subprogram->describes(F) ? Subprogram : nullptr;
52 }
53
5437 return nullptr;
5538 }
5639
10751075 /// \returns the line number where \p F is defined. If it returns 0,
10761076 /// it means that there is no debug information available for \p F.
10771077 unsigned SampleProfileLoader::getFunctionLoc(Function &F) {
1078 if (DISubprogram *S = getDISubprogram(&F))
1078 if (DISubprogram *S = F.getSubprogram())
10791079 return S->getLine();
10801080
10811081 // If the start of \p F is missing, emit a diagnostic to inform the user
11811181 unsigned Coverage = CoverageTracker.computeCoverage(Used, Total);
11821182 if (Coverage < SampleProfileRecordCoverage) {
11831183 F.getContext().diagnose(DiagnosticInfoSampleProfile(
1184 getDISubprogram(&F)->getFilename(), getFunctionLoc(F),
1184 F.getSubprogram()->getFilename(), getFunctionLoc(F),
11851185 Twine(Used) + " of " + Twine(Total) + " available profile records (" +
11861186 Twine(Coverage) + "%) were applied",
11871187 DS_Warning));
11941194 unsigned Coverage = CoverageTracker.computeCoverage(Used, Total);
11951195 if (Coverage < SampleProfileSampleCoverage) {
11961196 F.getContext().diagnose(DiagnosticInfoSampleProfile(
1197 getDISubprogram(&F)->getFilename(), getFunctionLoc(F),
1197 F.getSubprogram()->getFilename(), getFunctionLoc(F),
11981198 Twine(Used) + " of " + Twine(Total) + " available profile samples (" +
11991199 Twine(Coverage) + "%) were applied",
12001200 DS_Warning));
18901890
18911891 int StackMallocIdx = -1;
18921892 DebugLoc EntryDebugLocation;
1893 if (auto SP = getDISubprogram(&F))
1893 if (auto SP = F.getSubprogram())
18941894 EntryDebugLocation = DebugLoc::get(SP->getScopeLine(), 0, SP);
18951895
18961896 Instruction *InsBefore = AllocaVec[0];
492492 bool IsEntryBB = &BB == &F.getEntryBlock();
493493 DebugLoc EntryLoc;
494494 if (IsEntryBB) {
495 if (auto SP = getDISubprogram(&F))
495 if (auto SP = F.getSubprogram())
496496 EntryLoc = DebugLoc::get(SP->getScopeLine(), 0, SP);
497497 // Keep static allocas and llvm.localescape calls in the entry block. Even
498498 // if we aren't splitting the block, it's nice for allocas to be before
9898 return new AddDiscriminators();
9999 }
100100
101 static bool hasDebugInfo(const Function &F) {
102 DISubprogram *S = getDISubprogram(&F);
103 return S != nullptr;
104 }
105
106101 /// \brief Assign DWARF discriminators.
107102 ///
108103 /// To assign discriminators, we examine the boundaries of every
160155 // Simlarly, if the function has no debug info, do nothing.
161156 // Finally, if this module is built with dwarf versions earlier than 4,
162157 // do nothing (discriminator support is a DWARF 4 feature).
163 if (NoDiscriminators || !hasDebugInfo(F) ||
158 if (NoDiscriminators || !F.getSubprogram() ||
164159 F.getParent()->getDwarfVersion() < 4)
165160 return false;
166161
77 ; #5 }
88
99 ; Function Attrs: uwtable
10 define void @_Z3foov() #0 {
10 define void @_Z3foov() #0 !dbg !4 {
1111 call void @_Z3barv(), !dbg !10
1212 ; CHECK: call void @_Z3barv(), !dbg ![[CALL0:[0-9]+]]
1313 call void @_Z3barv(), !dbg !11