Skip to content

Commit 2aa8427

Browse files
committed
SILCloner: rename 'remapValue' to 'getMappedValue' to avoid confusion.
A follow up commit adds an API for SILCloner clients to set mapped values. Calling the map lookup "remap" would be unacceptably misleading.
1 parent 0777578 commit 2aa8427

File tree

11 files changed

+27
-28
lines changed

11 files changed

+27
-28
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
285285
///
286286
/// Assumes that `isValueCloned` is true.
287287
SILValue getOpValue(SILValue Value) {
288-
return asImpl().remapValue(Value);
288+
return asImpl().getMappedValue(Value);
289289
}
290290
template <size_t N, typename ArrayRefType>
291291
SmallVector<SILValue, N> getOpValueArray(ArrayRefType Values) {
292292
SmallVector<SILValue, N> Ret(Values.size());
293293
for (unsigned i = 0, e = Values.size(); i != e; ++i)
294-
Ret[i] = asImpl().remapValue(Values[i]);
294+
Ret[i] = asImpl().getMappedValue(Values[i]);
295295
return Ret;
296296
}
297297

@@ -351,7 +351,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
351351
ProtocolConformanceRef remapConformance(Type Ty, ProtocolConformanceRef C) {
352352
return C;
353353
}
354-
SILValue remapValue(SILValue Value);
354+
SILValue getMappedValue(SILValue Value);
355355
SILFunction *remapFunction(SILFunction *Func) { return Func; }
356356
SILBasicBlock *remapBasicBlock(SILBasicBlock *BB);
357357
void postProcess(SILInstruction *Orig, SILInstruction *Cloned);
@@ -472,7 +472,7 @@ class SILClonerWithScopes : public SILCloner<ImplClass> {
472472

473473
template<typename ImplClass>
474474
SILValue
475-
SILCloner<ImplClass>::remapValue(SILValue Value) {
475+
SILCloner<ImplClass>::getMappedValue(SILValue Value) {
476476
auto VI = ValueMap.find(Value);
477477
if (VI != ValueMap.end())
478478
return VI->second;

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class BaseThreadingCloner : public SILClonerWithScopes<BaseThreadingCloner> {
322322

323323
SILBasicBlock *remapBasicBlock(SILBasicBlock *BB) { return BB; }
324324

325-
SILValue remapValue(SILValue Value) {
325+
SILValue getMappedValue(SILValue Value) {
326326
// If this is a use of an instruction in another block, then just use it.
327327
if (auto SI = Value->getDefiningInstruction()) {
328328
if (SI->getParent() != FromBB)
@@ -334,8 +334,7 @@ class BaseThreadingCloner : public SILClonerWithScopes<BaseThreadingCloner> {
334334
assert(isa<SILUndef>(Value) && "Unexpected Value kind");
335335
return Value;
336336
}
337-
338-
return SILCloner<BaseThreadingCloner>::remapValue(Value);
337+
return SILCloner<BaseThreadingCloner>::getMappedValue(Value);
339338
}
340339

341340
void postProcess(SILInstruction *Orig, SILInstruction *Cloned) {

lib/SIL/SILInstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ namespace {
10911091
Result = Cloned;
10921092
SILCloner<TrivialCloner>::postProcess(Orig, Cloned);
10931093
}
1094-
SILValue remapValue(SILValue Value) {
1094+
SILValue getMappedValue(SILValue Value) {
10951095
return Value;
10961096
}
10971097
SILBasicBlock *remapBasicBlock(SILBasicBlock *BB) { return BB; }

lib/SILOptimizer/IPO/CapturePropagation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void CapturePropagationCloner::cloneClosure(
202202

203203
// The PartialApplyArg from the caller is now mapped to its cloned
204204
// instruction. Also map the original argument to the cloned instruction.
205-
entryArgs.push_back(remapValue(PartialApplyArg));
205+
entryArgs.push_back(getMappedValue(PartialApplyArg));
206206
++ArgIdx;
207207
}
208208
IsCloningConstant = false;

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ class InstructionsCloner : public SILClonerWithScopes<InstructionsCloner> {
175175

176176
SILBasicBlock *remapBasicBlock(SILBasicBlock *BB) { return BB; }
177177

178-
SILValue remapValue(SILValue Value) {
179-
return SILCloner<InstructionsCloner>::remapValue(Value);
178+
SILValue getMappedValue(SILValue Value) {
179+
return SILCloner<InstructionsCloner>::getMappedValue(Value);
180180
}
181181

182182
void postProcess(SILInstruction *Orig, SILInstruction *Cloned) {

lib/SILOptimizer/IPO/LetPropertiesOpts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class InitSequenceCloner : public SILClonerWithScopes<InitSequenceCloner> {
109109

110110
SILBasicBlock *remapBasicBlock(SILBasicBlock *BB) { return BB; }
111111

112-
SILValue remapValue(SILValue Value) {
113-
return SILCloner<InitSequenceCloner>::remapValue(Value);
112+
SILValue getMappedValue(SILValue Value) {
113+
return SILCloner<InitSequenceCloner>::getMappedValue(Value);
114114
}
115115

116116
void postProcess(SILInstruction *orig, SILInstruction *cloned) {
@@ -125,7 +125,7 @@ class InitSequenceCloner : public SILClonerWithScopes<InitSequenceCloner> {
125125
SILValue clone() {
126126
for (auto I : Init.Instructions)
127127
process(I);
128-
return remapValue(Init.Result);
128+
return getMappedValue(Init.Result);
129129
}
130130
};
131131

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ class RegionCloner : public SILCloner<RegionCloner> {
15791579
}
15801580
}
15811581

1582-
SILValue remapValue(SILValue V) {
1582+
SILValue getMappedValue(SILValue V) {
15831583
if (auto *BB = V->getParentBlock()) {
15841584
if (!DomTree.dominates(StartBB, BB)) {
15851585
// Must be a value that dominates the start basic block.
@@ -1588,7 +1588,7 @@ class RegionCloner : public SILCloner<RegionCloner> {
15881588
return V;
15891589
}
15901590
}
1591-
return SILCloner<RegionCloner>::remapValue(V);
1591+
return SILCloner<RegionCloner>::getMappedValue(V);
15921592
}
15931593

15941594
void postProcess(SILInstruction *Orig, SILInstruction *Cloned) {
@@ -1610,7 +1610,7 @@ class RegionCloner : public SILCloner<RegionCloner> {
16101610
// Update SSA form.
16111611
SSAUp.Initialize(V->getType());
16121612
SSAUp.AddAvailableValue(OrigBB, V);
1613-
SILValue NewVal = remapValue(V);
1613+
SILValue NewVal = getMappedValue(V);
16141614
SSAUp.AddAvailableValue(getOpBasicBlock(OrigBB), NewVal);
16151615
for (auto U : UseList) {
16161616
Operand *Use = U;

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ class LoopCloner : public SILCloner<LoopCloner> {
5454

5555
protected:
5656
// SILCloner CRTP override.
57-
SILValue remapValue(SILValue V) {
57+
SILValue getMappedValue(SILValue V) {
5858
if (auto *BB = V->getParentBlock()) {
5959
if (!Loop->contains(BB))
6060
return V;
6161
}
62-
return SILCloner<LoopCloner>::remapValue(V);
62+
return SILCloner<LoopCloner>::getMappedValue(V);
6363
}
6464
// SILCloner CRTP override.
6565
void postProcess(SILInstruction *Orig, SILInstruction *Cloned) {
@@ -281,7 +281,7 @@ void LoopCloner::collectLoopLiveOutValues(
281281
auto ArgumentValue = SILValue(Arg);
282282
if (!LoopLiveOutValues.count(ArgumentValue))
283283
LoopLiveOutValues[ArgumentValue].push_back(
284-
remapValue(ArgumentValue));
284+
getMappedValue(ArgumentValue));
285285
}
286286
}
287287
}
@@ -297,7 +297,7 @@ void LoopCloner::collectLoopLiveOutValues(
297297
assert(UsedValue == result && "Instructions must match");
298298

299299
if (!LoopLiveOutValues.count(UsedValue))
300-
LoopLiveOutValues[UsedValue].push_back(remapValue(result));
300+
LoopLiveOutValues[UsedValue].push_back(getMappedValue(result));
301301
}
302302
}
303303
}

lib/SILOptimizer/Transforms/CSE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ namespace {
603603
Result = Cloned;
604604
SILCloner<InstructionCloner>::postProcess(Orig, Cloned);
605605
}
606-
SILValue remapValue(SILValue Value) {
606+
SILValue getMappedValue(SILValue Value) {
607607
return Value;
608608
}
609609
SILBasicBlock *remapBasicBlock(SILBasicBlock *BB) { return BB; }

lib/SILOptimizer/Utils/Local.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ StaticInitCloner::clone(SingleValueInstruction *InitVal) {
15941594
}
15951595
}
15961596
}
1597-
return cast<SingleValueInstruction>(remapValue(InitVal));
1597+
return cast<SingleValueInstruction>(getMappedValue(InitVal));
15981598
}
15991599

16001600
Optional<FindLocalApplySitesResult>

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class BeginApplySite {
132132
bool processTerminator(
133133
TermInst *terminator, SILBasicBlock *returnToBB,
134134
llvm::function_ref<SILBasicBlock *(SILBasicBlock *)> remapBlock,
135-
llvm::function_ref<SILValue(SILValue)> remapValue) {
135+
llvm::function_ref<SILValue(SILValue)> getMappedValue) {
136136
// A yield branches to the begin_apply return block passing the yielded
137137
// results as branch arguments. Collect the yields target block for
138138
// resuming later. Pass an integer token to the begin_apply return block
@@ -147,7 +147,7 @@ class BeginApplySite {
147147
auto callerYields = BeginApply->getYieldedValues();
148148
assert(calleeYields.size() == callerYields.size());
149149
for (auto i : indices(calleeYields)) {
150-
auto remappedYield = remapValue(calleeYields[i]);
150+
auto remappedYield = getMappedValue(calleeYields[i]);
151151
callerYields[i]->replaceAllUsesWith(remappedYield);
152152
}
153153
Builder.createBranch(Loc, returnToBB);
@@ -471,14 +471,14 @@ void SILInlineCloner::visitTerminator(SILBasicBlock *BB) {
471471
[=](SILBasicBlock *Block) -> SILBasicBlock * {
472472
return this->remapBasicBlock(Block);
473473
},
474-
[=](SILValue Val) -> SILValue { return this->remapValue(Val); }))
474+
[=](SILValue Val) -> SILValue { return this->getMappedValue(Val); }))
475475
return;
476476
}
477477

478478
// Modify return terminators to branch to the return-to BB, rather than
479479
// trying to clone the ReturnInst.
480480
if (auto *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
481-
auto returnedValue = remapValue(RI->getOperand());
481+
auto returnedValue = getMappedValue(RI->getOperand());
482482
getBuilder().createBranch(Loc.getValue(), ReturnToBB, returnedValue);
483483
return;
484484
}
@@ -499,7 +499,7 @@ void SILInlineCloner::visitTerminator(SILBasicBlock *BB) {
499499
return;
500500
case FullApplySiteKind::TryApplyInst:
501501
auto tryAI = cast<TryApplyInst>(Apply);
502-
auto returnedValue = remapValue(TI->getOperand());
502+
auto returnedValue = getMappedValue(TI->getOperand());
503503
getBuilder().createBranch(Loc.getValue(), tryAI->getErrorBB(),
504504
returnedValue);
505505
return;

0 commit comments

Comments
 (0)