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 // This file declares the Cfg class, which represents the control flow | 10 // This file declares the Cfg class, which represents the control flow |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 CfgNode *getEntryNode() const { return Entry; } | 54 CfgNode *getEntryNode() const { return Entry; } |
55 // Create a node and append it to the end of the linearized list. | 55 // Create a node and append it to the end of the linearized list. |
56 CfgNode *makeNode(const IceString &Name = ""); | 56 CfgNode *makeNode(const IceString &Name = ""); |
57 SizeT getNumNodes() const { return Nodes.size(); } | 57 SizeT getNumNodes() const { return Nodes.size(); } |
58 const NodeList &getNodes() const { return Nodes; } | 58 const NodeList &getNodes() const { return Nodes; } |
59 | 59 |
60 // Manage instruction numbering. | 60 // Manage instruction numbering. |
61 InstNumberT newInstNumber() { return NextInstNumber++; } | 61 InstNumberT newInstNumber() { return NextInstNumber++; } |
62 | 62 |
63 // Manage Variables. | 63 // Manage Variables. |
| 64 // Create a new Variable with a particular type and an optional |
| 65 // name. The Node argument is the node where the variable is defined. |
| 66 template <typename T> |
| 67 T *makeVariable(Type Ty, const CfgNode *Node, const IceString &Name = "") { |
| 68 SizeT Index = Variables.size(); |
| 69 T *Var = T::create(this, Ty, Node, Index, Name); |
| 70 Variables.push_back(Var); |
| 71 return Var; |
| 72 } |
| 73 // TODO(stichnot): Remove this function with C++11, and use default |
| 74 // argument <typename T=Variable> above. |
64 Variable *makeVariable(Type Ty, const CfgNode *Node, | 75 Variable *makeVariable(Type Ty, const CfgNode *Node, |
65 const IceString &Name = ""); | 76 const IceString &Name = ""); |
66 SizeT getNumVariables() const { return Variables.size(); } | 77 SizeT getNumVariables() const { return Variables.size(); } |
67 const VarList &getVariables() const { return Variables; } | 78 const VarList &getVariables() const { return Variables; } |
68 | 79 |
69 // Manage arguments to the function. | 80 // Manage arguments to the function. |
70 void addArg(Variable *Arg); | 81 void addArg(Variable *Arg); |
71 const VarList &getArgs() const { return Args; } | 82 const VarList &getArgs() const { return Args; } |
72 VarList &getArgs() { return Args; } | 83 VarList &getArgs() { return Args; } |
73 | 84 |
(...skipping 18 matching lines...) Expand all Loading... |
92 void genCode(); | 103 void genCode(); |
93 void genFrame(); | 104 void genFrame(); |
94 void livenessLightweight(); | 105 void livenessLightweight(); |
95 void liveness(LivenessMode Mode); | 106 void liveness(LivenessMode Mode); |
96 bool validateLiveness() const; | 107 bool validateLiveness() const; |
97 void doBranchOpt(); | 108 void doBranchOpt(); |
98 | 109 |
99 // Manage the CurrentNode field, which is used for validating the | 110 // Manage the CurrentNode field, which is used for validating the |
100 // Variable::DefNode field during dumping/emitting. | 111 // Variable::DefNode field during dumping/emitting. |
101 void setCurrentNode(const CfgNode *Node) { CurrentNode = Node; } | 112 void setCurrentNode(const CfgNode *Node) { CurrentNode = Node; } |
| 113 void resetCurrentNode() { setCurrentNode(NULL); } |
102 const CfgNode *getCurrentNode() const { return CurrentNode; } | 114 const CfgNode *getCurrentNode() const { return CurrentNode; } |
103 | 115 |
104 void emit(); | 116 void emit(); |
105 void dump(const IceString &Message = ""); | 117 void dump(const IceString &Message = ""); |
106 | 118 |
107 // Allocate data of type T using the per-Cfg allocator. | 119 // Allocate data of type T using the per-Cfg allocator. |
108 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } | 120 template <typename T> T *allocate() { return Allocator.Allocate<T>(); } |
109 | 121 |
110 // Allocate an instruction of type T using the per-Cfg instruction allocator. | 122 // Allocate an instruction of type T using the per-Cfg instruction allocator. |
111 template <typename T> T *allocateInst() { return Allocator.Allocate<T>(); } | 123 template <typename T> T *allocateInst() { return Allocator.Allocate<T>(); } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 NodeList Nodes; // linearized node list; Entry should be first | 160 NodeList Nodes; // linearized node list; Entry should be first |
149 InstNumberT NextInstNumber; | 161 InstNumberT NextInstNumber; |
150 VarList Variables; | 162 VarList Variables; |
151 VarList Args; // subset of Variables, in argument order | 163 VarList Args; // subset of Variables, in argument order |
152 llvm::OwningPtr<Liveness> Live; | 164 llvm::OwningPtr<Liveness> Live; |
153 llvm::OwningPtr<TargetLowering> Target; | 165 llvm::OwningPtr<TargetLowering> Target; |
154 | 166 |
155 // CurrentNode is maintained during dumping/emitting just for | 167 // CurrentNode is maintained during dumping/emitting just for |
156 // validating Variable::DefNode. Normally, a traversal over | 168 // validating Variable::DefNode. Normally, a traversal over |
157 // CfgNodes maintains this, but before global operations like | 169 // CfgNodes maintains this, but before global operations like |
158 // register allocation, setCurrentNode(NULL) should be called to | 170 // register allocation, resetCurrentNode() should be called to avoid |
159 // avoid spurious validation failures. | 171 // spurious validation failures. |
160 const CfgNode *CurrentNode; | 172 const CfgNode *CurrentNode; |
161 | 173 |
162 Cfg(const Cfg &) LLVM_DELETED_FUNCTION; | 174 Cfg(const Cfg &) LLVM_DELETED_FUNCTION; |
163 Cfg &operator=(const Cfg &) LLVM_DELETED_FUNCTION; | 175 Cfg &operator=(const Cfg &) LLVM_DELETED_FUNCTION; |
164 }; | 176 }; |
165 | 177 |
166 } // end of namespace Ice | 178 } // end of namespace Ice |
167 | 179 |
168 #endif // SUBZERO_SRC_ICECFG_H | 180 #endif // SUBZERO_SRC_ICECFG_H |
OLD | NEW |