[Local] Generalize insertReplacementDbgValues, NFC
authorVedant Kumar <vsk@apple.com>
Wed, 20 Jun 2018 18:40:14 +0000 (18:40 +0000)
committerVedant Kumar <vsk@apple.com>
Wed, 20 Jun 2018 18:40:14 +0000 (18:40 +0000)
This utility should operate on Values, not Instructions. While I'm here,
I've also made it possible to skip emitting replacement dbg.values for
certain debug users (by having RewriteExpr return nullptr).

llvm-svn: 335152

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

index f09ebe5..5290651 100644 (file)
@@ -334,14 +334,16 @@ void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
 /// DIExpression.
 void salvageDebugInfo(Instruction &I);
 
-/// Assuming the instruction \p From is going to be deleted, insert replacement
+/// Assuming the value \p From is going to be deleted, insert replacement
 /// dbg.value intrinsics for each debug user of \p From. The newly-inserted
 /// dbg.values refer to \p To instead of \p From. Each replacement dbg.value
 /// has the same location and variable as the debug user it replaces, has a
 /// DIExpression determined by the result of \p RewriteExpr applied to an old
-/// debug user of \p From, and is placed before \p InsertBefore.
+/// debug user of \p From, and is placed before \p InsertBefore. If
+/// \p RewriteExpr returns nullptr, no replacement for the specified debug
+/// user is emitted.
 void insertReplacementDbgValues(
-    Instruction &From, Instruction &To, Instruction &InsertBefore,
+    Value &From, Value &To, Instruction &InsertBefore,
     function_ref<DIExpression *(DbgInfoIntrinsic &OldDII)> RewriteExpr);
 
 /// Remove all instructions from a basic block other than it's terminator
index 7dd74a1..a718276 100644 (file)
@@ -1672,7 +1672,7 @@ void llvm::salvageDebugInfo(Instruction &I) {
 }
 
 void llvm::insertReplacementDbgValues(
-    Instruction &From, Instruction &To, Instruction &InsertBefore,
+    Value &From, Value &To, Instruction &InsertBefore,
     function_ref<DIExpression *(DbgInfoIntrinsic &OldDII)> RewriteExpr) {
   // Collect all debug users of From.
   SmallVector<DbgInfoIntrinsic *, 1> Users;
@@ -1682,11 +1682,11 @@ void llvm::insertReplacementDbgValues(
 
   // Insert a replacement debug value for each old debug user. It's assumed
   // that the old debug users will be erased later.
-  DIBuilder DIB(*From.getModule());
+  DIBuilder DIB(*InsertBefore.getModule());
   for (auto *OldDII : Users)
-    DIB.insertDbgValueIntrinsic(&To, OldDII->getVariable(),
-                                RewriteExpr(*OldDII),
-                                OldDII->getDebugLoc().get(), &InsertBefore);
+    if (DIExpression *Expr = RewriteExpr(*OldDII))
+      DIB.insertDbgValueIntrinsic(&To, OldDII->getVariable(), Expr,
+                                  OldDII->getDebugLoc().get(), &InsertBefore);
 }
 
 unsigned llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) {