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 /// \brief Declares the Cfg class, which represents the control flow graph and | 11 /// \brief Declares the Cfg class, which represents the control flow graph and |
12 /// the overall per-function compilation context. | 12 /// 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" |
23 #include "IceStringPool.h" | |
23 #include "IceTypes.h" | 24 #include "IceTypes.h" |
24 | 25 |
25 namespace Ice { | 26 namespace Ice { |
26 | 27 |
27 class Cfg { | 28 class Cfg { |
28 Cfg() = delete; | 29 Cfg() = delete; |
29 Cfg(const Cfg &) = delete; | 30 Cfg(const Cfg &) = delete; |
30 Cfg &operator=(const Cfg &) = delete; | 31 Cfg &operator=(const Cfg &) = delete; |
31 | 32 |
32 public: | 33 public: |
(...skipping 13 matching lines...) Expand all Loading... | |
46 /// Returns true if any of the specified options in the verbose mask are set. | 47 /// Returns true if any of the specified options in the verbose mask are set. |
47 /// If the argument is omitted, it checks if any verbose options at all are | 48 /// If the argument is omitted, it checks if any verbose options at all are |
48 /// set. | 49 /// set. |
49 bool isVerbose(VerboseMask Mask = defaultVerboseMask()) const { | 50 bool isVerbose(VerboseMask Mask = defaultVerboseMask()) const { |
50 return VMask & Mask; | 51 return VMask & Mask; |
51 } | 52 } |
52 void setVerbose(VerboseMask Mask) { VMask = Mask; } | 53 void setVerbose(VerboseMask Mask) { VMask = Mask; } |
53 | 54 |
54 /// \name Manage the name and return type of the function being translated. | 55 /// \name Manage the name and return type of the function being translated. |
55 /// @{ | 56 /// @{ |
56 void setFunctionName(const IceString &Name) { FunctionName = Name; } | 57 void setFunctionName(GlobalString Name) { FunctionName = Name; } |
57 const IceString &getFunctionName() const { return FunctionName; } | 58 GlobalString getFunctionName() const { return FunctionName; } |
58 IceString getFunctionNameAndSize() const; | 59 std::string getFunctionNameAndSize() const; |
59 void setReturnType(Type Ty) { ReturnType = Ty; } | 60 void setReturnType(Type Ty) { ReturnType = Ty; } |
60 Type getReturnType() const { return ReturnType; } | 61 Type getReturnType() const { return ReturnType; } |
61 /// @} | 62 /// @} |
62 | 63 |
63 /// \name Manage the "internal" attribute of the function. | 64 /// \name Manage the "internal" attribute of the function. |
64 /// @{ | 65 /// @{ |
65 void setInternal(bool Internal) { IsInternalLinkage = Internal; } | 66 void setInternal(bool Internal) { IsInternalLinkage = Internal; } |
66 bool getInternal() const { return IsInternalLinkage; } | 67 bool getInternal() const { return IsInternalLinkage; } |
67 /// @} | 68 /// @} |
68 | 69 |
69 /// \name Manage errors. | 70 /// \name Manage errors. |
70 /// @{ | 71 /// @{ |
71 | 72 |
72 /// Translation error flagging. If support for some construct is known to be | 73 /// Translation error flagging. If support for some construct is known to be |
73 /// missing, instead of an assertion failure, setError() should be called and | 74 /// missing, instead of an assertion failure, setError() should be called and |
74 /// the error should be propagated back up. This way, we can gracefully fail | 75 /// the error should be propagated back up. This way, we can gracefully fail |
75 /// to translate and let a fallback translator handle the function. | 76 /// to translate and let a fallback translator handle the function. |
76 void setError(const IceString &Message); | 77 void setError(const std::string &Message); |
77 bool hasError() const { return HasError; } | 78 bool hasError() const { return HasError; } |
78 IceString getError() const { return ErrorMessage; } | 79 std::string getError() const { return ErrorMessage; } |
79 /// @} | 80 /// @} |
80 | 81 |
81 /// \name Manage nodes (a.k.a. basic blocks, CfgNodes). | 82 /// \name Manage nodes (a.k.a. basic blocks, CfgNodes). |
82 /// @{ | 83 /// @{ |
83 void setEntryNode(CfgNode *EntryNode) { Entry = EntryNode; } | 84 void setEntryNode(CfgNode *EntryNode) { Entry = EntryNode; } |
84 CfgNode *getEntryNode() const { return Entry; } | 85 CfgNode *getEntryNode() const { return Entry; } |
85 /// Create a node and append it to the end of the linearized list. The loop | 86 /// Create a node and append it to the end of the linearized list. The loop |
86 /// nest depth of the new node may not be valid if it is created after | 87 /// nest depth of the new node may not be valid if it is created after |
87 /// computeLoopNestDepth. | 88 /// computeLoopNestDepth. |
88 CfgNode *makeNode(); | 89 CfgNode *makeNode(); |
89 SizeT getNumNodes() const { return Nodes.size(); } | 90 SizeT getNumNodes() const { return Nodes.size(); } |
90 const NodeList &getNodes() const { return Nodes; } | 91 const NodeList &getNodes() const { return Nodes; } |
91 /// Swap nodes of Cfg with given list of nodes. The number of nodes must | 92 /// Swap nodes of Cfg with given list of nodes. The number of nodes must |
92 /// remain unchanged. | 93 /// remain unchanged. |
93 void swapNodes(NodeList &NewNodes); | 94 void swapNodes(NodeList &NewNodes); |
94 /// @} | 95 /// @} |
95 | 96 |
96 using IdentifierIndexType = int32_t; | 97 StringPool *getNodeStrings() const { return NodeStrings.get(); } |
John
2016/03/29 14:23:15
what's node strings? var strings?
Jim Stichnoth
2016/03/29 21:40:49
Done.
| |
97 /// Adds a name to the list and returns its index, suitable for the argument | 98 StringPool *getVarStrings() const { return VarStrings.get(); } |
98 /// to getIdentifierName(). No checking for duplicates is done. This is | |
99 /// generally used for node names and variable names to avoid embedding a | |
100 /// std::string inside an arena-allocated object. | |
101 IdentifierIndexType addIdentifierName(const IceString &Name) { | |
102 IdentifierIndexType Index = IdentifierNames.size(); | |
103 IdentifierNames.push_back(Name); | |
104 return Index; | |
105 } | |
106 const IceString &getIdentifierName(IdentifierIndexType Index) const { | |
107 return IdentifierNames[Index]; | |
108 } | |
109 enum { IdentifierIndexInvalid = -1 }; | |
110 | 99 |
111 /// \name Manage instruction numbering. | 100 /// \name Manage instruction numbering. |
112 /// @{ | 101 /// @{ |
113 InstNumberT newInstNumber() { return NextInstNumber++; } | 102 InstNumberT newInstNumber() { return NextInstNumber++; } |
114 InstNumberT getNextInstNumber() const { return NextInstNumber; } | 103 InstNumberT getNextInstNumber() const { return NextInstNumber; } |
115 /// @} | 104 /// @} |
116 | 105 |
117 /// \name Manage Variables. | 106 /// \name Manage Variables. |
118 /// @{ | 107 /// @{ |
119 | 108 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 void resetCurrentNode() { setCurrentNode(nullptr); } | 223 void resetCurrentNode() { setCurrentNode(nullptr); } |
235 const CfgNode *getCurrentNode() const { return CurrentNode; } | 224 const CfgNode *getCurrentNode() const { return CurrentNode; } |
236 /// @} | 225 /// @} |
237 | 226 |
238 /// Get the total amount of memory held by the per-Cfg allocator. This is | 227 /// Get the total amount of memory held by the per-Cfg allocator. This is |
239 /// mostly meant for use inside a debugger. | 228 /// mostly meant for use inside a debugger. |
240 static size_t getTotalMemoryMB(); | 229 static size_t getTotalMemoryMB(); |
241 | 230 |
242 void emit(); | 231 void emit(); |
243 void emitIAS(); | 232 void emitIAS(); |
244 static void emitTextHeader(const IceString &Name, GlobalContext *Ctx, | 233 static void emitTextHeader(GlobalString Name, GlobalContext *Ctx, |
245 const Assembler *Asm); | 234 const Assembler *Asm); |
246 void dump(const char *Message = ""); | 235 void dump(const char *Message = ""); |
247 | 236 |
248 /// Allocate data of type T using the per-Cfg allocator. | 237 /// Allocate data of type T using the per-Cfg allocator. |
249 template <typename T> T *allocate() { return Allocator->Allocate<T>(); } | 238 template <typename T> T *allocate() { return Allocator->Allocate<T>(); } |
250 | 239 |
251 /// Allocate an array of data of type T using the per-Cfg allocator. | 240 /// Allocate an array of data of type T using the per-Cfg allocator. |
252 template <typename T> T *allocateArrayOf(size_t NumElems) { | 241 template <typename T> T *allocateArrayOf(size_t NumElems) { |
253 return Allocator->Allocate<T>(NumElems); | 242 return Allocator->Allocate<T>(NumElems); |
254 } | 243 } |
(...skipping 15 matching lines...) Expand all Loading... | |
270 | 259 |
271 /// Adds a call to the ProfileSummary runtime function as the first | 260 /// Adds a call to the ProfileSummary runtime function as the first |
272 /// instruction in this CFG's entry block. | 261 /// instruction in this CFG's entry block. |
273 void addCallToProfileSummary(); | 262 void addCallToProfileSummary(); |
274 | 263 |
275 /// Iterates over the basic blocks in this CFG, adding profiling code to each | 264 /// Iterates over the basic blocks in this CFG, adding profiling code to each |
276 /// one of them. It returns a list with all the globals that the profiling | 265 /// one of them. It returns a list with all the globals that the profiling |
277 /// code needs to be defined. | 266 /// code needs to be defined. |
278 void profileBlocks(); | 267 void profileBlocks(); |
279 | 268 |
280 void createNodeNameDeclaration(const IceString &NodeAsmName); | 269 void createNodeNameDeclaration(const std::string &NodeAsmName); |
281 void | 270 void |
282 createBlockProfilingInfoDeclaration(const IceString &NodeAsmName, | 271 createBlockProfilingInfoDeclaration(const std::string &NodeAsmName, |
283 VariableDeclaration *NodeNameDeclaration); | 272 VariableDeclaration *NodeNameDeclaration); |
284 | 273 |
285 /// Delete registered jump table placeholder instructions. This should only be | 274 /// Delete registered jump table placeholder instructions. This should only be |
286 /// called once all repointing has taken place. | 275 /// called once all repointing has taken place. |
287 void deleteJumpTableInsts(); | 276 void deleteJumpTableInsts(); |
288 /// Iterate through the registered jump tables and emit them. | 277 /// Iterate through the registered jump tables and emit them. |
289 void emitJumpTables(); | 278 void emitJumpTables(); |
290 | 279 |
291 enum AllocaBaseVariableType { | 280 enum AllocaBaseVariableType { |
292 BVT_StackPointer, | 281 BVT_StackPointer, |
293 BVT_FramePointer, | 282 BVT_FramePointer, |
294 BVT_UserPointer | 283 BVT_UserPointer |
295 }; | 284 }; |
296 void sortAndCombineAllocas(CfgVector<Inst *> &Allocas, | 285 void sortAndCombineAllocas(CfgVector<Inst *> &Allocas, |
297 uint32_t CombinedAlignment, InstList &Insts, | 286 uint32_t CombinedAlignment, InstList &Insts, |
298 AllocaBaseVariableType BaseVariableType); | 287 AllocaBaseVariableType BaseVariableType); |
299 void findRematerializable(); | 288 void findRematerializable(); |
300 | 289 |
301 GlobalContext *Ctx; | 290 GlobalContext *Ctx; |
302 uint32_t SequenceNumber; /// output order for emission | 291 uint32_t SequenceNumber; /// output order for emission |
303 uint32_t ConstantBlindingCookie = 0; /// cookie for constant blinding | 292 uint32_t ConstantBlindingCookie = 0; /// cookie for constant blinding |
304 VerboseMask VMask; | 293 VerboseMask VMask; |
305 IceString FunctionName = ""; | 294 GlobalString FunctionName; |
306 Type ReturnType = IceType_void; | 295 Type ReturnType = IceType_void; |
307 bool IsInternalLinkage = false; | 296 bool IsInternalLinkage = false; |
308 bool HasError = false; | 297 bool HasError = false; |
309 bool FocusedTiming = false; | 298 bool FocusedTiming = false; |
310 IceString ErrorMessage = ""; | 299 std::string ErrorMessage = ""; |
311 CfgNode *Entry = nullptr; /// entry basic block | 300 CfgNode *Entry = nullptr; /// entry basic block |
312 NodeList Nodes; /// linearized node list; Entry should be first | 301 NodeList Nodes; /// linearized node list; Entry should be first |
313 std::vector<IceString> IdentifierNames; | |
314 InstNumberT NextInstNumber; | 302 InstNumberT NextInstNumber; |
315 VarList Variables; | 303 VarList Variables; |
316 VarList Args; /// subset of Variables, in argument order | 304 VarList Args; /// subset of Variables, in argument order |
317 VarList ImplicitArgs; /// subset of Variables | 305 VarList ImplicitArgs; /// subset of Variables |
318 std::unique_ptr<ArenaAllocator> Allocator; | 306 std::unique_ptr<ArenaAllocator> Allocator; |
307 // Separate string pools for CfgNode and Variable names, due to a combination | |
308 // of the uniqueness requirement, and assumptions in lit tests. | |
309 std::unique_ptr<StringPool> NodeStrings; | |
310 std::unique_ptr<StringPool> VarStrings; | |
319 std::unique_ptr<Liveness> Live; | 311 std::unique_ptr<Liveness> Live; |
320 std::unique_ptr<TargetLowering> Target; | 312 std::unique_ptr<TargetLowering> Target; |
321 std::unique_ptr<VariablesMetadata> VMetadata; | 313 std::unique_ptr<VariablesMetadata> VMetadata; |
322 std::unique_ptr<Assembler> TargetAssembler; | 314 std::unique_ptr<Assembler> TargetAssembler; |
323 /// Globals required by this CFG. Mostly used for the profiler's globals. | 315 /// Globals required by this CFG. Mostly used for the profiler's globals. |
324 std::unique_ptr<VariableDeclarationList> GlobalInits; | 316 std::unique_ptr<VariableDeclarationList> GlobalInits; |
325 CfgVector<InstJumpTable *> JumpTables; | 317 CfgVector<InstJumpTable *> JumpTables; |
326 | 318 |
327 /// CurrentNode is maintained during dumping/emitting just for validating | 319 /// CurrentNode is maintained during dumping/emitting just for validating |
328 /// Variable::DefNode. Normally, a traversal over CfgNodes maintains this, but | 320 /// Variable::DefNode. Normally, a traversal over CfgNodes maintains this, but |
329 /// before global operations like register allocation, resetCurrentNode() | 321 /// before global operations like register allocation, resetCurrentNode() |
330 /// should be called to avoid spurious validation failures. | 322 /// should be called to avoid spurious validation failures. |
331 const CfgNode *CurrentNode = nullptr; | 323 const CfgNode *CurrentNode = nullptr; |
332 | 324 |
333 public: | 325 public: |
334 static void TlsInit() { CfgAllocatorTraits::init(); } | 326 static void TlsInit() { CfgAllocatorTraits::init(); } |
335 }; | 327 }; |
336 | 328 |
337 template <> Variable *Cfg::makeVariable<Variable>(Type Ty); | 329 template <> Variable *Cfg::makeVariable<Variable>(Type Ty); |
338 | 330 |
331 struct NodeStringPoolTraits { | |
332 using OwnerType = Cfg; | |
333 static StringPool *getStrings(const OwnerType *PoolOwner) { | |
334 return PoolOwner->getNodeStrings(); | |
335 } | |
336 }; | |
337 using NodeString = StringID<NodeStringPoolTraits>; | |
338 | |
339 struct VariableStringPoolTraits { | |
340 using OwnerType = Cfg; | |
341 static StringPool *getStrings(const OwnerType *PoolOwner) { | |
342 return PoolOwner->getVarStrings(); | |
343 } | |
344 }; | |
345 using VariableString = StringID<VariableStringPoolTraits>; | |
346 | |
339 } // end of namespace Ice | 347 } // end of namespace Ice |
340 | 348 |
341 #endif // SUBZERO_SRC_ICECFG_H | 349 #endif // SUBZERO_SRC_ICECFG_H |
OLD | NEW |