OLD | NEW |
1 //===- subzero/src/IceCfg.h - Control flow graph ----------------*- C++ -*-===// | 1 //===- subzero/src/IceCfg.h - Control flow graph ----------------*- 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 /// This file declares the Cfg class, which represents the control flow | 11 /// This file declares the Cfg class, which represents the control flow graph |
12 /// graph and the overall per-function compilation context. | 12 /// and the overall per-function compilation context. |
13 /// | 13 /// |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #ifndef SUBZERO_SRC_ICECFG_H | 16 #ifndef SUBZERO_SRC_ICECFG_H |
17 #define SUBZERO_SRC_ICECFG_H | 17 #define SUBZERO_SRC_ICECFG_H |
18 | 18 |
19 #include "IceAssembler.h" | 19 #include "IceAssembler.h" |
20 #include "IceClFlags.h" | 20 #include "IceClFlags.h" |
21 #include "IceDefs.h" | 21 #include "IceDefs.h" |
22 #include "IceGlobalContext.h" | 22 #include "IceGlobalContext.h" |
(...skipping 20 matching lines...) Expand all Loading... |
43 } | 43 } |
44 /// Gets a pointer to the current thread's Cfg's allocator. | 44 /// Gets a pointer to the current thread's Cfg's allocator. |
45 static ArenaAllocator<> *getCurrentCfgAllocator() { | 45 static ArenaAllocator<> *getCurrentCfgAllocator() { |
46 assert(ICE_TLS_GET_FIELD(CurrentCfg)); | 46 assert(ICE_TLS_GET_FIELD(CurrentCfg)); |
47 return ICE_TLS_GET_FIELD(CurrentCfg)->Allocator.get(); | 47 return ICE_TLS_GET_FIELD(CurrentCfg)->Allocator.get(); |
48 } | 48 } |
49 | 49 |
50 GlobalContext *getContext() const { return Ctx; } | 50 GlobalContext *getContext() const { return Ctx; } |
51 uint32_t getSequenceNumber() const { return SequenceNumber; } | 51 uint32_t getSequenceNumber() const { return SequenceNumber; } |
52 | 52 |
53 /// Returns true if any of the specified options in the verbose mask | 53 /// Returns true if any of the specified options in the verbose mask are set. |
54 /// are set. If the argument is omitted, it checks if any verbose | 54 /// If the argument is omitted, it checks if any verbose options at all are |
55 /// options at all are set. | 55 /// set. |
56 bool isVerbose(VerboseMask Mask = IceV_All) const { return VMask & Mask; } | 56 bool isVerbose(VerboseMask Mask = IceV_All) const { return VMask & Mask; } |
57 void setVerbose(VerboseMask Mask) { VMask = Mask; } | 57 void setVerbose(VerboseMask Mask) { VMask = Mask; } |
58 | 58 |
59 /// \name Manage the name and return type of the function being translated. | 59 /// \name Manage the name and return type of the function being translated. |
60 /// @{ | 60 /// @{ |
61 void setFunctionName(const IceString &Name) { FunctionName = Name; } | 61 void setFunctionName(const IceString &Name) { FunctionName = Name; } |
62 IceString getFunctionName() const { return FunctionName; } | 62 IceString getFunctionName() const { return FunctionName; } |
63 void setReturnType(Type Ty) { ReturnType = Ty; } | 63 void setReturnType(Type Ty) { ReturnType = Ty; } |
64 /// @} | 64 /// @} |
65 | 65 |
66 /// \name Manage the "internal" attribute of the function. | 66 /// \name Manage the "internal" attribute of the function. |
67 /// @{ | 67 /// @{ |
68 void setInternal(bool Internal) { IsInternalLinkage = Internal; } | 68 void setInternal(bool Internal) { IsInternalLinkage = Internal; } |
69 bool getInternal() const { return IsInternalLinkage; } | 69 bool getInternal() const { return IsInternalLinkage; } |
70 /// @} | 70 /// @} |
71 | 71 |
72 /// \name Manage errors. | 72 /// \name Manage errors. |
73 /// @{ | 73 /// @{ |
74 | 74 |
75 /// Translation error flagging. If support for some construct is | 75 /// Translation error flagging. If support for some construct is known to be |
76 /// known to be missing, instead of an assertion failure, setError() | 76 /// missing, instead of an assertion failure, setError() should be called and |
77 /// should be called and the error should be propagated back up. | 77 /// the error should be propagated back up. This way, we can gracefully fail |
78 /// This way, we can gracefully fail to translate and let a fallback | 78 /// to translate and let a fallback translator handle the function. |
79 /// translator handle the function. | |
80 void setError(const IceString &Message); | 79 void setError(const IceString &Message); |
81 bool hasError() const { return HasError; } | 80 bool hasError() const { return HasError; } |
82 IceString getError() const { return ErrorMessage; } | 81 IceString getError() const { return ErrorMessage; } |
83 /// @} | 82 /// @} |
84 | 83 |
85 /// \name Manage nodes (a.k.a. basic blocks, CfgNodes). | 84 /// \name Manage nodes (a.k.a. basic blocks, CfgNodes). |
86 /// @{ | 85 /// @{ |
87 void setEntryNode(CfgNode *EntryNode) { Entry = EntryNode; } | 86 void setEntryNode(CfgNode *EntryNode) { Entry = EntryNode; } |
88 CfgNode *getEntryNode() const { return Entry; } | 87 CfgNode *getEntryNode() const { return Entry; } |
89 /// Create a node and append it to the end of the linearized list. The loop | 88 /// Create a node and append it to the end of the linearized list. The loop |
90 /// nest depth of the new node may not be valid if it is created after | 89 /// nest depth of the new node may not be valid if it is created after |
91 /// computeLoopNestDepth. | 90 /// computeLoopNestDepth. |
92 CfgNode *makeNode(); | 91 CfgNode *makeNode(); |
93 SizeT getNumNodes() const { return Nodes.size(); } | 92 SizeT getNumNodes() const { return Nodes.size(); } |
94 const NodeList &getNodes() const { return Nodes; } | 93 const NodeList &getNodes() const { return Nodes; } |
95 /// Swap nodes of Cfg with given list of nodes. | 94 /// Swap nodes of Cfg with given list of nodes. |
96 void swapNodes(NodeList &NewNodes); | 95 void swapNodes(NodeList &NewNodes); |
97 /// @} | 96 /// @} |
98 | 97 |
99 using IdentifierIndexType = int32_t; | 98 using IdentifierIndexType = int32_t; |
100 /// Adds a name to the list and returns its index, suitable for the | 99 /// Adds a name to the list and returns its index, suitable for the argument |
101 /// argument to getIdentifierName(). No checking for duplicates is | 100 /// to getIdentifierName(). No checking for duplicates is done. This is |
102 /// done. This is generally used for node names and variable names | 101 /// generally used for node names and variable names to avoid embedding a |
103 /// to avoid embedding a std::string inside an arena-allocated | 102 /// std::string inside an arena-allocated object. |
104 /// object. | |
105 IdentifierIndexType addIdentifierName(const IceString &Name) { | 103 IdentifierIndexType addIdentifierName(const IceString &Name) { |
106 IdentifierIndexType Index = IdentifierNames.size(); | 104 IdentifierIndexType Index = IdentifierNames.size(); |
107 IdentifierNames.push_back(Name); | 105 IdentifierNames.push_back(Name); |
108 return Index; | 106 return Index; |
109 } | 107 } |
110 const IceString &getIdentifierName(IdentifierIndexType Index) const { | 108 const IceString &getIdentifierName(IdentifierIndexType Index) const { |
111 return IdentifierNames[Index]; | 109 return IdentifierNames[Index]; |
112 } | 110 } |
113 enum { IdentifierIndexInvalid = -1 }; | 111 enum { IdentifierIndexInvalid = -1 }; |
114 | 112 |
115 /// \name Manage instruction numbering. | 113 /// \name Manage instruction numbering. |
116 /// @{ | 114 /// @{ |
117 InstNumberT newInstNumber() { return NextInstNumber++; } | 115 InstNumberT newInstNumber() { return NextInstNumber++; } |
118 InstNumberT getNextInstNumber() const { return NextInstNumber; } | 116 InstNumberT getNextInstNumber() const { return NextInstNumber; } |
119 /// @} | 117 /// @} |
120 | 118 |
121 /// \name Manage Variables. | 119 /// \name Manage Variables. |
122 /// @{ | 120 /// @{ |
123 | 121 |
124 /// Create a new Variable with a particular type and an optional | 122 /// Create a new Variable with a particular type and an optional name. The |
125 /// name. The Node argument is the node where the variable is defined. | 123 /// Node argument is the node where the variable is defined. |
126 // TODO(jpp): untemplate this with separate methods: makeVariable, | 124 // TODO(jpp): untemplate this with separate methods: makeVariable, |
127 // makeSpillVariable, and makeStackVariable. | 125 // makeSpillVariable, and makeStackVariable. |
128 template <typename T = Variable> T *makeVariable(Type Ty) { | 126 template <typename T = Variable> T *makeVariable(Type Ty) { |
129 SizeT Index = Variables.size(); | 127 SizeT Index = Variables.size(); |
130 T *Var = T::create(this, Ty, Index); | 128 T *Var = T::create(this, Ty, Index); |
131 Variables.push_back(Var); | 129 Variables.push_back(Var); |
132 return Var; | 130 return Var; |
133 } | 131 } |
134 SizeT getNumVariables() const { return Variables.size(); } | 132 SizeT getNumVariables() const { return Variables.size(); } |
135 const VarList &getVariables() const { return Variables; } | 133 const VarList &getVariables() const { return Variables; } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void setFocusedTiming() { FocusedTiming = true; } | 166 void setFocusedTiming() { FocusedTiming = true; } |
169 uint32_t getConstantBlindingCookie() const { return ConstantBlindingCookie; } | 167 uint32_t getConstantBlindingCookie() const { return ConstantBlindingCookie; } |
170 /// @} | 168 /// @} |
171 | 169 |
172 /// Returns true if Var is a global variable that is used by the profiling | 170 /// Returns true if Var is a global variable that is used by the profiling |
173 /// code. | 171 /// code. |
174 static bool isProfileGlobal(const VariableDeclaration &Var); | 172 static bool isProfileGlobal(const VariableDeclaration &Var); |
175 | 173 |
176 /// Passes over the CFG. | 174 /// Passes over the CFG. |
177 void translate(); | 175 void translate(); |
178 /// After the CFG is fully constructed, iterate over the nodes and | 176 /// After the CFG is fully constructed, iterate over the nodes and compute the |
179 /// compute the predecessor and successor edges, in the form of | 177 /// predecessor and successor edges, in the form of CfgNode::InEdges[] and |
180 /// CfgNode::InEdges[] and CfgNode::OutEdges[]. | 178 /// CfgNode::OutEdges[]. |
181 void computeInOutEdges(); | 179 void computeInOutEdges(); |
182 void renumberInstructions(); | 180 void renumberInstructions(); |
183 void placePhiLoads(); | 181 void placePhiLoads(); |
184 void placePhiStores(); | 182 void placePhiStores(); |
185 void deletePhis(); | 183 void deletePhis(); |
186 void advancedPhiLowering(); | 184 void advancedPhiLowering(); |
187 void reorderNodes(); | 185 void reorderNodes(); |
188 void shuffleNodes(); | 186 void shuffleNodes(); |
189 void doAddressOpt(); | 187 void doAddressOpt(); |
190 void doArgLowering(); | 188 void doArgLowering(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 VarList ImplicitArgs; /// subset of Variables | 267 VarList ImplicitArgs; /// subset of Variables |
270 std::unique_ptr<ArenaAllocator<>> Allocator; | 268 std::unique_ptr<ArenaAllocator<>> Allocator; |
271 std::unique_ptr<Liveness> Live; | 269 std::unique_ptr<Liveness> Live; |
272 std::unique_ptr<TargetLowering> Target; | 270 std::unique_ptr<TargetLowering> Target; |
273 std::unique_ptr<VariablesMetadata> VMetadata; | 271 std::unique_ptr<VariablesMetadata> VMetadata; |
274 std::unique_ptr<Assembler> TargetAssembler; | 272 std::unique_ptr<Assembler> TargetAssembler; |
275 /// Globals required by this CFG. Mostly used for the profiler's globals. | 273 /// Globals required by this CFG. Mostly used for the profiler's globals. |
276 std::unique_ptr<VariableDeclarationList> GlobalInits; | 274 std::unique_ptr<VariableDeclarationList> GlobalInits; |
277 std::vector<InstJumpTable *> JumpTables; | 275 std::vector<InstJumpTable *> JumpTables; |
278 | 276 |
279 /// CurrentNode is maintained during dumping/emitting just for | 277 /// CurrentNode is maintained during dumping/emitting just for validating |
280 /// validating Variable::DefNode. Normally, a traversal over | 278 /// Variable::DefNode. Normally, a traversal over CfgNodes maintains this, but |
281 /// CfgNodes maintains this, but before global operations like | 279 /// before global operations like register allocation, resetCurrentNode() |
282 /// register allocation, resetCurrentNode() should be called to avoid | 280 /// should be called to avoid spurious validation failures. |
283 /// spurious validation failures. | |
284 const CfgNode *CurrentNode = nullptr; | 281 const CfgNode *CurrentNode = nullptr; |
285 | 282 |
286 /// Maintain a pointer in TLS to the current Cfg being translated. | 283 /// Maintain a pointer in TLS to the current Cfg being translated. This is |
287 /// This is primarily for accessing its allocator statelessly, but | 284 /// primarily for accessing its allocator statelessly, but other uses are |
288 /// other uses are possible. | 285 /// possible. |
289 ICE_TLS_DECLARE_FIELD(const Cfg *, CurrentCfg); | 286 ICE_TLS_DECLARE_FIELD(const Cfg *, CurrentCfg); |
290 | 287 |
291 public: | 288 public: |
292 static void TlsInit() { ICE_TLS_INIT_FIELD(CurrentCfg); } | 289 static void TlsInit() { ICE_TLS_INIT_FIELD(CurrentCfg); } |
293 }; | 290 }; |
294 | 291 |
295 } // end of namespace Ice | 292 } // end of namespace Ice |
296 | 293 |
297 #endif // SUBZERO_SRC_ICECFG_H | 294 #endif // SUBZERO_SRC_ICECFG_H |
OLD | NEW |