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_SRC_ICECFG_H | |
16 #define SUBZERO_SRC_ICECFG_H | |
17 | |
18 #include "IceDefs.h" | |
19 #include "IceTypes.h" | |
20 #include "IceGlobalContext.h" | |
21 | |
22 #include "llvm/ADT/OwningPtr.h" | |
23 #include "llvm/Support/Allocator.h" | |
24 | |
25 class IceCfg { | |
26 public: | |
27 IceCfg(IceGlobalContext *Ctx); | |
28 ~IceCfg(); | |
29 | |
30 IceGlobalContext *getContext() const { return Ctx; } | |
31 | |
32 // Manage the name and return type of the function being translated. | |
33 void setName(const IceString &FunctionName) { Name = FunctionName; } | |
34 IceString getName() const { return Name; } | |
35 void setReturnType(IceType ReturnType) { Type = ReturnType; } | |
36 | |
37 // Manage the "internal" attribute of the function. | |
38 void setInternal(bool Internal) { IsInternal = Internal; } | |
39 bool getInternal() const { return IsInternal; } | |
40 | |
41 // Translation error flagging. If support for some construct is | |
42 // known to be missing, instead of an assertion failure, setError() | |
43 // should be called and the error should be propagated back up. | |
44 // This way, we can gracefully fail to translate and let a fallback | |
45 // translator handle the function. | |
46 void setError(const IceString &Message); | |
47 bool hasError() const { return HasError; } | |
48 IceString getError() const { return ErrorMessage; } | |
49 | |
50 // Manage nodes (a.k.a. basic blocks, IceCfgNodes). | |
51 void setEntryNode(IceCfgNode *EntryNode) { Entry = EntryNode; } | |
52 IceCfgNode *getEntryNode() const { return Entry; } | |
53 // Create a node and append it to the end of the linearized list. | |
54 IceCfgNode *makeNode(const IceString &Name = ""); | |
JF
2014/04/16 01:27:32
Your CFG doesn't seem to have an exit node? How do
Jim Stichnoth
2014/04/21 20:26:40
So far, the only Subzero pass/algorithm that itera
JF
2014/04/23 03:51:28
My point is: if each return is succeeded by the ex
Jim Stichnoth
2014/04/26 15:02:11
OK, I think what you're saying/suggesting would be
| |
55 uint32_t getNumNodes() const { return Nodes.size(); } | |
56 const IceNodeList &getNodes() const { return Nodes; } | |
57 | |
58 // Manage instruction numbering. | |
59 int newInstNumber() { return NextInstNumber++; } | |
60 | |
61 // Manage IceVariables. | |
62 IceVariable *makeVariable(IceType Type, const IceCfgNode *Node, | |
63 const IceString &Name = ""); | |
64 uint32_t getNumVariables() const { return Variables.size(); } | |
65 const IceVarList &getVariables() const { return Variables; } | |
66 | |
67 // Manage arguments to the function. | |
68 void addArg(IceVariable *Arg); | |
69 const IceVarList &getArgs() const { return Args; } | |
70 | |
71 void registerEdges(); | |
JF
2014/04/16 01:27:32
What does this do?
Jim Stichnoth
2014/04/21 20:26:40
This was documented in IceCfgNode::registerEdges()
| |
72 void setCurrentNode(const IceCfgNode *Node) { CurrentNode = Node; } | |
73 const IceCfgNode *getCurrentNode() const { return CurrentNode; } | |
JF
2014/04/16 01:27:32
What are current nodes in a CFG?
Jim Stichnoth
2014/04/21 20:26:40
This is described in the documentation below of th
JF
2014/04/23 03:51:28
As discussed offline, add a TODO to remove the pre
Jim Stichnoth
2014/04/26 15:02:11
Done.
| |
74 void dump(); | |
JF
2014/04/16 01:27:32
Your other dump functions seem to take in a stream
Jim Stichnoth
2014/04/21 20:26:40
Are you looking at the latest patchset? The dump(
| |
75 | |
76 // Allocate data of type T using the per-Cfg allocator. | |
77 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } | |
78 | |
79 // Allocate an instruction of type T using the per-Cfg instruction allocator. | |
80 template <typename T> T *allocateInst() { return Allocator.Allocate<T>(); } | |
81 | |
82 // Allocate an array of data of type T using the per-Cfg allocator. | |
83 template <typename T> T *allocateArrayOf(size_t NumElems) { | |
84 return Allocator.Allocate<T>(NumElems); | |
85 } | |
86 | |
87 private: | |
88 // TODO: for now, everything is allocated from the same allocator. In the | |
89 // future we may want to split this to several allocators, for example in | |
90 // order to use a "Recycler" to preserve memory. If we keep all allocation | |
91 // requests from the Cfg exposed via methods, we can always switch the | |
92 // implementation over at a later point. | |
93 llvm::BumpPtrAllocator Allocator; | |
94 | |
95 IceGlobalContext *Ctx; | |
96 IceString Name; // function name | |
97 IceType Type; // return type | |
98 bool IsInternal; // internal linkage | |
JF
2014/04/16 01:27:32
The comments above could just be the variable name
Jim Stichnoth
2014/04/21 20:26:40
Done.
| |
99 bool HasError; | |
JF
2014/04/16 01:27:32
Isn't that just ErrorMessage.size() != 0 ?
Jim Stichnoth
2014/04/21 20:26:40
Not if you call setError("blah") followed by setEr
| |
100 IceString ErrorMessage; | |
101 IceCfgNode *Entry; // entry basic block | |
102 IceNodeList Nodes; // linearized node list; Entry should be first | |
103 int NextInstNumber; | |
104 IceVarList Variables; | |
105 IceVarList Args; // subset of Variables, in argument order | |
106 | |
107 // CurrentNode is maintained during dumping/emitting just for | |
108 // validating IceVariable::DefNode. Normally, a traversal over | |
109 // IceCfgNodes maintains this, but before global operations like | |
110 // register allocation, setCurrentNode(NULL) should be called to | |
111 // avoid spurious validation failures. | |
112 const IceCfgNode *CurrentNode; | |
113 | |
114 IceCfg(const IceCfg &) LLVM_DELETED_FUNCTION; | |
115 IceCfg &operator=(const IceCfg &) LLVM_DELETED_FUNCTION; | |
116 }; | |
117 | |
118 #endif // SUBZERO_SRC_ICECFG_H | |
OLD | NEW |