ColdBlockInfo: overhaul analysis pass

The old analysis pass doesn't take into account profile data, nor does
it consider post-dominance. It primarily dealt with _fastPath/_slowPath.

A block that is dominated by a cold block is itself cold. That's true
whether it's forwards or backwards dominance.

We can also consider a call to any `Never` returning function as a
cold-exit, though the block(s) leading up to that call may be executed
frequently because of concurrency. For now, I'm ignoring the concurrency
case and assuming it's cold. To make use of this "no return" prediction,
use the `-enable-noreturn-prediction` flag, which is currently off by
default.
This commit is contained in:
Kavon Farvardin
2024-08-26 16:04:58 -07:00
parent 1c3ef6c51d
commit 7203a4fa73
13 changed files with 647 additions and 136 deletions

View File

@@ -154,10 +154,13 @@ class COWArrayOpt {
// analyzing.
SILValue CurrentArrayAddr;
public:
COWArrayOpt(RCIdentityFunctionInfo *RCIA, SILLoop *L, DominanceAnalysis *DA)
COWArrayOpt(RCIdentityFunctionInfo *RCIA, SILLoop *L, DominanceAnalysis *DA,
PostDominanceAnalysis *PDA)
: RCIA(RCIA), Function(L->getHeader()->getParent()), Loop(L),
Preheader(L->getLoopPreheader()), DomTree(DA->get(Function)),
ColdBlocks(DA), CachedSafeLoop(false, false), ReachingBlocks(Function) {}
ColdBlocks(DA, PDA), CachedSafeLoop(false, false), ReachingBlocks(Function) {
ColdBlocks.analyze(Function);
}
bool run();
@@ -1063,6 +1066,7 @@ class COWArrayOptPass : public SILFunctionTransform {
<< getFunction()->getName() << "\n");
auto *DA = PM->getAnalysis<DominanceAnalysis>();
auto *PDA = PM->getAnalysis<PostDominanceAnalysis>();
auto *LA = PM->getAnalysis<SILLoopAnalysis>();
auto *RCIA =
PM->getAnalysis<RCIdentityAnalysis>()->get(getFunction());
@@ -1084,7 +1088,7 @@ class COWArrayOptPass : public SILFunctionTransform {
bool HasChanged = false;
for (auto *L : Loops)
HasChanged |= COWArrayOpt(RCIA, L, DA).run();
HasChanged |= COWArrayOpt(RCIA, L, DA, PDA).run();
if (HasChanged)
invalidateAnalysis(SILAnalysis::InvalidationKind::CallsAndInstructions);