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

Side by Side Diff: src/IceCfg.h

Issue 1838753002: Subzero: Remove IceString. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes 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
« no previous file with comments | « src/IceBrowserCompileServer.cpp ('k') | src/IceCfg.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 /// String pool for CfgNode::Name values.
97 /// Adds a name to the list and returns its index, suitable for the argument 98 StringPool *getNodeStrings() const { return NodeStrings.get(); }
98 /// to getIdentifierName(). No checking for duplicates is done. This is 99 /// String pool for Variable::Name values.
99 /// generally used for node names and variable names to avoid embedding a 100 StringPool *getVarStrings() const { return VarStrings.get(); }
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 101
111 /// \name Manage instruction numbering. 102 /// \name Manage instruction numbering.
112 /// @{ 103 /// @{
113 InstNumberT newInstNumber() { return NextInstNumber++; } 104 InstNumberT newInstNumber() { return NextInstNumber++; }
114 InstNumberT getNextInstNumber() const { return NextInstNumber; } 105 InstNumberT getNextInstNumber() const { return NextInstNumber; }
115 /// @} 106 /// @}
116 107
117 /// \name Manage Variables. 108 /// \name Manage Variables.
118 /// @{ 109 /// @{
119 110
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 void resetCurrentNode() { setCurrentNode(nullptr); } 225 void resetCurrentNode() { setCurrentNode(nullptr); }
235 const CfgNode *getCurrentNode() const { return CurrentNode; } 226 const CfgNode *getCurrentNode() const { return CurrentNode; }
236 /// @} 227 /// @}
237 228
238 /// Get the total amount of memory held by the per-Cfg allocator. This is 229 /// Get the total amount of memory held by the per-Cfg allocator. This is
239 /// mostly meant for use inside a debugger. 230 /// mostly meant for use inside a debugger.
240 static size_t getTotalMemoryMB(); 231 static size_t getTotalMemoryMB();
241 232
242 void emit(); 233 void emit();
243 void emitIAS(); 234 void emitIAS();
244 static void emitTextHeader(const IceString &Name, GlobalContext *Ctx, 235 static void emitTextHeader(GlobalString Name, GlobalContext *Ctx,
245 const Assembler *Asm); 236 const Assembler *Asm);
246 void dump(const char *Message = ""); 237 void dump(const char *Message = "");
247 238
248 /// Allocate data of type T using the per-Cfg allocator. 239 /// Allocate data of type T using the per-Cfg allocator.
249 template <typename T> T *allocate() { return Allocator->Allocate<T>(); } 240 template <typename T> T *allocate() { return Allocator->Allocate<T>(); }
250 241
251 /// Allocate an array of data of type T using the per-Cfg allocator. 242 /// Allocate an array of data of type T using the per-Cfg allocator.
252 template <typename T> T *allocateArrayOf(size_t NumElems) { 243 template <typename T> T *allocateArrayOf(size_t NumElems) {
253 return Allocator->Allocate<T>(NumElems); 244 return Allocator->Allocate<T>(NumElems);
254 } 245 }
(...skipping 15 matching lines...) Expand all
270 261
271 /// Adds a call to the ProfileSummary runtime function as the first 262 /// Adds a call to the ProfileSummary runtime function as the first
272 /// instruction in this CFG's entry block. 263 /// instruction in this CFG's entry block.
273 void addCallToProfileSummary(); 264 void addCallToProfileSummary();
274 265
275 /// Iterates over the basic blocks in this CFG, adding profiling code to each 266 /// 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 267 /// one of them. It returns a list with all the globals that the profiling
277 /// code needs to be defined. 268 /// code needs to be defined.
278 void profileBlocks(); 269 void profileBlocks();
279 270
280 void createNodeNameDeclaration(const IceString &NodeAsmName); 271 void createNodeNameDeclaration(const std::string &NodeAsmName);
281 void 272 void
282 createBlockProfilingInfoDeclaration(const IceString &NodeAsmName, 273 createBlockProfilingInfoDeclaration(const std::string &NodeAsmName,
283 VariableDeclaration *NodeNameDeclaration); 274 VariableDeclaration *NodeNameDeclaration);
284 275
285 /// Delete registered jump table placeholder instructions. This should only be 276 /// Delete registered jump table placeholder instructions. This should only be
286 /// called once all repointing has taken place. 277 /// called once all repointing has taken place.
287 void deleteJumpTableInsts(); 278 void deleteJumpTableInsts();
288 /// Iterate through the registered jump tables and emit them. 279 /// Iterate through the registered jump tables and emit them.
289 void emitJumpTables(); 280 void emitJumpTables();
290 281
291 enum AllocaBaseVariableType { 282 enum AllocaBaseVariableType {
292 BVT_StackPointer, 283 BVT_StackPointer,
293 BVT_FramePointer, 284 BVT_FramePointer,
294 BVT_UserPointer 285 BVT_UserPointer
295 }; 286 };
296 void sortAndCombineAllocas(CfgVector<Inst *> &Allocas, 287 void sortAndCombineAllocas(CfgVector<Inst *> &Allocas,
297 uint32_t CombinedAlignment, InstList &Insts, 288 uint32_t CombinedAlignment, InstList &Insts,
298 AllocaBaseVariableType BaseVariableType); 289 AllocaBaseVariableType BaseVariableType);
299 void findRematerializable(); 290 void findRematerializable();
300 291
301 GlobalContext *Ctx; 292 GlobalContext *Ctx;
302 uint32_t SequenceNumber; /// output order for emission 293 uint32_t SequenceNumber; /// output order for emission
303 uint32_t ConstantBlindingCookie = 0; /// cookie for constant blinding 294 uint32_t ConstantBlindingCookie = 0; /// cookie for constant blinding
304 VerboseMask VMask; 295 VerboseMask VMask;
305 IceString FunctionName = ""; 296 GlobalString FunctionName;
306 Type ReturnType = IceType_void; 297 Type ReturnType = IceType_void;
307 bool IsInternalLinkage = false; 298 bool IsInternalLinkage = false;
308 bool HasError = false; 299 bool HasError = false;
309 bool FocusedTiming = false; 300 bool FocusedTiming = false;
310 IceString ErrorMessage = ""; 301 std::string ErrorMessage = "";
311 CfgNode *Entry = nullptr; /// entry basic block 302 CfgNode *Entry = nullptr; /// entry basic block
312 NodeList Nodes; /// linearized node list; Entry should be first 303 NodeList Nodes; /// linearized node list; Entry should be first
313 std::vector<IceString> IdentifierNames;
314 InstNumberT NextInstNumber; 304 InstNumberT NextInstNumber;
315 VarList Variables; 305 VarList Variables;
316 VarList Args; /// subset of Variables, in argument order 306 VarList Args; /// subset of Variables, in argument order
317 VarList ImplicitArgs; /// subset of Variables 307 VarList ImplicitArgs; /// subset of Variables
318 std::unique_ptr<ArenaAllocator> Allocator; 308 std::unique_ptr<ArenaAllocator> Allocator;
309 // Separate string pools for CfgNode and Variable names, due to a combination
310 // of the uniqueness requirement, and assumptions in lit tests.
311 std::unique_ptr<StringPool> NodeStrings;
312 std::unique_ptr<StringPool> VarStrings;
319 std::unique_ptr<Liveness> Live; 313 std::unique_ptr<Liveness> Live;
320 std::unique_ptr<TargetLowering> Target; 314 std::unique_ptr<TargetLowering> Target;
321 std::unique_ptr<VariablesMetadata> VMetadata; 315 std::unique_ptr<VariablesMetadata> VMetadata;
322 std::unique_ptr<Assembler> TargetAssembler; 316 std::unique_ptr<Assembler> TargetAssembler;
323 /// Globals required by this CFG. Mostly used for the profiler's globals. 317 /// Globals required by this CFG. Mostly used for the profiler's globals.
324 std::unique_ptr<VariableDeclarationList> GlobalInits; 318 std::unique_ptr<VariableDeclarationList> GlobalInits;
325 CfgVector<InstJumpTable *> JumpTables; 319 CfgVector<InstJumpTable *> JumpTables;
326 320
327 /// CurrentNode is maintained during dumping/emitting just for validating 321 /// CurrentNode is maintained during dumping/emitting just for validating
328 /// Variable::DefNode. Normally, a traversal over CfgNodes maintains this, but 322 /// Variable::DefNode. Normally, a traversal over CfgNodes maintains this, but
329 /// before global operations like register allocation, resetCurrentNode() 323 /// before global operations like register allocation, resetCurrentNode()
330 /// should be called to avoid spurious validation failures. 324 /// should be called to avoid spurious validation failures.
331 const CfgNode *CurrentNode = nullptr; 325 const CfgNode *CurrentNode = nullptr;
332 326
333 public: 327 public:
334 static void TlsInit() { CfgAllocatorTraits::init(); } 328 static void TlsInit() { CfgAllocatorTraits::init(); }
335 }; 329 };
336 330
337 template <> Variable *Cfg::makeVariable<Variable>(Type Ty); 331 template <> Variable *Cfg::makeVariable<Variable>(Type Ty);
338 332
333 struct NodeStringPoolTraits {
334 using OwnerType = Cfg;
335 static StringPool *getStrings(const OwnerType *PoolOwner) {
336 return PoolOwner->getNodeStrings();
337 }
338 };
339 using NodeString = StringID<NodeStringPoolTraits>;
340
341 struct VariableStringPoolTraits {
342 using OwnerType = Cfg;
343 static StringPool *getStrings(const OwnerType *PoolOwner) {
344 return PoolOwner->getVarStrings();
345 }
346 };
347 using VariableString = StringID<VariableStringPoolTraits>;
348
339 } // end of namespace Ice 349 } // end of namespace Ice
340 350
341 #endif // SUBZERO_SRC_ICECFG_H 351 #endif // SUBZERO_SRC_ICECFG_H
OLDNEW
« no previous file with comments | « src/IceBrowserCompileServer.cpp ('k') | src/IceCfg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698