[llvm] r212128 - DebugInfo: Keep track of subprograms who's arguments have been promoted.

David Blaikie dblaikie at gmail.com
Tue Jul 1 14:13:37 PDT 2014


Author: dblaikie
Date: Tue Jul  1 16:13:37 2014
New Revision: 212128

URL: http://llvm.org/viewvc/llvm-project?rev=212128&view=rev
Log:
DebugInfo: Keep track of subprograms who's arguments have been promoted.

Matching behavior with DeadArgumentElimination (and leveraging some
now-common infrastructure), keep track of the function from debug info
metadata if arguments are promoted.

This may produce interesting debug info - since the arguments may be
missing or of different types... but at least backtraces, inlining, etc,
will be correct.

Modified:
    llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
    llvm/trunk/test/Transforms/ArgumentPromotion/dbg.ll

Modified: llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=212128&r1=212127&r2=212128&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp Tue Jul  1 16:13:37 2014
@@ -39,6 +39,7 @@
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
@@ -80,8 +81,10 @@ namespace {
     CallGraphNode *DoPromotion(Function *F,
                                SmallPtrSet<Argument*, 8> &ArgsToPromote,
                                SmallPtrSet<Argument*, 8> &ByValArgsToTransform);
+    bool doInitialization(CallGraph &CG) override;
     /// The maximum number of elements to expand, or 0 for unlimited.
     unsigned maxElements;
+    DenseMap<Function *, DISubprogram> FunctionDIs;
   };
 }
 
@@ -604,6 +607,10 @@ CallGraphNode *ArgPromotion::DoPromotion
   Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
   NF->copyAttributesFrom(F);
 
+  // Patch the pointer to LLVM function in debug info descriptor.
+  auto DI = FunctionDIs.find(F);
+  if (DI != FunctionDIs.end())
+    DI->second.replaceFunction(NF);
   
   DEBUG(dbgs() << "ARG PROMOTION:  Promoting to:" << *NF << "\n"
         << "From: " << *F);
@@ -903,3 +910,8 @@ CallGraphNode *ArgPromotion::DoPromotion
   
   return NF_CGN;
 }
+
+bool ArgPromotion::doInitialization(CallGraph &CG) {
+  FunctionDIs = makeSubprogramMap(CG.getModule());
+  return CallGraphSCCPass::doInitialization(CG);
+}

Modified: llvm/trunk/test/Transforms/ArgumentPromotion/dbg.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ArgumentPromotion/dbg.ll?rev=212128&r1=212127&r2=212128&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ArgumentPromotion/dbg.ll (original)
+++ llvm/trunk/test/Transforms/ArgumentPromotion/dbg.ll Tue Jul  1 16:13:37 2014
@@ -1,5 +1,7 @@
 ; RUN: opt < %s -argpromotion -S | FileCheck %s
-; CHECK: call void @test(), !dbg !1
+; CHECK: call void @test(), !dbg [[DBG_LOC:![0-9]]]
+; CHECK: [[TEST_FN:.*]] = {{.*}} void ()* @test
+; CHECK: [[DBG_LOC]] = metadata !{i32 8, i32 0, metadata [[TEST_FN]], null}
 
 define internal void @test(i32* %X) {
   ret void
@@ -10,8 +12,11 @@ define void @caller() {
   ret void
 }
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!0}
+!llvm.dbg.cu = !{!3}
 
+!0 = metadata !{i32 2, metadata !"Debug Info Version", i32 1}
 !1 = metadata !{i32 8, i32 0, metadata !2, null}
-!2 = metadata !{}
-!3 = metadata !{i32 2, metadata !"Debug Info Version", i32 1}
+!2 = metadata !{i32 786478, null, null, metadata !"test", metadata !"test", metadata !"", i32 3, null, i1 true, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i32*)* @test, null, null, null, i32 3}
+!3 = metadata !{i32 786449, null, i32 4, metadata !"clang version 3.5.0 ", i1 false, metadata !"", i32 0, null, null, metadata !4, null, null, metadata !"", i32 2} ; [ DW_TAG_compile_unit ] [/usr/local/google/home/blaikie/dev/scratch/pr20038/reduce/<stdin>] [DW_LANG_C_plus_plus]
+!4 = metadata !{metadata !2}





More information about the llvm-commits mailing list