@@ -406,8 +406,7 @@ struct AddressLoweringState {
406
406
// All function-exiting terminators (return or throw instructions).
407
407
SmallVector<TermInst *, 8 > exitingInsts;
408
408
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.
411
410
std::unique_ptr<PhiRewriter> phiRewriter;
412
411
413
412
AddressLoweringState (SILFunction *function, DominanceInfo *domInfo)
@@ -758,10 +757,11 @@ static Operand *getProjectedDefOperand(SILValue value) {
758
757
}
759
758
}
760
759
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.
765
765
static Operand *getReusedStorageOperand (SILValue value) {
766
766
switch (value->getKind ()) {
767
767
default :
@@ -785,7 +785,7 @@ static Operand *getReusedStorageOperand(SILValue value) {
785
785
}
786
786
787
787
// / 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
789
789
// / forwards its operands to arguments.
790
790
// /
791
791
// / TODO: Handle SwitchValueInst, CheckedCastValueBranchInst.
@@ -1446,7 +1446,7 @@ AddressMaterialization::materializeProjectionIntoUse(Operand *operand,
1446
1446
// ===----------------------------------------------------------------------===//
1447
1447
// PhiRewriter
1448
1448
//
1449
- // Insert copies on CFG edges to break phi operand interferences.
1449
+ // Insert moves on CFG edges to break phi operand interferences.
1450
1450
// ===----------------------------------------------------------------------===//
1451
1451
1452
1452
namespace {
@@ -1456,18 +1456,18 @@ namespace {
1456
1456
// 1. Materialize the phi address. If the phi projects into a use, this requires
1457
1457
// initialization of the user's storage in each predecessor.
1458
1458
//
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
1460
1460
// materialized phi address.
1461
1461
//
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
1463
1463
// 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
1468
1468
// read must occur before the write.
1469
1469
//
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
1471
1471
// and destination of the new phi interferes with other phis (the classic
1472
1472
// phi-swap problem).
1473
1473
//
@@ -1486,18 +1486,18 @@ namespace {
1486
1486
// br bb3(val0, val1)
1487
1487
// bb2:
1488
1488
// 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
1492
1492
// dealloc_stack temp
1493
1493
// br bb3(val1, val1)
1494
1494
// bb3(phi0, phi1):
1495
1495
class PhiRewriter {
1496
1496
AddressLoweringState &pass;
1497
1497
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
1499
1499
// occur on the CFG edge. Keep track of them to resolve anti-dependencies.
1500
- SmallPtrSet<CopyAddrInst *, 16 > phiCopies ;
1500
+ SmallPtrSet<CopyAddrInst *, 16 > phiMoves ;
1501
1501
1502
1502
public:
1503
1503
PhiRewriter (AddressLoweringState &pass) : pass(pass) {}
@@ -1508,18 +1508,18 @@ class PhiRewriter {
1508
1508
PhiRewriter (const PhiRewriter &) = delete ;
1509
1509
PhiRewriter &operator =(const PhiRewriter &) = delete ;
1510
1510
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,
1513
1513
IsInitialization);
1514
- phiCopies .insert (copy );
1515
- return copy ;
1514
+ phiMoves .insert (move );
1515
+ return move ;
1516
1516
}
1517
1517
1518
- struct CopyPosition {
1519
- SILBasicBlock::iterator latestCopyPos ;
1518
+ struct MovePosition {
1519
+ SILBasicBlock::iterator latestMovePos ;
1520
1520
bool foundAntiDependenceCycle = false ;
1521
1521
};
1522
- CopyPosition findPhiCopyPosition (PhiOperand phiOper);
1522
+ MovePosition findPhiMovePosition (PhiOperand phiOper);
1523
1523
};
1524
1524
} // anonymous namespace
1525
1525
@@ -1529,32 +1529,32 @@ void PhiRewriter::materializeOperand(PhiOperand phiOper) {
1529
1529
if (operStorage.isPhiProjection ()) {
1530
1530
if (operStorage.projectedStorageID
1531
1531
== 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.
1533
1533
return ;
1534
1534
}
1535
1535
}
1536
1536
auto phiOperAddress = operStorage.getMaterializedAddress ();
1537
1537
1538
- auto copyPos = findPhiCopyPosition (phiOper);
1538
+ auto movePos = findPhiMovePosition (phiOper);
1539
1539
1540
- auto builder = pass.getBuilder (copyPos. latestCopyPos );
1540
+ auto builder = pass.getBuilder (movePos. latestMovePos );
1541
1541
AddressMaterialization addrMat (pass, builder);
1542
1542
1543
1543
auto &phiStorage = pass.valueStorageMap .getStorage (phiOper.getValue ());
1544
1544
SILValue phiAddress =
1545
1545
addrMat.materializeUseProjectionStorage (phiStorage,
1546
1546
/* intoPhiOperand*/ true );
1547
1547
1548
- if (!copyPos .foundAntiDependenceCycle ) {
1549
- createPhiCopy (builder, phiOperAddress, phiAddress);
1548
+ if (!movePos .foundAntiDependenceCycle ) {
1549
+ createPhiMove (builder, phiOperAddress, phiAddress);
1550
1550
return ;
1551
1551
}
1552
1552
AllocStackInst *alloc =
1553
1553
builder.createAllocStack (pass.genLoc (), phiOper.getValue ()->getType ());
1554
- createPhiCopy (builder, phiOperAddress, alloc);
1554
+ createPhiMove (builder, phiOperAddress, alloc);
1555
1555
1556
1556
auto tempBuilder = pass.getBuilder (phiOper.getBranch ()->getIterator ());
1557
- createPhiCopy (tempBuilder, alloc, phiAddress);
1557
+ createPhiMove (tempBuilder, alloc, phiAddress);
1558
1558
tempBuilder.createDeallocStack (pass.genLoc (), alloc);
1559
1559
}
1560
1560
@@ -1565,9 +1565,9 @@ PhiRewriter &AddressLoweringState::getPhiRewriter() {
1565
1565
return *(this ->phiRewriter .get ());
1566
1566
}
1567
1567
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) {
1571
1571
auto phiBaseAddress =
1572
1572
pass.valueStorageMap .getBaseStorage (phiOper.getValue ()).storageAddress ;
1573
1573
@@ -1578,34 +1578,34 @@ PhiRewriter::CopyPosition PhiRewriter::findPhiCopyPosition(PhiOperand phiOper) {
1578
1578
auto insertPt = phiOper.getBranch ()->getIterator ();
1579
1579
bool foundEarliestInsertPoint = false ;
1580
1580
1581
- CopyPosition copyPos ;
1582
- copyPos. latestCopyPos = insertPt;
1581
+ MovePosition movePos ;
1582
+ movePos. latestMovePos = insertPt;
1583
1583
1584
- // Continue scanning until all phi copies have been checked for interference.
1584
+ // Continue scanning until all phi moves have been checked for interference.
1585
1585
for (auto beginIter = phiOper.predBlock ->begin (); insertPt != beginIter;) {
1586
1586
--insertPt;
1587
1587
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 ))
1590
1590
break ;
1591
1591
1592
1592
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
1595
1595
// the phi storage before this point.
1596
1596
foundEarliestInsertPoint = true ;
1597
1597
}
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
1600
1600
// of the operand storage after this point.
1601
- copyPos. latestCopyPos = insertPt;
1601
+ movePos. latestMovePos = insertPt;
1602
1602
// If the earliest and latest points conflict, allocate a temporary.
1603
1603
if (foundEarliestInsertPoint) {
1604
- copyPos .foundAntiDependenceCycle = true ;
1604
+ movePos .foundAntiDependenceCycle = true ;
1605
1605
}
1606
1606
}
1607
1607
}
1608
- return copyPos ;
1608
+ return movePos ;
1609
1609
}
1610
1610
1611
1611
// ===----------------------------------------------------------------------===//
0 commit comments