OLD | NEW |
1 //===- subzero/src/IceLiveness.h - Liveness analysis ------------*- C++ -*-===// | 1 //===- subzero/src/IceLiveness.h - Liveness analysis ------------*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file declares the Liveness and LivenessNode classes, | 10 // This file declares the Liveness and LivenessNode classes, |
(...skipping 19 matching lines...) Expand all Loading... |
30 LivenessNode() : NumLocals(0) {} | 30 LivenessNode() : NumLocals(0) {} |
31 // NumLocals is the number of Variables local to this block. | 31 // NumLocals is the number of Variables local to this block. |
32 SizeT NumLocals; | 32 SizeT NumLocals; |
33 // LiveToVarMap maps a liveness bitvector index to a Variable. This | 33 // LiveToVarMap maps a liveness bitvector index to a Variable. This |
34 // is generally just for printing/dumping. The index should be less | 34 // is generally just for printing/dumping. The index should be less |
35 // than NumLocals + Liveness::NumGlobals. | 35 // than NumLocals + Liveness::NumGlobals. |
36 std::vector<Variable *> LiveToVarMap; | 36 std::vector<Variable *> LiveToVarMap; |
37 // LiveIn and LiveOut track the in- and out-liveness of the global | 37 // LiveIn and LiveOut track the in- and out-liveness of the global |
38 // variables. The size of each vector is | 38 // variables. The size of each vector is |
39 // LivenessNode::NumGlobals. | 39 // LivenessNode::NumGlobals. |
40 llvm::BitVector LiveIn, LiveOut; | 40 LivenessBV LiveIn, LiveOut; |
41 // LiveBegin and LiveEnd track the instruction numbers of the start | 41 // LiveBegin and LiveEnd track the instruction numbers of the start |
42 // and end of each variable's live range within this block. The | 42 // and end of each variable's live range within this block. The |
43 // size of each vector is NumLocals + Liveness::NumGlobals. | 43 // index/key of each element is less than NumLocals + |
44 std::vector<InstNumberT> LiveBegin, LiveEnd; | 44 // Liveness::NumGlobals. |
| 45 LiveBeginEndMap LiveBegin, LiveEnd; |
45 | 46 |
46 private: | 47 private: |
47 // TODO: Disable these constructors when Liveness::Nodes is no | 48 // TODO: Disable these constructors when Liveness::Nodes is no |
48 // longer an STL container. | 49 // longer an STL container. |
49 // LivenessNode(const LivenessNode &) = delete; | 50 // LivenessNode(const LivenessNode &) = delete; |
50 // LivenessNode &operator=(const LivenessNode &) = delete; | 51 // LivenessNode &operator=(const LivenessNode &) = delete; |
51 }; | 52 }; |
52 | 53 |
53 class Liveness { | 54 class Liveness { |
54 public: | 55 public: |
55 Liveness(Cfg *Func, LivenessMode Mode) | 56 Liveness(Cfg *Func, LivenessMode Mode) |
56 : Func(Func), Mode(Mode), NumGlobals(0) {} | 57 : Func(Func), Mode(Mode), NumGlobals(0) {} |
57 void init(); | 58 void init(); |
| 59 Cfg *getFunc() const { return Func; } |
| 60 LivenessMode getMode() const { return Mode; } |
58 Variable *getVariable(SizeT LiveIndex, const CfgNode *Node) const; | 61 Variable *getVariable(SizeT LiveIndex, const CfgNode *Node) const; |
59 SizeT getLiveIndex(const Variable *Var) const; | 62 SizeT getLiveIndex(SizeT VarIndex) const { return VarToLiveMap[VarIndex]; } |
60 SizeT getNumGlobalVars() const { return NumGlobals; } | 63 SizeT getNumGlobalVars() const { return NumGlobals; } |
61 SizeT getNumVarsInNode(const CfgNode *Node) const { | 64 SizeT getNumVarsInNode(const CfgNode *Node) const { |
62 return NumGlobals + Nodes[Node->getIndex()].NumLocals; | 65 return NumGlobals + Nodes[Node->getIndex()].NumLocals; |
63 } | 66 } |
64 llvm::BitVector &getLiveIn(const CfgNode *Node) { | 67 LivenessBV &getLiveIn(const CfgNode *Node) { |
65 return Nodes[Node->getIndex()].LiveIn; | 68 return Nodes[Node->getIndex()].LiveIn; |
66 } | 69 } |
67 llvm::BitVector &getLiveOut(const CfgNode *Node) { | 70 LivenessBV &getLiveOut(const CfgNode *Node) { |
68 return Nodes[Node->getIndex()].LiveOut; | 71 return Nodes[Node->getIndex()].LiveOut; |
69 } | 72 } |
70 std::vector<InstNumberT> &getLiveBegin(const CfgNode *Node) { | 73 LiveBeginEndMap *getLiveBegin(const CfgNode *Node) { |
71 return Nodes[Node->getIndex()].LiveBegin; | 74 return &Nodes[Node->getIndex()].LiveBegin; |
72 } | 75 } |
73 std::vector<InstNumberT> &getLiveEnd(const CfgNode *Node) { | 76 LiveBeginEndMap *getLiveEnd(const CfgNode *Node) { |
74 return Nodes[Node->getIndex()].LiveEnd; | 77 return &Nodes[Node->getIndex()].LiveEnd; |
75 } | 78 } |
76 LiveRange &getLiveRange(Variable *Var); | 79 LiveRange &getLiveRange(Variable *Var); |
77 void addLiveRange(Variable *Var, InstNumberT Start, InstNumberT End, | 80 void addLiveRange(Variable *Var, InstNumberT Start, InstNumberT End, |
78 uint32_t WeightDelta); | 81 uint32_t WeightDelta); |
79 | 82 |
80 private: | 83 private: |
81 Cfg *Func; | 84 Cfg *Func; |
82 LivenessMode Mode; | 85 LivenessMode Mode; |
83 SizeT NumGlobals; | 86 SizeT NumGlobals; |
84 // Size of Nodes is Cfg::Nodes.size(). | 87 // Size of Nodes is Cfg::Nodes.size(). |
85 std::vector<LivenessNode> Nodes; | 88 std::vector<LivenessNode> Nodes; |
86 // VarToLiveMap maps a Variable's Variable::Number to its live index | 89 // VarToLiveMap maps a Variable's Variable::Number to its live index |
87 // within its basic block. | 90 // within its basic block. |
88 std::vector<SizeT> VarToLiveMap; | 91 std::vector<SizeT> VarToLiveMap; |
89 // LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for | 92 // LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for |
90 // non-local variables. | 93 // non-local variables. |
91 std::vector<Variable *> LiveToVarMap; | 94 std::vector<Variable *> LiveToVarMap; |
92 // LiveRanges maps a Variable::Number to its live range. | 95 // LiveRanges maps a Variable::Number to its live range. |
93 std::vector<LiveRange> LiveRanges; | 96 std::vector<LiveRange> LiveRanges; |
94 Liveness(const Liveness &) = delete; | 97 Liveness(const Liveness &) = delete; |
95 Liveness &operator=(const Liveness &) = delete; | 98 Liveness &operator=(const Liveness &) = delete; |
96 }; | 99 }; |
97 | 100 |
98 } // end of namespace Ice | 101 } // end of namespace Ice |
99 | 102 |
100 #endif // SUBZERO_SRC_ICELIVENESS_H | 103 #endif // SUBZERO_SRC_ICELIVENESS_H |
OLD | NEW |