If an AllocaInst referred by DbgDeclareInst is used by a LoadInst then the LoadInst...
authorDevang Patel <dpatel@apple.com>
Fri, 18 Mar 2011 23:45:43 +0000 (23:45 +0000)
committerDevang Patel <dpatel@apple.com>
Fri, 18 Mar 2011 23:45:43 +0000 (23:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127924 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/Local.h
lib/Transforms/Utils/Local.cpp

index 16bcc545033fcf03f443e1cf92d1bfc0c4d7903f..f63796c4eab5a4dea6d515e4be498555a1517990 100644 (file)
@@ -24,6 +24,7 @@ class BranchInst;
 class Instruction;
 class DbgDeclareInst;
 class StoreInst;
+class LoadInst;
 class Value;
 class Pass;
 class PHINode;
@@ -170,6 +171,11 @@ static inline unsigned getKnownAlignment(Value *V, const TargetData *TD = 0) {
 bool ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
                                      StoreInst *SI, DIBuilder &Builder);
 
+/// Inserts a llvm.dbg.value instrinsic before the stores to an alloca'd value
+/// that has an associated llvm.dbg.decl intrinsic.
+bool ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
+                                     LoadInst *LI, DIBuilder &Builder);
+
 /// LowerDbgDeclare - Lowers llvm.dbg.declare intrinsics into appropriate set
 /// of llvm.dbg.value intrinsics.
 bool LowerDbgDeclare(Function &F);
index 623d89b2f631773026501d6614b1ecc73b097bad..88c6f18c6ede34484472ef1efa4a25eeb00ff292 100644 (file)
@@ -794,6 +794,28 @@ bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
   return true;
 }
 
+/// Inserts a llvm.dbg.value instrinsic before the stores to an alloca'd value
+/// that has an associated llvm.dbg.decl intrinsic.
+bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
+                                           LoadInst *LI, DIBuilder &Builder) {
+  DIVariable DIVar(DDI->getVariable());
+  if (!DIVar.Verify())
+    return false;
+
+  Instruction *DbgVal = 
+    Builder.insertDbgValueIntrinsic(LI->getOperand(0), 0,
+                                    DIVar, LI);
+  
+  // Propagate any debug metadata from the store onto the dbg.value.
+  DebugLoc LIDL = LI->getDebugLoc();
+  if (!LIDL.isUnknown())
+    DbgVal->setDebugLoc(LIDL);
+  // Otherwise propagate debug metadata from dbg.declare.
+  else
+    DbgVal->setDebugLoc(DDI->getDebugLoc());
+  return true;
+}
+
 /// LowerDbgDeclare - Lowers llvm.dbg.declare intrinsics into appropriate set
 /// of llvm.dbg.value intrinsics.
 bool llvm::LowerDbgDeclare(Function &F) {
@@ -815,6 +837,8 @@ bool llvm::LowerDbgDeclare(Function &F) {
            UI != E; ++UI)
         if (StoreInst *SI = dyn_cast<StoreInst>(*UI))
           ConvertDebugDeclareToDebugValue(DDI, SI, DIB);
+        else if (LoadInst *LI = dyn_cast<LoadInst>(*UI))
+          ConvertDebugDeclareToDebugValue(DDI, LI, DIB);
     }
     DDI->eraseFromParent();
   }