With change reporting in transformation passes in mind.
/// Replace uses of one Value with another.
///
/// Replaces all references to the "From" definition with references to the
- /// "To" definition.
- void replaceUsesOfWith(Value *From, Value *To);
+ /// "To" definition. Returns whether any uses were replaced.
+ bool replaceUsesOfWith(Value *From, Value *To);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
// User Class
//===----------------------------------------------------------------------===//
-void User::replaceUsesOfWith(Value *From, Value *To) {
- if (From == To) return; // Duh what?
+bool User::replaceUsesOfWith(Value *From, Value *To) {
+ bool Changed = false;
+ if (From == To) return Changed; // Duh what?
assert((!isa<Constant>(this) || isa<GlobalValue>(this)) &&
"Cannot call User::replaceUsesOfWith on a constant!");
// "To", adding "this" to the uses list of To, and
// most importantly, removing "this" from the use list of "From".
setOperand(i, To);
+ Changed = true;
}
if (auto DVI = dyn_cast_or_null<DbgVariableIntrinsic>(this)) {
- if (is_contained(DVI->location_ops(), From))
+ if (is_contained(DVI->location_ops(), From)) {
DVI->replaceVariableLocationOp(From, To);
+ Changed = true;
+ }
}
+
+ return Changed;
}
//===----------------------------------------------------------------------===//
auto XUser = find(X.users(), &(I1));
EXPECT_NE(XUser, X.user_end());
- XUser->replaceUsesOfWith(&X, &I0);
- EXPECT_EQ(X.user_begin() ,X.user_end());
- EXPECT_NE(I0.user_begin() ,I0.user_end());
+ EXPECT_TRUE(XUser->replaceUsesOfWith(&X, &I0));
+ EXPECT_EQ(X.user_begin(), X.user_end());
+ EXPECT_NE(I0.user_begin(), I0.user_end());
+
+ // All uses have already been replaced, nothing more to do.
+ EXPECT_FALSE(XUser->replaceUsesOfWith(&X, &I0));
}
TEST(UserTest, PersonalityUser) {