[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.
This commit is contained in:
Michael Gottesman
2021-02-24 10:44:26 -08:00
parent 60ae2262b0
commit 248292b9da

View File

@@ -105,6 +105,7 @@ class COWArrayOpt {
RCIdentityFunctionInfo *RCIA;
SILFunction *Function;
SILLoop *Loop;
Optional<SmallVector<SILBasicBlock *, 8>> LoopExitingBlocks;
SILBasicBlock *Preheader;
DominanceInfo *DomTree;
bool HasChanged = false;
@@ -195,6 +196,16 @@ private:
return inst->getOperand(0);
return cast<SingleValueInstruction>(inst);
}
ArrayRef<SILBasicBlock *> getLoopExitingBlocks() const {
if (!LoopExitingBlocks) {
auto *self = const_cast<COWArrayOpt *>(this);
self->LoopExitingBlocks.emplace();
Loop->getExitingBlocks(*self->LoopExitingBlocks);
}
return *LoopExitingBlocks;
}
};
} // end anonymous namespace
@@ -990,9 +1001,7 @@ bool COWArrayOpt::hoistMakeMutable(ArraySemanticsCall MakeMutable,
}
bool COWArrayOpt::dominatesExitingBlocks(SILBasicBlock *BB) {
llvm::SmallVector<SILBasicBlock *, 8> ExitingBlocks;
Loop->getExitingBlocks(ExitingBlocks);
for (SILBasicBlock *Exiting : ExitingBlocks) {
for (SILBasicBlock *Exiting : getLoopExitingBlocks()) {
if (!DomTree->dominates(BB, Exiting))
return false;
}