aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
diff options
context:
space:
mode:
authorStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>2021-05-24 14:55:49 -0700
committerStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>2021-05-25 02:12:01 -0700
commit8f681d5b272eeb5c0d13d225313f4ea9517f59f5 (patch)
tree1d0b82aa8141f66abea21180340c42d77a750caf /llvm/lib/IR/Value.cpp
parent78eaff2ef8a984859a04f944522280360ee825aa (diff)
downloadllvm-8f681d5b272eeb5c0d13d225313f4ea9517f59f5.zip
llvm-8f681d5b272eeb5c0d13d225313f4ea9517f59f5.tar.gz
llvm-8f681d5b272eeb5c0d13d225313f4ea9517f59f5.tar.bz2
[IR] Allow Value::replaceUsesWithIf() to process constants
The change is currently NFC, but exploited by the depending D102954. Code to handle constants is borrowed from the general implementation of Value::doRAUW(). Differential Revision: https://reviews.llvm.org/D103051
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r--llvm/lib/IR/Value.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 8d6918c..d5587b4 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -532,6 +532,29 @@ void Value::replaceNonMetadataUsesWith(Value *New) {
doRAUW(New, ReplaceMetadataUses::No);
}
+void Value::replaceUsesWithIf(Value *New,
+ llvm::function_ref<bool(Use &U)> ShouldReplace) {
+ assert(New && "Value::replaceUsesWithIf(<null>) is invalid!");
+ assert(New->getType() == getType() &&
+ "replaceUses of value with new value of different type!");
+
+ for (use_iterator UI = use_begin(), E = use_end(); UI != E;) {
+ Use &U = *UI;
+ ++UI;
+ if (!ShouldReplace(U))
+ continue;
+ // Must handle Constants specially, we cannot call replaceUsesOfWith on a
+ // constant because they are uniqued.
+ if (auto *C = dyn_cast<Constant>(U.getUser())) {
+ if (!isa<GlobalValue>(C)) {
+ C->handleOperandChange(this, New);
+ continue;
+ }
+ }
+ U.set(New);
+ }
+}
+
/// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
/// with New.
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) {