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 3 // found in the LICENSE file. 4 5 #include "src/v8.h" 6 7 #if V8_TARGET_ARCH_ARM64 8 9 #include "src/ic/ic.h" 10 #include "src/ic/ic-compiler.h" 11 12 namespace v8 { 13 namespace internal { 14 15 #define __ ACCESS_MASM(masm) 16 17 void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm, 18 StrictMode strict_mode) { 19 ASM_LOCATION("PropertyICCompiler::GenerateRuntimeSetProperty"); 20 21 __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(), 22 StoreDescriptor::ValueRegister()); 23 24 __ Mov(x10, Smi::FromInt(strict_mode)); 25 __ Push(x10); 26 27 // Do tail-call to runtime routine. 28 __ TailCallRuntime(Runtime::kSetProperty, 4, 1); 29 } 30 31 32 #undef __ 33 #define __ ACCESS_MASM(masm()) 34 35 36 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types, 37 CodeHandleList* handlers, 38 Handle<Name> name, 39 Code::StubType type, 40 IcCheckType check) { 41 Label miss; 42 43 if (check == PROPERTY && 44 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) { 45 // In case we are compiling an IC for dictionary loads and stores, just 46 // check whether the name is unique. 47 if (name.is_identical_to(isolate()->factory()->normal_ic_symbol())) { 48 Register tmp = scratch1(); 49 __ JumpIfSmi(this->name(), &miss); 50 __ Ldr(tmp, FieldMemOperand(this->name(), HeapObject::kMapOffset)); 51 __ Ldrb(tmp, FieldMemOperand(tmp, Map::kInstanceTypeOffset)); 52 __ JumpIfNotUniqueNameInstanceType(tmp, &miss); 53 } else { 54 __ CompareAndBranch(this->name(), Operand(name), ne, &miss); 55 } 56 } 57 58 Label number_case; 59 Label* smi_target = IncludesNumberType(types) ? &number_case : &miss; 60 __ JumpIfSmi(receiver(), smi_target); 61 62 // Polymorphic keyed stores may use the map register 63 Register map_reg = scratch1(); 64 DCHECK(kind() != Code::KEYED_STORE_IC || 65 map_reg.is(ElementTransitionAndStoreDescriptor::MapRegister())); 66 __ Ldr(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset)); 67 int receiver_count = types->length(); 68 int number_of_handled_maps = 0; 69 for (int current = 0; current < receiver_count; ++current) { 70 Handle<HeapType> type = types->at(current); 71 Handle<Map> map = IC::TypeToMap(*type, isolate()); 72 if (!map->is_deprecated()) { 73 number_of_handled_maps++; 74 Label try_next; 75 __ Cmp(map_reg, Operand(map)); 76 __ B(ne, &try_next); 77 if (type->Is(HeapType::Number())) { 78 DCHECK(!number_case.is_unused()); 79 __ Bind(&number_case); 80 } 81 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET); 82 __ Bind(&try_next); 83 } 84 } 85 DCHECK(number_of_handled_maps != 0); 86 87 __ Bind(&miss); 88 TailCallBuiltin(masm(), MissBuiltin(kind())); 89 90 // Return the generated code. 91 InlineCacheState state = 92 (number_of_handled_maps > 1) ? POLYMORPHIC : MONOMORPHIC; 93 return GetCode(kind(), type, name, state); 94 } 95 96 97 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic( 98 MapHandleList* receiver_maps, CodeHandleList* handler_stubs, 99 MapHandleList* transitioned_maps) { 100 Label miss; 101 102 ASM_LOCATION("PropertyICCompiler::CompileStorePolymorphic"); 103 104 __ JumpIfSmi(receiver(), &miss); 105 106 int receiver_count = receiver_maps->length(); 107 __ Ldr(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset)); 108 for (int i = 0; i < receiver_count; i++) { 109 __ Cmp(scratch1(), Operand(receiver_maps->at(i))); 110 111 Label skip; 112 __ B(&skip, ne); 113 if (!transitioned_maps->at(i).is_null()) { 114 // This argument is used by the handler stub. For example, see 115 // ElementsTransitionGenerator::GenerateMapChangeElementsTransition. 116 __ Mov(transition_map(), Operand(transitioned_maps->at(i))); 117 } 118 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET); 119 __ Bind(&skip); 120 } 121 122 __ Bind(&miss); 123 TailCallBuiltin(masm(), MissBuiltin(kind())); 124 125 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC); 126 } 127 128 129 #undef __ 130 } 131 } // namespace v8::internal 132 133 #endif // V8_TARGET_ARCH_ARM64 134