Skip to content

Commit 248292b

Browse files
committed
[cowarrayopt] Instead of always recomputing the loop we are analyzings exiting blocks when checking for dominance, use a cache.
Saves a bunch of compile time when compiling the stdlib. Specifically, when compiling the iOS 32 bit stdlib + sil-verify-all, this shaves off ~20% of the compile time.
1 parent 60ae226 commit 248292b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class COWArrayOpt {
105105
RCIdentityFunctionInfo *RCIA;
106106
SILFunction *Function;
107107
SILLoop *Loop;
108+
Optional<SmallVector<SILBasicBlock *, 8>> LoopExitingBlocks;
108109
SILBasicBlock *Preheader;
109110
DominanceInfo *DomTree;
110111
bool HasChanged = false;
@@ -195,6 +196,16 @@ class COWArrayOpt {
195196
return inst->getOperand(0);
196197
return cast<SingleValueInstruction>(inst);
197198
}
199+
200+
ArrayRef<SILBasicBlock *> getLoopExitingBlocks() const {
201+
if (!LoopExitingBlocks) {
202+
auto *self = const_cast<COWArrayOpt *>(this);
203+
self->LoopExitingBlocks.emplace();
204+
Loop->getExitingBlocks(*self->LoopExitingBlocks);
205+
}
206+
return *LoopExitingBlocks;
207+
}
208+
198209
};
199210
} // end anonymous namespace
200211

@@ -990,9 +1001,7 @@ bool COWArrayOpt::hoistMakeMutable(ArraySemanticsCall MakeMutable,
9901001
}
9911002

9921003
bool COWArrayOpt::dominatesExitingBlocks(SILBasicBlock *BB) {
993-
llvm::SmallVector<SILBasicBlock *, 8> ExitingBlocks;
994-
Loop->getExitingBlocks(ExitingBlocks);
995-
for (SILBasicBlock *Exiting : ExitingBlocks) {
1004+
for (SILBasicBlock *Exiting : getLoopExitingBlocks()) {
9961005
if (!DomTree->dominates(BB, Exiting))
9971006
return false;
9981007
}

0 commit comments

Comments
 (0)