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* CompareOpHintToType(CompareOperationHint hint) { | |
197 switch (hint) { | |
198 case CompareOperationHint::kNone: | |
199 return AstType::None(); | |
200 case CompareOperationHint::kSignedSmall: | |
201 return AstType::SignedSmall(); | |
202 case CompareOperationHint::kNumber: | |
203 return AstType::Number(); | |
204 case CompareOperationHint::kNumberOrOddball: | |
205 return AstType::NumberOrOddball(); | |
206 case CompareOperationHint::kAny: | |
207 return AstType::Any(); | |
208 } | |
209 UNREACHABLE(); | |
210 return AstType::None(); | |
211 } | |
212 | |
213 AstType* BinaryOpHintToType(BinaryOperationHint hint) { | |
214 switch (hint) { | |
215 case BinaryOperationHint::kNone: | |
216 return AstType::None(); | |
217 case BinaryOperationHint::kSignedSmall: | |
218 return AstType::SignedSmall(); | |
219 case BinaryOperationHint::kSigned32: | |
220 return AstType::Signed32(); | |
221 case BinaryOperationHint::kNumberOrOddball: | |
mythria
2016/09/26 20:37:34
We only collect feedback about Number. We change i
| |
222 return AstType::Number(); | |
223 case BinaryOperationHint::kString: | |
224 return AstType::String(); | |
225 case BinaryOperationHint::kAny: | |
226 return AstType::Any(); | |
227 } | |
228 UNREACHABLE(); | |
229 return AstType::None(); | |
230 } | |
231 | |
232 } // end anonymous namespace | |
233 | |
234 void TypeFeedbackOracle::CompareType(TypeFeedbackId id, FeedbackVectorSlot slot, | |
235 AstType** left_type, AstType** right_type, | |
196 AstType** combined_type) { | 236 AstType** combined_type) { |
197 Handle<Object> info = GetInfo(id); | 237 Handle<Object> info = GetInfo(id); |
238 // A check for a valid slot is not sufficient here. InstanceOf collects | |
239 // type feedback in a General slot. | |
198 if (!info->IsCode()) { | 240 if (!info->IsCode()) { |
mythria
2016/09/26 20:37:34
I had to change this check because now instance of
| |
199 // For some comparisons we don't have ICs, e.g. LiteralCompareTypeof. | 241 // For some comparisons we don't have type feedback, e.g. |
242 // LiteralCompareTypeof. | |
200 *left_type = *right_type = *combined_type = AstType::None(); | 243 *left_type = *right_type = *combined_type = AstType::None(); |
201 return; | 244 return; |
202 } | 245 } |
246 | |
247 // Feedback from Ignition. The feedback slot will be allocated and initialized | |
248 // to AstType::None() even when ignition is not enabled. So it is safe to get | |
249 // feedback from the type feedback vector. | |
250 DCHECK(!slot.IsInvalid()); | |
251 CompareICNexus nexus(feedback_vector_, slot); | |
252 *left_type = *right_type = *combined_type = | |
253 CompareOpHintToType(nexus.GetCompareOperationFeedback()); | |
254 | |
255 // Merge the feedback from full-codegen if available. | |
203 Handle<Code> code = Handle<Code>::cast(info); | 256 Handle<Code> code = Handle<Code>::cast(info); |
204 | |
205 Handle<Map> map; | 257 Handle<Map> map; |
206 Map* raw_map = code->FindFirstMap(); | 258 Map* raw_map = code->FindFirstMap(); |
207 if (raw_map != NULL) Map::TryUpdate(handle(raw_map)).ToHandle(&map); | 259 if (raw_map != NULL) Map::TryUpdate(handle(raw_map)).ToHandle(&map); |
208 | 260 |
209 if (code->is_compare_ic_stub()) { | 261 if (code->is_compare_ic_stub()) { |
210 CompareICStub stub(code->stub_key(), isolate()); | 262 CompareICStub stub(code->stub_key(), isolate()); |
211 *left_type = CompareICState::StateToType(zone(), stub.left()); | 263 AstType* left_type_from_ic = |
212 *right_type = CompareICState::StateToType(zone(), stub.right()); | 264 CompareICState::StateToType(zone(), stub.left()); |
213 *combined_type = CompareICState::StateToType(zone(), stub.state(), map); | 265 *left_type = AstType::Union(*left_type, left_type_from_ic, zone()); |
266 AstType* right_type_from_ic = | |
267 CompareICState::StateToType(zone(), stub.right()); | |
268 *right_type = AstType::Union(*right_type, right_type_from_ic, zone()); | |
269 AstType* combined_type_from_ic = | |
270 CompareICState::StateToType(zone(), stub.state(), map); | |
271 *combined_type = | |
272 AstType::Union(*combined_type, combined_type_from_ic, zone()); | |
214 } | 273 } |
215 } | 274 } |
216 | 275 |
217 void TypeFeedbackOracle::BinaryType(TypeFeedbackId id, AstType** left, | 276 void TypeFeedbackOracle::BinaryType(TypeFeedbackId id, FeedbackVectorSlot slot, |
218 AstType** right, AstType** result, | 277 AstType** left, AstType** right, |
278 AstType** result, | |
219 Maybe<int>* fixed_right_arg, | 279 Maybe<int>* fixed_right_arg, |
220 Handle<AllocationSite>* allocation_site, | 280 Handle<AllocationSite>* allocation_site, |
221 Token::Value op) { | 281 Token::Value op) { |
222 Handle<Object> object = GetInfo(id); | 282 Handle<Object> object = GetInfo(id); |
223 if (!object->IsCode()) { | 283 if (slot.IsInvalid()) { |
224 // For some binary ops we don't have ICs, e.g. Token::COMMA, but for the | 284 // For some binary ops we don't have ICs or feedback slots, |
225 // operations covered by the BinaryOpIC we should always have them. | 285 // e.g. Token::COMMA, but for the operations covered by the BinaryOpIC we |
286 // should always have them. | |
287 DCHECK(!object->IsCode()); | |
226 DCHECK(op < BinaryOpICState::FIRST_TOKEN || | 288 DCHECK(op < BinaryOpICState::FIRST_TOKEN || |
227 op > BinaryOpICState::LAST_TOKEN); | 289 op > BinaryOpICState::LAST_TOKEN); |
228 *left = *right = *result = AstType::None(); | 290 *left = *right = *result = AstType::None(); |
229 *fixed_right_arg = Nothing<int>(); | 291 *fixed_right_arg = Nothing<int>(); |
230 *allocation_site = Handle<AllocationSite>::null(); | 292 *allocation_site = Handle<AllocationSite>::null(); |
231 return; | 293 return; |
232 } | 294 } |
295 | |
296 // Feedback from Ignition. The feedback slot will be allocated and initialized | |
297 // to AstType::None() even when ignition is not enabled. So it is safe to get | |
298 // feedback from the type feedback vector. | |
299 DCHECK(!slot.IsInvalid()); | |
300 BinaryOpICNexus nexus(feedback_vector_, slot); | |
301 *left = *right = *result = | |
302 BinaryOpHintToType(nexus.GetBinaryOperationFeedback()); | |
303 *fixed_right_arg = Nothing<int>(); | |
304 *allocation_site = Handle<AllocationSite>::null(); | |
305 | |
306 if (!object->IsCode()) return; | |
307 | |
308 // Merge the feedback from full-codegen if available. | |
233 Handle<Code> code = Handle<Code>::cast(object); | 309 Handle<Code> code = Handle<Code>::cast(object); |
234 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); | 310 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); |
235 BinaryOpICState state(isolate(), code->extra_ic_state()); | 311 BinaryOpICState state(isolate(), code->extra_ic_state()); |
236 DCHECK_EQ(op, state.op()); | 312 DCHECK_EQ(op, state.op()); |
237 | 313 |
238 *left = state.GetLeftType(); | 314 *left = AstType::Union(*left, state.GetLeftType(), zone()); |
239 *right = state.GetRightType(); | 315 *right = AstType::Union(*right, state.GetRightType(), zone()); |
240 *result = state.GetResultType(); | 316 *result = AstType::Union(*result, state.GetResultType(), zone()); |
241 *fixed_right_arg = state.fixed_right_arg(); | 317 *fixed_right_arg = state.fixed_right_arg(); |
242 | 318 |
243 AllocationSite* first_allocation_site = code->FindFirstAllocationSite(); | 319 AllocationSite* first_allocation_site = code->FindFirstAllocationSite(); |
244 if (first_allocation_site != NULL) { | 320 if (first_allocation_site != NULL) { |
245 *allocation_site = handle(first_allocation_site); | 321 *allocation_site = handle(first_allocation_site); |
246 } else { | 322 } else { |
247 *allocation_site = Handle<AllocationSite>::null(); | 323 *allocation_site = Handle<AllocationSite>::null(); |
248 } | 324 } |
249 } | 325 } |
250 | 326 |
251 AstType* TypeFeedbackOracle::CountType(TypeFeedbackId id) { | 327 AstType* TypeFeedbackOracle::CountType(TypeFeedbackId id, |
328 FeedbackVectorSlot slot) { | |
252 Handle<Object> object = GetInfo(id); | 329 Handle<Object> object = GetInfo(id); |
253 if (!object->IsCode()) return AstType::None(); | 330 if (slot.IsInvalid()) { |
331 DCHECK(!object->IsCode()); | |
332 return AstType::None(); | |
333 } | |
334 | |
335 DCHECK(!slot.IsInvalid()); | |
336 BinaryOpICNexus nexus(feedback_vector_, slot); | |
337 AstType* type = BinaryOpHintToType(nexus.GetBinaryOperationFeedback()); | |
338 | |
339 if (!object->IsCode()) return type; | |
340 | |
254 Handle<Code> code = Handle<Code>::cast(object); | 341 Handle<Code> code = Handle<Code>::cast(object); |
255 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); | 342 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); |
256 BinaryOpICState state(isolate(), code->extra_ic_state()); | 343 BinaryOpICState state(isolate(), code->extra_ic_state()); |
257 return state.GetLeftType(); | 344 return AstType::Union(type, state.GetLeftType(), zone()); |
258 } | 345 } |
259 | 346 |
260 | 347 |
261 bool TypeFeedbackOracle::HasOnlyStringMaps(SmallMapList* receiver_types) { | 348 bool TypeFeedbackOracle::HasOnlyStringMaps(SmallMapList* receiver_types) { |
262 bool all_strings = receiver_types->length() > 0; | 349 bool all_strings = receiver_types->length() > 0; |
263 for (int i = 0; i < receiver_types->length(); i++) { | 350 for (int i = 0; i < receiver_types->length(); i++) { |
264 all_strings &= receiver_types->at(i)->IsStringMap(); | 351 all_strings &= receiver_types->at(i)->IsStringMap(); |
265 } | 352 } |
266 return all_strings; | 353 return all_strings; |
267 } | 354 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 // Dictionary has been allocated with sufficient size for all elements. | 545 // Dictionary has been allocated with sufficient size for all elements. |
459 DisallowHeapAllocation no_need_to_resize_dictionary; | 546 DisallowHeapAllocation no_need_to_resize_dictionary; |
460 HandleScope scope(isolate()); | 547 HandleScope scope(isolate()); |
461 USE(UnseededNumberDictionary::AtNumberPut( | 548 USE(UnseededNumberDictionary::AtNumberPut( |
462 dictionary_, IdToKey(ast_id), handle(target, isolate()))); | 549 dictionary_, IdToKey(ast_id), handle(target, isolate()))); |
463 } | 550 } |
464 | 551 |
465 | 552 |
466 } // namespace internal | 553 } // namespace internal |
467 } // namespace v8 | 554 } // namespace v8 |
OLD | NEW |