Skip to content

Commit 293bdad

Browse files
committed
ColdBlockInfo: overhaul the analysis
1 parent aa0291c commit 293bdad

File tree

5 files changed

+193
-236
lines changed

5 files changed

+193
-236
lines changed

include/swift/SILOptimizer/Analysis/ColdBlockInfo.h

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,45 @@ class ColdBlockInfo {
2929
DominanceAnalysis *DA;
3030
PostDominanceAnalysis *PDA;
3131

32-
/// Each block in this map has been determined to be either cold or hot.
33-
llvm::DenseMap<const SILBasicBlock*, bool> ColdBlockMap;
34-
35-
// This is a cache and shouldn't be copied around.
36-
ColdBlockInfo(const ColdBlockInfo &) = delete;
37-
ColdBlockInfo &operator=(const ColdBlockInfo &) = delete;
38-
39-
/// Tri-value return code for checking branch hints.
40-
enum BranchHint : unsigned {
41-
None,
42-
LikelyTrue,
43-
LikelyFalse
32+
// Represents the temperatures of edges flowing into a block.
33+
//
34+
// T = "top" -- both warm and cold edges
35+
// / \
36+
// Warm Cold
37+
// \ /
38+
// B = "bottom" -- neither warm or cold edges
39+
struct State {
40+
// Each state kind, as an integer, is its position in any bit vectors.
41+
enum Temperature {
42+
Warm = 0,
43+
Cold = 1
44+
};
45+
46+
// Number of states, excluding Top or Bottom, in this flow problem.
47+
static constexpr unsigned NumStates = 2;
4448
};
4549

46-
enum {
47-
RecursionDepthLimit = 3
48-
};
50+
using Energy = std::bitset<State::NumStates>;
51+
static std::string toString(Energy e);
4952

50-
// \returns none if there is no known temperature for the block.
51-
std::optional<bool> queryIsCold(const SILBasicBlock *BB);
53+
/// Each block in this map has been determined to be cold and/or warm.
54+
llvm::DenseMap<const SILBasicBlock*, Energy> EnergyMap;
55+
bool changedMap = false;
5256

53-
BranchHint getBranchHint(SILValue Cond, int recursionDepth);
54-
55-
bool isSlowPath(const SILBasicBlock *FromBB, const SILBasicBlock *ToBB,
56-
int recursionDepth);
57+
// This is a cache and shouldn't be copied around.
58+
ColdBlockInfo(const ColdBlockInfo &) = delete;
59+
ColdBlockInfo &operator=(const ColdBlockInfo &) = delete;
60+
LLVM_DUMP_METHOD void dump() const;
5761

58-
bool isCold(const SILBasicBlock *BB,
59-
int recursionDepth);
62+
void resetToCold(const SILBasicBlock *BB);
63+
void set(const SILBasicBlock *BB, State::Temperature temp);
6064

6165
public:
6266
ColdBlockInfo(DominanceAnalysis *DA, PostDominanceAnalysis *PDA);
6367

64-
/// Pre-seed the info with information starting at the exits of the function.
65-
/// Recommended prior to querying if blocks are cold in a function.
66-
void analyzeExits(SILFunction *Fn);
67-
68-
bool isSlowPath(const SILBasicBlock *FromBB, const SILBasicBlock *ToBB) {
69-
return isSlowPath(FromBB, ToBB, 0);
70-
}
68+
void analyze(SILFunction *F);
7169

72-
bool isCold(const SILBasicBlock *BB) { return isCold(BB, 0); }
70+
bool isCold(const SILBasicBlock *BB) const;
7371
};
7472
} // end namespace swift
7573

include/swift/SILOptimizer/Utils/PerformanceInlinerUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class ShortestPathAnalysis {
429429
return;
430430

431431
BlockInfoStorage.resize(numBlocks);
432-
CBI.analyzeExits(F);
432+
CBI.analyze(F);
433433

434434
// First step: compute the length of the blocks.
435435
unsigned BlockIdx = 0;

0 commit comments

Comments
 (0)