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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 M(BinarySmiOp, BinarySmiOpComp) \ | 97 M(BinarySmiOp, BinarySmiOpComp) \ |
98 M(BinaryMintOp, BinaryMintOpComp) \ | 98 M(BinaryMintOp, BinaryMintOpComp) \ |
99 M(BinaryDoubleOp, BinaryDoubleOpComp) \ | 99 M(BinaryDoubleOp, BinaryDoubleOpComp) \ |
100 M(UnarySmiOp, UnarySmiOpComp) \ | 100 M(UnarySmiOp, UnarySmiOpComp) \ |
101 M(NumberNegate, NumberNegateComp) \ | 101 M(NumberNegate, NumberNegateComp) \ |
102 M(CheckStackOverflow, CheckStackOverflowComp) \ | 102 M(CheckStackOverflow, CheckStackOverflowComp) \ |
103 M(DoubleToDouble, DoubleToDoubleComp) \ | 103 M(DoubleToDouble, DoubleToDoubleComp) \ |
104 M(SmiToDouble, SmiToDoubleComp) \ | 104 M(SmiToDouble, SmiToDoubleComp) \ |
105 M(CheckClass, CheckClassComp) \ | 105 M(CheckClass, CheckClassComp) \ |
106 M(CheckSmi, CheckSmiComp) \ | 106 M(CheckSmi, CheckSmiComp) \ |
107 M(Materialize, MaterializeComp) | 107 M(Materialize, MaterializeComp) \ |
| 108 M(CheckEitherNonSmi, CheckEitherNonSmiComp) \ |
| 109 M(UnboxedDoubleBinaryOp, UnboxedDoubleBinaryOpComp) \ |
| 110 M(UnboxDouble, UnboxDoubleComp) \ |
| 111 M(BoxDouble, BoxDoubleComp) |
108 | 112 |
109 | 113 |
110 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; | 114 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; |
111 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) | 115 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) |
112 FOR_EACH_VALUE(FORWARD_DECLARATION) | 116 FOR_EACH_VALUE(FORWARD_DECLARATION) |
113 #undef FORWARD_DECLARATION | 117 #undef FORWARD_DECLARATION |
114 | 118 |
115 // Forward declarations. | 119 // Forward declarations. |
116 class BindInstr; | 120 class BindInstr; |
117 class BranchInstr; | 121 class BranchInstr; |
118 class BufferFormatter; | 122 class BufferFormatter; |
119 class ComparisonComp; | 123 class ComparisonComp; |
120 class Definition; | 124 class Definition; |
121 class Instruction; | 125 class Instruction; |
122 class PushArgumentInstr; | 126 class PushArgumentInstr; |
123 class Value; | 127 class Value; |
124 | 128 |
| 129 |
| 130 enum Representation { |
| 131 kTagged, kUnboxedDouble |
| 132 }; |
| 133 |
| 134 |
125 class Computation : public ZoneAllocated { | 135 class Computation : public ZoneAllocated { |
126 public: | 136 public: |
127 Computation() : deopt_id_(Isolate::kNoDeoptId), ic_data_(NULL), locs_(NULL) { | 137 Computation() : deopt_id_(Isolate::kNoDeoptId), ic_data_(NULL), locs_(NULL) { |
128 Isolate* isolate = Isolate::Current(); | 138 Isolate* isolate = Isolate::Current(); |
129 deopt_id_ = isolate->GetNextDeoptId(); | 139 deopt_id_ = isolate->GetNextDeoptId(); |
130 ic_data_ = isolate->GetICDataForDeoptId(deopt_id_); | 140 ic_data_ = isolate->GetICDataForDeoptId(deopt_id_); |
131 } | 141 } |
132 | 142 |
133 // Unique id used for deoptimization. | 143 // Unique id used for deoptimization. |
134 intptr_t deopt_id() const { return deopt_id_; } | 144 intptr_t deopt_id() const { return deopt_id_; } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 enum ComputationKind { | 228 enum ComputationKind { |
219 #define DECLARE_COMPUTATION_KIND(ShortName, ClassName) k##ShortName, | 229 #define DECLARE_COMPUTATION_KIND(ShortName, ClassName) k##ShortName, |
220 | 230 |
221 FOR_EACH_COMPUTATION(DECLARE_COMPUTATION_KIND) | 231 FOR_EACH_COMPUTATION(DECLARE_COMPUTATION_KIND) |
222 | 232 |
223 #undef DECLARE_COMPUTATION_KIND | 233 #undef DECLARE_COMPUTATION_KIND |
224 }; | 234 }; |
225 | 235 |
226 virtual ComputationKind computation_kind() const = 0; | 236 virtual ComputationKind computation_kind() const = 0; |
227 | 237 |
| 238 virtual Representation representation() const { |
| 239 return kTagged; |
| 240 } |
| 241 |
228 // Declare predicate for each computation. | 242 // Declare predicate for each computation. |
229 #define DECLARE_PREDICATE(ShortName, ClassName) \ | 243 #define DECLARE_PREDICATE(ShortName, ClassName) \ |
230 inline bool Is##ShortName() const; \ | 244 inline bool Is##ShortName() const; \ |
231 inline const ClassName* As##ShortName() const; \ | 245 inline const ClassName* As##ShortName() const; \ |
232 inline ClassName* As##ShortName(); | 246 inline ClassName* As##ShortName(); |
233 FOR_EACH_COMPUTATION(DECLARE_PREDICATE) | 247 FOR_EACH_COMPUTATION(DECLARE_PREDICATE) |
234 #undef DECLARE_PREDICATE | 248 #undef DECLARE_PREDICATE |
235 | 249 |
236 private: | 250 private: |
237 intptr_t deopt_id_; | 251 intptr_t deopt_id_; |
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 virtual bool CanDeoptimize() const { return false; } | 1669 virtual bool CanDeoptimize() const { return false; } |
1656 | 1670 |
1657 private: | 1671 private: |
1658 const LocalVariable& exception_var_; | 1672 const LocalVariable& exception_var_; |
1659 const LocalVariable& stacktrace_var_; | 1673 const LocalVariable& stacktrace_var_; |
1660 | 1674 |
1661 DISALLOW_COPY_AND_ASSIGN(CatchEntryComp); | 1675 DISALLOW_COPY_AND_ASSIGN(CatchEntryComp); |
1662 }; | 1676 }; |
1663 | 1677 |
1664 | 1678 |
| 1679 class CheckEitherNonSmiComp : public TemplateComputation<2> { |
| 1680 public: |
| 1681 CheckEitherNonSmiComp(Value* left, |
| 1682 Value* right, |
| 1683 InstanceCallComp* instance_call) |
| 1684 : instance_call_(instance_call) { |
| 1685 ASSERT(left != NULL); |
| 1686 ASSERT(right != NULL); |
| 1687 inputs_[0] = left; |
| 1688 inputs_[1] = right; |
| 1689 } |
| 1690 |
| 1691 DECLARE_COMPUTATION(CheckEitherNonSmi) |
| 1692 |
| 1693 virtual bool CanDeoptimize() const { return true; } |
| 1694 |
| 1695 virtual bool HasSideEffect() const { return false; } |
| 1696 |
| 1697 Value* left() const { return inputs_[0]; } |
| 1698 |
| 1699 Value* right() const { return inputs_[1]; } |
| 1700 |
| 1701 virtual Definition* TryReplace(BindInstr* instr) const; |
| 1702 |
| 1703 private: |
| 1704 InstanceCallComp* instance_call_; |
| 1705 |
| 1706 DISALLOW_COPY_AND_ASSIGN(CheckEitherNonSmiComp); |
| 1707 }; |
| 1708 |
| 1709 |
| 1710 class BoxDoubleComp : public TemplateComputation<1> { |
| 1711 public: |
| 1712 BoxDoubleComp(Value* value, InstanceCallComp* instance_call) |
| 1713 : instance_call_(instance_call) { |
| 1714 ASSERT(value != NULL); |
| 1715 inputs_[0] = value; |
| 1716 } |
| 1717 |
| 1718 Value* value() const { return inputs_[0]; } |
| 1719 InstanceCallComp* instance_call() const { return instance_call_; } |
| 1720 |
| 1721 virtual bool CanDeoptimize() const { return false; } |
| 1722 |
| 1723 virtual intptr_t ResultCid() const; |
| 1724 |
| 1725 DECLARE_COMPUTATION(BoxDouble) |
| 1726 |
| 1727 private: |
| 1728 InstanceCallComp* instance_call_; |
| 1729 |
| 1730 DISALLOW_COPY_AND_ASSIGN(BoxDoubleComp); |
| 1731 }; |
| 1732 |
| 1733 |
| 1734 class UnboxDoubleComp : public TemplateComputation<1> { |
| 1735 public: |
| 1736 UnboxDoubleComp(Value* value, InstanceCallComp* instance_call) |
| 1737 : instance_call_(instance_call) { |
| 1738 ASSERT(value != NULL); |
| 1739 inputs_[0] = value; |
| 1740 } |
| 1741 |
| 1742 Value* value() const { return inputs_[0]; } |
| 1743 InstanceCallComp* instance_call() const { return instance_call_; } |
| 1744 |
| 1745 virtual bool CanDeoptimize() const { |
| 1746 return value()->ResultCid() != kDoubleCid; |
| 1747 } |
| 1748 |
| 1749 virtual Representation representation() const { |
| 1750 return kUnboxedDouble; |
| 1751 } |
| 1752 |
| 1753 DECLARE_COMPUTATION(UnboxDouble) |
| 1754 |
| 1755 private: |
| 1756 InstanceCallComp* instance_call_; |
| 1757 |
| 1758 DISALLOW_COPY_AND_ASSIGN(UnboxDoubleComp); |
| 1759 }; |
| 1760 |
| 1761 |
| 1762 class UnboxedDoubleBinaryOpComp : public TemplateComputation<2> { |
| 1763 public: |
| 1764 UnboxedDoubleBinaryOpComp(Token::Kind op_kind, |
| 1765 Value* left, |
| 1766 Value* right) |
| 1767 : op_kind_(op_kind) { |
| 1768 ASSERT(left != NULL); |
| 1769 ASSERT(right != NULL); |
| 1770 inputs_[0] = left; |
| 1771 inputs_[1] = right; |
| 1772 } |
| 1773 |
| 1774 Value* left() const { return inputs_[0]; } |
| 1775 Value* right() const { return inputs_[1]; } |
| 1776 |
| 1777 Token::Kind op_kind() const { return op_kind_; } |
| 1778 |
| 1779 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 1780 |
| 1781 virtual bool CanDeoptimize() const { return false; } |
| 1782 |
| 1783 virtual Representation representation() const { |
| 1784 return kUnboxedDouble; |
| 1785 } |
| 1786 |
| 1787 DECLARE_COMPUTATION(UnboxedDoubleBinaryOp) |
| 1788 |
| 1789 private: |
| 1790 const Token::Kind op_kind_; |
| 1791 |
| 1792 DISALLOW_COPY_AND_ASSIGN(UnboxedDoubleBinaryOpComp); |
| 1793 }; |
| 1794 |
| 1795 |
1665 class BinarySmiOpComp : public TemplateComputation<2> { | 1796 class BinarySmiOpComp : public TemplateComputation<2> { |
1666 public: | 1797 public: |
1667 BinarySmiOpComp(Token::Kind op_kind, | 1798 BinarySmiOpComp(Token::Kind op_kind, |
1668 InstanceCallComp* instance_call, | 1799 InstanceCallComp* instance_call, |
1669 Value* left, | 1800 Value* left, |
1670 Value* right) | 1801 Value* right) |
1671 : op_kind_(op_kind), | 1802 : op_kind_(op_kind), |
1672 instance_call_(instance_call) { | 1803 instance_call_(instance_call) { |
1673 ASSERT(left != NULL); | 1804 ASSERT(left != NULL); |
1674 ASSERT(right != NULL); | 1805 ASSERT(right != NULL); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 } | 2259 } |
2129 | 2260 |
2130 Environment* env() const { return env_; } | 2261 Environment* env() const { return env_; } |
2131 void set_env(Environment* env) { env_ = env; } | 2262 void set_env(Environment* env) { env_ = env; } |
2132 | 2263 |
2133 intptr_t lifetime_position() const { return lifetime_position_; } | 2264 intptr_t lifetime_position() const { return lifetime_position_; } |
2134 void set_lifetime_position(intptr_t pos) { | 2265 void set_lifetime_position(intptr_t pos) { |
2135 lifetime_position_ = pos; | 2266 lifetime_position_ = pos; |
2136 } | 2267 } |
2137 | 2268 |
| 2269 virtual Representation representation() const { |
| 2270 return kTagged; |
| 2271 } |
| 2272 |
2138 private: | 2273 private: |
2139 friend class BindInstr; // Needed for BindInstr::InsertBefore. | 2274 friend class BindInstr; // Needed for BindInstr::InsertBefore. |
2140 | 2275 |
2141 intptr_t lifetime_position_; // Position used by register allocator. | 2276 intptr_t lifetime_position_; // Position used by register allocator. |
2142 Instruction* previous_; | 2277 Instruction* previous_; |
2143 Instruction* next_; | 2278 Instruction* next_; |
2144 Environment* env_; | 2279 Environment* env_; |
2145 DISALLOW_COPY_AND_ASSIGN(Instruction); | 2280 DISALLOW_COPY_AND_ASSIGN(Instruction); |
2146 }; | 2281 }; |
2147 | 2282 |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2682 return computation()->Equals(other->computation()); | 2817 return computation()->Equals(other->computation()); |
2683 } | 2818 } |
2684 | 2819 |
2685 virtual LocationSummary* locs() { | 2820 virtual LocationSummary* locs() { |
2686 return computation()->locs(); | 2821 return computation()->locs(); |
2687 } | 2822 } |
2688 | 2823 |
2689 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 2824 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
2690 | 2825 |
2691 // Insert this instruction before 'next'. | 2826 // Insert this instruction before 'next'. |
2692 void InsertBefore(BindInstr* next); | 2827 void InsertBefore(Instruction* next); |
| 2828 |
| 2829 // Insert this instruction after 'prev'. |
| 2830 void InsertAfter(Instruction* prev); |
| 2831 |
| 2832 virtual Representation representation() const { |
| 2833 return computation()->representation(); |
| 2834 } |
2693 | 2835 |
2694 private: | 2836 private: |
2695 Computation* computation_; | 2837 Computation* computation_; |
2696 const bool is_used_; | 2838 const bool is_used_; |
2697 | 2839 |
2698 DISALLOW_COPY_AND_ASSIGN(BindInstr); | 2840 DISALLOW_COPY_AND_ASSIGN(BindInstr); |
2699 }; | 2841 }; |
2700 | 2842 |
2701 | 2843 |
2702 class PhiInstr : public Definition { | 2844 class PhiInstr : public Definition { |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3135 ForwardInstructionIterator* current_iterator_; | 3277 ForwardInstructionIterator* current_iterator_; |
3136 | 3278 |
3137 private: | 3279 private: |
3138 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 3280 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
3139 }; | 3281 }; |
3140 | 3282 |
3141 | 3283 |
3142 } // namespace dart | 3284 } // namespace dart |
3143 | 3285 |
3144 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 3286 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
OLD | NEW |