Skip to content

Commit 7fb9bca

Browse files
committed
[Mem2Reg] NFC: Lifted livePhiBlocks higher.
Move it all the way up into MemoryToRegisters::run in preparation for using it to canonicalize new phis.
1 parent c9e0bb5 commit 7fb9bca

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ class StackAllocationPromoter {
950950
}
951951

952952
/// Promote the Allocation.
953-
void run();
953+
void run(BasicBlockSetVector &livePhiBlocks);
954954

955955
private:
956956
/// Promote AllocStacks into SSA.
@@ -1808,19 +1808,14 @@ void StackAllocationPromoter::promoteAllocationToPhi(
18081808
LLVM_DEBUG(llvm::dbgs() << "*** Finished placing Phis ***\n");
18091809
}
18101810

1811-
void StackAllocationPromoter::run() {
1811+
void StackAllocationPromoter::run(BasicBlockSetVector &livePhiBlocks) {
18121812
auto *function = asi->getFunction();
18131813

18141814
// Reduce the number of load/stores in the function to minimum.
18151815
// After this phase we are left with up to one load and store
18161816
// per block and the last store is recorded.
18171817
pruneAllocStackUsage();
18181818

1819-
// The blocks which still have new phis after fixBranchesAndUses runs. These
1820-
// are not necessarily the same as phiBlocks because fixBranchesAndUses
1821-
// removes superfluous proactive phis.
1822-
BasicBlockSetVector livePhiBlocks(asi->getFunction());
1823-
18241819
// Replace AllocStacks with Phi-nodes.
18251820
promoteAllocationToPhi(livePhiBlocks);
18261821

@@ -1931,7 +1926,8 @@ class MemoryToRegisters {
19311926
///
19321927
/// Note: Populates instructionsToDelete with the instructions the caller is
19331928
/// responsible for deleting.
1934-
bool promoteAllocation(AllocStackInst *asi);
1929+
bool promoteAllocation(AllocStackInst *asi,
1930+
BasicBlockSetVector &livePhiBlocks);
19351931

19361932
public:
19371933
/// C'tor
@@ -2132,7 +2128,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
21322128
/// or false if not. On success, this returns true and usually drops all of the
21332129
/// uses of the AllocStackInst, but never deletes the ASI itself. Callers
21342130
/// should check to see if the ASI is dead after this and remove it if so.
2135-
bool MemoryToRegisters::promoteAllocation(AllocStackInst *alloc) {
2131+
bool MemoryToRegisters::promoteAllocation(AllocStackInst *alloc,
2132+
BasicBlockSetVector &livePhiBlocks) {
21362133
LLVM_DEBUG(llvm::dbgs() << "*** Memory to register looking at: " << *alloc);
21372134
++NumAllocStackFound;
21382135

@@ -2174,7 +2171,8 @@ bool MemoryToRegisters::promoteAllocation(AllocStackInst *alloc) {
21742171
auto &domTreeLevels = getDomTreeLevels();
21752172
StackAllocationPromoter(alloc, domInfo, domTreeLevels, ctx, deleter,
21762173
instructionsToDelete)
2177-
.run();
2174+
.run(livePhiBlocks);
2175+
21782176
return true;
21792177
}
21802178

@@ -2194,7 +2192,11 @@ bool MemoryToRegisters::run() {
21942192
if (!asi)
21952193
continue;
21962194

2197-
if (promoteAllocation(asi)) {
2195+
// The blocks which still have new phis after fixBranchesAndUses runs.
2196+
// These are not necessarily the same as phiBlocks because
2197+
// fixBranchesAndUses removes superfluous proactive phis.
2198+
BasicBlockSetVector livePhiBlocks(asi->getFunction());
2199+
if (promoteAllocation(asi, livePhiBlocks)) {
21982200
for (auto *inst : instructionsToDelete) {
21992201
deleter.forceDelete(inst);
22002202
}

0 commit comments

Comments
 (0)