Chromium Code Reviews| 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 BeginEndMap 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(const Variable *Var) const; |
|
jvoung (off chromium)
2014/10/13 20:50:50
Can this variant of getLiveIndex() be removed now?
Jim Stichnoth
2014/10/13 23:15:22
Done.
| |
| 63 SizeT getLiveIndex(SizeT VarIndex) const { return VarToLiveMap[VarIndex]; } | |
| 60 SizeT getNumGlobalVars() const { return NumGlobals; } | 64 SizeT getNumGlobalVars() const { return NumGlobals; } |
| 61 SizeT getNumVarsInNode(const CfgNode *Node) const { | 65 SizeT getNumVarsInNode(const CfgNode *Node) const { |
| 62 return NumGlobals + Nodes[Node->getIndex()].NumLocals; | 66 return NumGlobals + Nodes[Node->getIndex()].NumLocals; |
| 63 } | 67 } |
| 64 llvm::BitVector &getLiveIn(const CfgNode *Node) { | 68 LivenessBV &getLiveIn(const CfgNode *Node) { |
| 65 return Nodes[Node->getIndex()].LiveIn; | 69 return Nodes[Node->getIndex()].LiveIn; |
| 66 } | 70 } |
| 67 llvm::BitVector &getLiveOut(const CfgNode *Node) { | 71 LivenessBV &getLiveOut(const CfgNode *Node) { |
| 68 return Nodes[Node->getIndex()].LiveOut; | 72 return Nodes[Node->getIndex()].LiveOut; |
| 69 } | 73 } |
| 70 std::vector<InstNumberT> &getLiveBegin(const CfgNode *Node) { | 74 BeginEndMap *getLiveBegin(const CfgNode *Node) { |
| 71 return Nodes[Node->getIndex()].LiveBegin; | 75 return &Nodes[Node->getIndex()].LiveBegin; |
| 72 } | 76 } |
| 73 std::vector<InstNumberT> &getLiveEnd(const CfgNode *Node) { | 77 BeginEndMap *getLiveEnd(const CfgNode *Node) { |
| 74 return Nodes[Node->getIndex()].LiveEnd; | 78 return &Nodes[Node->getIndex()].LiveEnd; |
| 75 } | 79 } |
| 76 LiveRange &getLiveRange(Variable *Var); | 80 LiveRange &getLiveRange(Variable *Var); |
| 77 void addLiveRange(Variable *Var, InstNumberT Start, InstNumberT End, | 81 void addLiveRange(Variable *Var, InstNumberT Start, InstNumberT End, |
| 78 uint32_t WeightDelta); | 82 uint32_t WeightDelta); |
| 79 | 83 |
| 80 private: | 84 private: |
| 81 Cfg *Func; | 85 Cfg *Func; |
| 82 LivenessMode Mode; | 86 LivenessMode Mode; |
| 83 SizeT NumGlobals; | 87 SizeT NumGlobals; |
| 84 // Size of Nodes is Cfg::Nodes.size(). | 88 // Size of Nodes is Cfg::Nodes.size(). |
| 85 std::vector<LivenessNode> Nodes; | 89 std::vector<LivenessNode> Nodes; |
| 86 // VarToLiveMap maps a Variable's Variable::Number to its live index | 90 // VarToLiveMap maps a Variable's Variable::Number to its live index |
| 87 // within its basic block. | 91 // within its basic block. |
| 88 std::vector<SizeT> VarToLiveMap; | 92 std::vector<SizeT> VarToLiveMap; |
| 89 // LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for | 93 // LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for |
| 90 // non-local variables. | 94 // non-local variables. |
| 91 std::vector<Variable *> LiveToVarMap; | 95 std::vector<Variable *> LiveToVarMap; |
| 92 // LiveRanges maps a Variable::Number to its live range. | 96 // LiveRanges maps a Variable::Number to its live range. |
| 93 std::vector<LiveRange> LiveRanges; | 97 std::vector<LiveRange> LiveRanges; |
| 94 Liveness(const Liveness &) = delete; | 98 Liveness(const Liveness &) = delete; |
| 95 Liveness &operator=(const Liveness &) = delete; | 99 Liveness &operator=(const Liveness &) = delete; |
| 96 }; | 100 }; |
| 97 | 101 |
| 98 } // end of namespace Ice | 102 } // end of namespace Ice |
| 99 | 103 |
| 100 #endif // SUBZERO_SRC_ICELIVENESS_H | 104 #endif // SUBZERO_SRC_ICELIVENESS_H |
| OLD | NEW |