[llvm-commits] [llvm] r125567 - in /llvm/trunk/lib/Analysis: DbgInfoPrinter.cpp DebugInfo.cpp

Devang Patel dpatel at apple.com
Tue Feb 15 09:24:56 PST 2011


Author: dpatel
Date: Tue Feb 15 11:24:56 2011
New Revision: 125567

URL: http://llvm.org/viewvc/llvm-project?rev=125567&view=rev
Log:
Print function info. Patch by Minjang Kim.

Modified:
    llvm/trunk/lib/Analysis/DbgInfoPrinter.cpp
    llvm/trunk/lib/Analysis/DebugInfo.cpp

Modified: llvm/trunk/lib/Analysis/DbgInfoPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DbgInfoPrinter.cpp?rev=125567&r1=125566&r2=125567&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/DbgInfoPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/DbgInfoPrinter.cpp Tue Feb 15 11:24:56 2011
@@ -66,8 +66,12 @@
 
   Out << "; ";
   WriteAsOperand(Out, V, false, 0);
-  Out << " is variable " << DisplayName
-      << " of type " << Type << " declared at ";
+  if (isa<Function>(V)) 
+    Out << " is function " << DisplayName
+        << " of type " << Type << " declared at ";
+  else
+    Out << " is variable " << DisplayName
+        << " of type " << Type << " declared at ";
 
   if (PrintDirectory)
     Out << Directory << "/";

Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=125567&r1=125566&r2=125567&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Feb 15 11:24:56 2011
@@ -1592,6 +1592,23 @@
   return 0;
 }
 
+/// Find the debug info descriptor corresponding to this function.
+static Value *findDbgSubprogramDeclare(Function *V) {
+  const Module *M = V->getParent();
+  NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.sp");
+  if (!NMD)
+    return 0;
+
+  for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
+    DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i)));
+    if (!DIG.isSubprogram())
+      continue;
+    if (DISubprogram(DIG).getFunction() == V)
+      return DIG;
+  }
+  return 0;
+}
+
 /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
 /// It looks through pointer casts too.
 static const DbgDeclareInst *findDbgDeclare(const Value *V) {
@@ -1633,6 +1650,17 @@
     LineNo = Var.getLineNumber();
     Unit = Var.getCompileUnit();
     TypeD = Var.getType();
+  } else if (Function *F = dyn_cast<Function>(const_cast<Value*>(V))){
+    Value *DIF = findDbgSubprogramDeclare(F);
+    if (!DIF) return false;
+    DISubprogram Var(cast<MDNode>(DIF));
+
+    StringRef D = Var.getDisplayName();
+    if (!D.empty())
+      DisplayName = D;
+    LineNo = Var.getLineNumber();
+    Unit = Var.getCompileUnit();
+    TypeD = Var.getType();
   } else {
     const DbgDeclareInst *DDI = findDbgDeclare(V);
     if (!DDI) return false;





More information about the llvm-commits mailing list