Mercurial > hg > CbC > CbC_gcc
comparison gcc/go/gofrontend/escape.h @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
49 // Return this level's suffix value. | 49 // Return this level's suffix value. |
50 int | 50 int |
51 suffix_value() const | 51 suffix_value() const |
52 { return this->suffix_value_; } | 52 { return this->suffix_value_; } |
53 | 53 |
54 // Increase the level because a node is referenced. | 54 // Increase the level because a node is dereferenced. |
55 Level | 55 Level |
56 increase() const | 56 increase() const |
57 { | 57 { |
58 if (this->value_ <= MIN_LEVEL) | 58 if (this->value_ <= MIN_LEVEL) |
59 return Level(MIN_LEVEL, 0); | 59 return Level(MIN_LEVEL, 0); |
60 | 60 |
61 return Level(this->value_ + 1, this->suffix_value_ + 1); | 61 return Level(this->value_ + 1, this->suffix_value_ + 1); |
62 } | 62 } |
63 | 63 |
64 // Decrease the level because a node is dereferenced. | 64 // Decrease the level because a node is referenced. |
65 Level | 65 Level |
66 decrease() const | 66 decrease() const |
67 { | 67 { |
68 if (this->value_ <= MIN_LEVEL) | 68 if (this->value_ <= MIN_LEVEL) |
69 return Level(MIN_LEVEL, 0); | 69 return Level(MIN_LEVEL, 0); |
102 return Level(MIN_LEVEL, 0); | 102 return Level(MIN_LEVEL, 0); |
103 return Level(i, 0); | 103 return Level(i, 0); |
104 } | 104 } |
105 | 105 |
106 private: | 106 private: |
107 // The sum of all indirects (-1) and references (+1) applied to a Node. | 107 // The sum of all references (-1) and indirects (+1) applied to a Node. |
108 int value_; | 108 int value_; |
109 // The sum of all indirects (-1) abd references (+1) applied to a copied Node. | 109 // The sum of all references (-1) abd indirects (+1) applied to a copied Node. |
110 int suffix_value_; | 110 int suffix_value_; |
111 }; | 111 }; |
112 | 112 |
113 // A node in the escape graph. This node is an alias to a particular node | 113 // A node in the escape graph. This node is an alias to a particular node |
114 // in the Go parse tree. Specifically, it can represent an expression node, | 114 // in the Go parse tree. Specifically, it can represent an expression node, |
121 // interesting during the analysis. | 121 // interesting during the analysis. |
122 enum Node_classification | 122 enum Node_classification |
123 { | 123 { |
124 NODE_OBJECT, | 124 NODE_OBJECT, |
125 NODE_EXPRESSION, | 125 NODE_EXPRESSION, |
126 NODE_STATEMENT | 126 NODE_STATEMENT, |
127 // A "fake" node that models the indirection of its child node. | |
128 // This node does not correspond to an AST node. | |
129 NODE_INDIRECT | |
127 }; | 130 }; |
128 | 131 |
129 // The state necessary to keep track of how a node escapes. | 132 // The state necessary to keep track of how a node escapes. |
130 struct Escape_state | 133 struct Escape_state |
131 { | 134 { |
159 ESCAPE_UNKNOWN, | 162 ESCAPE_UNKNOWN, |
160 // Does not escape to heap, result, or parameters. | 163 // Does not escape to heap, result, or parameters. |
161 ESCAPE_NONE, | 164 ESCAPE_NONE, |
162 // Is returned or reachable from a return statement. | 165 // Is returned or reachable from a return statement. |
163 ESCAPE_RETURN, | 166 ESCAPE_RETURN, |
164 // Allocated in an inner loop, assigned to an outer loop, | |
165 // which allows construction of non-escaping but arbitrarily large linked | |
166 // data structures (i.e., not eligible for allocation in a fixed-size stack | |
167 // stack frame). | |
168 ESCAPE_SCOPE, | |
169 // Reachable from the heap. | 167 // Reachable from the heap. |
170 ESCAPE_HEAP, | 168 ESCAPE_HEAP, |
171 // By construction will not escape. | 169 // By construction will not escape. |
172 ESCAPE_NEVER | 170 ESCAPE_NEVER |
173 }; | 171 }; |
174 | 172 |
175 // Multiple constructors for each classification. | 173 // Multiple constructors for each classification. |
176 Node(Named_object* no) | 174 Node(Named_object* no) |
177 : classification_(NODE_OBJECT), state_(NULL), encoding_(ESCAPE_UNKNOWN) | 175 : classification_(NODE_OBJECT), state_(NULL), encoding_(ESCAPE_UNKNOWN), |
176 child_(NULL) | |
178 { this->u_.object_val = no; } | 177 { this->u_.object_val = no; } |
179 | 178 |
180 Node(Expression* e) | 179 Node(Expression* e) |
181 : classification_(NODE_EXPRESSION), state_(NULL), encoding_(ESCAPE_UNKNOWN) | 180 : classification_(NODE_EXPRESSION), state_(NULL), encoding_(ESCAPE_UNKNOWN), |
181 child_(NULL) | |
182 { this->u_.expression_val = e; } | 182 { this->u_.expression_val = e; } |
183 | 183 |
184 Node(Statement* s) | 184 Node(Statement* s) |
185 : classification_(NODE_STATEMENT), state_(NULL), encoding_(ESCAPE_UNKNOWN) | 185 : classification_(NODE_STATEMENT), state_(NULL), encoding_(ESCAPE_UNKNOWN), |
186 child_(NULL) | |
186 { this->u_.statement_val = s; } | 187 { this->u_.statement_val = s; } |
188 | |
189 Node(Node *n) | |
190 : classification_(NODE_INDIRECT), state_(NULL), encoding_(ESCAPE_UNKNOWN), | |
191 child_(n) | |
192 {} | |
193 | |
194 ~Node(); | |
187 | 195 |
188 // Return this node's type. | 196 // Return this node's type. |
189 Type* | 197 Type* |
190 type() const; | 198 type() const; |
191 | 199 |
192 // Return this node's location. | 200 // Return this node's location. |
193 Location | 201 Location |
194 location() const; | 202 location() const; |
195 | 203 |
204 // Return the location where the node's underlying object is defined. | |
205 Location | |
206 definition_location() const; | |
207 | |
196 // Return this node's AST formatted string. | 208 // Return this node's AST formatted string. |
197 std::string | 209 std::string |
198 ast_format(Gogo*) const; | 210 ast_format(Gogo*) const; |
199 | 211 |
200 // Return this node's detailed format string. | 212 // Return this node's detailed format string. |
201 std::string | 213 std::string |
202 details() const; | 214 details(); |
203 | 215 |
204 std::string | 216 std::string |
205 op_format() const; | 217 op_format() const; |
206 | 218 |
207 // Return this node's escape state. | 219 // Return this node's escape state. |
208 Escape_state* | 220 Escape_state* |
209 state(Escape_context* context, Named_object* fn); | 221 state(Escape_context* context, Named_object* fn); |
210 | 222 |
211 // Return this node's escape encoding. | 223 // Return this node's escape encoding. |
212 int | 224 int |
213 encoding() const | 225 encoding(); |
214 { return this->encoding_; } | |
215 | 226 |
216 // Set the node's escape encoding. | 227 // Set the node's escape encoding. |
217 void | 228 void |
218 set_encoding(int enc); | 229 set_encoding(int enc); |
219 | 230 |
246 return (this->classification_ == NODE_STATEMENT | 257 return (this->classification_ == NODE_STATEMENT |
247 ? this->u_.statement_val | 258 ? this->u_.statement_val |
248 : NULL); | 259 : NULL); |
249 } | 260 } |
250 | 261 |
262 bool | |
263 is_indirect() const | |
264 { return this->classification_ == NODE_INDIRECT; } | |
265 | |
266 // Return its child node. | |
267 // Child node is used only in indirect node, and in expression node | |
268 // representing slicing an array. | |
269 Node* | |
270 child() const | |
271 { return this->child_; } | |
272 | |
273 // Set the child node. | |
274 void | |
275 set_child(Node* n) | |
276 { this->child_ = n; } | |
277 | |
251 // Static creation methods for each value supported in the union. | 278 // Static creation methods for each value supported in the union. |
252 static Node* | 279 static Node* |
253 make_node(Named_object*); | 280 make_node(Named_object*); |
254 | 281 |
255 static Node* | 282 static Node* |
256 make_node(Expression*); | 283 make_node(Expression*); |
257 | 284 |
258 static Node* | 285 static Node* |
259 make_node(Statement*); | 286 make_node(Statement*); |
287 | |
288 static Node* | |
289 make_indirect_node(Node*); | |
260 | 290 |
261 // Return the maximum of an existing escape encoding E and a new | 291 // Return the maximum of an existing escape encoding E and a new |
262 // escape type. | 292 // escape type. |
263 static int | 293 static int |
264 max_encoding(int e, int etype); | 294 max_encoding(int e, int etype); |
265 | 295 |
266 // Return a modified encoding for an input parameter that flows into an | 296 // Return a modified encoding for an input parameter that flows into an |
267 // output parameter. | 297 // output parameter. |
268 static int | 298 static int |
269 note_inout_flows(int e, int index, Level level); | 299 note_inout_flows(int e, int index, Level level); |
300 | |
301 // Reclaim nodes. | |
302 static void | |
303 reclaim_nodes(); | |
270 | 304 |
271 private: | 305 private: |
272 // The classification of this Node. | 306 // The classification of this Node. |
273 Node_classification classification_; | 307 Node_classification classification_; |
274 // The value union. | 308 // The value union. |
288 // | Return Encoding: (width - ESCAPE_RETURN_BITS) | | 322 // | Return Encoding: (width - ESCAPE_RETURN_BITS) | |
289 // | Content Escapes bit: 1 | | 323 // | Content Escapes bit: 1 | |
290 // | Escapement_encoding: ESCAPE_BITS | | 324 // | Escapement_encoding: ESCAPE_BITS | |
291 int encoding_; | 325 int encoding_; |
292 | 326 |
327 // Child node, used only in indirect node, and expression node representing | |
328 // slicing an array. | |
329 Node* child_; | |
330 | |
293 // Cache all the Nodes created via Node::make_node to make the API simpler. | 331 // Cache all the Nodes created via Node::make_node to make the API simpler. |
294 static std::map<Named_object*, Node*> objects; | 332 static std::map<Named_object*, Node*> objects; |
295 static std::map<Expression*, Node*> expressions; | 333 static std::map<Expression*, Node*> expressions; |
296 static std::map<Statement*, Node*> statements; | 334 static std::map<Statement*, Node*> statements; |
335 | |
336 // Collection of all NODE_INDIRECT Nodes, used for reclaiming memory. This | |
337 // is not a cache -- each make_indirect_node will make a fresh Node. | |
338 static std::vector<Node*> indirects; | |
297 }; | 339 }; |
298 | 340 |
299 // The amount of bits used for the escapement encoding. | 341 // The amount of bits used for the escapement encoding. |
300 static const int ESCAPE_BITS = 3; | 342 static const int ESCAPE_BITS = 3; |
301 | 343 |