Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/ic/ic.cc

Issue 2182103002: [KeyedLoadIC] Support Smi "handlers" for simple field loads (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ic/ic.h ('k') | src/ic/ic-compiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ic/ic.h" 5 #include "src/ic/ic.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-arguments-inl.h" 8 #include "src/api-arguments-inl.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 Handle<Object> handler) { 545 Handle<Object> handler) {
546 DCHECK(UseVector()); 546 DCHECK(UseVector());
547 if (kind() == Code::LOAD_IC) { 547 if (kind() == Code::LOAD_IC) {
548 LoadICNexus* nexus = casted_nexus<LoadICNexus>(); 548 LoadICNexus* nexus = casted_nexus<LoadICNexus>();
549 nexus->ConfigureMonomorphic(map, handler); 549 nexus->ConfigureMonomorphic(map, handler);
550 } else if (kind() == Code::LOAD_GLOBAL_IC) { 550 } else if (kind() == Code::LOAD_GLOBAL_IC) {
551 LoadGlobalICNexus* nexus = casted_nexus<LoadGlobalICNexus>(); 551 LoadGlobalICNexus* nexus = casted_nexus<LoadGlobalICNexus>();
552 nexus->ConfigureHandlerMode(Handle<Code>::cast(handler)); 552 nexus->ConfigureHandlerMode(Handle<Code>::cast(handler));
553 } else if (kind() == Code::KEYED_LOAD_IC) { 553 } else if (kind() == Code::KEYED_LOAD_IC) {
554 KeyedLoadICNexus* nexus = casted_nexus<KeyedLoadICNexus>(); 554 KeyedLoadICNexus* nexus = casted_nexus<KeyedLoadICNexus>();
555 nexus->ConfigureMonomorphic(name, map, Handle<Code>::cast(handler)); 555 nexus->ConfigureMonomorphic(name, map, handler);
556 } else if (kind() == Code::STORE_IC) { 556 } else if (kind() == Code::STORE_IC) {
557 StoreICNexus* nexus = casted_nexus<StoreICNexus>(); 557 StoreICNexus* nexus = casted_nexus<StoreICNexus>();
558 nexus->ConfigureMonomorphic(map, Handle<Code>::cast(handler)); 558 nexus->ConfigureMonomorphic(map, Handle<Code>::cast(handler));
559 } else { 559 } else {
560 DCHECK(kind() == Code::KEYED_STORE_IC); 560 DCHECK(kind() == Code::KEYED_STORE_IC);
561 KeyedStoreICNexus* nexus = casted_nexus<KeyedStoreICNexus>(); 561 KeyedStoreICNexus* nexus = casted_nexus<KeyedStoreICNexus>();
562 nexus->ConfigureMonomorphic(name, map, Handle<Code>::cast(handler)); 562 nexus->ConfigureMonomorphic(name, map, Handle<Code>::cast(handler));
563 } 563 }
564 564
565 vector_set_ = true; 565 vector_set_ = true;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 Map* transitioned_map = nullptr; 774 Map* transitioned_map = nullptr;
775 if (more_general_transition) { 775 if (more_general_transition) {
776 MapHandleList map_list; 776 MapHandleList map_list;
777 map_list.Add(handle(target_map)); 777 map_list.Add(handle(target_map));
778 transitioned_map = source_map->FindElementsKindTransitionedMap(&map_list); 778 transitioned_map = source_map->FindElementsKindTransitionedMap(&map_list);
779 } 779 }
780 return transitioned_map == target_map; 780 return transitioned_map == target_map;
781 } 781 }
782 782
783 void IC::PatchCache(Handle<Name> name, Handle<Object> code) { 783 void IC::PatchCache(Handle<Name> name, Handle<Object> code) {
784 DCHECK(code->IsCode() || (kind() == Code::LOAD_IC && code->IsSmi())); 784 DCHECK(code->IsCode() || (code->IsSmi() && (kind() == Code::LOAD_IC ||
785 kind() == Code::KEYED_LOAD_IC)));
785 switch (state()) { 786 switch (state()) {
786 case UNINITIALIZED: 787 case UNINITIALIZED:
787 case PREMONOMORPHIC: 788 case PREMONOMORPHIC:
788 UpdateMonomorphicIC(code, name); 789 UpdateMonomorphicIC(code, name);
789 break; 790 break;
790 case RECOMPUTE_HANDLER: 791 case RECOMPUTE_HANDLER:
791 case MONOMORPHIC: 792 case MONOMORPHIC:
792 if (kind() == Code::LOAD_GLOBAL_IC) { 793 if (kind() == Code::LOAD_GLOBAL_IC) {
793 UpdateMonomorphicIC(code, name); 794 UpdateMonomorphicIC(code, name);
794 break; 795 break;
(...skipping 26 matching lines...) Expand all
821 return LoadICTFStub(isolate).GetCode(); 822 return LoadICTFStub(isolate).GetCode();
822 } 823 }
823 return LoadICStub(isolate).GetCode(); 824 return LoadICStub(isolate).GetCode();
824 } 825 }
825 826
826 Handle<Code> LoadGlobalIC::initialize_stub_in_optimized_code( 827 Handle<Code> LoadGlobalIC::initialize_stub_in_optimized_code(
827 Isolate* isolate, ExtraICState extra_state) { 828 Isolate* isolate, ExtraICState extra_state) {
828 return LoadGlobalICStub(isolate, LoadGlobalICState(extra_state)).GetCode(); 829 return LoadGlobalICStub(isolate, LoadGlobalICState(extra_state)).GetCode();
829 } 830 }
830 831
831 Handle<Code> KeyedLoadIC::initialize_stub_in_optimized_code( 832 Handle<Code> KeyedLoadIC::initialize_stub_in_optimized_code(Isolate* isolate) {
832 Isolate* isolate, ExtraICState extra_state) { 833 if (FLAG_tf_load_ic_stub) {
833 // TODO(ishell): remove extra_ic_state 834 return KeyedLoadICTFStub(isolate).GetCode();
835 }
834 return KeyedLoadICStub(isolate).GetCode(); 836 return KeyedLoadICStub(isolate).GetCode();
835 } 837 }
836 838
837 Handle<Code> KeyedStoreIC::initialize_stub_in_optimized_code( 839 Handle<Code> KeyedStoreIC::initialize_stub_in_optimized_code(
838 Isolate* isolate, LanguageMode language_mode) { 840 Isolate* isolate, LanguageMode language_mode) {
839 StoreICState state = StoreICState(language_mode); 841 StoreICState state = StoreICState(language_mode);
840 return KeyedStoreICStub(isolate, state).GetCode(); 842 return KeyedStoreICStub(isolate, state).GetCode();
841 } 843 }
842 844
843 845
844 Handle<Code> KeyedStoreIC::ChooseMegamorphicStub(Isolate* isolate, 846 Handle<Code> KeyedStoreIC::ChooseMegamorphicStub(Isolate* isolate,
845 ExtraICState extra_state) { 847 ExtraICState extra_state) {
846 LanguageMode mode = StoreICState::GetLanguageMode(extra_state); 848 LanguageMode mode = StoreICState::GetLanguageMode(extra_state);
847 return is_strict(mode) 849 return is_strict(mode)
848 ? isolate->builtins()->KeyedStoreIC_Megamorphic_Strict() 850 ? isolate->builtins()->KeyedStoreIC_Megamorphic_Strict()
849 : isolate->builtins()->KeyedStoreIC_Megamorphic(); 851 : isolate->builtins()->KeyedStoreIC_Megamorphic();
850 } 852 }
851 853
852 Handle<Object> LoadIC::SimpleFieldLoad(FieldIndex index) { 854 Handle<Object> LoadIC::SimpleFieldLoad(FieldIndex index) {
853 if (kind() == Code::LOAD_IC && FLAG_tf_load_ic_stub) { 855 if (FLAG_tf_load_ic_stub) {
854 return handle(Smi::FromInt(index.GetLoadByFieldOffset()), isolate()); 856 return handle(Smi::FromInt(index.GetLoadByFieldOffset()), isolate());
855 } 857 }
856 DCHECK(kind() == Code::KEYED_LOAD_IC || !FLAG_tf_load_ic_stub);
857 TRACE_HANDLER_STATS(isolate(), LoadIC_LoadFieldStub); 858 TRACE_HANDLER_STATS(isolate(), LoadIC_LoadFieldStub);
858 LoadFieldStub stub(isolate(), index); 859 LoadFieldStub stub(isolate(), index);
859 return stub.GetCode(); 860 return stub.GetCode();
860 } 861 }
861 862
862 863
863 bool IsCompatibleReceiver(LookupIterator* lookup, Handle<Map> receiver_map) { 864 bool IsCompatibleReceiver(LookupIterator* lookup, Handle<Map> receiver_map) {
864 DCHECK(lookup->state() == LookupIterator::ACCESSOR); 865 DCHECK(lookup->state() == LookupIterator::ACCESSOR);
865 Isolate* isolate = lookup->isolate(); 866 Isolate* isolate = lookup->isolate();
866 Handle<Object> accessors = lookup->GetAccessors(); 867 Handle<Object> accessors = lookup->GetAccessors();
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 1348
1348 void KeyedLoadIC::UpdateLoadElement(Handle<HeapObject> receiver) { 1349 void KeyedLoadIC::UpdateLoadElement(Handle<HeapObject> receiver) {
1349 Handle<Map> receiver_map(receiver->map(), isolate()); 1350 Handle<Map> receiver_map(receiver->map(), isolate());
1350 DCHECK(receiver_map->instance_type() != JS_VALUE_TYPE && 1351 DCHECK(receiver_map->instance_type() != JS_VALUE_TYPE &&
1351 receiver_map->instance_type() != JS_PROXY_TYPE); // Checked by caller. 1352 receiver_map->instance_type() != JS_PROXY_TYPE); // Checked by caller.
1352 MapHandleList target_receiver_maps; 1353 MapHandleList target_receiver_maps;
1353 TargetMaps(&target_receiver_maps); 1354 TargetMaps(&target_receiver_maps);
1354 1355
1355 if (target_receiver_maps.length() == 0) { 1356 if (target_receiver_maps.length() == 0) {
1356 Handle<Code> handler = 1357 Handle<Code> handler =
1357 PropertyICCompiler::ComputeKeyedLoadMonomorphicHandler( 1358 ElementHandlerCompiler::GetKeyedLoadHandler(receiver_map, isolate());
1358 receiver_map, extra_ic_state());
1359 return ConfigureVectorState(Handle<Name>(), receiver_map, handler); 1359 return ConfigureVectorState(Handle<Name>(), receiver_map, handler);
1360 } 1360 }
1361 1361
1362 for (int i = 0; i < target_receiver_maps.length(); i++) { 1362 for (int i = 0; i < target_receiver_maps.length(); i++) {
1363 Handle<Map> map = target_receiver_maps.at(i); 1363 Handle<Map> map = target_receiver_maps.at(i);
1364 if (map.is_null()) continue; 1364 if (map.is_null()) continue;
1365 if (map->instance_type() == JS_VALUE_TYPE) { 1365 if (map->instance_type() == JS_VALUE_TYPE) {
1366 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "JSValue"); 1366 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "JSValue");
1367 return; 1367 return;
1368 } 1368 }
1369 if (map->instance_type() == JS_PROXY_TYPE) { 1369 if (map->instance_type() == JS_PROXY_TYPE) {
1370 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "JSProxy"); 1370 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "JSProxy");
1371 return; 1371 return;
1372 } 1372 }
1373 } 1373 }
1374 1374
1375 // The first time a receiver is seen that is a transitioned version of the 1375 // The first time a receiver is seen that is a transitioned version of the
1376 // previous monomorphic receiver type, assume the new ElementsKind is the 1376 // previous monomorphic receiver type, assume the new ElementsKind is the
1377 // monomorphic type. This benefits global arrays that only transition 1377 // monomorphic type. This benefits global arrays that only transition
1378 // once, and all call sites accessing them are faster if they remain 1378 // once, and all call sites accessing them are faster if they remain
1379 // monomorphic. If this optimistic assumption is not true, the IC will 1379 // monomorphic. If this optimistic assumption is not true, the IC will
1380 // miss again and it will become polymorphic and support both the 1380 // miss again and it will become polymorphic and support both the
1381 // untransitioned and transitioned maps. 1381 // untransitioned and transitioned maps.
1382 if (state() == MONOMORPHIC && !receiver->IsString() && 1382 if (state() == MONOMORPHIC && !receiver->IsString() &&
1383 IsMoreGeneralElementsKindTransition( 1383 IsMoreGeneralElementsKindTransition(
1384 target_receiver_maps.at(0)->elements_kind(), 1384 target_receiver_maps.at(0)->elements_kind(),
1385 Handle<JSObject>::cast(receiver)->GetElementsKind())) { 1385 Handle<JSObject>::cast(receiver)->GetElementsKind())) {
1386 Handle<Code> handler = 1386 Handle<Code> handler =
1387 PropertyICCompiler::ComputeKeyedLoadMonomorphicHandler( 1387 ElementHandlerCompiler::GetKeyedLoadHandler(receiver_map, isolate());
1388 receiver_map, extra_ic_state());
1389 return ConfigureVectorState(Handle<Name>(), receiver_map, handler); 1388 return ConfigureVectorState(Handle<Name>(), receiver_map, handler);
1390 } 1389 }
1391 1390
1392 DCHECK(state() != GENERIC); 1391 DCHECK(state() != GENERIC);
1393 1392
1394 // Determine the list of receiver maps that this call site has seen, 1393 // Determine the list of receiver maps that this call site has seen,
1395 // adding the map that was just encountered. 1394 // adding the map that was just encountered.
1396 if (!AddOneReceiverMapIfMissing(&target_receiver_maps, receiver_map)) { 1395 if (!AddOneReceiverMapIfMissing(&target_receiver_maps, receiver_map)) {
1397 // If the miss wasn't due to an unseen map, a polymorphic stub 1396 // If the miss wasn't due to an unseen map, a polymorphic stub
1398 // won't help, use the generic stub. 1397 // won't help, use the generic stub.
1399 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "same map added twice"); 1398 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "same map added twice");
1400 return; 1399 return;
1401 } 1400 }
1402 1401
1403 // If the maximum number of receiver maps has been exceeded, use the generic 1402 // If the maximum number of receiver maps has been exceeded, use the generic
1404 // version of the IC. 1403 // version of the IC.
1405 if (target_receiver_maps.length() > kMaxKeyedPolymorphism) { 1404 if (target_receiver_maps.length() > kMaxKeyedPolymorphism) {
1406 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "max polymorph exceeded"); 1405 TRACE_GENERIC_IC(isolate(), "KeyedLoadIC", "max polymorph exceeded");
1407 return; 1406 return;
1408 } 1407 }
1409 1408
1410 List<Handle<Object>> handlers(target_receiver_maps.length()); 1409 List<Handle<Object>> handlers(target_receiver_maps.length());
1411 TRACE_HANDLER_STATS(isolate(), KeyedLoadIC_PolymorphicElement);
1412 ElementHandlerCompiler compiler(isolate()); 1410 ElementHandlerCompiler compiler(isolate());
1413 compiler.CompileElementHandlers(&target_receiver_maps, &handlers); 1411 compiler.CompileElementHandlers(&target_receiver_maps, &handlers);
1414 ConfigureVectorState(Handle<Name>(), &target_receiver_maps, &handlers); 1412 ConfigureVectorState(Handle<Name>(), &target_receiver_maps, &handlers);
1415 } 1413 }
1416 1414
1417 1415
1418 MaybeHandle<Object> KeyedLoadIC::Load(Handle<Object> object, 1416 MaybeHandle<Object> KeyedLoadIC::Load(Handle<Object> object,
1419 Handle<Object> key) { 1417 Handle<Object> key) {
1420 if (MigrateDeprecated(object)) { 1418 if (MigrateDeprecated(object)) {
1421 Handle<Object> result; 1419 Handle<Object> result;
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
3041 DCHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, 3039 DCHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC,
3042 vector->GetKind(vector_slot)); 3040 vector->GetKind(vector_slot));
3043 KeyedLoadICNexus nexus(vector, vector_slot); 3041 KeyedLoadICNexus nexus(vector, vector_slot);
3044 KeyedLoadIC ic(IC::EXTRA_CALL_FRAME, isolate, &nexus); 3042 KeyedLoadIC ic(IC::EXTRA_CALL_FRAME, isolate, &nexus);
3045 ic.UpdateState(receiver, key); 3043 ic.UpdateState(receiver, key);
3046 RETURN_RESULT_OR_FAILURE(isolate, ic.Load(receiver, key)); 3044 RETURN_RESULT_OR_FAILURE(isolate, ic.Load(receiver, key));
3047 } 3045 }
3048 } 3046 }
3049 } // namespace internal 3047 } // namespace internal
3050 } // namespace v8 3048 } // namespace v8
OLDNEW
« no previous file with comments | « src/ic/ic.h ('k') | src/ic/ic-compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698