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 14 matching lines...) Loading... |
25 | 25 |
26 namespace Ice { | 26 namespace Ice { |
27 | 27 |
28 class LivenessNode { | 28 class LivenessNode { |
29 // TODO: Disable these constructors when Liveness::Nodes is no | 29 // TODO: Disable these constructors when Liveness::Nodes is no |
30 // longer an STL container. | 30 // longer an STL container. |
31 // LivenessNode(const LivenessNode &) = delete; | 31 // LivenessNode(const LivenessNode &) = delete; |
32 // LivenessNode &operator=(const LivenessNode &) = delete; | 32 // LivenessNode &operator=(const LivenessNode &) = delete; |
33 | 33 |
34 public: | 34 public: |
35 LivenessNode() : NumLocals(0) {} | 35 LivenessNode() : NumLocals(0), NumNonDeadPhis(0) {} |
36 // NumLocals is the number of Variables local to this block. | 36 // NumLocals is the number of Variables local to this block. |
37 SizeT NumLocals; | 37 SizeT NumLocals; |
| 38 // NumNonDeadPhis tracks the number of Phi instructions that |
| 39 // Inst::liveness() identified as tentatively live. If |
| 40 // NumNonDeadPhis changes from the last liveness pass, then liveness |
| 41 // has not yet converged. |
| 42 SizeT NumNonDeadPhis; |
38 // LiveToVarMap maps a liveness bitvector index to a Variable. This | 43 // LiveToVarMap maps a liveness bitvector index to a Variable. This |
39 // is generally just for printing/dumping. The index should be less | 44 // is generally just for printing/dumping. The index should be less |
40 // than NumLocals + Liveness::NumGlobals. | 45 // than NumLocals + Liveness::NumGlobals. |
41 std::vector<Variable *> LiveToVarMap; | 46 std::vector<Variable *> LiveToVarMap; |
42 // LiveIn and LiveOut track the in- and out-liveness of the global | 47 // LiveIn and LiveOut track the in- and out-liveness of the global |
43 // variables. The size of each vector is | 48 // variables. The size of each vector is |
44 // LivenessNode::NumGlobals. | 49 // LivenessNode::NumGlobals. |
45 LivenessBV LiveIn, LiveOut; | 50 LivenessBV LiveIn, LiveOut; |
46 // LiveBegin and LiveEnd track the instruction numbers of the start | 51 // LiveBegin and LiveEnd track the instruction numbers of the start |
47 // and end of each variable's live range within this block. The | 52 // and end of each variable's live range within this block. The |
(...skipping 11 matching lines...) Loading... |
59 : Func(Func), Mode(Mode), NumGlobals(0) {} | 64 : Func(Func), Mode(Mode), NumGlobals(0) {} |
60 void init(); | 65 void init(); |
61 Cfg *getFunc() const { return Func; } | 66 Cfg *getFunc() const { return Func; } |
62 LivenessMode getMode() const { return Mode; } | 67 LivenessMode getMode() const { return Mode; } |
63 Variable *getVariable(SizeT LiveIndex, const CfgNode *Node) const; | 68 Variable *getVariable(SizeT LiveIndex, const CfgNode *Node) const; |
64 SizeT getLiveIndex(SizeT VarIndex) const { return VarToLiveMap[VarIndex]; } | 69 SizeT getLiveIndex(SizeT VarIndex) const { return VarToLiveMap[VarIndex]; } |
65 SizeT getNumGlobalVars() const { return NumGlobals; } | 70 SizeT getNumGlobalVars() const { return NumGlobals; } |
66 SizeT getNumVarsInNode(const CfgNode *Node) const { | 71 SizeT getNumVarsInNode(const CfgNode *Node) const { |
67 return NumGlobals + Nodes[Node->getIndex()].NumLocals; | 72 return NumGlobals + Nodes[Node->getIndex()].NumLocals; |
68 } | 73 } |
| 74 SizeT &getNumNonDeadPhis(const CfgNode *Node) { |
| 75 return Nodes[Node->getIndex()].NumNonDeadPhis; |
| 76 } |
69 LivenessBV &getLiveIn(const CfgNode *Node) { | 77 LivenessBV &getLiveIn(const CfgNode *Node) { |
70 return Nodes[Node->getIndex()].LiveIn; | 78 SizeT Index = Node->getIndex(); |
| 79 resize(Index); |
| 80 return Nodes[Index].LiveIn; |
71 } | 81 } |
72 LivenessBV &getLiveOut(const CfgNode *Node) { | 82 LivenessBV &getLiveOut(const CfgNode *Node) { |
73 return Nodes[Node->getIndex()].LiveOut; | 83 SizeT Index = Node->getIndex(); |
| 84 resize(Index); |
| 85 return Nodes[Index].LiveOut; |
74 } | 86 } |
75 LiveBeginEndMap *getLiveBegin(const CfgNode *Node) { | 87 LiveBeginEndMap *getLiveBegin(const CfgNode *Node) { |
76 return &Nodes[Node->getIndex()].LiveBegin; | 88 SizeT Index = Node->getIndex(); |
| 89 resize(Index); |
| 90 return &Nodes[Index].LiveBegin; |
77 } | 91 } |
78 LiveBeginEndMap *getLiveEnd(const CfgNode *Node) { | 92 LiveBeginEndMap *getLiveEnd(const CfgNode *Node) { |
79 return &Nodes[Node->getIndex()].LiveEnd; | 93 SizeT Index = Node->getIndex(); |
| 94 resize(Index); |
| 95 return &Nodes[Index].LiveEnd; |
80 } | 96 } |
81 | 97 |
82 private: | 98 private: |
| 99 // Resize Nodes so that Nodes[Index] is valid. |
| 100 void resize(SizeT Index) { |
| 101 if (Index >= Nodes.size()) |
| 102 Nodes.resize(Index + 1); |
| 103 } |
83 Cfg *Func; | 104 Cfg *Func; |
84 LivenessMode Mode; | 105 LivenessMode Mode; |
85 SizeT NumGlobals; | 106 SizeT NumGlobals; |
86 // Size of Nodes is Cfg::Nodes.size(). | 107 // Size of Nodes is Cfg::Nodes.size(). |
87 std::vector<LivenessNode> Nodes; | 108 std::vector<LivenessNode> Nodes; |
88 // VarToLiveMap maps a Variable's Variable::Number to its live index | 109 // VarToLiveMap maps a Variable's Variable::Number to its live index |
89 // within its basic block. | 110 // within its basic block. |
90 std::vector<SizeT> VarToLiveMap; | 111 std::vector<SizeT> VarToLiveMap; |
91 // LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for | 112 // LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for |
92 // non-local variables. | 113 // non-local variables. |
93 std::vector<Variable *> LiveToVarMap; | 114 std::vector<Variable *> LiveToVarMap; |
94 }; | 115 }; |
95 | 116 |
96 } // end of namespace Ice | 117 } // end of namespace Ice |
97 | 118 |
98 #endif // SUBZERO_SRC_ICELIVENESS_H | 119 #endif // SUBZERO_SRC_ICELIVENESS_H |
OLD | NEW |