aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
diff options
context:
space:
mode:
authorOCHyams <orlando.hyams@sony.com>2021-04-19 10:31:41 +0100
committerOCHyams <orlando.hyams@sony.com>2021-04-19 11:06:53 +0100
commitbbccdf6f81979c0707c6ce25bf7c70be82e2629a (patch)
tree22b45dd759f456eead02b86e23573b0288d021b9 /llvm/lib/IR/Value.cpp
parent31686d13dc584459ecc3fc253cc243a84317221a (diff)
downloadllvm-bbccdf6f81979c0707c6ce25bf7c70be82e2629a.zip
llvm-bbccdf6f81979c0707c6ce25bf7c70be82e2629a.tar.gz
llvm-bbccdf6f81979c0707c6ce25bf7c70be82e2629a.tar.bz2
[DebugInfo] Replace debug uses in replaceUsesOutsideBlock
Value::replaceUsesOutsideBlock doesn't replace debug uses which leads to an unnecessary reduction in variable location coverage. Fix this, add a unittest for it, and add a regression test demonstrating the change through instcombine's replacedSelectWithOperand. Reviewed By: djtodoro Differential Revision: https://reviews.llvm.org/D99169
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r--llvm/lib/IR/Value.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 7003508..e0b72dc 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -18,6 +18,7 @@
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DerivedUser.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
@@ -531,6 +532,17 @@ void Value::replaceNonMetadataUsesWith(Value *New) {
doRAUW(New, ReplaceMetadataUses::No);
}
+/// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
+/// with New.
+static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) {
+ SmallVector<DbgVariableIntrinsic *> DbgUsers;
+ findDbgUsers(DbgUsers, V);
+ for (auto *DVI : DbgUsers) {
+ if (DVI->getParent() != BB)
+ DVI->replaceVariableLocationOp(V, New);
+ }
+}
+
// Like replaceAllUsesWith except it does not handle constants or basic blocks.
// This routine leaves uses within BB.
void Value::replaceUsesOutsideBlock(Value *New, BasicBlock *BB) {
@@ -541,6 +553,7 @@ void Value::replaceUsesOutsideBlock(Value *New, BasicBlock *BB) {
"replaceUses of value with new value of different type!");
assert(BB && "Basic block that may contain a use of 'New' must be defined\n");
+ replaceDbgUsesOutsideBlock(this, New, BB);
replaceUsesWithIf(New, [BB](Use &U) {
auto *I = dyn_cast<Instruction>(U.getUser());
// Don't replace if it's an instruction in the BB basic block.