mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-18 18:42:46 +02:00
[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
This commit is contained in:
parent
5d534d8259
commit
c7c6ba1331
@ -311,27 +311,15 @@ public:
|
||||
/// Go through the uses list for this definition and make each use point
|
||||
/// to "V" if the callback ShouldReplace returns true for the given Use.
|
||||
/// Unlike replaceAllUsesWith() this function does not support basic block
|
||||
/// values or constant users.
|
||||
/// values.
|
||||
void 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;
|
||||
U.set(New);
|
||||
}
|
||||
}
|
||||
llvm::function_ref<bool(Use &U)> ShouldReplace);
|
||||
|
||||
/// replaceUsesOutsideBlock - Go through the uses list for this definition and
|
||||
/// make each use point to "V" instead of "this" when the use is outside the
|
||||
/// block. 'This's use list is expected to have at least one element.
|
||||
/// Unlike replaceAllUsesWith() this function does not support basic block
|
||||
/// values or constant users.
|
||||
/// values.
|
||||
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user