File tree Expand file tree Collapse file tree 2 files changed +26
-15
lines changed Expand file tree Collapse file tree 2 files changed +26
-15
lines changed Original file line number Diff line number Diff line change @@ -311,27 +311,15 @@ class Value {
311
311
// / Go through the uses list for this definition and make each use point
312
312
// / to "V" if the callback ShouldReplace returns true for the given Use.
313
313
// / Unlike replaceAllUsesWith() this function does not support basic block
314
- // / values or constant users .
314
+ // / values.
315
315
void replaceUsesWithIf (Value *New,
316
- llvm::function_ref<bool (Use &U)> ShouldReplace) {
317
- assert (New && " Value::replaceUsesWithIf(<null>) is invalid!" );
318
- assert (New->getType () == getType () &&
319
- " replaceUses of value with new value of different type!" );
320
-
321
- for (use_iterator UI = use_begin (), E = use_end (); UI != E;) {
322
- Use &U = *UI;
323
- ++UI;
324
- if (!ShouldReplace (U))
325
- continue ;
326
- U.set (New);
327
- }
328
- }
316
+ llvm::function_ref<bool (Use &U)> ShouldReplace);
329
317
330
318
// / replaceUsesOutsideBlock - Go through the uses list for this definition and
331
319
// / make each use point to "V" instead of "this" when the use is outside the
332
320
// / block. 'This's use list is expected to have at least one element.
333
321
// / Unlike replaceAllUsesWith() this function does not support basic block
334
- // / values or constant users .
322
+ // / values.
335
323
void replaceUsesOutsideBlock (Value *V, BasicBlock *BB);
336
324
337
325
// ----------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -532,6 +532,29 @@ void Value::replaceNonMetadataUsesWith(Value *New) {
532
532
doRAUW (New, ReplaceMetadataUses::No);
533
533
}
534
534
535
+ void Value::replaceUsesWithIf (Value *New,
536
+ llvm::function_ref<bool (Use &U)> ShouldReplace) {
537
+ assert (New && " Value::replaceUsesWithIf(<null>) is invalid!" );
538
+ assert (New->getType () == getType () &&
539
+ " replaceUses of value with new value of different type!" );
540
+
541
+ for (use_iterator UI = use_begin (), E = use_end (); UI != E;) {
542
+ Use &U = *UI;
543
+ ++UI;
544
+ if (!ShouldReplace (U))
545
+ continue ;
546
+ // Must handle Constants specially, we cannot call replaceUsesOfWith on a
547
+ // constant because they are uniqued.
548
+ if (auto *C = dyn_cast<Constant>(U.getUser ())) {
549
+ if (!isa<GlobalValue>(C)) {
550
+ C->handleOperandChange (this , New);
551
+ continue ;
552
+ }
553
+ }
554
+ U.set (New);
555
+ }
556
+ }
557
+
535
558
// / Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
536
559
// / with New.
537
560
static void replaceDbgUsesOutsideBlock (Value *V, Value *New, BasicBlock *BB) {
You can’t perform that action at this time.
0 commit comments