| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 Instruction* RemoveFromGraph(bool return_previous = true); | 612 Instruction* RemoveFromGraph(bool return_previous = true); |
| 613 | 613 |
| 614 // Normal instructions can have 0 (inside a block) or 1 (last instruction in | 614 // Normal instructions can have 0 (inside a block) or 1 (last instruction in |
| 615 // a block) successors. Branch instruction with >1 successors override this | 615 // a block) successors. Branch instruction with >1 successors override this |
| 616 // function. | 616 // function. |
| 617 virtual intptr_t SuccessorCount() const; | 617 virtual intptr_t SuccessorCount() const; |
| 618 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 618 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 619 | 619 |
| 620 void Goto(JoinEntryInstr* entry); | 620 void Goto(JoinEntryInstr* entry); |
| 621 | 621 |
| 622 // Mutate assigned_vars to add the local variable index for all | |
| 623 // frame-allocated locals assigned to by the instruction. | |
| 624 virtual void RecordAssignedVars(BitVector* assigned_vars, | |
| 625 intptr_t fixed_parameter_count); | |
| 626 | |
| 627 virtual const char* DebugName() const = 0; | 622 virtual const char* DebugName() const = 0; |
| 628 | 623 |
| 629 // Printing support. | 624 // Printing support. |
| 630 virtual void PrintTo(BufferFormatter* f) const; | 625 virtual void PrintTo(BufferFormatter* f) const; |
| 631 virtual void PrintOperandsTo(BufferFormatter* f) const; | 626 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 632 | 627 |
| 633 #define INSTRUCTION_TYPE_CHECK(type) \ | 628 #define INSTRUCTION_TYPE_CHECK(type) \ |
| 634 bool Is##type() { return (As##type() != NULL); } \ | 629 bool Is##type() { return (As##type() != NULL); } \ |
| 635 virtual type##Instr* As##type() { return NULL; } | 630 virtual type##Instr* As##type() { return NULL; } |
| 636 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) | 631 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 // The array 'assigned_vars' maps preorder block numbers to the set of | 957 // The array 'assigned_vars' maps preorder block numbers to the set of |
| 963 // assigned frame-allocated local variables in the block. As a side | 958 // assigned frame-allocated local variables in the block. As a side |
| 964 // effect of this function, the set of basic block predecessors (e.g., | 959 // effect of this function, the set of basic block predecessors (e.g., |
| 965 // block entry instructions of predecessor blocks) and also the last | 960 // block entry instructions of predecessor blocks) and also the last |
| 966 // instruction in the block is recorded in each entry instruction. | 961 // instruction in the block is recorded in each entry instruction. |
| 967 void DiscoverBlocks( | 962 void DiscoverBlocks( |
| 968 BlockEntryInstr* predecessor, | 963 BlockEntryInstr* predecessor, |
| 969 GrowableArray<BlockEntryInstr*>* preorder, | 964 GrowableArray<BlockEntryInstr*>* preorder, |
| 970 GrowableArray<BlockEntryInstr*>* postorder, | 965 GrowableArray<BlockEntryInstr*>* postorder, |
| 971 GrowableArray<intptr_t>* parent, | 966 GrowableArray<intptr_t>* parent, |
| 972 GrowableArray<BitVector*>* assigned_vars, | |
| 973 intptr_t variable_count, | 967 intptr_t variable_count, |
| 974 intptr_t fixed_parameter_count); | 968 intptr_t fixed_parameter_count); |
| 975 | 969 |
| 976 virtual intptr_t InputCount() const { return 0; } | 970 virtual intptr_t InputCount() const { return 0; } |
| 977 virtual Value* InputAt(intptr_t i) const { | 971 virtual Value* InputAt(intptr_t i) const { |
| 978 UNREACHABLE(); | 972 UNREACHABLE(); |
| 979 return NULL; | 973 return NULL; |
| 980 } | 974 } |
| 981 | 975 |
| 982 virtual intptr_t ArgumentCount() const { return 0; } | 976 virtual intptr_t ArgumentCount() const { return 0; } |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 // Precondition: use lists must be properly calculated. | 1377 // Precondition: use lists must be properly calculated. |
| 1384 // Postcondition: use lists and use values are still valid. | 1378 // Postcondition: use lists and use values are still valid. |
| 1385 void ReplaceUsesWith(Definition* other); | 1379 void ReplaceUsesWith(Definition* other); |
| 1386 | 1380 |
| 1387 // Replace this definition and all uses with another definition. If | 1381 // Replace this definition and all uses with another definition. If |
| 1388 // replacing during iteration, pass the iterator so that the instruction | 1382 // replacing during iteration, pass the iterator so that the instruction |
| 1389 // can be replaced without affecting iteration order, otherwise pass a | 1383 // can be replaced without affecting iteration order, otherwise pass a |
| 1390 // NULL iterator. | 1384 // NULL iterator. |
| 1391 void ReplaceWith(Definition* other, ForwardInstructionIterator* iterator); | 1385 void ReplaceWith(Definition* other, ForwardInstructionIterator* iterator); |
| 1392 | 1386 |
| 1393 virtual void RecordAssignedVars(BitVector* assigned_vars, | |
| 1394 intptr_t fixed_parameter_count); | |
| 1395 | |
| 1396 // Printing support. These functions are sometimes overridden for custom | 1387 // Printing support. These functions are sometimes overridden for custom |
| 1397 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". | 1388 // formatting. Otherwise, it prints in the format "opcode(op1, op2, op3)". |
| 1398 virtual void PrintTo(BufferFormatter* f) const; | 1389 virtual void PrintTo(BufferFormatter* f) const; |
| 1399 virtual void PrintOperandsTo(BufferFormatter* f) const; | 1390 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 1400 | 1391 |
| 1401 // A value in the constant propagation lattice. | 1392 // A value in the constant propagation lattice. |
| 1402 // - non-constant sentinel | 1393 // - non-constant sentinel |
| 1403 // - a constant (any non-sentinel value) | 1394 // - a constant (any non-sentinel value) |
| 1404 // - unknown sentinel | 1395 // - unknown sentinel |
| 1405 Object& constant_value() const { return constant_value_; } | 1396 Object& constant_value() const { return constant_value_; } |
| (...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2702 | 2693 |
| 2703 // 'True' for recognized list constructors. | 2694 // 'True' for recognized list constructors. |
| 2704 bool is_known_list_constructor_; | 2695 bool is_known_list_constructor_; |
| 2705 | 2696 |
| 2706 DISALLOW_COPY_AND_ASSIGN(StaticCallInstr); | 2697 DISALLOW_COPY_AND_ASSIGN(StaticCallInstr); |
| 2707 }; | 2698 }; |
| 2708 | 2699 |
| 2709 | 2700 |
| 2710 class LoadLocalInstr : public TemplateDefinition<0> { | 2701 class LoadLocalInstr : public TemplateDefinition<0> { |
| 2711 public: | 2702 public: |
| 2712 explicit LoadLocalInstr(const LocalVariable& local) : local_(local) { } | 2703 explicit LoadLocalInstr(const LocalVariable& local) |
| 2704 : local_(local), is_last_(false) { } |
| 2713 | 2705 |
| 2714 DECLARE_INSTRUCTION(LoadLocal) | 2706 DECLARE_INSTRUCTION(LoadLocal) |
| 2715 virtual CompileType ComputeType() const; | 2707 virtual CompileType ComputeType() const; |
| 2716 | 2708 |
| 2717 const LocalVariable& local() const { return local_; } | 2709 const LocalVariable& local() const { return local_; } |
| 2718 | 2710 |
| 2719 virtual void PrintOperandsTo(BufferFormatter* f) const; | 2711 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 2720 | 2712 |
| 2721 virtual bool CanDeoptimize() const { return false; } | 2713 virtual bool CanDeoptimize() const { return false; } |
| 2722 | 2714 |
| 2723 virtual bool HasSideEffect() const { | 2715 virtual bool HasSideEffect() const { |
| 2724 UNREACHABLE(); | 2716 UNREACHABLE(); |
| 2725 return false; | 2717 return false; |
| 2726 } | 2718 } |
| 2727 | 2719 |
| 2720 void mark_last() { is_last_ = true; } |
| 2721 bool is_last() const { return is_last_; } |
| 2722 |
| 2728 private: | 2723 private: |
| 2729 const LocalVariable& local_; | 2724 const LocalVariable& local_; |
| 2725 bool is_last_; |
| 2730 | 2726 |
| 2731 DISALLOW_COPY_AND_ASSIGN(LoadLocalInstr); | 2727 DISALLOW_COPY_AND_ASSIGN(LoadLocalInstr); |
| 2732 }; | 2728 }; |
| 2733 | 2729 |
| 2734 | 2730 |
| 2735 class StoreLocalInstr : public TemplateDefinition<1> { | 2731 class StoreLocalInstr : public TemplateDefinition<1> { |
| 2736 public: | 2732 public: |
| 2737 StoreLocalInstr(const LocalVariable& local, Value* value) : local_(local) { | 2733 StoreLocalInstr(const LocalVariable& local, Value* value) |
| 2734 : local_(local), is_dead_(false), is_last_(false) { |
| 2738 SetInputAt(0, value); | 2735 SetInputAt(0, value); |
| 2739 } | 2736 } |
| 2740 | 2737 |
| 2741 DECLARE_INSTRUCTION(StoreLocal) | 2738 DECLARE_INSTRUCTION(StoreLocal) |
| 2742 virtual CompileType* ComputeInitialType() const; | 2739 virtual CompileType* ComputeInitialType() const; |
| 2743 | 2740 |
| 2744 const LocalVariable& local() const { return local_; } | 2741 const LocalVariable& local() const { return local_; } |
| 2745 Value* value() const { return inputs_[0]; } | 2742 Value* value() const { return inputs_[0]; } |
| 2746 | 2743 |
| 2747 virtual void RecordAssignedVars(BitVector* assigned_vars, | |
| 2748 intptr_t fixed_parameter_count); | |
| 2749 | |
| 2750 virtual void PrintOperandsTo(BufferFormatter* f) const; | 2744 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 2751 | 2745 |
| 2752 virtual bool CanDeoptimize() const { return false; } | 2746 virtual bool CanDeoptimize() const { return false; } |
| 2753 | 2747 |
| 2754 virtual bool HasSideEffect() const { | 2748 virtual bool HasSideEffect() const { |
| 2755 UNREACHABLE(); | 2749 UNREACHABLE(); |
| 2756 return false; | 2750 return false; |
| 2757 } | 2751 } |
| 2758 | 2752 |
| 2753 void mark_dead() { is_dead_ = true; } |
| 2754 bool is_dead() const { return is_dead_; } |
| 2755 |
| 2756 void mark_last() { is_last_ = true; } |
| 2757 bool is_last() const { return is_last_; } |
| 2758 |
| 2759 private: | 2759 private: |
| 2760 const LocalVariable& local_; | 2760 const LocalVariable& local_; |
| 2761 bool is_dead_; |
| 2762 bool is_last_; |
| 2761 | 2763 |
| 2762 DISALLOW_COPY_AND_ASSIGN(StoreLocalInstr); | 2764 DISALLOW_COPY_AND_ASSIGN(StoreLocalInstr); |
| 2763 }; | 2765 }; |
| 2764 | 2766 |
| 2765 | 2767 |
| 2766 class NativeCallInstr : public TemplateDefinition<0> { | 2768 class NativeCallInstr : public TemplateDefinition<0> { |
| 2767 public: | 2769 public: |
| 2768 explicit NativeCallInstr(NativeBodyNode* node) | 2770 explicit NativeCallInstr(NativeBodyNode* node) |
| 2769 : ast_node_(*node) {} | 2771 : ast_node_(*node) {} |
| 2770 | 2772 |
| (...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4668 ForwardInstructionIterator* current_iterator_; | 4670 ForwardInstructionIterator* current_iterator_; |
| 4669 | 4671 |
| 4670 private: | 4672 private: |
| 4671 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 4673 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 4672 }; | 4674 }; |
| 4673 | 4675 |
| 4674 | 4676 |
| 4675 } // namespace dart | 4677 } // namespace dart |
| 4676 | 4678 |
| 4677 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 4679 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |