Skip to content

Commit ec172cd

Browse files
committed
Remove SILValue::replaceAllUsesWith.
It's not needed anymore because we can use ValueBase::replaceAllUses
1 parent f2c0283 commit ec172cd

15 files changed

+25
-34
lines changed

include/swift/SIL/SILValue.h

-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ class SILValue {
230230
/// intrinsic call.
231231
SILValue stripExpectIntrinsic();
232232

233-
void replaceAllUsesWith(SILValue V);
234-
235233
void dump() const;
236234
void print(raw_ostream &os) const;
237235

lib/Parse/ParseSIL.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ void SILParser::setLocalValue(ValueBase *Value, StringRef Name,
546546
HadError = true;
547547
} else {
548548
// Forward references only live here if they have a single result.
549-
SILValue(Entry).replaceAllUsesWith(SILValue(Value));
549+
Entry->replaceAllUsesWith(Value);
550550
}
551551
Entry = Value;
552552
return;

lib/SIL/SILValue.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ static_assert(sizeof(SILValue) == sizeof(uintptr_t),
3434
// Utility Methods
3535
//===----------------------------------------------------------------------===//
3636

37-
void SILValue::replaceAllUsesWith(SILValue V) {
38-
assert(*this != V && "Cannot RAUW a value with itself");
39-
assert(getType() == V.getType() && "Invalid type");
40-
while (!use_empty())
41-
(**use_begin()).set(V);
42-
}
43-
4437
static bool isRCIdentityPreservingCast(ValueKind Kind) {
4538
switch (Kind) {
4639
case ValueKind::UpcastInst:

lib/SILGen/SILGenEpilog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ SILGenFunction::emitEpilogBB(SILLocation TopLevel) {
9595
if (needsArg) {
9696
returnValue = predBranch->getArgs()[0];
9797
// RAUW the old BB argument (if any) with the new value.
98-
SILValue(*epilogBB->bbarg_begin()).replaceAllUsesWith(returnValue);
98+
(*epilogBB->bbarg_begin())->replaceAllUsesWith(returnValue.getDef());
9999
}
100100

101101
// If we are optimizing, we should use the return location from the single,

lib/SILOptimizer/IPO/FunctionSignatureOpts.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ unsigned ArgumentDescriptor::updateOptimizedBBArgs(SILBuilder &Builder,
397397

398398
// Replace all uses of the original arg with undef so it does not have any
399399
// uses.
400-
SILValue OrigArg = SILValue(BB->getBBArg(OldArgOffset));
401-
OrigArg.replaceAllUsesWith(SILUndef::get(OrigArg.getType(), BB->getModule()));
400+
SILArgument *OrigArg = BB->getBBArg(OldArgOffset);
401+
OrigArg->replaceAllUsesWith(SILUndef::get(OrigArg->getType(), BB->getModule()));
402402

403403
// Now erase the old argument since it does not have any uses. We also
404404
// decrement ArgOffset since we have one less argument now.

lib/SILOptimizer/Mandatory/ConstantPropagation.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ constantFoldStringConcatenation(ApplyInst *AI,
766766
return false;
767767

768768
// Replace all uses of the old instruction by a new instruction.
769-
SILValue(AI).replaceAllUsesWith(Concatenated);
769+
AI->replaceAllUsesWith(Concatenated);
770770

771771
auto RemoveCallback = [&](SILInstruction *DeadI) { WorkList.remove(DeadI); };
772772
// Remove operands that are not used anymore.
@@ -861,7 +861,7 @@ processFunction(SILFunction &F, bool EnableDiagnostics,
861861
[&](SILInstruction *I, ValueBase *V) { /* ReplaceInstUsesAction */
862862

863863
InvalidateInstructions = true;
864-
SILValue(I).replaceAllUsesWith(V);
864+
I->replaceAllUsesWith(V);
865865
},
866866
[&](SILInstruction *I) { /* EraseAction */
867867
auto *TI = dyn_cast<TermInst>(I);
@@ -1036,7 +1036,7 @@ processFunction(SILFunction &F, bool EnableDiagnostics,
10361036

10371037

10381038
// We were able to fold, so all users should use the new folded value.
1039-
SILValue(User).replaceAllUsesWith(C);
1039+
User->replaceAllUsesWith(C.getDef());
10401040

10411041
// The new constant could be further folded now, add it to the worklist.
10421042
if (auto *Inst = dyn_cast<SILInstruction>(C.getDef()))

lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
171171
SILArgument *Arg = *AI;
172172

173173
// We were able to fold, so all users should use the new folded value.
174-
SILValue(Arg).replaceAllUsesWith(Args[Idx]);
174+
Arg->replaceAllUsesWith(Args[Idx].getDef());
175175
NumBasicBlockArgsPropagated++;
176176
}
177177

lib/SILOptimizer/Transforms/RedundantLoadElimination.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ bool RLEContext::run() {
13421342
DEBUG(llvm::dbgs() << "Replacing " << SILValue(F.first) << "With "
13431343
<< F.second);
13441344
SILChanged = true;
1345-
SILValue(F.first).replaceAllUsesWith(F.second);
1345+
F.first->replaceAllUsesWith(F.second.getDef());
13461346
InstsToDelete.insert(F.first);
13471347
++NumForwardedLoads;
13481348
}

lib/SILOptimizer/Transforms/RemovePin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class RemovePinInsts : public SILFunctionTransform {
111111
Changed = true;
112112
auto *Enum = SILBuilder(PinDef).createOptionalSome(
113113
PinDef->getLoc(), PinDef->getOperand(), PinDef->getType());
114-
SILValue(PinDef).replaceAllUsesWith(Enum);
114+
PinDef->replaceAllUsesWith(Enum);
115115
Unpin->eraseFromParent();
116116
PinDef->eraseFromParent();
117117
// Remove this pindef from AvailablePins.

lib/SILOptimizer/Transforms/SILCodeMotion.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static bool sinkArgument(SILBasicBlock *BB, unsigned ArgNum) {
423423
if (!FSI)
424424
return false;
425425

426-
SILValue Undef = SILUndef::get(FirstPredArg.getType(), BB->getModule());
426+
auto *Undef = SILUndef::get(FirstPredArg.getType(), BB->getModule());
427427

428428
// Delete the debug info of the instruction that we are about to sink.
429429
deleteAllDebugUses(FSI);
@@ -435,7 +435,7 @@ static bool sinkArgument(SILBasicBlock *BB, unsigned ArgNum) {
435435
// The instruction we are lowering has an argument which is different
436436
// for each predecessor. We need to sink the instruction, then add
437437
// arguments for each predecessor.
438-
SILValue(BB->getBBArg(ArgNum)).replaceAllUsesWith(FSI);
438+
BB->getBBArg(ArgNum)->replaceAllUsesWith(FSI);
439439

440440
const auto &ArgType = FSI->getOperand(*DifferentOperandIndex).getType();
441441
BB->replaceBBArg(ArgNum, ArgType);
@@ -465,16 +465,16 @@ static bool sinkArgument(SILBasicBlock *BB, unsigned ArgNum) {
465465
}
466466

467467
// Sink one of the copies of the instruction.
468-
FirstPredArg.replaceAllUsesWith(Undef);
468+
FirstPredArg->replaceAllUsesWith(Undef);
469469
FSI->moveBefore(&*BB->begin());
470-
SILValue(BB->getBBArg(ArgNum)).replaceAllUsesWith(FirstPredArg);
470+
BB->getBBArg(ArgNum)->replaceAllUsesWith(FirstPredArg.getDef());
471471

472472
// The argument is no longer in use. Replace all incoming inputs with undef
473473
// and try to delete the instruction.
474474
for (auto S : Clones)
475475
if (S.getDef() != FSI) {
476476
deleteAllDebugUses(S.getDef());
477-
S.replaceAllUsesWith(Undef);
477+
S->replaceAllUsesWith(Undef);
478478
auto DeadArgInst = cast<SILInstruction>(S.getDef());
479479
recursivelyDeleteTriviallyDeadInstructions(DeadArgInst);
480480
}

lib/SILOptimizer/Transforms/SILSROA.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void SROAMemoryUseAnalyzer::chopUpAlloca(std::vector<AllocStackInst *> &Worklist
236236
Elements.push_back(B.createLoad(LI->getLoc(), NewAI));
237237
auto *Agg = createAgg(B, LI->getLoc(), LI->getType().getObjectType(),
238238
Elements);
239-
SILValue(LI).replaceAllUsesWith(Agg);
239+
LI->replaceAllUsesWith(Agg);
240240
LI->eraseFromParent();
241241
}
242242

@@ -252,8 +252,8 @@ void SROAMemoryUseAnalyzer::chopUpAlloca(std::vector<AllocStackInst *> &Worklist
252252

253253
// Forward any field extracts to the new allocation.
254254
for (auto *Ext : ExtractInsts) {
255-
SILValue NewValue = NewAllocations[getEltNoForProjection(Ext)];
256-
SILValue(Ext).replaceAllUsesWith(NewValue);
255+
AllocStackInst *NewValue = NewAllocations[getEltNoForProjection(Ext)];
256+
Ext->replaceAllUsesWith(NewValue);
257257
Ext->eraseFromParent();
258258
}
259259

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ bool SimplifyCFG::simplifyBranchBlock(BranchInst *BI) {
10771077
// branch operands, since they must dominate the dest block.
10781078
for (unsigned i = 0, e = BI->getArgs().size(); i != e; ++i) {
10791079
if (DestBB->getBBArg(i) != BI->getArg(i).getDef())
1080-
SILValue(DestBB->getBBArg(i)).replaceAllUsesWith(BI->getArg(i));
1080+
DestBB->getBBArg(i)->replaceAllUsesWith(BI->getArg(i).getDef());
10811081
else {
10821082
// We must be processing an unreachable part of the cfg with a cycle.
10831083
// bb1(arg1): // preds: bb3
@@ -2490,7 +2490,7 @@ bool ArgumentSplitter::createNewArguments() {
24902490
assert(Agg->hasValue() && "Expected a result");
24912491
}
24922492

2493-
SILValue(Arg).replaceAllUsesWith(SILValue(Agg));
2493+
Arg->replaceAllUsesWith(Agg);
24942494

24952495
// Look at all users of agg and see if we can simplify any of them. This will
24962496
// eliminate struct_extracts/tuple_extracts from the newly created aggregate

lib/SILOptimizer/Utils/CFG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ bool swift::mergeBasicBlockWithSuccessor(SILBasicBlock *BB, DominanceInfo *DT,
728728
// If there are any BB arguments in the destination, replace them with the
729729
// branch operands, since they must dominate the dest block.
730730
for (unsigned i = 0, e = Branch->getArgs().size(); i != e; ++i)
731-
SILValue(SuccBB->getBBArg(i)).replaceAllUsesWith(Branch->getArg(i));
731+
SuccBB->getBBArg(i)->replaceAllUsesWith(Branch->getArg(i).getDef());
732732

733733
Branch->eraseFromParent();
734734

lib/SILOptimizer/Utils/Local.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ bool swift::simplifyUsers(SILInstruction *I) {
22212221
if (!S)
22222222
continue;
22232223

2224-
SILValue(User).replaceAllUsesWith(S);
2224+
User->replaceAllUsesWith(S.getDef());
22252225
User->eraseFromParent();
22262226
Changed = true;
22272227
}

lib/SILOptimizer/Utils/SILInliner.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool SILInliner::inlineFunction(FullApplySite AI, ArrayRef<SILValue> Args) {
112112
if (ReturnInst *RI = dyn_cast<ReturnInst>(CalleeEntryBB->getTerminator())) {
113113
// Replace all uses of the apply instruction with the operands of the
114114
// return instruction, appropriately mapped.
115-
SILValue(nonTryAI).replaceAllUsesWith(remapValue(RI->getOperand()));
115+
nonTryAI->replaceAllUsesWith(remapValue(RI->getOperand()).getDef());
116116
return true;
117117
}
118118
}
@@ -137,10 +137,10 @@ bool SILInliner::inlineFunction(FullApplySite AI, ArrayRef<SILValue> Args) {
137137
SILFunction::iterator(ReturnToBB));
138138

139139
// Create an argument on the return-to BB representing the returned value.
140-
SILValue RetArg = new (F.getModule()) SILArgument(ReturnToBB,
140+
auto *RetArg = new (F.getModule()) SILArgument(ReturnToBB,
141141
AI.getInstruction()->getType());
142142
// Replace all uses of the ApplyInst with the new argument.
143-
SILValue(AI.getInstruction()).replaceAllUsesWith(RetArg);
143+
AI.getInstruction()->replaceAllUsesWith(RetArg);
144144
}
145145

146146
// Now iterate over the callee BBs and fix up the terminators.

0 commit comments

Comments
 (0)