| 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 |
| 359 // Returns true if the run-time type check can be eliminated. |
| 360 bool CanSkipTypeCheck(intptr_t token_pos, |
| 361 Value* value, |
| 362 const AbstractType& dst_type, |
| 363 const String& dst_name); |
| 364 |
| 365 void BuildLetTempExpressions(LetNode* node); |
| 366 |
| 349 private: | 367 private: |
| 368 friend class TempLocalScope; // For ReturnDefinition. |
| 369 |
| 350 // Specify a definition of the final result. Adds the definition to | 370 // Specify a definition of the final result. Adds the definition to |
| 351 // the graph, but normally overridden in subclasses. | 371 // the graph, but normally overridden in subclasses. |
| 352 virtual void ReturnDefinition(Definition* definition) { | 372 virtual void ReturnDefinition(Definition* definition) { |
| 353 Do(definition); | 373 Do(definition); |
| 354 } | 374 } |
| 355 | 375 |
| 356 protected: | |
| 357 // Returns true if the run-time type check can be eliminated. | |
| 358 bool CanSkipTypeCheck(intptr_t token_pos, | |
| 359 Value* value, | |
| 360 const AbstractType& dst_type, | |
| 361 const String& dst_name); | |
| 362 | |
| 363 private: | |
| 364 // Shared global state. | 376 // Shared global state. |
| 365 FlowGraphBuilder* owner_; | 377 FlowGraphBuilder* owner_; |
| 366 | 378 |
| 367 // Input parameters. | 379 // Input parameters. |
| 368 intptr_t temp_index_; | 380 intptr_t temp_index_; |
| 369 | 381 |
| 370 // Output parameters. | 382 // Output parameters. |
| 371 Instruction* entry_; | 383 Instruction* entry_; |
| 372 Instruction* exit_; | 384 Instruction* exit_; |
| 373 }; | 385 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 394 virtual void VisitStoreLocalNode(StoreLocalNode* node); | 406 virtual void VisitStoreLocalNode(StoreLocalNode* node); |
| 395 virtual void VisitStoreIndexedNode(StoreIndexedNode* node); | 407 virtual void VisitStoreIndexedNode(StoreIndexedNode* node); |
| 396 virtual void VisitStoreInstanceFieldNode(StoreInstanceFieldNode* node); | 408 virtual void VisitStoreInstanceFieldNode(StoreInstanceFieldNode* node); |
| 397 virtual void VisitInstanceSetterNode(InstanceSetterNode* node); | 409 virtual void VisitInstanceSetterNode(InstanceSetterNode* node); |
| 398 virtual void VisitThrowNode(ThrowNode* node); | 410 virtual void VisitThrowNode(ThrowNode* node); |
| 399 virtual void VisitClosureCallNode(ClosureCallNode* node); | 411 virtual void VisitClosureCallNode(ClosureCallNode* node); |
| 400 virtual void VisitStaticSetterNode(StaticSetterNode* node); | 412 virtual void VisitStaticSetterNode(StaticSetterNode* node); |
| 401 virtual void VisitStoreStaticFieldNode(StoreStaticFieldNode* node); | 413 virtual void VisitStoreStaticFieldNode(StoreStaticFieldNode* node); |
| 402 virtual void VisitTypeNode(TypeNode* node); | 414 virtual void VisitTypeNode(TypeNode* node); |
| 403 virtual void VisitCommaNode(CommaNode* node); | 415 virtual void VisitCommaNode(CommaNode* node); |
| 416 virtual void VisitLetNode(LetNode* node); |
| 404 | 417 |
| 405 Value* value() const { return value_; } | 418 Value* value() const { return value_; } |
| 406 | 419 |
| 407 protected: | 420 protected: |
| 408 // Output parameters. | 421 // Output parameters. |
| 409 Value* value_; | 422 Value* value_; |
| 410 | 423 |
| 411 private: | 424 private: |
| 412 // Helper to set the output state to return a Value. | 425 // Helper to set the output state to return a Value. |
| 413 virtual void ReturnValue(Value* value) { value_ = value; } | 426 virtual void ReturnValue(Value* value) { value_ = value; } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 // Output parameters. | 496 // Output parameters. |
| 484 GrowableArray<TargetEntryInstr**> true_successor_addresses_; | 497 GrowableArray<TargetEntryInstr**> true_successor_addresses_; |
| 485 GrowableArray<TargetEntryInstr**> false_successor_addresses_; | 498 GrowableArray<TargetEntryInstr**> false_successor_addresses_; |
| 486 | 499 |
| 487 intptr_t condition_token_pos_; | 500 intptr_t condition_token_pos_; |
| 488 }; | 501 }; |
| 489 | 502 |
| 490 } // namespace dart | 503 } // namespace dart |
| 491 | 504 |
| 492 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 505 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
| OLD | NEW |