summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-06-20 16:50:25 +0000
committerVedant Kumar <vsk@apple.com>2018-06-20 16:50:25 +0000
commit6fa24b0b7fb755114ca3ac50c6617e917222a893 (patch)
tree19d4fef37b764d2e5087f10c2582216744a03cc3 /llvm/lib/Transforms
parent37fbb92652e81aa81554e042ea4f87baf754f5a6 (diff)
downloadbcm5719-llvm-6fa24b0b7fb755114ca3ac50c6617e917222a893.tar.gz
bcm5719-llvm-6fa24b0b7fb755114ca3ac50c6617e917222a893.zip
[Local] Add a utility to insert replacement dbg.values, NFC
The purpose of this utility is to make it easier for optimizations to insert replacement dbg.values for instructions they are deleting. This is useful in situations where salvageDebugInfo is inapplicable, say, because the new dbg.value cannot refer to an operand of the dying value. The utility is called insertReplacementDbgValues. It assumes that the instruction 'From' is going to be deleted, and inserts replacement dbg.values for each debug user of 'From'. The newly-inserted dbg.values refer to 'To' instead of '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 'RewriteExpr' applied to an old debug user of 'From', and is placed before 'InsertBefore'. This should simplify future patches, like D48331. llvm-svn: 335144
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp17
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp18
2 files changed, 24 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 9f297b0aab0..aa86dddf04d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -268,17 +268,12 @@ Instruction *InstCombiner::commonCastTransforms(CastInst &CI) {
// the second cast (CI). CSrc will then have a good chance of being dead.
auto *Res = CastInst::Create(NewOpc, CSrc->getOperand(0), CI.getType());
- // If the eliminable cast has debug users, insert a debug value after the
- // cast pointing to the new Value.
- SmallVector<DbgInfoIntrinsic *, 1> CSrcDbgInsts;
- findDbgUsers(CSrcDbgInsts, CSrc);
- if (CSrcDbgInsts.size()) {
- DIBuilder DIB(*CI.getModule());
- for (auto *DII : CSrcDbgInsts)
- DIB.insertDbgValueIntrinsic(
- Res, DII->getVariable(), DII->getExpression(),
- DII->getDebugLoc().get(), &*std::next(CI.getIterator()));
- }
+ // Replace debug users of the eliminable cast by emitting debug values
+ // which refer to the new cast.
+ insertReplacementDbgValues(
+ *CSrc, *Res, *std::next(CI.getIterator()),
+ [](DbgInfoIntrinsic &OldDII) { return OldDII.getExpression(); });
+
return Res;
}
}
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 3a43025cb83..7dd74a1aa40 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1671,6 +1671,24 @@ void llvm::salvageDebugInfo(Instruction &I) {
}
}
+void llvm::insertReplacementDbgValues(
+ Instruction &From, Instruction &To, Instruction &InsertBefore,
+ function_ref<DIExpression *(DbgInfoIntrinsic &OldDII)> RewriteExpr) {
+ // Collect all debug users of From.
+ SmallVector<DbgInfoIntrinsic *, 1> Users;
+ findDbgUsers(Users, &From);
+ if (Users.empty())
+ return;
+
+ // 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());
+ for (auto *OldDII : Users)
+ DIB.insertDbgValueIntrinsic(&To, OldDII->getVariable(),
+ RewriteExpr(*OldDII),
+ OldDII->getDebugLoc().get(), &InsertBefore);
+}
+
unsigned llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) {
unsigned NumDeadInst = 0;
// Delete the instructions backwards, as it has a reduced likelihood of
OpenPOWER on IntegriCloud