summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp18
-rw-r--r--llvm/lib/Transforms/Scalar/SampleProfile.cpp25
2 files changed, 19 insertions, 24 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 04eb65bc2a7..56b06230e22 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -912,6 +912,24 @@ DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
return DISubprogram();
}
+DISubprogram llvm::getDISubprogram(const Function *F) {
+ // We look for the first instr that has a debug annotation leading back to F.
+ const LLVMContext &Ctx = F->getParent()->getContext();
+ for (auto &BB : *F) {
+ for (auto &Inst : BB.getInstList()) {
+ DebugLoc DLoc = Inst.getDebugLoc();
+ if (DLoc.isUnknown())
+ continue;
+ const MDNode *Scope = DLoc.getScopeNode(Ctx);
+ DISubprogram Subprogram = getDISubprogram(Scope);
+ if (Subprogram.describes(F))
+ return Subprogram;
+ }
+ }
+
+ return DISubprogram();
+}
+
DICompositeType llvm::getDICompositeType(DIType T) {
if (T.isCompositeType())
return DICompositeType(T);
diff --git a/llvm/lib/Transforms/Scalar/SampleProfile.cpp b/llvm/lib/Transforms/Scalar/SampleProfile.cpp
index 4f746577f8e..fedbcf3a7c0 100644
--- a/llvm/lib/Transforms/Scalar/SampleProfile.cpp
+++ b/llvm/lib/Transforms/Scalar/SampleProfile.cpp
@@ -627,29 +627,6 @@ void SampleProfileLoader::propagateWeights(Function &F) {
}
}
-/// \brief Locate the DISubprogram for F.
-///
-/// We look for the first instruction that has a debug annotation
-/// leading back to \p F.
-///
-/// \returns a valid DISubprogram, if found. Otherwise, it returns an empty
-/// DISubprogram.
-static const DISubprogram getDISubprogram(Function &F, const LLVMContext &Ctx) {
- for (auto &BI : F) {
- BasicBlock *BB = &BI;
- for (auto &Inst : BB->getInstList()) {
- DebugLoc DLoc = Inst.getDebugLoc();
- if (DLoc.isUnknown())
- continue;
- const MDNode *Scope = DLoc.getScopeNode(Ctx);
- DISubprogram Subprogram = getDISubprogram(Scope);
- return Subprogram.describes(&F) ? Subprogram : DISubprogram();
- }
- }
-
- return DISubprogram();
-}
-
/// \brief Get the line number for the function header.
///
/// This looks up function \p F in the current compilation unit and
@@ -662,7 +639,7 @@ static const DISubprogram getDISubprogram(Function &F, const LLVMContext &Ctx) {
/// \returns the line number where \p F is defined. If it returns 0,
/// it means that there is no debug information available for \p F.
unsigned SampleProfileLoader::getFunctionLoc(Function &F) {
- const DISubprogram &S = getDISubprogram(F, *Ctx);
+ DISubprogram S = getDISubprogram(&F);
if (S.isSubprogram())
return S.getLineNumber();
OpenPOWER on IntegriCloud