Skip to content

Commit 71175f7

Browse files
committed
Rename "phi copy" to "phi move" for consistency with documentation.
In classic compiler terminology, this is a "phi copy" algorithm. But the documentation now tries to clearly distinguish between "semantics copies" vs. moves, where moves are "storage copies".
1 parent c4e167f commit 71175f7

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ struct AddressLoweringState {
406406
// All function-exiting terminators (return or throw instructions).
407407
SmallVector<TermInst *, 8> exitingInsts;
408408

409-
// Copies from a phi's operand storage to the phi storage. These logically
410-
// occur on the CFG edge. Keep track of them to resolve anti-dependencies.
409+
// Handle moves from a phi's operand storage to the phi storage.
411410
std::unique_ptr<PhiRewriter> phiRewriter;
412411

413412
AddressLoweringState(SILFunction *function, DominanceInfo *domInfo)
@@ -758,10 +757,11 @@ static Operand *getProjectedDefOperand(SILValue value) {
758757
}
759758
}
760759

761-
/// Return the operand of the reused storage. These operations are always
762-
/// rewritten by the use rewriter and destructively reuse their operand's
763-
/// storage. If the result is address-only, then the operand must be
764-
/// address-only (otherwise, the operand would not necessarilly have storage).
760+
/// If \p value is a an existential or enum, then return the existential or enum
761+
/// operand. These operations are always rewritten by the UseRewriter and always
762+
/// destructively reuse the same storage as their operand. Note that if the
763+
/// operation's result is address-only, then the operand must be address-only
764+
/// and therefore must mapped to ValueStorage.
765765
static Operand *getReusedStorageOperand(SILValue value) {
766766
switch (value->getKind()) {
767767
default:
@@ -785,7 +785,7 @@ static Operand *getReusedStorageOperand(SILValue value) {
785785
}
786786

787787
/// If \p operand can project into its user, return the SILValue representing
788-
/// user's storage. The user may composes an aggregate from its operands or
788+
/// user's storage. The user may compose an aggregate from its operands or
789789
/// forwards its operands to arguments.
790790
///
791791
/// TODO: Handle SwitchValueInst, CheckedCastValueBranchInst.
@@ -1446,7 +1446,7 @@ AddressMaterialization::materializeProjectionIntoUse(Operand *operand,
14461446
//===----------------------------------------------------------------------===//
14471447
// PhiRewriter
14481448
//
1449-
// Insert copies on CFG edges to break phi operand interferences.
1449+
// Insert moves on CFG edges to break phi operand interferences.
14501450
//===----------------------------------------------------------------------===//
14511451

14521452
namespace {
@@ -1456,18 +1456,18 @@ namespace {
14561456
// 1. Materialize the phi address. If the phi projects into a use, this requires
14571457
// initialization of the user's storage in each predecessor.
14581458
//
1459-
// 2. If the phi operand is not coalesced, then copy the operand into the
1459+
// 2. If the phi operand is not coalesced, then move the operand into the
14601460
// materialized phi address.
14611461
//
1462-
// For blocks with multiple phis, all copies of phi operands semantically occur
1462+
// For blocks with multiple phis, all moves of phi operands semantically occur
14631463
// in parallel on the CFG edge from the predecessor to the phi block. As these
1464-
// copies are inserted into the predecessor's intruction list, maintain the
1465-
// illusion of parallel copies by resolving any interference between the phi
1466-
// copies. This is done by checking for anti-dependencies to or from other phi
1467-
// copies. If one phi copy's source reads from another phi copy's dest, then the
1464+
// moves are inserted into the predecessor's intruction list, maintain the
1465+
// illusion of parallel moves by resolving any interference between the phi
1466+
// moves. This is done by checking for anti-dependencies to or from other phi
1467+
// moves. If one phi move's source reads from another phi move's dest, then the
14681468
// read must occur before the write.
14691469
//
1470-
// Insert a second copy to break an anti-dependence cycle when both the source
1470+
// Insert a second move to break an anti-dependence cycle when both the source
14711471
// and destination of the new phi interferes with other phis (the classic
14721472
// phi-swap problem).
14731473
//
@@ -1486,18 +1486,18 @@ namespace {
14861486
// br bb3(val0, val1)
14871487
// bb2:
14881488
// temp = alloc_stack
1489-
// copy_addr addr0 to temp
1490-
// copy_addr addr1 to addr0
1491-
// copy_addr temp to addr1
1489+
// copy_addr [take] addr0 to [initialization] temp
1490+
// copy_addr [take] addr1 to [initialization] addr0
1491+
// copy_addr [take] temp to [initialization] addr1
14921492
// dealloc_stack temp
14931493
// br bb3(val1, val1)
14941494
// bb3(phi0, phi1):
14951495
class PhiRewriter {
14961496
AddressLoweringState &pass;
14971497

1498-
// A set of copies from a phi operand storage to phi storage. These logically
1498+
// A set of moves from a phi operand storage to phi storage. These logically
14991499
// occur on the CFG edge. Keep track of them to resolve anti-dependencies.
1500-
SmallPtrSet<CopyAddrInst *, 16> phiCopies;
1500+
SmallPtrSet<CopyAddrInst *, 16> phiMoves;
15011501

15021502
public:
15031503
PhiRewriter(AddressLoweringState &pass) : pass(pass) {}
@@ -1508,18 +1508,18 @@ class PhiRewriter {
15081508
PhiRewriter(const PhiRewriter &) = delete;
15091509
PhiRewriter &operator=(const PhiRewriter &) = delete;
15101510

1511-
CopyAddrInst *createPhiCopy(SILBuilder &builder, SILValue from, SILValue to) {
1512-
auto *copy = builder.createCopyAddr(pass.genLoc(), from, to, IsTake,
1511+
CopyAddrInst *createPhiMove(SILBuilder &builder, SILValue from, SILValue to) {
1512+
auto *move = builder.createCopyAddr(pass.genLoc(), from, to, IsTake,
15131513
IsInitialization);
1514-
phiCopies.insert(copy);
1515-
return copy;
1514+
phiMoves.insert(move);
1515+
return move;
15161516
}
15171517

1518-
struct CopyPosition {
1519-
SILBasicBlock::iterator latestCopyPos;
1518+
struct MovePosition {
1519+
SILBasicBlock::iterator latestMovePos;
15201520
bool foundAntiDependenceCycle = false;
15211521
};
1522-
CopyPosition findPhiCopyPosition(PhiOperand phiOper);
1522+
MovePosition findPhiMovePosition(PhiOperand phiOper);
15231523
};
15241524
} // anonymous namespace
15251525

@@ -1529,32 +1529,32 @@ void PhiRewriter::materializeOperand(PhiOperand phiOper) {
15291529
if (operStorage.isPhiProjection()) {
15301530
if (operStorage.projectedStorageID
15311531
== pass.valueStorageMap.getOrdinal(phiOper.getValue())) {
1532-
// This operand was coalesced with this particular phi. No copy needed.
1532+
// This operand was coalesced with this particular phi. No move needed.
15331533
return;
15341534
}
15351535
}
15361536
auto phiOperAddress = operStorage.getMaterializedAddress();
15371537

1538-
auto copyPos = findPhiCopyPosition(phiOper);
1538+
auto movePos = findPhiMovePosition(phiOper);
15391539

1540-
auto builder = pass.getBuilder(copyPos.latestCopyPos);
1540+
auto builder = pass.getBuilder(movePos.latestMovePos);
15411541
AddressMaterialization addrMat(pass, builder);
15421542

15431543
auto &phiStorage = pass.valueStorageMap.getStorage(phiOper.getValue());
15441544
SILValue phiAddress =
15451545
addrMat.materializeUseProjectionStorage(phiStorage,
15461546
/*intoPhiOperand*/ true);
15471547

1548-
if (!copyPos.foundAntiDependenceCycle) {
1549-
createPhiCopy(builder, phiOperAddress, phiAddress);
1548+
if (!movePos.foundAntiDependenceCycle) {
1549+
createPhiMove(builder, phiOperAddress, phiAddress);
15501550
return;
15511551
}
15521552
AllocStackInst *alloc =
15531553
builder.createAllocStack(pass.genLoc(), phiOper.getValue()->getType());
1554-
createPhiCopy(builder, phiOperAddress, alloc);
1554+
createPhiMove(builder, phiOperAddress, alloc);
15551555

15561556
auto tempBuilder = pass.getBuilder(phiOper.getBranch()->getIterator());
1557-
createPhiCopy(tempBuilder, alloc, phiAddress);
1557+
createPhiMove(tempBuilder, alloc, phiAddress);
15581558
tempBuilder.createDeallocStack(pass.genLoc(), alloc);
15591559
}
15601560

@@ -1565,9 +1565,9 @@ PhiRewriter &AddressLoweringState::getPhiRewriter() {
15651565
return *(this->phiRewriter.get());
15661566
}
15671567

1568-
// Return the latest position at which a copy into this phi may be emitted
1569-
// without violating an anti-dependence on another phi copy.
1570-
PhiRewriter::CopyPosition PhiRewriter::findPhiCopyPosition(PhiOperand phiOper) {
1568+
// Return the latest position at which a move into this phi may be emitted
1569+
// without violating an anti-dependence on another phi move.
1570+
PhiRewriter::MovePosition PhiRewriter::findPhiMovePosition(PhiOperand phiOper) {
15711571
auto phiBaseAddress =
15721572
pass.valueStorageMap.getBaseStorage(phiOper.getValue()).storageAddress;
15731573

@@ -1578,34 +1578,34 @@ PhiRewriter::CopyPosition PhiRewriter::findPhiCopyPosition(PhiOperand phiOper) {
15781578
auto insertPt = phiOper.getBranch()->getIterator();
15791579
bool foundEarliestInsertPoint = false;
15801580

1581-
CopyPosition copyPos;
1582-
copyPos.latestCopyPos = insertPt;
1581+
MovePosition movePos;
1582+
movePos.latestMovePos = insertPt;
15831583

1584-
// Continue scanning until all phi copies have been checked for interference.
1584+
// Continue scanning until all phi moves have been checked for interference.
15851585
for (auto beginIter = phiOper.predBlock->begin(); insertPt != beginIter;) {
15861586
--insertPt;
15871587

1588-
auto *phiCopy = dyn_cast<CopyAddrInst>(&*insertPt);
1589-
if (!phiCopy || !phiCopies.contains(phiCopy))
1588+
auto *phiMove = dyn_cast<CopyAddrInst>(&*insertPt);
1589+
if (!phiMove || !phiMoves.contains(phiMove))
15901590
break;
15911591

15921592
if (!foundEarliestInsertPoint
1593-
&& getAccessBase(phiCopy->getSrc()) == phiBaseAddress) {
1594-
// Anti-dependence from the phi copy to the phi value. Do not copy into
1593+
&& getAccessBase(phiMove->getSrc()) == phiBaseAddress) {
1594+
// Anti-dependence from the phi move to the phi value. Do not move into
15951595
// the phi storage before this point.
15961596
foundEarliestInsertPoint = true;
15971597
}
1598-
if (getAccessBase(phiCopy->getDest()) == operBaseAddress) {
1599-
// Anti-dependence from the phi operand to the phi copy. Do not copy out
1598+
if (getAccessBase(phiMove->getDest()) == operBaseAddress) {
1599+
// Anti-dependence from the phi operand to the phi move. Do not move out
16001600
// of the operand storage after this point.
1601-
copyPos.latestCopyPos = insertPt;
1601+
movePos.latestMovePos = insertPt;
16021602
// If the earliest and latest points conflict, allocate a temporary.
16031603
if (foundEarliestInsertPoint) {
1604-
copyPos.foundAntiDependenceCycle = true;
1604+
movePos.foundAntiDependenceCycle = true;
16051605
}
16061606
}
16071607
}
1608-
return copyPos;
1608+
return movePos;
16091609
}
16101610

16111611
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)