@@ -29,47 +29,45 @@ class ColdBlockInfo {
29
29
DominanceAnalysis *DA;
30
30
PostDominanceAnalysis *PDA;
31
31
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 ;
44
48
};
45
49
46
- enum {
47
- RecursionDepthLimit = 3
48
- };
50
+ using Energy = std::bitset<State::NumStates>;
51
+ static std::string toString (Energy e);
49
52
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 ;
52
56
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 ;
57
61
58
- bool isCold (const SILBasicBlock *BB,
59
- int recursionDepth );
62
+ void resetToCold (const SILBasicBlock *BB);
63
+ void set ( const SILBasicBlock *BB, State::Temperature temp );
60
64
61
65
public:
62
66
ColdBlockInfo (DominanceAnalysis *DA, PostDominanceAnalysis *PDA);
63
67
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);
71
69
72
- bool isCold (const SILBasicBlock *BB) { return isCold (BB, 0 ); }
70
+ bool isCold (const SILBasicBlock *BB) const ;
73
71
};
74
72
} // end namespace swift
75
73
0 commit comments