15
15
16
16
#include " llvm/ADT/DenseMap.h"
17
17
#include " swift/SIL/SILValue.h"
18
+ #include < bitset>
18
19
19
20
namespace swift {
20
21
class DominanceAnalysis ;
@@ -29,47 +30,45 @@ class ColdBlockInfo {
29
30
DominanceAnalysis *DA;
30
31
PostDominanceAnalysis *PDA;
31
32
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
33
+ // Represents the temperatures of edges flowing into a block.
34
+ //
35
+ // T = "top" -- both warm and cold edges
36
+ // / \
37
+ // Warm Cold
38
+ // \ /
39
+ // B = "bottom" -- neither warm or cold edges
40
+ struct State {
41
+ // Each state kind, as an integer, is its position in any bit vectors.
42
+ enum Temperature {
43
+ Warm = 0 ,
44
+ Cold = 1
45
+ };
46
+
47
+ // Number of states, excluding Top or Bottom, in this flow problem.
48
+ static constexpr unsigned NumStates = 2 ;
44
49
};
45
50
46
- enum {
47
- RecursionDepthLimit = 3
48
- };
51
+ using Energy = std::bitset<State::NumStates>;
52
+ static std::string toString (Energy e);
49
53
50
- // \returns none if there is no known temperature for the block.
51
- std::optional<bool > queryIsCold (const SILBasicBlock *BB);
54
+ // / Each block in this map has been determined to be cold and/or warm.
55
+ llvm::DenseMap<const SILBasicBlock*, Energy> EnergyMap;
56
+ bool changedMap = false ;
52
57
53
- BranchHint getBranchHint (SILValue Cond, int recursionDepth);
54
-
55
- bool isSlowPath (const SILBasicBlock *FromBB, const SILBasicBlock *ToBB,
56
- int recursionDepth) ;
58
+ // This is a cache and shouldn't be copied around.
59
+ ColdBlockInfo ( const ColdBlockInfo &) = delete ;
60
+ ColdBlockInfo & operator = (const ColdBlockInfo &) = delete ;
61
+ LLVM_DUMP_METHOD void dump () const ;
57
62
58
- bool isCold (const SILBasicBlock *BB,
59
- int recursionDepth );
63
+ void resetToCold (const SILBasicBlock *BB);
64
+ void set ( const SILBasicBlock *BB, State::Temperature temp );
60
65
61
66
public:
62
67
ColdBlockInfo (DominanceAnalysis *DA, PostDominanceAnalysis *PDA);
63
68
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
- }
69
+ void analyze (SILFunction *F);
71
70
72
- bool isCold (const SILBasicBlock *BB) { return isCold (BB, 0 ); }
71
+ bool isCold (const SILBasicBlock *BB) const ;
73
72
};
74
73
} // end namespace swift
75
74
0 commit comments