@@ -847,7 +847,6 @@ namespace {
847
847
848
848
// / Promotes a single AllocStackInst into registers..
849
849
class StackAllocationPromoter {
850
- using BlockSetVector = BasicBlockSetVector;
851
850
using BlockToInstMap = llvm::DenseMap<SILBasicBlock *, SILInstruction *>;
852
851
853
852
// Use a priority queue keyed on dominator tree level so that inserted nodes
@@ -955,56 +954,58 @@ class StackAllocationPromoter {
955
954
956
955
private:
957
956
// / Promote AllocStacks into SSA.
958
- void promoteAllocationToPhi (BlockSetVector &livePhiBlocks);
957
+ void promoteAllocationToPhi (BasicBlockSetVector &livePhiBlocks);
959
958
960
959
// / Replace the dummy nodes with new block arguments.
961
- void addBlockArguments (BlockSetVector &phiBlocks);
960
+ void addBlockArguments (BasicBlockSetVector &phiBlocks);
962
961
963
962
// / Check if \p phi is a proactively added phi by SILMem2Reg
964
- bool isProactivePhi (SILPhiArgument *phi, const BlockSetVector &phiBlocks);
963
+ bool isProactivePhi (SILPhiArgument *phi,
964
+ const BasicBlockSetVector &phiBlocks);
965
965
966
966
// / Check if \p proactivePhi is live.
967
967
bool isNecessaryProactivePhi (SILPhiArgument *proactivePhi,
968
- const BlockSetVector &phiBlocks);
968
+ const BasicBlockSetVector &phiBlocks);
969
969
970
970
// / Given a \p proactivePhi that is live, backward propagate liveness to
971
971
// / other proactivePhis.
972
972
void propagateLiveness (SILPhiArgument *proactivePhi,
973
- const BlockSetVector &phiBlocks,
973
+ const BasicBlockSetVector &phiBlocks,
974
974
SmallPtrSetImpl<SILPhiArgument *> &livePhis);
975
975
976
976
// / End the lexical borrow scope that is introduced for lexical alloc_stack
977
977
// / instructions.
978
- void endLexicalLifetime (BlockSetVector &phiBlocks);
978
+ void endLexicalLifetime (BasicBlockSetVector &phiBlocks);
979
979
980
980
// / Fix all of the branch instructions and the uses to use
981
981
// / the AllocStack definitions (which include stores and Phis).
982
- void fixBranchesAndUses (BlockSetVector &blocks, BlockSetVector &liveBlocks);
982
+ void fixBranchesAndUses (BasicBlockSetVector &blocks,
983
+ BasicBlockSetVector &liveBlocks);
983
984
984
985
// / update the branch instructions with the new Phi argument.
985
986
// / The blocks in \p PhiBlocks are blocks that define a value, \p Dest is
986
987
// / the branch destination, and \p Pred is the predecessors who's branch we
987
988
// / modify.
988
- void fixPhiPredBlock (BlockSetVector &phiBlocks, SILBasicBlock *dest,
989
+ void fixPhiPredBlock (BasicBlockSetVector &phiBlocks, SILBasicBlock *dest,
989
990
SILBasicBlock *pred);
990
991
991
992
// / Get the values for this AllocStack variable that are flowing out of
992
993
// / StartBB.
993
- llvm::Optional<LiveValues> getLiveOutValues (BlockSetVector &phiBlocks,
994
+ llvm::Optional<LiveValues> getLiveOutValues (BasicBlockSetVector &phiBlocks,
994
995
SILBasicBlock *startBlock);
995
996
996
997
// / Get the values for this AllocStack variable that are flowing out of
997
998
// / StartBB or undef if there are none.
998
- LiveValues getEffectiveLiveOutValues (BlockSetVector &phiBlocks,
999
+ LiveValues getEffectiveLiveOutValues (BasicBlockSetVector &phiBlocks,
999
1000
SILBasicBlock *startBlock);
1000
1001
1001
1002
// / Get the values for this AllocStack variable that are flowing into block.
1002
- llvm::Optional<LiveValues> getLiveInValues (BlockSetVector &phiBlocks,
1003
+ llvm::Optional<LiveValues> getLiveInValues (BasicBlockSetVector &phiBlocks,
1003
1004
SILBasicBlock *block);
1004
1005
1005
1006
// / Get the values for this AllocStack variable that are flowing into block or
1006
1007
// / undef if there are none.
1007
- LiveValues getEffectiveLiveInValues (BlockSetVector &phiBlocks,
1008
+ LiveValues getEffectiveLiveInValues (BasicBlockSetVector &phiBlocks,
1008
1009
SILBasicBlock *block);
1009
1010
1010
1011
// / Prune AllocStacks usage in the function. Scan the function
@@ -1256,7 +1257,8 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
1256
1257
return nullptr ;
1257
1258
}
1258
1259
1259
- void StackAllocationPromoter::addBlockArguments (BlockSetVector &phiBlocks) {
1260
+ void StackAllocationPromoter::addBlockArguments (
1261
+ BasicBlockSetVector &phiBlocks) {
1260
1262
LLVM_DEBUG (llvm::dbgs () << " *** Adding new block arguments.\n " );
1261
1263
1262
1264
for (auto *block : phiBlocks) {
@@ -1266,7 +1268,7 @@ void StackAllocationPromoter::addBlockArguments(BlockSetVector &phiBlocks) {
1266
1268
}
1267
1269
1268
1270
llvm::Optional<LiveValues>
1269
- StackAllocationPromoter::getLiveOutValues (BlockSetVector &phiBlocks,
1271
+ StackAllocationPromoter::getLiveOutValues (BasicBlockSetVector &phiBlocks,
1270
1272
SILBasicBlock *startBlock) {
1271
1273
LLVM_DEBUG (llvm::dbgs () << " *** Searching for a value definition.\n " );
1272
1274
// Walk the Dom tree in search of a defining value:
@@ -1301,9 +1303,8 @@ StackAllocationPromoter::getLiveOutValues(BlockSetVector &phiBlocks,
1301
1303
return llvm::None;
1302
1304
}
1303
1305
1304
- LiveValues
1305
- StackAllocationPromoter::getEffectiveLiveOutValues (BlockSetVector &phiBlocks,
1306
- SILBasicBlock *startBlock) {
1306
+ LiveValues StackAllocationPromoter::getEffectiveLiveOutValues (
1307
+ BasicBlockSetVector &phiBlocks, SILBasicBlock *startBlock) {
1307
1308
if (auto values = getLiveOutValues (phiBlocks, startBlock)) {
1308
1309
return *values;
1309
1310
}
@@ -1312,7 +1313,7 @@ StackAllocationPromoter::getEffectiveLiveOutValues(BlockSetVector &phiBlocks,
1312
1313
}
1313
1314
1314
1315
llvm::Optional<LiveValues>
1315
- StackAllocationPromoter::getLiveInValues (BlockSetVector &phiBlocks,
1316
+ StackAllocationPromoter::getLiveInValues (BasicBlockSetVector &phiBlocks,
1316
1317
SILBasicBlock *block) {
1317
1318
// First, check if there is a Phi value in the current block. We know that
1318
1319
// our loads happen before stores, so we need to first check for Phi nodes
@@ -1337,9 +1338,8 @@ StackAllocationPromoter::getLiveInValues(BlockSetVector &phiBlocks,
1337
1338
return getLiveOutValues (phiBlocks, iDom->getBlock ());
1338
1339
}
1339
1340
1340
- LiveValues
1341
- StackAllocationPromoter::getEffectiveLiveInValues (BlockSetVector &phiBlocks,
1342
- SILBasicBlock *block) {
1341
+ LiveValues StackAllocationPromoter::getEffectiveLiveInValues (
1342
+ BasicBlockSetVector &phiBlocks, SILBasicBlock *block) {
1343
1343
if (auto values = getLiveInValues (phiBlocks, block)) {
1344
1344
return *values;
1345
1345
}
@@ -1348,7 +1348,7 @@ StackAllocationPromoter::getEffectiveLiveInValues(BlockSetVector &phiBlocks,
1348
1348
return LiveValues::forOwned (undef, undef);
1349
1349
}
1350
1350
1351
- void StackAllocationPromoter::fixPhiPredBlock (BlockSetVector &phiBlocks,
1351
+ void StackAllocationPromoter::fixPhiPredBlock (BasicBlockSetVector &phiBlocks,
1352
1352
SILBasicBlock *destBlock,
1353
1353
SILBasicBlock *predBlock) {
1354
1354
TermInst *ti = predBlock->getTerminator ();
@@ -1366,15 +1366,15 @@ void StackAllocationPromoter::fixPhiPredBlock(BlockSetVector &phiBlocks,
1366
1366
deleter.forceDelete (ti);
1367
1367
}
1368
1368
1369
- bool StackAllocationPromoter::isProactivePhi (SILPhiArgument *phi,
1370
- const BlockSetVector &phiBlocks) {
1369
+ bool StackAllocationPromoter::isProactivePhi (
1370
+ SILPhiArgument *phi, const BasicBlockSetVector &phiBlocks) {
1371
1371
auto *phiBlock = phi->getParentBlock ();
1372
1372
return phiBlocks.contains (phiBlock) &&
1373
1373
phi == phiBlock->getArgument (phiBlock->getNumArguments () - 1 );
1374
1374
}
1375
1375
1376
1376
bool StackAllocationPromoter::isNecessaryProactivePhi (
1377
- SILPhiArgument *proactivePhi, const BlockSetVector &phiBlocks) {
1377
+ SILPhiArgument *proactivePhi, const BasicBlockSetVector &phiBlocks) {
1378
1378
assert (isProactivePhi (proactivePhi, phiBlocks));
1379
1379
for (auto *use : proactivePhi->getUses ()) {
1380
1380
auto *branch = dyn_cast<BranchInst>(use->getUser ());
@@ -1392,7 +1392,7 @@ bool StackAllocationPromoter::isNecessaryProactivePhi(
1392
1392
}
1393
1393
1394
1394
void StackAllocationPromoter::propagateLiveness (
1395
- SILPhiArgument *proactivePhi, const BlockSetVector &phiBlocks,
1395
+ SILPhiArgument *proactivePhi, const BasicBlockSetVector &phiBlocks,
1396
1396
SmallPtrSetImpl<SILPhiArgument *> &livePhis) {
1397
1397
assert (isProactivePhi (proactivePhi, phiBlocks));
1398
1398
if (livePhis.contains (proactivePhi))
@@ -1412,8 +1412,8 @@ void StackAllocationPromoter::propagateLiveness(
1412
1412
}
1413
1413
}
1414
1414
1415
- void StackAllocationPromoter::fixBranchesAndUses (BlockSetVector &phiBlocks,
1416
- BlockSetVector &phiBlocksOut) {
1415
+ void StackAllocationPromoter::fixBranchesAndUses (
1416
+ BasicBlockSetVector &phiBlocks, BasicBlockSetVector &phiBlocksOut) {
1417
1417
// First update uses of the value.
1418
1418
SmallVector<SILInstruction *, 4 > collectedLoads;
1419
1419
// Collect all alloc_stack uses.
@@ -1565,7 +1565,8 @@ void StackAllocationPromoter::fixBranchesAndUses(BlockSetVector &phiBlocks,
1565
1565
// /
1566
1566
// / This can only happen if the successor is a CFG merge and all paths
1567
1567
// / from here lead to unreachable.
1568
- void StackAllocationPromoter::endLexicalLifetime (BlockSetVector &phiBlocks) {
1568
+ void StackAllocationPromoter::endLexicalLifetime (
1569
+ BasicBlockSetVector &phiBlocks) {
1569
1570
if (!lexicalLifetimeEnsured (asi))
1570
1571
return ;
1571
1572
@@ -1679,7 +1680,7 @@ void StackAllocationPromoter::endLexicalLifetime(BlockSetVector &phiBlocks) {
1679
1680
1680
1681
void StackAllocationPromoter::pruneAllocStackUsage () {
1681
1682
LLVM_DEBUG (llvm::dbgs () << " *** Pruning : " << *asi);
1682
- BlockSetVector functionBlocks (asi->getFunction ());
1683
+ BasicBlockSetVector functionBlocks (asi->getFunction ());
1683
1684
1684
1685
// Insert all of the blocks that asi is live in.
1685
1686
for (auto *use : asi->getUses ())
@@ -1703,11 +1704,11 @@ void StackAllocationPromoter::pruneAllocStackUsage() {
1703
1704
}
1704
1705
1705
1706
void StackAllocationPromoter::promoteAllocationToPhi (
1706
- BlockSetVector &livePhiBlocks) {
1707
+ BasicBlockSetVector &livePhiBlocks) {
1707
1708
LLVM_DEBUG (llvm::dbgs () << " *** Placing Phis for : " << *asi);
1708
1709
1709
1710
// A list of blocks that will require new Phi values.
1710
- BlockSetVector phiBlocks (asi->getFunction ());
1711
+ BasicBlockSetVector phiBlocks (asi->getFunction ());
1711
1712
1712
1713
// The "piggy-bank" data-structure that we use for processing the dom-tree
1713
1714
// bottom-up.
@@ -1818,7 +1819,7 @@ void StackAllocationPromoter::run() {
1818
1819
// The blocks which still have new phis after fixBranchesAndUses runs. These
1819
1820
// are not necessarily the same as phiBlocks because fixBranchesAndUses
1820
1821
// removes superfluous proactive phis.
1821
- BlockSetVector livePhiBlocks (asi->getFunction ());
1822
+ BasicBlockSetVector livePhiBlocks (asi->getFunction ());
1822
1823
1823
1824
// Replace AllocStacks with Phi-nodes.
1824
1825
promoteAllocationToPhi (livePhiBlocks);
0 commit comments