OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_FLOW_GRAPH_BUILDER_H_ | 5 #ifndef VM_FLOW_GRAPH_BUILDER_H_ |
6 #define VM_FLOW_GRAPH_BUILDER_H_ | 6 #define VM_FLOW_GRAPH_BUILDER_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 intptr_t num_non_copied_params() const { | 133 intptr_t num_non_copied_params() const { |
134 return num_non_copied_params_; | 134 return num_non_copied_params_; |
135 } | 135 } |
136 intptr_t num_stack_locals() const { | 136 intptr_t num_stack_locals() const { |
137 return num_stack_locals_; | 137 return num_stack_locals_; |
138 } | 138 } |
139 | 139 |
140 bool IsInlining() const { return (exit_collector_ != NULL); } | 140 bool IsInlining() const { return (exit_collector_ != NULL); } |
141 InlineExitCollector* exit_collector() const { return exit_collector_; } | 141 InlineExitCollector* exit_collector() const { return exit_collector_; } |
142 | 142 |
| 143 intptr_t args_pushed() const { return args_pushed_; } |
| 144 void add_args_pushed(intptr_t n) { args_pushed_ += n; } |
| 145 |
143 private: | 146 private: |
144 intptr_t parameter_count() const { | 147 intptr_t parameter_count() const { |
145 return num_copied_params_ + num_non_copied_params_; | 148 return num_copied_params_ + num_non_copied_params_; |
146 } | 149 } |
147 intptr_t variable_count() const { | 150 intptr_t variable_count() const { |
148 return parameter_count() + num_stack_locals_; | 151 return parameter_count() + num_stack_locals_; |
149 } | 152 } |
150 | 153 |
151 const ParsedFunction& parsed_function_; | 154 const ParsedFunction& parsed_function_; |
152 const Array& ic_data_array_; | 155 const Array& ic_data_array_; |
153 | 156 |
154 const intptr_t num_copied_params_; | 157 const intptr_t num_copied_params_; |
155 const intptr_t num_non_copied_params_; | 158 const intptr_t num_non_copied_params_; |
156 const intptr_t num_stack_locals_; // Does not include any parameters. | 159 const intptr_t num_stack_locals_; // Does not include any parameters. |
157 InlineExitCollector* const exit_collector_; | 160 InlineExitCollector* const exit_collector_; |
158 | 161 |
159 intptr_t last_used_block_id_; | 162 intptr_t last_used_block_id_; |
160 intptr_t context_level_; | 163 intptr_t context_level_; |
161 intptr_t last_used_try_index_; | 164 intptr_t last_used_try_index_; |
162 intptr_t try_index_; | 165 intptr_t try_index_; |
163 GraphEntryInstr* graph_entry_; | 166 GraphEntryInstr* graph_entry_; |
164 | 167 |
| 168 // Outgoing argument stack height. |
| 169 intptr_t args_pushed_; |
| 170 |
165 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); | 171 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); |
166 }; | 172 }; |
167 | 173 |
168 | 174 |
169 class TestGraphVisitor; | 175 class TestGraphVisitor; |
170 | 176 |
171 // Translate an AstNode to a control-flow graph fragment for its effects | 177 // Translate an AstNode to a control-flow graph fragment for its effects |
172 // (e.g., a statement or an expression in an effect context). Implements a | 178 // (e.g., a statement or an expression in an effect context). Implements a |
173 // function from an AstNode and next temporary index to a graph fragment | 179 // function from an AstNode and next temporary index to a graph fragment |
174 // with a single entry and at most one exit. The fragment is represented by | 180 // with a single entry and at most one exit. The fragment is represented by |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // Moves parent context into the context register. | 317 // Moves parent context into the context register. |
312 void UnchainContext(); | 318 void UnchainContext(); |
313 | 319 |
314 void CloseFragment() { exit_ = NULL; } | 320 void CloseFragment() { exit_ = NULL; } |
315 intptr_t AllocateTempIndex() { return temp_index_++; } | 321 intptr_t AllocateTempIndex() { return temp_index_++; } |
316 void DeallocateTempIndex(intptr_t n) { | 322 void DeallocateTempIndex(intptr_t n) { |
317 ASSERT(temp_index_ >= n); | 323 ASSERT(temp_index_ >= n); |
318 temp_index_ -= n; | 324 temp_index_ -= n; |
319 } | 325 } |
320 | 326 |
| 327 // Returns a local variable index for a temporary local that is |
| 328 // on top of the current expression stack. |
| 329 intptr_t GetCurrentTempLocalIndex() const; |
| 330 |
321 Value* BuildObjectAllocation(ConstructorCallNode* node); | 331 Value* BuildObjectAllocation(ConstructorCallNode* node); |
322 void BuildConstructorCall(ConstructorCallNode* node, | 332 void BuildConstructorCall(ConstructorCallNode* node, |
323 PushArgumentInstr* alloc_value); | 333 PushArgumentInstr* alloc_value); |
324 | 334 |
325 void BuildStoreContext(const LocalVariable& variable); | 335 void BuildStoreContext(const LocalVariable& variable); |
326 void BuildLoadContext(const LocalVariable& variable); | 336 void BuildLoadContext(const LocalVariable& variable); |
327 | 337 |
328 void BuildThrowNode(ThrowNode* node); | 338 void BuildThrowNode(ThrowNode* node); |
329 | 339 |
330 StaticCallInstr* BuildStaticNoSuchMethodCall( | 340 StaticCallInstr* BuildStaticNoSuchMethodCall( |
331 const Class& target_class, | 341 const Class& target_class, |
332 AstNode* receiver, | 342 AstNode* receiver, |
333 const String& method_name, | 343 const String& method_name, |
334 ArgumentListNode* method_arguments); | 344 ArgumentListNode* method_arguments); |
335 | 345 |
336 StaticCallInstr* BuildThrowNoSuchMethodError(intptr_t token_pos, | 346 StaticCallInstr* BuildThrowNoSuchMethodError(intptr_t token_pos, |
337 const Class& function_class, | 347 const Class& function_class, |
338 const String& function_name, | 348 const String& function_name, |
339 int invocation_type); | 349 int invocation_type); |
340 | 350 |
341 void BuildStaticSetter(StaticSetterNode* node, bool result_is_needed); | 351 void BuildStaticSetter(StaticSetterNode* node, bool result_is_needed); |
342 Definition* BuildStoreStaticField(StoreStaticFieldNode* node, | 352 Definition* BuildStoreStaticField(StoreStaticFieldNode* node, |
343 bool result_is_needed); | 353 bool result_is_needed); |
344 | 354 |
345 ClosureCallInstr* BuildClosureCall(ClosureCallNode* node); | 355 ClosureCallInstr* BuildClosureCall(ClosureCallNode* node); |
346 | 356 |
347 Value* BuildNullValue(); | 357 Value* BuildNullValue(); |
348 | 358 |
349 private: | |
350 // Specify a definition of the final result. Adds the definition to | |
351 // the graph, but normally overridden in subclasses. | |
352 virtual void ReturnDefinition(Definition* definition) { | |
353 Do(definition); | |
354 } | |
355 | |
356 protected: | |
357 // Returns true if the run-time type check can be eliminated. | 359 // Returns true if the run-time type check can be eliminated. |
358 bool CanSkipTypeCheck(intptr_t token_pos, | 360 bool CanSkipTypeCheck(intptr_t token_pos, |
359 Value* value, | 361 Value* value, |
360 const AbstractType& dst_type, | 362 const AbstractType& dst_type, |
361 const String& dst_name); | 363 const String& dst_name); |
362 | 364 |
363 private: | 365 private: |
| 366 friend class TempLocalScope; // For ReturnDefinition. |
| 367 |
| 368 // Specify a definition of the final result. Adds the definition to |
| 369 // the graph, but normally overridden in subclasses. |
| 370 virtual void ReturnDefinition(Definition* definition) { |
| 371 Do(definition); |
| 372 } |
| 373 |
364 // Shared global state. | 374 // Shared global state. |
365 FlowGraphBuilder* owner_; | 375 FlowGraphBuilder* owner_; |
366 | 376 |
367 // Input parameters. | 377 // Input parameters. |
368 intptr_t temp_index_; | 378 intptr_t temp_index_; |
369 | 379 |
370 // Output parameters. | 380 // Output parameters. |
371 Instruction* entry_; | 381 Instruction* entry_; |
372 Instruction* exit_; | 382 Instruction* exit_; |
373 }; | 383 }; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // Output parameters. | 493 // Output parameters. |
484 GrowableArray<TargetEntryInstr**> true_successor_addresses_; | 494 GrowableArray<TargetEntryInstr**> true_successor_addresses_; |
485 GrowableArray<TargetEntryInstr**> false_successor_addresses_; | 495 GrowableArray<TargetEntryInstr**> false_successor_addresses_; |
486 | 496 |
487 intptr_t condition_token_pos_; | 497 intptr_t condition_token_pos_; |
488 }; | 498 }; |
489 | 499 |
490 } // namespace dart | 500 } // namespace dart |
491 | 501 |
492 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 502 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
OLD | NEW |