]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/commitdiff
Make getDISubprogram(const Function *F) available in LLVM
authorTimur Iskhodzhanov <timurrrr@google.com>
Thu, 23 Oct 2014 23:46:28 +0000 (23:46 +0000)
committerTimur Iskhodzhanov <timurrrr@google.com>
Thu, 23 Oct 2014 23:46:28 +0000 (23:46 +0000)
Reviewed at http://reviews.llvm.org/D5950

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220536 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DebugInfo.h
lib/IR/DebugInfo.cpp
lib/Transforms/Scalar/SampleProfile.cpp

index 63fbe60ded56c14dc3a4dfc709a35d5cd220913e..2a248e88a064ec2a4a750ee702e1a6886fa9def0 100644 (file)
@@ -961,6 +961,11 @@ public:
 /// \brief Find subprogram that is enclosing this scope.
 DISubprogram getDISubprogram(const MDNode *Scope);
 
 /// \brief Find subprogram that is enclosing this scope.
 DISubprogram getDISubprogram(const MDNode *Scope);
 
+/// \brief Find debug info for a given function.
+/// \returns a valid DISubprogram, if found. Otherwise, it returns an empty
+/// DISubprogram.
+DISubprogram getDISubprogram(const Function *F);
+
 /// \brief Find underlying composite type.
 DICompositeType getDICompositeType(DIType T);
 
 /// \brief Find underlying composite type.
 DICompositeType getDICompositeType(DIType T);
 
index 04eb65bc2a721b0cf0d51a647b3586244fa20d47..56b06230e22b1309436441105ac20d2ac928d151 100644 (file)
@@ -912,6 +912,24 @@ DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
   return DISubprogram();
 }
 
   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);
 DICompositeType llvm::getDICompositeType(DIType T) {
   if (T.isCompositeType())
     return DICompositeType(T);
index 4f746577f8e59a48a8370ecf6a7ee7d5eb1845e3..fedbcf3a7c003cbe9285c5ab8359c0c93de9aab3 100644 (file)
@@ -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
 /// \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) {
 /// \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();
 
   if (S.isSubprogram())
     return S.getLineNumber();