OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/ic/ic-state.h" | 5 #include "src/ic/ic-state.h" |
6 | 6 |
7 #include "src/ic/ic.h" | 7 #include "src/ic/ic.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 | 31 |
32 BinaryOpICState::BinaryOpICState(Isolate* isolate, ExtraICState extra_ic_state) | 32 BinaryOpICState::BinaryOpICState(Isolate* isolate, ExtraICState extra_ic_state) |
33 : fixed_right_arg_( | 33 : fixed_right_arg_( |
34 HasFixedRightArgField::decode(extra_ic_state) | 34 HasFixedRightArgField::decode(extra_ic_state) |
35 ? Just(1 << FixedRightArgValueField::decode(extra_ic_state)) | 35 ? Just(1 << FixedRightArgValueField::decode(extra_ic_state)) |
36 : Nothing<int>()), | 36 : Nothing<int>()), |
37 isolate_(isolate) { | 37 isolate_(isolate) { |
38 op_ = | 38 op_ = |
39 static_cast<Token::Value>(FIRST_TOKEN + OpField::decode(extra_ic_state)); | 39 static_cast<Token::Value>(FIRST_TOKEN + OpField::decode(extra_ic_state)); |
40 strong_ = StrengthField::decode(extra_ic_state); | |
41 left_kind_ = LeftKindField::decode(extra_ic_state); | 40 left_kind_ = LeftKindField::decode(extra_ic_state); |
42 right_kind_ = fixed_right_arg_.IsJust() | 41 right_kind_ = fixed_right_arg_.IsJust() |
43 ? (Smi::IsValid(fixed_right_arg_.FromJust()) ? SMI : INT32) | 42 ? (Smi::IsValid(fixed_right_arg_.FromJust()) ? SMI : INT32) |
44 : RightKindField::decode(extra_ic_state); | 43 : RightKindField::decode(extra_ic_state); |
45 result_kind_ = ResultKindField::decode(extra_ic_state); | 44 result_kind_ = ResultKindField::decode(extra_ic_state); |
46 DCHECK_LE(FIRST_TOKEN, op_); | 45 DCHECK_LE(FIRST_TOKEN, op_); |
47 DCHECK_LE(op_, LAST_TOKEN); | 46 DCHECK_LE(op_, LAST_TOKEN); |
48 } | 47 } |
49 | 48 |
50 | 49 |
51 ExtraICState BinaryOpICState::GetExtraICState() const { | 50 ExtraICState BinaryOpICState::GetExtraICState() const { |
52 ExtraICState extra_ic_state = | 51 ExtraICState extra_ic_state = |
53 OpField::encode(op_ - FIRST_TOKEN) | LeftKindField::encode(left_kind_) | | 52 OpField::encode(op_ - FIRST_TOKEN) | LeftKindField::encode(left_kind_) | |
54 ResultKindField::encode(result_kind_) | StrengthField::encode(strong_) | | 53 ResultKindField::encode(result_kind_) | |
55 HasFixedRightArgField::encode(fixed_right_arg_.IsJust()); | 54 HasFixedRightArgField::encode(fixed_right_arg_.IsJust()); |
56 if (fixed_right_arg_.IsJust()) { | 55 if (fixed_right_arg_.IsJust()) { |
57 extra_ic_state = FixedRightArgValueField::update( | 56 extra_ic_state = FixedRightArgValueField::update( |
58 extra_ic_state, WhichPowerOf2(fixed_right_arg_.FromJust())); | 57 extra_ic_state, WhichPowerOf2(fixed_right_arg_.FromJust())); |
59 } else { | 58 } else { |
60 extra_ic_state = RightKindField::update(extra_ic_state, right_kind_); | 59 extra_ic_state = RightKindField::update(extra_ic_state, right_kind_); |
61 } | 60 } |
62 return extra_ic_state; | 61 return extra_ic_state; |
63 } | 62 } |
64 | 63 |
65 | 64 |
66 // static | 65 // static |
67 void BinaryOpICState::GenerateAheadOfTime( | 66 void BinaryOpICState::GenerateAheadOfTime( |
68 Isolate* isolate, void (*Generate)(Isolate*, const BinaryOpICState&)) { | 67 Isolate* isolate, void (*Generate)(Isolate*, const BinaryOpICState&)) { |
69 // TODO(olivf) We should investigate why adding stubs to the snapshot is so | 68 // TODO(olivf) We should investigate why adding stubs to the snapshot is so |
70 // expensive at runtime. When solved we should be able to add most binops to | 69 // expensive at runtime. When solved we should be able to add most binops to |
71 // the snapshot instead of hand-picking them. | 70 // the snapshot instead of hand-picking them. |
72 // Generated list of commonly used stubs | 71 // Generated list of commonly used stubs |
73 #define GENERATE(op, left_kind, right_kind, result_kind) \ | 72 #define GENERATE(op, left_kind, right_kind, result_kind) \ |
74 do { \ | 73 do { \ |
75 BinaryOpICState state(isolate, op, Strength::WEAK); \ | 74 BinaryOpICState state(isolate, op); \ |
76 state.left_kind_ = left_kind; \ | 75 state.left_kind_ = left_kind; \ |
77 state.fixed_right_arg_ = Nothing<int>(); \ | 76 state.fixed_right_arg_ = Nothing<int>(); \ |
78 state.right_kind_ = right_kind; \ | 77 state.right_kind_ = right_kind; \ |
79 state.result_kind_ = result_kind; \ | 78 state.result_kind_ = result_kind; \ |
80 Generate(isolate, state); \ | 79 Generate(isolate, state); \ |
81 } while (false) | 80 } while (false) |
82 GENERATE(Token::ADD, INT32, INT32, INT32); | 81 GENERATE(Token::ADD, INT32, INT32, INT32); |
83 GENERATE(Token::ADD, INT32, INT32, NUMBER); | 82 GENERATE(Token::ADD, INT32, INT32, NUMBER); |
84 GENERATE(Token::ADD, INT32, NUMBER, NUMBER); | 83 GENERATE(Token::ADD, INT32, NUMBER, NUMBER); |
85 GENERATE(Token::ADD, INT32, SMI, INT32); | 84 GENERATE(Token::ADD, INT32, SMI, INT32); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 GENERATE(Token::SUB, INT32, SMI, INT32); | 166 GENERATE(Token::SUB, INT32, SMI, INT32); |
168 GENERATE(Token::SUB, NUMBER, INT32, NUMBER); | 167 GENERATE(Token::SUB, NUMBER, INT32, NUMBER); |
169 GENERATE(Token::SUB, NUMBER, NUMBER, NUMBER); | 168 GENERATE(Token::SUB, NUMBER, NUMBER, NUMBER); |
170 GENERATE(Token::SUB, NUMBER, SMI, NUMBER); | 169 GENERATE(Token::SUB, NUMBER, SMI, NUMBER); |
171 GENERATE(Token::SUB, SMI, INT32, INT32); | 170 GENERATE(Token::SUB, SMI, INT32, INT32); |
172 GENERATE(Token::SUB, SMI, NUMBER, NUMBER); | 171 GENERATE(Token::SUB, SMI, NUMBER, NUMBER); |
173 GENERATE(Token::SUB, SMI, SMI, SMI); | 172 GENERATE(Token::SUB, SMI, SMI, SMI); |
174 #undef GENERATE | 173 #undef GENERATE |
175 #define GENERATE(op, left_kind, fixed_right_arg_value, result_kind) \ | 174 #define GENERATE(op, left_kind, fixed_right_arg_value, result_kind) \ |
176 do { \ | 175 do { \ |
177 BinaryOpICState state(isolate, op, Strength::WEAK); \ | 176 BinaryOpICState state(isolate, op); \ |
178 state.left_kind_ = left_kind; \ | 177 state.left_kind_ = left_kind; \ |
179 state.fixed_right_arg_ = Just(fixed_right_arg_value); \ | 178 state.fixed_right_arg_ = Just(fixed_right_arg_value); \ |
180 state.right_kind_ = SMI; \ | 179 state.right_kind_ = SMI; \ |
181 state.result_kind_ = result_kind; \ | 180 state.result_kind_ = result_kind; \ |
182 Generate(isolate, state); \ | 181 Generate(isolate, state); \ |
183 } while (false) | 182 } while (false) |
184 GENERATE(Token::MOD, SMI, 2, SMI); | 183 GENERATE(Token::MOD, SMI, 2, SMI); |
185 GENERATE(Token::MOD, SMI, 4, SMI); | 184 GENERATE(Token::MOD, SMI, 4, SMI); |
186 GENERATE(Token::MOD, SMI, 8, SMI); | 185 GENERATE(Token::MOD, SMI, 8, SMI); |
187 GENERATE(Token::MOD, SMI, 16, SMI); | 186 GENERATE(Token::MOD, SMI, 16, SMI); |
(...skipping 13 matching lines...) Expand all Loading... |
201 return Type::Unsigned32(); | 200 return Type::Unsigned32(); |
202 } | 201 } |
203 DCHECK_NE(GENERIC, result_kind); | 202 DCHECK_NE(GENERIC, result_kind); |
204 return KindToType(result_kind); | 203 return KindToType(result_kind); |
205 } | 204 } |
206 | 205 |
207 | 206 |
208 std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s) { | 207 std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s) { |
209 os << "(" << Token::Name(s.op_); | 208 os << "(" << Token::Name(s.op_); |
210 if (s.CouldCreateAllocationMementos()) os << "_CreateAllocationMementos"; | 209 if (s.CouldCreateAllocationMementos()) os << "_CreateAllocationMementos"; |
211 if (is_strong(s.strength())) os << "_Strong"; | |
212 os << ":" << BinaryOpICState::KindToString(s.left_kind_) << "*"; | 210 os << ":" << BinaryOpICState::KindToString(s.left_kind_) << "*"; |
213 if (s.fixed_right_arg_.IsJust()) { | 211 if (s.fixed_right_arg_.IsJust()) { |
214 os << s.fixed_right_arg_.FromJust(); | 212 os << s.fixed_right_arg_.FromJust(); |
215 } else { | 213 } else { |
216 os << BinaryOpICState::KindToString(s.right_kind_); | 214 os << BinaryOpICState::KindToString(s.right_kind_); |
217 } | 215 } |
218 return os << "->" << BinaryOpICState::KindToString(s.result_kind_) << ")"; | 216 return os << "->" << BinaryOpICState::KindToString(s.result_kind_) << ")"; |
219 } | 217 } |
220 | 218 |
221 | 219 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 case RECEIVER: | 499 case RECEIVER: |
502 case GENERIC: | 500 case GENERIC: |
503 return GENERIC; | 501 return GENERIC; |
504 } | 502 } |
505 UNREACHABLE(); | 503 UNREACHABLE(); |
506 return GENERIC; // Make the compiler happy. | 504 return GENERIC; // Make the compiler happy. |
507 } | 505 } |
508 | 506 |
509 } // namespace internal | 507 } // namespace internal |
510 } // namespace v8 | 508 } // namespace v8 |
OLD | NEW |