| 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_INTERMEDIATE_LANGUAGE_H_ | 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ |
| 6 #define VM_INTERMEDIATE_LANGUAGE_H_ | 6 #define VM_INTERMEDIATE_LANGUAGE_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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 Instruction* RemoveFromGraph(bool return_previous = true); | 372 Instruction* RemoveFromGraph(bool return_previous = true); |
| 373 | 373 |
| 374 // Normal instructions can have 0 (inside a block) or 1 (last instruction in | 374 // Normal instructions can have 0 (inside a block) or 1 (last instruction in |
| 375 // a block) successors. Branch instruction with >1 successors override this | 375 // a block) successors. Branch instruction with >1 successors override this |
| 376 // function. | 376 // function. |
| 377 virtual intptr_t SuccessorCount() const; | 377 virtual intptr_t SuccessorCount() const; |
| 378 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 378 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 379 | 379 |
| 380 void Goto(JoinEntryInstr* entry); | 380 void Goto(JoinEntryInstr* entry); |
| 381 | 381 |
| 382 // Discover basic-block structure by performing a recursive depth first | |
| 383 // traversal of the instruction graph reachable from this instruction. As | |
| 384 // a side effect, the block entry instructions in the graph are assigned | |
| 385 // numbers in both preorder and postorder. The array 'preorder' maps | |
| 386 // preorder block numbers to the block entry instruction with that number | |
| 387 // and analogously for the array 'postorder'. The depth first spanning | |
| 388 // tree is recorded in the array 'parent', which maps preorder block | |
| 389 // numbers to the preorder number of the block's spanning-tree parent. | |
| 390 // The array 'assigned_vars' maps preorder block numbers to the set of | |
| 391 // assigned frame-allocated local variables in the block. As a side | |
| 392 // effect of this function, the set of basic block predecessors (e.g., | |
| 393 // block entry instructions of predecessor blocks) and also the last | |
| 394 // instruction in the block is recorded in each entry instruction. | |
| 395 virtual void DiscoverBlocks( | |
| 396 BlockEntryInstr* current_block, | |
| 397 GrowableArray<BlockEntryInstr*>* preorder, | |
| 398 GrowableArray<BlockEntryInstr*>* postorder, | |
| 399 GrowableArray<intptr_t>* parent, | |
| 400 GrowableArray<BitVector*>* assigned_vars, | |
| 401 intptr_t variable_count, | |
| 402 intptr_t fixed_parameter_count) { | |
| 403 // Never called for instructions except block entries and branches. | |
| 404 UNREACHABLE(); | |
| 405 } | |
| 406 | |
| 407 // Mutate assigned_vars to add the local variable index for all | 382 // Mutate assigned_vars to add the local variable index for all |
| 408 // frame-allocated locals assigned to by the instruction. | 383 // frame-allocated locals assigned to by the instruction. |
| 409 virtual void RecordAssignedVars(BitVector* assigned_vars, | 384 virtual void RecordAssignedVars(BitVector* assigned_vars, |
| 410 intptr_t fixed_parameter_count); | 385 intptr_t fixed_parameter_count); |
| 411 | 386 |
| 412 virtual const char* DebugName() const = 0; | 387 virtual const char* DebugName() const = 0; |
| 413 | 388 |
| 414 // Printing support. | 389 // Printing support. |
| 415 virtual void PrintTo(BufferFormatter* f) const; | 390 virtual void PrintTo(BufferFormatter* f) const; |
| 416 virtual void PrintOperandsTo(BufferFormatter* f) const; | 391 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 return parallel_move_ != NULL; | 695 return parallel_move_ != NULL; |
| 721 } | 696 } |
| 722 | 697 |
| 723 ParallelMoveInstr* GetParallelMove() { | 698 ParallelMoveInstr* GetParallelMove() { |
| 724 if (parallel_move_ == NULL) { | 699 if (parallel_move_ == NULL) { |
| 725 parallel_move_ = new ParallelMoveInstr(); | 700 parallel_move_ = new ParallelMoveInstr(); |
| 726 } | 701 } |
| 727 return parallel_move_; | 702 return parallel_move_; |
| 728 } | 703 } |
| 729 | 704 |
| 730 virtual void DiscoverBlocks( | 705 // Discover basic-block structure by performing a recursive depth first |
| 706 // traversal of the instruction graph reachable from this instruction. As |
| 707 // a side effect, the block entry instructions in the graph are assigned |
| 708 // numbers in both preorder and postorder. The array 'preorder' maps |
| 709 // preorder block numbers to the block entry instruction with that number |
| 710 // and analogously for the array 'postorder'. The depth first spanning |
| 711 // tree is recorded in the array 'parent', which maps preorder block |
| 712 // numbers to the preorder number of the block's spanning-tree parent. |
| 713 // The array 'assigned_vars' maps preorder block numbers to the set of |
| 714 // assigned frame-allocated local variables in the block. As a side |
| 715 // effect of this function, the set of basic block predecessors (e.g., |
| 716 // block entry instructions of predecessor blocks) and also the last |
| 717 // instruction in the block is recorded in each entry instruction. |
| 718 void DiscoverBlocks( |
| 731 BlockEntryInstr* current_block, | 719 BlockEntryInstr* current_block, |
| 732 GrowableArray<BlockEntryInstr*>* preorder, | 720 GrowableArray<BlockEntryInstr*>* preorder, |
| 733 GrowableArray<BlockEntryInstr*>* postorder, | 721 GrowableArray<BlockEntryInstr*>* postorder, |
| 734 GrowableArray<intptr_t>* parent, | 722 GrowableArray<intptr_t>* parent, |
| 735 GrowableArray<BitVector*>* assigned_vars, | 723 GrowableArray<BitVector*>* assigned_vars, |
| 736 intptr_t variable_count, | 724 intptr_t variable_count, |
| 737 intptr_t fixed_parameter_count); | 725 intptr_t fixed_parameter_count); |
| 738 | 726 |
| 739 virtual intptr_t InputCount() const { return 0; } | 727 virtual intptr_t InputCount() const { return 0; } |
| 740 virtual Value* InputAt(intptr_t i) const { | 728 virtual Value* InputAt(intptr_t i) const { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 intptr_t loop_depth_; | 797 intptr_t loop_depth_; |
| 810 | 798 |
| 811 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); | 799 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); |
| 812 }; | 800 }; |
| 813 | 801 |
| 814 | 802 |
| 815 class ForwardInstructionIterator : public ValueObject { | 803 class ForwardInstructionIterator : public ValueObject { |
| 816 public: | 804 public: |
| 817 explicit ForwardInstructionIterator(BlockEntryInstr* block_entry) | 805 explicit ForwardInstructionIterator(BlockEntryInstr* block_entry) |
| 818 : block_entry_(block_entry), current_(block_entry) { | 806 : block_entry_(block_entry), current_(block_entry) { |
| 819 ASSERT(block_entry_->last_instruction()->next() == NULL); | |
| 820 Advance(); | 807 Advance(); |
| 821 } | 808 } |
| 822 | 809 |
| 823 void Advance() { | 810 void Advance() { |
| 824 ASSERT(!Done()); | 811 ASSERT(!Done()); |
| 825 current_ = current_->next(); | 812 current_ = current_->next(); |
| 826 } | 813 } |
| 827 | 814 |
| 828 bool Done() const { return current_ == NULL; } | 815 bool Done() const { return current_ == NULL; } |
| 829 | 816 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 DECLARE_INSTRUCTION(GraphEntry) | 858 DECLARE_INSTRUCTION(GraphEntry) |
| 872 | 859 |
| 873 virtual intptr_t PredecessorCount() const { return 0; } | 860 virtual intptr_t PredecessorCount() const { return 0; } |
| 874 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { | 861 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { |
| 875 UNREACHABLE(); | 862 UNREACHABLE(); |
| 876 return NULL; | 863 return NULL; |
| 877 } | 864 } |
| 878 virtual intptr_t SuccessorCount() const; | 865 virtual intptr_t SuccessorCount() const; |
| 879 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 866 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 880 | 867 |
| 881 virtual void DiscoverBlocks( | |
| 882 BlockEntryInstr* current_block, | |
| 883 GrowableArray<BlockEntryInstr*>* preorder, | |
| 884 GrowableArray<BlockEntryInstr*>* postorder, | |
| 885 GrowableArray<intptr_t>* parent, | |
| 886 GrowableArray<BitVector*>* assigned_vars, | |
| 887 intptr_t variable_count, | |
| 888 intptr_t fixed_parameter_count); | |
| 889 | |
| 890 void AddCatchEntry(TargetEntryInstr* entry) { catch_entries_.Add(entry); } | 868 void AddCatchEntry(TargetEntryInstr* entry) { catch_entries_.Add(entry); } |
| 891 | 869 |
| 892 virtual void PrepareEntry(FlowGraphCompiler* compiler); | 870 virtual void PrepareEntry(FlowGraphCompiler* compiler); |
| 893 | 871 |
| 894 GrowableArray<Definition*>* initial_definitions() { | 872 GrowableArray<Definition*>* initial_definitions() { |
| 895 return &initial_definitions_; | 873 return &initial_definitions_; |
| 896 } | 874 } |
| 897 ConstantInstr* constant_null(); | 875 ConstantInstr* constant_null(); |
| 898 | 876 |
| 899 intptr_t spill_slot_count() const { return spill_slot_count_; } | 877 intptr_t spill_slot_count() const { return spill_slot_count_; } |
| 900 void set_spill_slot_count(intptr_t count) { | 878 void set_spill_slot_count(intptr_t count) { |
| 901 ASSERT(count >= 0); | 879 ASSERT(count >= 0); |
| 902 spill_slot_count_ = count; | 880 spill_slot_count_ = count; |
| 903 } | 881 } |
| 904 | 882 |
| 905 TargetEntryInstr* normal_entry() const { return normal_entry_; } | 883 TargetEntryInstr* normal_entry() const { return normal_entry_; } |
| 906 | 884 |
| 907 virtual void PrintTo(BufferFormatter* f) const; | 885 virtual void PrintTo(BufferFormatter* f) const; |
| 908 | 886 |
| 909 private: | 887 private: |
| 910 virtual void ClearPredecessors() { UNREACHABLE(); } | 888 virtual void ClearPredecessors() {} |
| 911 virtual void AddPredecessor(BlockEntryInstr* predecessor) { UNREACHABLE(); } | 889 virtual void AddPredecessor(BlockEntryInstr* predecessor) { UNREACHABLE(); } |
| 912 | 890 |
| 913 TargetEntryInstr* normal_entry_; | 891 TargetEntryInstr* normal_entry_; |
| 914 GrowableArray<TargetEntryInstr*> catch_entries_; | 892 GrowableArray<TargetEntryInstr*> catch_entries_; |
| 915 GrowableArray<Definition*> initial_definitions_; | 893 GrowableArray<Definition*> initial_definitions_; |
| 916 intptr_t spill_slot_count_; | 894 intptr_t spill_slot_count_; |
| 917 | 895 |
| 918 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr); | 896 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr); |
| 919 }; | 897 }; |
| 920 | 898 |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 | 1477 |
| 1500 TargetEntryInstr* true_successor() const { return true_successor_; } | 1478 TargetEntryInstr* true_successor() const { return true_successor_; } |
| 1501 TargetEntryInstr* false_successor() const { return false_successor_; } | 1479 TargetEntryInstr* false_successor() const { return false_successor_; } |
| 1502 | 1480 |
| 1503 TargetEntryInstr** true_successor_address() { return &true_successor_; } | 1481 TargetEntryInstr** true_successor_address() { return &true_successor_; } |
| 1504 TargetEntryInstr** false_successor_address() { return &false_successor_; } | 1482 TargetEntryInstr** false_successor_address() { return &false_successor_; } |
| 1505 | 1483 |
| 1506 virtual intptr_t SuccessorCount() const; | 1484 virtual intptr_t SuccessorCount() const; |
| 1507 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 1485 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 1508 | 1486 |
| 1509 virtual void DiscoverBlocks( | |
| 1510 BlockEntryInstr* current_block, | |
| 1511 GrowableArray<BlockEntryInstr*>* preorder, | |
| 1512 GrowableArray<BlockEntryInstr*>* postorder, | |
| 1513 GrowableArray<intptr_t>* parent, | |
| 1514 GrowableArray<BitVector*>* assigned_vars, | |
| 1515 intptr_t variable_count, | |
| 1516 intptr_t fixed_parameter_count); | |
| 1517 | |
| 1518 | |
| 1519 void EmitBranchOnCondition(FlowGraphCompiler* compiler, | 1487 void EmitBranchOnCondition(FlowGraphCompiler* compiler, |
| 1520 Condition true_condition); | 1488 Condition true_condition); |
| 1521 | 1489 |
| 1522 void EmitBranchOnValue(FlowGraphCompiler* compiler, bool result); | 1490 void EmitBranchOnValue(FlowGraphCompiler* compiler, bool result); |
| 1523 | 1491 |
| 1524 private: | 1492 private: |
| 1525 TargetEntryInstr* true_successor_; | 1493 TargetEntryInstr* true_successor_; |
| 1526 TargetEntryInstr* false_successor_; | 1494 TargetEntryInstr* false_successor_; |
| 1527 | 1495 |
| 1528 DISALLOW_COPY_AND_ASSIGN(ControlInstruction); | 1496 DISALLOW_COPY_AND_ASSIGN(ControlInstruction); |
| (...skipping 2825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4354 ForwardInstructionIterator* current_iterator_; | 4322 ForwardInstructionIterator* current_iterator_; |
| 4355 | 4323 |
| 4356 private: | 4324 private: |
| 4357 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 4325 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 4358 }; | 4326 }; |
| 4359 | 4327 |
| 4360 | 4328 |
| 4361 } // namespace dart | 4329 } // namespace dart |
| 4362 | 4330 |
| 4363 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 4331 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |