OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_IC_STATE_H_ | 5 #ifndef V8_IC_STATE_H_ |
6 #define V8_IC_STATE_H_ | 6 #define V8_IC_STATE_H_ |
7 | 7 |
8 #include "src/macro-assembler.h" | 8 #include "src/macro-assembler.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 class CallTypeBits : public BitField<CallType, Code::kArgumentsBits, 1> {}; | 47 class CallTypeBits : public BitField<CallType, Code::kArgumentsBits, 1> {}; |
48 | 48 |
49 const int argc_; | 49 const int argc_; |
50 const CallType call_type_; | 50 const CallType call_type_; |
51 }; | 51 }; |
52 | 52 |
53 | 53 |
54 std::ostream& operator<<(std::ostream& os, const CallICState& s); | 54 std::ostream& operator<<(std::ostream& os, const CallICState& s); |
55 | 55 |
56 | 56 |
57 // Mode to overwrite BinaryExpression values. | |
58 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; | |
59 | |
60 class BinaryOpICState FINAL BASE_EMBEDDED { | 57 class BinaryOpICState FINAL BASE_EMBEDDED { |
61 public: | 58 public: |
62 BinaryOpICState(Isolate* isolate, ExtraICState extra_ic_state); | 59 BinaryOpICState(Isolate* isolate, ExtraICState extra_ic_state); |
63 | 60 |
64 BinaryOpICState(Isolate* isolate, Token::Value op, OverwriteMode mode) | 61 BinaryOpICState(Isolate* isolate, Token::Value op) |
65 : op_(op), | 62 : op_(op), |
66 mode_(mode), | |
67 left_kind_(NONE), | 63 left_kind_(NONE), |
68 right_kind_(NONE), | 64 right_kind_(NONE), |
69 result_kind_(NONE), | 65 result_kind_(NONE), |
70 isolate_(isolate) { | 66 isolate_(isolate) { |
71 DCHECK_LE(FIRST_TOKEN, op); | 67 DCHECK_LE(FIRST_TOKEN, op); |
72 DCHECK_LE(op, LAST_TOKEN); | 68 DCHECK_LE(op, LAST_TOKEN); |
73 } | 69 } |
74 | 70 |
75 InlineCacheState GetICState() const { | 71 InlineCacheState GetICState() const { |
76 if (Max(left_kind_, right_kind_) == NONE) { | 72 if (Max(left_kind_, right_kind_) == NONE) { |
77 return ::v8::internal::UNINITIALIZED; | 73 return ::v8::internal::UNINITIALIZED; |
78 } | 74 } |
79 if (Max(left_kind_, right_kind_) == GENERIC) { | 75 if (Max(left_kind_, right_kind_) == GENERIC) { |
80 return ::v8::internal::MEGAMORPHIC; | 76 return ::v8::internal::MEGAMORPHIC; |
81 } | 77 } |
82 if (Min(left_kind_, right_kind_) == GENERIC) { | 78 if (Min(left_kind_, right_kind_) == GENERIC) { |
83 return ::v8::internal::GENERIC; | 79 return ::v8::internal::GENERIC; |
84 } | 80 } |
85 return ::v8::internal::MONOMORPHIC; | 81 return ::v8::internal::MONOMORPHIC; |
86 } | 82 } |
87 | 83 |
88 ExtraICState GetExtraICState() const; | 84 ExtraICState GetExtraICState() const; |
89 | 85 |
90 static void GenerateAheadOfTime(Isolate*, | 86 static void GenerateAheadOfTime(Isolate*, |
91 void (*Generate)(Isolate*, | 87 void (*Generate)(Isolate*, |
92 const BinaryOpICState&)); | 88 const BinaryOpICState&)); |
93 | 89 |
94 bool CanReuseDoubleBox() const { | |
95 return (result_kind_ > SMI && result_kind_ <= NUMBER) && | |
96 ((mode_ == OVERWRITE_LEFT && left_kind_ > SMI && | |
97 left_kind_ <= NUMBER) || | |
98 (mode_ == OVERWRITE_RIGHT && right_kind_ > SMI && | |
99 right_kind_ <= NUMBER)); | |
100 } | |
101 | |
102 // Returns true if the IC _could_ create allocation mementos. | 90 // Returns true if the IC _could_ create allocation mementos. |
103 bool CouldCreateAllocationMementos() const { | 91 bool CouldCreateAllocationMementos() const { |
104 if (left_kind_ == STRING || right_kind_ == STRING) { | 92 if (left_kind_ == STRING || right_kind_ == STRING) { |
105 DCHECK_EQ(Token::ADD, op_); | 93 DCHECK_EQ(Token::ADD, op_); |
106 return true; | 94 return true; |
107 } | 95 } |
108 return false; | 96 return false; |
109 } | 97 } |
110 | 98 |
111 // Returns true if the IC _should_ create allocation mementos. | 99 // Returns true if the IC _should_ create allocation mementos. |
112 bool ShouldCreateAllocationMementos() const { | 100 bool ShouldCreateAllocationMementos() const { |
113 return FLAG_allocation_site_pretenuring && CouldCreateAllocationMementos(); | 101 return FLAG_allocation_site_pretenuring && CouldCreateAllocationMementos(); |
114 } | 102 } |
115 | 103 |
116 bool HasSideEffects() const { | 104 bool HasSideEffects() const { |
117 return Max(left_kind_, right_kind_) == GENERIC; | 105 return Max(left_kind_, right_kind_) == GENERIC; |
118 } | 106 } |
119 | 107 |
120 // Returns true if the IC should enable the inline smi code (i.e. if either | 108 // Returns true if the IC should enable the inline smi code (i.e. if either |
121 // parameter may be a smi). | 109 // parameter may be a smi). |
122 bool UseInlinedSmiCode() const { | 110 bool UseInlinedSmiCode() const { |
123 return KindMaybeSmi(left_kind_) || KindMaybeSmi(right_kind_); | 111 return KindMaybeSmi(left_kind_) || KindMaybeSmi(right_kind_); |
124 } | 112 } |
125 | 113 |
126 static const int FIRST_TOKEN = Token::BIT_OR; | 114 static const int FIRST_TOKEN = Token::BIT_OR; |
127 static const int LAST_TOKEN = Token::MOD; | 115 static const int LAST_TOKEN = Token::MOD; |
128 | 116 |
129 Token::Value op() const { return op_; } | 117 Token::Value op() const { return op_; } |
130 OverwriteMode mode() const { return mode_; } | |
131 Maybe<int> fixed_right_arg() const { return fixed_right_arg_; } | 118 Maybe<int> fixed_right_arg() const { return fixed_right_arg_; } |
132 | 119 |
133 Type* GetLeftType(Zone* zone) const { return KindToType(left_kind_, zone); } | 120 Type* GetLeftType(Zone* zone) const { return KindToType(left_kind_, zone); } |
134 Type* GetRightType(Zone* zone) const { return KindToType(right_kind_, zone); } | 121 Type* GetRightType(Zone* zone) const { return KindToType(right_kind_, zone); } |
135 Type* GetResultType(Zone* zone) const; | 122 Type* GetResultType(Zone* zone) const; |
136 | 123 |
137 void Update(Handle<Object> left, Handle<Object> right, Handle<Object> result); | 124 void Update(Handle<Object> left, Handle<Object> right, Handle<Object> result); |
138 | 125 |
139 Isolate* isolate() const { return isolate_; } | 126 Isolate* isolate() const { return isolate_; } |
140 | 127 |
141 private: | 128 private: |
142 friend std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s); | 129 friend std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s); |
143 | 130 |
144 enum Kind { NONE, SMI, INT32, NUMBER, STRING, GENERIC }; | 131 enum Kind { NONE, SMI, INT32, NUMBER, STRING, GENERIC }; |
145 | 132 |
146 Kind UpdateKind(Handle<Object> object, Kind kind) const; | 133 Kind UpdateKind(Handle<Object> object, Kind kind) const; |
147 | 134 |
148 static const char* KindToString(Kind kind); | 135 static const char* KindToString(Kind kind); |
149 static Type* KindToType(Kind kind, Zone* zone); | 136 static Type* KindToType(Kind kind, Zone* zone); |
150 static bool KindMaybeSmi(Kind kind) { | 137 static bool KindMaybeSmi(Kind kind) { |
151 return (kind >= SMI && kind <= NUMBER) || kind == GENERIC; | 138 return (kind >= SMI && kind <= NUMBER) || kind == GENERIC; |
152 } | 139 } |
153 | 140 |
154 // We truncate the last bit of the token. | 141 // We truncate the last bit of the token. |
155 STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 4)); | 142 STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 4)); |
156 class OpField : public BitField<int, 0, 4> {}; | 143 class OpField : public BitField<int, 0, 4> {}; |
157 class OverwriteModeField : public BitField<OverwriteMode, 4, 2> {}; | 144 class ResultKindField : public BitField<Kind, 4, 3> {}; |
158 class ResultKindField : public BitField<Kind, 6, 3> {}; | 145 class LeftKindField : public BitField<Kind, 7, 3> {}; |
159 class LeftKindField : public BitField<Kind, 9, 3> {}; | |
160 // When fixed right arg is set, we don't need to store the right kind. | 146 // When fixed right arg is set, we don't need to store the right kind. |
161 // Thus the two fields can overlap. | 147 // Thus the two fields can overlap. |
162 class HasFixedRightArgField : public BitField<bool, 12, 1> {}; | 148 class HasFixedRightArgField : public BitField<bool, 10, 1> {}; |
163 class FixedRightArgValueField : public BitField<int, 13, 4> {}; | 149 class FixedRightArgValueField : public BitField<int, 11, 4> {}; |
164 class RightKindField : public BitField<Kind, 13, 3> {}; | 150 class RightKindField : public BitField<Kind, 11, 3> {}; |
165 | 151 |
166 Token::Value op_; | 152 Token::Value op_; |
167 OverwriteMode mode_; | |
168 Kind left_kind_; | 153 Kind left_kind_; |
169 Kind right_kind_; | 154 Kind right_kind_; |
170 Kind result_kind_; | 155 Kind result_kind_; |
171 Maybe<int> fixed_right_arg_; | 156 Maybe<int> fixed_right_arg_; |
172 Isolate* isolate_; | 157 Isolate* isolate_; |
173 }; | 158 }; |
174 | 159 |
175 | 160 |
176 std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s); | 161 std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s); |
177 | 162 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 private: | 214 private: |
230 class ContextualModeBits : public BitField<ContextualMode, 0, 1> {}; | 215 class ContextualModeBits : public BitField<ContextualMode, 0, 1> {}; |
231 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0); | 216 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0); |
232 | 217 |
233 const ExtraICState state_; | 218 const ExtraICState state_; |
234 }; | 219 }; |
235 } | 220 } |
236 } | 221 } |
237 | 222 |
238 #endif // V8_IC_STATE_H_ | 223 #endif // V8_IC_STATE_H_ |
OLD | NEW |