OLD | NEW |
---|---|
(Empty) | |
1 //===- subzero/src/IceCfg.h - Control flow graph ----------------*- C++ -*-===// | |
2 // | |
3 // The Subzero Code Generator | |
4 // | |
5 // This file is distributed under the University of Illinois Open Source | |
6 // License. See LICENSE.TXT for details. | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 // | |
10 // This file declares the IceCfg class, which represents the control | |
11 // flow graph and the overall per-function compilation context. | |
12 // | |
13 //===----------------------------------------------------------------------===// | |
14 | |
15 #ifndef SUBZERO_ICECFG_H | |
jvoung (off chromium)
2014/03/22 00:29:39
Should the header guards have "_SRC_" now that the
Jim Stichnoth
2014/03/24 13:18:53
Done.
| |
16 #define SUBZERO_ICECFG_H | |
17 | |
18 #include "IceDefs.h" | |
19 #include "IceTypes.h" | |
20 | |
21 #include "llvm/Support/Allocator.h" | |
22 | |
23 class IceCfg { | |
24 public: | |
25 IceCfg(); | |
26 ~IceCfg(); | |
27 | |
28 // Manage the name and return type of the function being translated. | |
29 void setName(const IceString &FunctionName) { Name = FunctionName; } | |
30 IceString getName() const { return Name; } | |
31 void setReturnType(IceType ReturnType) { Type = ReturnType; } | |
32 | |
33 // When emitting assembly, we allow a string to be prepended to | |
34 // names of translated functions. This makes it easier to create an | |
35 // execution test against a reference translator like llc, with both | |
36 // translators using the same bitcode as input. | |
37 void setTestPrefix(const IceString &Prefix) { TestPrefix = Prefix; } | |
38 IceString getTestPrefix() const { return TestPrefix; } | |
39 IceString mangleName(const IceString &Name) const { | |
40 return getTestPrefix() + Name; | |
41 } | |
42 | |
43 // Manage the "internal" attribute of the function. | |
44 void setInternal(bool Internal) { IsInternal = Internal; } | |
45 bool getInternal() const { return IsInternal; } | |
46 | |
47 // Translation error flagging. If support for some construct is | |
48 // known to be missing, instead of an assertion failure, setError() | |
49 // should be called and the error should be propagated back up. | |
50 // This way, we can gracefully fail to translate and let a fallback | |
51 // translator handle the function. | |
52 void setError(const IceString &Message); | |
53 bool hasError() const { return HasError; } | |
54 IceString getError() const { return ErrorMessage; } | |
55 | |
56 // Manage nodes (a.k.a. basic blocks, IceCfgNodes). | |
57 void setEntryNode(IceCfgNode *EntryNode) { Entry = EntryNode; } | |
58 IceCfgNode *getEntryNode() const { return Entry; } | |
59 // Create a node and append it to the end of the linearized list. | |
60 IceCfgNode *makeNode(const IceString &Name = ""); | |
61 uint32_t getNumNodes() const { return Nodes.size(); } | |
62 const IceNodeList &getNodes() const { return Nodes; } | |
63 | |
64 // Manage instruction numbering. | |
65 int newInstNumber() { return NextInstNumber++; } | |
66 | |
67 // Manage IceVariables. | |
68 IceVariable *makeVariable(IceType Type, const IceCfgNode *Node, | |
69 const IceString &Name = ""); | |
70 uint32_t getNumVariables() const { return Variables.size(); } | |
71 const IceVarList &getVariables() const { return Variables; } | |
72 | |
73 // Manage arguments to the function. | |
74 void addArg(IceVariable *Arg); | |
75 const IceVarList &getArgs() const { return Args; } | |
76 | |
77 // Manage IceConstants. | |
78 // getConstant*() functions are not const because they might add | |
79 // something to the constant pool. | |
80 IceConstant *getConstantInt(IceType Type, uint64_t ConstantInt64); | |
81 IceConstant *getConstantFloat(float Value); | |
82 IceConstant *getConstantDouble(double Value); | |
83 // Returns a symbolic constant. Handle is currently unused but is | |
84 // reserved to hold something LLVM-specific to facilitate linking. | |
85 IceConstant *getConstantSym(IceType Type, const void *Handle, int64_t Offset, | |
86 const IceString &Name = "", | |
87 bool SuppressMangling = false); | |
88 | |
89 void registerEdges(); | |
90 void dump() const; | |
91 | |
92 // Allocate an instruction of type T using the per-Cfg instruction allocator. | |
93 template <typename T> T *allocateInst() { return Allocator.Allocate<T>(); } | |
94 | |
95 // Allocate an array of data of type T using the per-Cfg allocator. | |
96 template <typename T> T *allocateArrayOf(size_t NumElems) { | |
97 return Allocator.Allocate<T>(NumElems); | |
98 } | |
99 | |
100 mutable IceOstream Str; | |
101 | |
102 private: | |
103 // TODO: for now, everything is allocated from the same allocator. In the | |
104 // future we may want to split this to several allocators, for example in | |
105 // order to use a "Recycler" to preserve memory. If we keep all allocation | |
106 // requests from the Cfg exposed via methods, we can always switch the | |
107 // implementation over at a later point. | |
108 llvm::BumpPtrAllocator Allocator; | |
109 | |
110 IceString Name; // function name | |
111 IceString TestPrefix; // prepended to all symbol names, for testing | |
112 IceType Type; // return type | |
113 bool IsInternal; // internal linkage | |
114 bool HasError; | |
115 IceString ErrorMessage; | |
116 IceCfgNode *Entry; // entry basic block | |
117 IceNodeList Nodes; // linearized node list; Entry should be first | |
118 int NextInstNumber; | |
119 IceVarList Variables; | |
120 IceVarList Args; // subset of Variables, in argument order | |
121 class IceConstantPool *ConstantPool; | |
122 }; | |
123 | |
124 #endif // SUBZERO_ICECFG_H | |
OLD | NEW |