Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: src/IceLiveness.h

Issue 1838973005: Subzero. Liveness memory management. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Adds TODO to investigate why CfgLocalAllocators can't be cached Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /// \file 10 /// \file
11 /// \brief Declares the Liveness and LivenessNode classes, which are used for 11 /// \brief Declares the Liveness and LivenessNode classes, which are used for
12 /// liveness analysis. 12 /// liveness analysis.
13 /// 13 ///
14 /// The node-specific information tracked for each Variable includes whether it 14 /// The node-specific information tracked for each Variable includes whether it
15 /// is live on entry, whether it is live on exit, the instruction number that 15 /// is live on entry, whether it is live on exit, the instruction number that
16 /// starts its live range, and the instruction number that ends its live range. 16 /// starts its live range, and the instruction number that ends its live range.
17 /// At the Cfg level, the actual live intervals are recorded. 17 /// At the Cfg level, the actual live intervals are recorded.
18 /// 18 ///
19 //===----------------------------------------------------------------------===// 19 //===----------------------------------------------------------------------===//
20 20
21 #ifndef SUBZERO_SRC_ICELIVENESS_H 21 #ifndef SUBZERO_SRC_ICELIVENESS_H
22 #define SUBZERO_SRC_ICELIVENESS_H 22 #define SUBZERO_SRC_ICELIVENESS_H
23 23
24 #include "IceDefs.h" 24 #include "IceDefs.h"
25 #include "IceBitVector.h" 25 #include "IceBitVector.h"
26 #include "IceCfgNode.h" 26 #include "IceCfgNode.h"
27 #include "IceTLS.h"
27 #include "IceTypes.h" 28 #include "IceTypes.h"
28 29
30 #include <memory>
31 #include <utility>
32
29 namespace Ice { 33 namespace Ice {
30 34
31 class Liveness { 35 class Liveness {
32 Liveness() = delete; 36 Liveness() = delete;
33 Liveness(const Liveness &) = delete; 37 Liveness(const Liveness &) = delete;
34 Liveness &operator=(const Liveness &) = delete; 38 Liveness &operator=(const Liveness &) = delete;
35 39
36 class LivenessNode { 40 class LivenessNode {
37 LivenessNode &operator=(const LivenessNode &) = delete; 41 LivenessNode &operator=(const LivenessNode &) = delete;
38 42
39 public: 43 public:
40 LivenessNode() = default; 44 LivenessNode() = default;
41 LivenessNode(const LivenessNode &) = default; 45 LivenessNode(const LivenessNode &) = default;
42 /// NumLocals is the number of Variables local to this block. 46 /// NumLocals is the number of Variables local to this block.
43 SizeT NumLocals = 0; 47 SizeT NumLocals = 0;
44 /// NumNonDeadPhis tracks the number of Phi instructions that 48 /// NumNonDeadPhis tracks the number of Phi instructions that
45 /// Inst::liveness() identified as tentatively live. If NumNonDeadPhis 49 /// Inst::liveness() identified as tentatively live. If NumNonDeadPhis
46 /// changes from the last liveness pass, then liveness has not yet 50 /// changes from the last liveness pass, then liveness has not yet
47 /// converged. 51 /// converged.
48 SizeT NumNonDeadPhis = 0; 52 SizeT NumNonDeadPhis = 0;
49 // LiveToVarMap maps a liveness bitvector index to a Variable. This is 53 // LiveToVarMap maps a liveness bitvector index to a Variable. This is
50 // generally just for printing/dumping. The index should be less than 54 // generally just for printing/dumping. The index should be less than
51 // NumLocals + Liveness::NumGlobals. 55 // NumLocals + Liveness::NumGlobals.
52 CfgVector<Variable *> LiveToVarMap; 56 LivenessVector<Variable *> LiveToVarMap;
53 // LiveIn and LiveOut track the in- and out-liveness of the global 57 // LiveIn and LiveOut track the in- and out-liveness of the global
54 // variables. The size of each vector is LivenessNode::NumGlobals. 58 // variables. The size of each vector is LivenessNode::NumGlobals.
55 LivenessBV LiveIn, LiveOut; 59 LivenessBV LiveIn, LiveOut;
56 // LiveBegin and LiveEnd track the instruction numbers of the start and end 60 // LiveBegin and LiveEnd track the instruction numbers of the start and end
57 // of each variable's live range within this block. The index/key of each 61 // of each variable's live range within this block. The index/key of each
58 // element is less than NumLocals + Liveness::NumGlobals. 62 // element is less than NumLocals + Liveness::NumGlobals.
59 LiveBeginEndMap LiveBegin, LiveEnd; 63 LiveBeginEndMap LiveBegin, LiveEnd;
60 }; 64 };
61 65
62 public: 66 public:
63 Liveness(Cfg *Func, LivenessMode Mode) : Func(Func), Mode(Mode) {}
64 void init(); 67 void init();
65 void initPhiEdgeSplits(NodeList::const_iterator FirstNode, 68 void initPhiEdgeSplits(NodeList::const_iterator FirstNode,
66 VarList::const_iterator FirstVar); 69 VarList::const_iterator FirstVar);
67 Cfg *getFunc() const { return Func; } 70 Cfg *getFunc() const { return Func; }
68 LivenessMode getMode() const { return Mode; } 71 LivenessMode getMode() const { return Mode; }
69 Variable *getVariable(SizeT LiveIndex, const CfgNode *Node) const; 72 Variable *getVariable(SizeT LiveIndex, const CfgNode *Node) const;
70 SizeT getLiveIndex(SizeT VarIndex) const { return VarToLiveMap[VarIndex]; } 73 SizeT getLiveIndex(SizeT VarIndex) const { return VarToLiveMap[VarIndex]; }
71 SizeT getNumGlobalVars() const { return NumGlobals; } 74 SizeT getNumGlobalVars() const { return NumGlobals; }
72 SizeT getNumVarsInNode(const CfgNode *Node) const { 75 SizeT getNumVarsInNode(const CfgNode *Node) const {
73 return NumGlobals + Nodes[Node->getIndex()].NumLocals; 76 return NumGlobals + Nodes[Node->getIndex()].NumLocals;
(...skipping 17 matching lines...) Expand all
91 resize(Index); 94 resize(Index);
92 return &Nodes[Index].LiveBegin; 95 return &Nodes[Index].LiveBegin;
93 } 96 }
94 LiveBeginEndMap *getLiveEnd(const CfgNode *Node) { 97 LiveBeginEndMap *getLiveEnd(const CfgNode *Node) {
95 SizeT Index = Node->getIndex(); 98 SizeT Index = Node->getIndex();
96 resize(Index); 99 resize(Index);
97 return &Nodes[Index].LiveEnd; 100 return &Nodes[Index].LiveEnd;
98 } 101 }
99 bool getRangeMask(SizeT Index) const { return RangeMask[Index]; } 102 bool getRangeMask(SizeT Index) const { return RangeMask[Index]; }
100 103
104 ArenaAllocator *getAllocator() const { return Alloc.get(); }
105
106 static std::unique_ptr<Liveness> create(Cfg *Func, LivenessMode Mode) {
107 return std::unique_ptr<Liveness>(new Liveness(Func, Mode));
108 }
109
110 static void TlsInit() { LivenessAllocatorTraits::init(); }
111
112 std::string dumpStr() const {
113 return "MaxLocals(" + std::to_string(MaxLocals) + "), "
114 "NumGlobals(" +
115 std::to_string(NumGlobals) + ")";
116 }
117
101 private: 118 private:
119 SizeT MaxLocals = 0;
Jim Stichnoth 2016/03/31 16:23:20 Should these data members be grouped with the othe
John 2016/04/01 13:52:04 Done.
120 SizeT NumGlobals = 0;
121
122 Liveness(Cfg *Func, LivenessMode Mode)
123 : Alloc(new ArenaAllocator()), AllocScope(this), Func(Func), Mode(Mode) {}
124
102 void initInternal(NodeList::const_iterator FirstNode, 125 void initInternal(NodeList::const_iterator FirstNode,
103 VarList::const_iterator FirstVar, bool IsFullInit); 126 VarList::const_iterator FirstVar, bool IsFullInit);
104 /// Resize Nodes so that Nodes[Index] is valid. 127 /// Resize Nodes so that Nodes[Index] is valid.
105 void resize(SizeT Index) { 128 void resize(SizeT Index) {
106 if (Index >= Nodes.size()) 129 if (Index >= Nodes.size()) {
130 assert(false);
Jim Stichnoth 2016/03/31 16:23:20 I like this very much. What do you think about re
John 2016/04/01 13:52:04 I would expect the code to work correctly if the a
107 Nodes.resize(Index + 1); 131 Nodes.resize(Index + 1);
132 }
108 } 133 }
134 std::unique_ptr<ArenaAllocator> Alloc;
135 LivenessAllocatorScope AllocScope; // Must be declared after Alloc.
109 Cfg *Func; 136 Cfg *Func;
110 LivenessMode Mode; 137 LivenessMode Mode;
111 SizeT NumGlobals = 0;
112 /// Size of Nodes is Cfg::Nodes.size(). 138 /// Size of Nodes is Cfg::Nodes.size().
113 CfgVector<LivenessNode> Nodes; 139 LivenessVector<LivenessNode> Nodes;
114 /// VarToLiveMap maps a Variable's Variable::Number to its live index within 140 /// VarToLiveMap maps a Variable's Variable::Number to its live index within
115 /// its basic block. 141 /// its basic block.
116 CfgVector<SizeT> VarToLiveMap; 142 LivenessVector<SizeT> VarToLiveMap;
117 /// LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for non-local 143 /// LiveToVarMap is analogous to LivenessNode::LiveToVarMap, but for non-local
118 /// variables. 144 /// variables.
119 CfgVector<Variable *> LiveToVarMap; 145 LivenessVector<Variable *> LiveToVarMap;
120 /// RangeMask[Variable::Number] indicates whether we want to track that 146 /// RangeMask[Variable::Number] indicates whether we want to track that
121 /// Variable's live range. 147 /// Variable's live range.
122 LivenessBV RangeMask; 148 LivenessBV RangeMask;
123 /// ScratchBV is a bitvector that can be reused across CfgNode passes, to 149 /// ScratchBV is a bitvector that can be reused across CfgNode passes, to
124 /// avoid having to allocate/deallocate memory so frequently. 150 /// avoid having to allocate/deallocate memory so frequently.
125 LivenessBV ScratchBV; 151 LivenessBV ScratchBV;
126 }; 152 };
127 153
128 } // end of namespace Ice 154 } // end of namespace Ice
129 155
130 #endif // SUBZERO_SRC_ICELIVENESS_H 156 #endif // SUBZERO_SRC_ICELIVENESS_H
OLDNEW
« src/IceGlobalContext.cpp ('K') | « src/IceGlobalContext.cpp ('k') | src/IceLiveness.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698