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 #include "src/type-info.h" | 5 #include "src/type-info.h" |
6 | 6 |
7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/ic/ic.h" | 9 #include "src/ic/ic.h" |
10 #include "src/ic/stub-cache.h" | 10 #include "src/ic/stub-cache.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 | 184 |
185 Handle<AllocationSite> TypeFeedbackOracle::GetCallNewAllocationSite( | 185 Handle<AllocationSite> TypeFeedbackOracle::GetCallNewAllocationSite( |
186 FeedbackVectorSlot slot) { | 186 FeedbackVectorSlot slot) { |
187 Handle<Object> info = GetInfo(slot); | 187 Handle<Object> info = GetInfo(slot); |
188 if (info->IsAllocationSite()) { | 188 if (info->IsAllocationSite()) { |
189 return Handle<AllocationSite>::cast(info); | 189 return Handle<AllocationSite>::cast(info); |
190 } | 190 } |
191 return Handle<AllocationSite>::null(); | 191 return Handle<AllocationSite>::null(); |
192 } | 192 } |
193 | 193 |
194 void TypeFeedbackOracle::CompareType(TypeFeedbackId id, AstType** left_type, | 194 namespace { |
195 AstType** right_type, | 195 |
196 AstType** combined_type) { | 196 AstType* CompareOpHintToType(CompareOperationHint hint) { |
mythria
2016/09/22 14:09:42
I actually wanted to move it to the CompareICNexus
| |
197 switch (hint) { | |
198 case CompareOperationHint::kNone: | |
199 return AstType::None(); | |
200 case CompareOperationHint::kSignedSmall: | |
201 return AstType::SignedSmall(); | |
202 case CompareOperationHint::kNumberOrOddball: | |
203 return AstType::Number(); | |
204 case CompareOperationHint::kAny: | |
205 default: | |
206 return AstType::Any(); | |
207 } | |
208 UNREACHABLE(); | |
209 return AstType::None(); | |
210 } | |
211 | |
212 AstType* BinaryOpHintToType(BinaryOperationHint hint) { | |
213 switch (hint) { | |
214 case BinaryOperationHint::kNone: | |
215 return AstType::None(); | |
216 case BinaryOperationHint::kSignedSmall: | |
217 return AstType::SignedSmall(); | |
218 case BinaryOperationHint::kNumberOrOddball: | |
219 return AstType::Number(); | |
220 case BinaryOperationHint::kAny: | |
221 default: | |
222 return AstType::Any(); | |
223 } | |
224 UNREACHABLE(); | |
225 return AstType::None(); | |
226 } | |
227 | |
228 } // end anonymous namespace | |
229 | |
230 void TypeFeedbackOracle::CompareType(TypeFeedbackId id, FeedbackVectorSlot slot, | |
231 AstType** left_type, AstType** right_type, | |
232 AstType** combined_type, | |
233 bool feedback_from_ignition) { | |
197 Handle<Object> info = GetInfo(id); | 234 Handle<Object> info = GetInfo(id); |
198 if (!info->IsCode()) { | 235 if (!info->IsCode()) { |
199 // For some comparisons we don't have ICs, e.g. LiteralCompareTypeof. | 236 // For some comparisons we don't have ICs, e.g. LiteralCompareTypeof. |
200 *left_type = *right_type = *combined_type = AstType::None(); | 237 *left_type = *right_type = *combined_type = AstType::None(); |
201 return; | 238 return; |
202 } | 239 } |
240 | |
241 // Feedback from Ignition. The feedback slot will be allocated and initialized | |
242 // to AstType::None() even when ignition is not enabled. So it is safe to get | |
243 // feedback from the type feedback vector. | |
244 if (feedback_from_ignition) { | |
245 DCHECK(!slot.IsInvalid()); | |
246 CompareICNexus nexus(feedback_vector_, slot); | |
247 *left_type = *right_type = *combined_type = | |
248 CompareOpHintToType(nexus.GetCompareOperationFeedback()); | |
249 return; | |
250 } | |
251 | |
252 // Feedback from IC. | |
203 Handle<Code> code = Handle<Code>::cast(info); | 253 Handle<Code> code = Handle<Code>::cast(info); |
204 | |
205 Handle<Map> map; | 254 Handle<Map> map; |
206 Map* raw_map = code->FindFirstMap(); | 255 Map* raw_map = code->FindFirstMap(); |
207 if (raw_map != NULL) Map::TryUpdate(handle(raw_map)).ToHandle(&map); | 256 if (raw_map != NULL) Map::TryUpdate(handle(raw_map)).ToHandle(&map); |
208 | 257 |
209 if (code->is_compare_ic_stub()) { | 258 if (code->is_compare_ic_stub()) { |
210 CompareICStub stub(code->stub_key(), isolate()); | 259 CompareICStub stub(code->stub_key(), isolate()); |
211 *left_type = CompareICState::StateToType(zone(), stub.left()); | 260 *left_type = CompareICState::StateToType(zone(), stub.left()); |
212 *right_type = CompareICState::StateToType(zone(), stub.right()); | 261 *right_type = CompareICState::StateToType(zone(), stub.right()); |
213 *combined_type = CompareICState::StateToType(zone(), stub.state(), map); | 262 *combined_type = CompareICState::StateToType(zone(), stub.state(), map); |
263 } else { | |
264 *left_type = *right_type = *combined_type = AstType::None(); | |
214 } | 265 } |
215 } | 266 } |
216 | 267 |
217 void TypeFeedbackOracle::BinaryType(TypeFeedbackId id, AstType** left, | 268 void TypeFeedbackOracle::BinaryType(TypeFeedbackId id, FeedbackVectorSlot slot, |
218 AstType** right, AstType** result, | 269 AstType** left, AstType** right, |
270 AstType** result, | |
219 Maybe<int>* fixed_right_arg, | 271 Maybe<int>* fixed_right_arg, |
220 Handle<AllocationSite>* allocation_site, | 272 Handle<AllocationSite>* allocation_site, |
221 Token::Value op) { | 273 Token::Value op, |
274 bool feedback_from_ignition) { | |
222 Handle<Object> object = GetInfo(id); | 275 Handle<Object> object = GetInfo(id); |
223 if (!object->IsCode()) { | 276 if (!object->IsCode()) { |
224 // For some binary ops we don't have ICs, e.g. Token::COMMA, but for the | 277 // For some binary ops we don't have ICs or feedback slots, |
225 // operations covered by the BinaryOpIC we should always have them. | 278 // e.g. Token::COMMA, but for the operations covered by the BinaryOpIC we |
279 // should always have them. | |
280 DCHECK(slot.IsInvalid()); | |
226 DCHECK(op < BinaryOpICState::FIRST_TOKEN || | 281 DCHECK(op < BinaryOpICState::FIRST_TOKEN || |
227 op > BinaryOpICState::LAST_TOKEN); | 282 op > BinaryOpICState::LAST_TOKEN); |
228 *left = *right = *result = AstType::None(); | 283 *left = *right = *result = AstType::None(); |
229 *fixed_right_arg = Nothing<int>(); | 284 *fixed_right_arg = Nothing<int>(); |
230 *allocation_site = Handle<AllocationSite>::null(); | 285 *allocation_site = Handle<AllocationSite>::null(); |
231 return; | 286 return; |
232 } | 287 } |
288 | |
289 // Feedback from Ignition. | |
290 if (feedback_from_ignition) { | |
291 DCHECK(!slot.IsInvalid()); | |
292 BinaryOpICNexus nexus(feedback_vector_, slot); | |
293 *left = *right = *result = | |
294 BinaryOpHintToType(nexus.GetBinaryOperationFeedback()); | |
295 *fixed_right_arg = Nothing<int>(); | |
296 *allocation_site = Handle<AllocationSite>::null(); | |
297 return; | |
298 } | |
299 | |
300 // Feedback from IC. | |
233 Handle<Code> code = Handle<Code>::cast(object); | 301 Handle<Code> code = Handle<Code>::cast(object); |
234 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); | 302 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); |
235 BinaryOpICState state(isolate(), code->extra_ic_state()); | 303 BinaryOpICState state(isolate(), code->extra_ic_state()); |
236 DCHECK_EQ(op, state.op()); | 304 DCHECK_EQ(op, state.op()); |
237 | 305 |
238 *left = state.GetLeftType(); | 306 *left = state.GetLeftType(); |
239 *right = state.GetRightType(); | 307 *right = state.GetRightType(); |
240 *result = state.GetResultType(); | 308 *result = state.GetResultType(); |
241 *fixed_right_arg = state.fixed_right_arg(); | 309 *fixed_right_arg = state.fixed_right_arg(); |
242 | 310 |
243 AllocationSite* first_allocation_site = code->FindFirstAllocationSite(); | 311 AllocationSite* first_allocation_site = code->FindFirstAllocationSite(); |
244 if (first_allocation_site != NULL) { | 312 if (first_allocation_site != NULL) { |
245 *allocation_site = handle(first_allocation_site); | 313 *allocation_site = handle(first_allocation_site); |
246 } else { | 314 } else { |
247 *allocation_site = Handle<AllocationSite>::null(); | 315 *allocation_site = Handle<AllocationSite>::null(); |
248 } | 316 } |
249 } | 317 } |
250 | 318 |
251 AstType* TypeFeedbackOracle::CountType(TypeFeedbackId id) { | 319 AstType* TypeFeedbackOracle::CountType(TypeFeedbackId id, |
320 FeedbackVectorSlot slot, | |
321 bool feedback_from_ignition) { | |
252 Handle<Object> object = GetInfo(id); | 322 Handle<Object> object = GetInfo(id); |
253 if (!object->IsCode()) return AstType::None(); | 323 if (!object->IsCode()) { |
324 DCHECK(slot.IsInvalid()); | |
325 return AstType::None(); | |
326 } | |
327 | |
328 if (feedback_from_ignition) { | |
329 DCHECK(!slot.IsInvalid()); | |
330 BinaryOpICNexus nexus(feedback_vector_, slot); | |
331 return BinaryOpHintToType(nexus.GetBinaryOperationFeedback()); | |
332 } | |
333 | |
334 // Feedback from IC. | |
254 Handle<Code> code = Handle<Code>::cast(object); | 335 Handle<Code> code = Handle<Code>::cast(object); |
255 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); | 336 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); |
256 BinaryOpICState state(isolate(), code->extra_ic_state()); | 337 BinaryOpICState state(isolate(), code->extra_ic_state()); |
257 return state.GetLeftType(); | 338 return state.GetLeftType(); |
258 } | 339 } |
259 | 340 |
260 | 341 |
261 bool TypeFeedbackOracle::HasOnlyStringMaps(SmallMapList* receiver_types) { | 342 bool TypeFeedbackOracle::HasOnlyStringMaps(SmallMapList* receiver_types) { |
262 bool all_strings = receiver_types->length() > 0; | 343 bool all_strings = receiver_types->length() > 0; |
263 for (int i = 0; i < receiver_types->length(); i++) { | 344 for (int i = 0; i < receiver_types->length(); i++) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 // Dictionary has been allocated with sufficient size for all elements. | 539 // Dictionary has been allocated with sufficient size for all elements. |
459 DisallowHeapAllocation no_need_to_resize_dictionary; | 540 DisallowHeapAllocation no_need_to_resize_dictionary; |
460 HandleScope scope(isolate()); | 541 HandleScope scope(isolate()); |
461 USE(UnseededNumberDictionary::AtNumberPut( | 542 USE(UnseededNumberDictionary::AtNumberPut( |
462 dictionary_, IdToKey(ast_id), handle(target, isolate()))); | 543 dictionary_, IdToKey(ast_id), handle(target, isolate()))); |
463 } | 544 } |
464 | 545 |
465 | 546 |
466 } // namespace internal | 547 } // namespace internal |
467 } // namespace v8 | 548 } // namespace v8 |
OLD | NEW |