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
3 // found in the LICENSE file.
7 #if V8_TARGET_ARCH_MIPS
9 #include "src/codegen.h"
10 #include "src/ic-inl.h"
11 #include "src/stub-cache.h"
16 #define __ ACCESS_MASM(masm)
19 static void ProbeTable(Isolate* isolate,
22 StubCache::Table table,
25 // Number of the cache entry, not scaled.
29 Register offset_scratch) {
30 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
31 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
32 ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
34 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address());
35 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address());
36 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address());
38 // Check the relative positions of the address fields.
39 DCHECK(value_off_addr > key_off_addr);
40 DCHECK((value_off_addr - key_off_addr) % 4 == 0);
41 DCHECK((value_off_addr - key_off_addr) < (256 * 4));
42 DCHECK(map_off_addr > key_off_addr);
43 DCHECK((map_off_addr - key_off_addr) % 4 == 0);
44 DCHECK((map_off_addr - key_off_addr) < (256 * 4));
47 Register base_addr = scratch;
50 // Multiply by 3 because there are 3 fields per entry (name, code, map).
51 __ sll(offset_scratch, offset, 1);
52 __ Addu(offset_scratch, offset_scratch, offset);
54 // Calculate the base address of the entry.
55 __ li(base_addr, Operand(key_offset));
56 __ sll(at, offset_scratch, kPointerSizeLog2);
57 __ Addu(base_addr, base_addr, at);
59 // Check that the key in the entry matches the name.
60 __ lw(at, MemOperand(base_addr, 0));
61 __ Branch(&miss, ne, name, Operand(at));
63 // Check the map matches.
64 __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr));
65 __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset));
66 __ Branch(&miss, ne, at, Operand(scratch2));
68 // Get the code entry from the cache.
69 Register code = scratch2;
71 __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr));
73 // Check that the flags match what we're looking for.
74 Register flags_reg = base_addr;
76 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset));
77 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup));
78 __ Branch(&miss, ne, flags_reg, Operand(flags));
81 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
83 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
88 // Jump to the first instruction in the code stub.
89 __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag));
92 // Miss: fall through.
97 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
98 MacroAssembler* masm, Label* miss_label, Register receiver,
99 Handle<Name> name, Register scratch0, Register scratch1) {
100 DCHECK(name->IsUniqueName());
101 DCHECK(!receiver.is(scratch0));
102 Counters* counters = masm->isolate()->counters();
103 __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
104 __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
108 const int kInterceptorOrAccessCheckNeededMask =
109 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
111 // Bail out if the receiver has a named interceptor or requires access checks.
112 Register map = scratch1;
113 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
114 __ lbu(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
115 __ And(scratch0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
116 __ Branch(miss_label, ne, scratch0, Operand(zero_reg));
118 // Check that receiver is a JSObject.
119 __ lbu(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
120 __ Branch(miss_label, lt, scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
122 // Load properties array.
123 Register properties = scratch0;
124 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
125 // Check that the properties array is a dictionary.
126 __ lw(map, FieldMemOperand(properties, HeapObject::kMapOffset));
127 Register tmp = properties;
128 __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
129 __ Branch(miss_label, ne, map, Operand(tmp));
131 // Restore the temporarily used register.
132 __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
135 NameDictionaryLookupStub::GenerateNegativeLookup(masm,
143 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
147 void StubCache::GenerateProbe(MacroAssembler* masm,
155 Isolate* isolate = masm->isolate();
158 // Make sure that code is valid. The multiplying code relies on the
159 // entry size being 12.
160 DCHECK(sizeof(Entry) == 12);
162 // Make sure the flags does not name a specific type.
163 DCHECK(Code::ExtractTypeFromFlags(flags) == 0);
165 // Make sure that there are no register conflicts.
166 DCHECK(!scratch.is(receiver));
167 DCHECK(!scratch.is(name));
168 DCHECK(!extra.is(receiver));
169 DCHECK(!extra.is(name));
170 DCHECK(!extra.is(scratch));
171 DCHECK(!extra2.is(receiver));
172 DCHECK(!extra2.is(name));
173 DCHECK(!extra2.is(scratch));
174 DCHECK(!extra2.is(extra));
176 // Check register validity.
177 DCHECK(!scratch.is(no_reg));
178 DCHECK(!extra.is(no_reg));
179 DCHECK(!extra2.is(no_reg));
180 DCHECK(!extra3.is(no_reg));
182 Counters* counters = masm->isolate()->counters();
183 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1,
186 // Check that the receiver isn't a smi.
187 __ JumpIfSmi(receiver, &miss);
189 // Get the map of the receiver and compute the hash.
190 __ lw(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
191 __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset));
192 __ Addu(scratch, scratch, at);
193 uint32_t mask = kPrimaryTableSize - 1;
194 // We shift out the last two bits because they are not part of the hash and
195 // they are always 01 for maps.
196 __ srl(scratch, scratch, kCacheIndexShift);
197 __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask));
198 __ And(scratch, scratch, Operand(mask));
200 // Probe the primary table.
212 // Primary miss: Compute hash for secondary probe.
213 __ srl(at, name, kCacheIndexShift);
214 __ Subu(scratch, scratch, at);
215 uint32_t mask2 = kSecondaryTableSize - 1;
216 __ Addu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2));
217 __ And(scratch, scratch, Operand(mask2));
219 // Probe the secondary table.
231 // Cache miss: Fall-through and let caller handle the miss by
232 // entering the runtime system.
234 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1,
239 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
240 MacroAssembler* masm, int index, Register prototype, Label* miss) {
241 Isolate* isolate = masm->isolate();
242 // Get the global function with the given index.
243 Handle<JSFunction> function(
244 JSFunction::cast(isolate->native_context()->get(index)));
246 // Check we're still in the same context.
247 Register scratch = prototype;
248 const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
249 __ lw(scratch, MemOperand(cp, offset));
250 __ lw(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
251 __ lw(scratch, MemOperand(scratch, Context::SlotOffset(index)));
253 __ Branch(miss, ne, at, Operand(scratch));
255 // Load its initial map. The global functions all have initial maps.
256 __ li(prototype, Handle<Map>(function->initial_map()));
257 // Load the prototype from the initial map.
258 __ lw(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
262 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
263 MacroAssembler* masm, Register receiver, Register scratch1,
264 Register scratch2, Label* miss_label) {
265 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
266 __ Ret(USE_DELAY_SLOT);
267 __ mov(v0, scratch1);
271 void PropertyHandlerCompiler::GenerateCheckPropertyCell(
272 MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
273 Register scratch, Label* miss) {
274 Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
275 DCHECK(cell->value()->IsTheHole());
276 __ li(scratch, Operand(cell));
277 __ lw(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
278 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
279 __ Branch(miss, ne, scratch, Operand(at));
283 static void PushInterceptorArguments(MacroAssembler* masm,
287 Handle<JSObject> holder_obj) {
288 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
289 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
290 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
291 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
292 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
294 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
295 DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
296 Register scratch = name;
297 __ li(scratch, Operand(interceptor));
298 __ Push(scratch, receiver, holder);
302 static void CompileCallLoadPropertyWithInterceptor(
303 MacroAssembler* masm,
307 Handle<JSObject> holder_obj,
309 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
310 __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
311 NamedLoadHandlerCompiler::kInterceptorArgsLength);
315 // Generate call to api function.
316 void PropertyHandlerCompiler::GenerateFastApiCall(
317 MacroAssembler* masm, const CallOptimization& optimization,
318 Handle<Map> receiver_map, Register receiver, Register scratch_in,
319 bool is_store, int argc, Register* values) {
320 DCHECK(!receiver.is(scratch_in));
321 // Preparing to push, adjust sp.
322 __ Subu(sp, sp, Operand((argc + 1) * kPointerSize));
323 __ sw(receiver, MemOperand(sp, argc * kPointerSize)); // Push receiver.
324 // Write the arguments to stack frame.
325 for (int i = 0; i < argc; i++) {
326 Register arg = values[argc-1-i];
327 DCHECK(!receiver.is(arg));
328 DCHECK(!scratch_in.is(arg));
329 __ sw(arg, MemOperand(sp, (argc-1-i) * kPointerSize)); // Push arg.
331 DCHECK(optimization.is_simple_api_call());
333 // Abi for CallApiFunctionStub.
334 Register callee = a0;
335 Register call_data = t0;
336 Register holder = a2;
337 Register api_function_address = a1;
339 // Put holder in place.
340 CallOptimization::HolderLookup holder_lookup;
341 Handle<JSObject> api_holder = optimization.LookupHolderOfExpectedType(
344 switch (holder_lookup) {
345 case CallOptimization::kHolderIsReceiver:
346 __ Move(holder, receiver);
348 case CallOptimization::kHolderFound:
349 __ li(holder, api_holder);
351 case CallOptimization::kHolderNotFound:
356 Isolate* isolate = masm->isolate();
357 Handle<JSFunction> function = optimization.constant_function();
358 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
359 Handle<Object> call_data_obj(api_call_info->data(), isolate);
361 // Put callee in place.
362 __ li(callee, function);
364 bool call_data_undefined = false;
365 // Put call_data in place.
366 if (isolate->heap()->InNewSpace(*call_data_obj)) {
367 __ li(call_data, api_call_info);
368 __ lw(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
369 } else if (call_data_obj->IsUndefined()) {
370 call_data_undefined = true;
371 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
373 __ li(call_data, call_data_obj);
375 // Put api_function_address in place.
376 Address function_address = v8::ToCData<Address>(api_call_info->callback());
377 ApiFunction fun(function_address);
378 ExternalReference::Type type = ExternalReference::DIRECT_API_CALL;
379 ExternalReference ref = ExternalReference(&fun, type, masm->isolate());
380 __ li(api_function_address, Operand(ref));
383 CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
384 __ TailCallStub(&stub);
388 void PropertyAccessCompiler::GenerateTailCall(MacroAssembler* masm,
390 __ Jump(code, RelocInfo::CODE_TARGET);
395 #define __ ACCESS_MASM(masm())
398 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
400 if (!label->is_unused()) {
402 __ li(this->name(), Operand(name));
407 // Generate StoreTransition code, value is passed in a0 register.
408 // After executing generated code, the receiver_reg and name_reg
410 void NamedStoreHandlerCompiler::GenerateStoreTransition(
411 Handle<Map> transition, Handle<Name> name, Register receiver_reg,
412 Register storage_reg, Register value_reg, Register scratch1,
413 Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
417 int descriptor = transition->LastAdded();
418 DescriptorArray* descriptors = transition->instance_descriptors();
419 PropertyDetails details = descriptors->GetDetails(descriptor);
420 Representation representation = details.representation();
421 DCHECK(!representation.IsNone());
423 if (details.type() == CONSTANT) {
424 Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
425 __ li(scratch1, constant);
426 __ Branch(miss_label, ne, value_reg, Operand(scratch1));
427 } else if (representation.IsSmi()) {
428 __ JumpIfNotSmi(value_reg, miss_label);
429 } else if (representation.IsHeapObject()) {
430 __ JumpIfSmi(value_reg, miss_label);
431 HeapType* field_type = descriptors->GetFieldType(descriptor);
432 HeapType::Iterator<Map> it = field_type->Classes();
435 __ lw(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
438 // Do the CompareMap() directly within the Branch() functions.
439 current = it.Current();
442 __ Branch(miss_label, ne, scratch1, Operand(current));
445 __ Branch(&do_store, eq, scratch1, Operand(current));
449 } else if (representation.IsDouble()) {
450 Label do_store, heap_number;
451 __ LoadRoot(scratch3, Heap::kMutableHeapNumberMapRootIndex);
452 __ AllocateHeapNumber(storage_reg, scratch1, scratch2, scratch3, slow,
453 TAG_RESULT, MUTABLE);
455 __ JumpIfNotSmi(value_reg, &heap_number);
456 __ SmiUntag(scratch1, value_reg);
457 __ mtc1(scratch1, f6);
461 __ bind(&heap_number);
462 __ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex,
463 miss_label, DONT_DO_SMI_CHECK);
464 __ ldc1(f4, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
467 __ sdc1(f4, FieldMemOperand(storage_reg, HeapNumber::kValueOffset));
470 // Stub never generated for objects that require access checks.
471 DCHECK(!transition->is_access_check_needed());
473 // Perform map transition for the receiver if necessary.
474 if (details.type() == FIELD &&
475 Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
476 // The properties must be extended before we can store the value.
477 // We jump to a runtime call that extends the properties array.
478 __ push(receiver_reg);
479 __ li(a2, Operand(transition));
481 __ TailCallExternalReference(
482 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
488 // Update the map of the object.
489 __ li(scratch1, Operand(transition));
490 __ sw(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
492 // Update the write barrier for the map field.
493 __ RecordWriteField(receiver_reg,
494 HeapObject::kMapOffset,
502 if (details.type() == CONSTANT) {
503 DCHECK(value_reg.is(a0));
504 __ Ret(USE_DELAY_SLOT);
509 int index = transition->instance_descriptors()->GetFieldIndex(
510 transition->LastAdded());
512 // Adjust for the number of properties stored in the object. Even in the
513 // face of a transition we can use the old map here because the size of the
514 // object and the number of in-object properties is not going to change.
515 index -= transition->inobject_properties();
517 // TODO(verwaest): Share this code as a code stub.
518 SmiCheck smi_check = representation.IsTagged()
519 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
521 // Set the property straight into the object.
522 int offset = transition->instance_size() + (index * kPointerSize);
523 if (representation.IsDouble()) {
524 __ sw(storage_reg, FieldMemOperand(receiver_reg, offset));
526 __ sw(value_reg, FieldMemOperand(receiver_reg, offset));
529 if (!representation.IsSmi()) {
530 // Update the write barrier for the array address.
531 if (!representation.IsDouble()) {
532 __ mov(storage_reg, value_reg);
534 __ RecordWriteField(receiver_reg,
544 // Write to the properties array.
545 int offset = index * kPointerSize + FixedArray::kHeaderSize;
546 // Get the properties array
548 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
549 if (representation.IsDouble()) {
550 __ sw(storage_reg, FieldMemOperand(scratch1, offset));
552 __ sw(value_reg, FieldMemOperand(scratch1, offset));
555 if (!representation.IsSmi()) {
556 // Update the write barrier for the array address.
557 if (!representation.IsDouble()) {
558 __ mov(storage_reg, value_reg);
560 __ RecordWriteField(scratch1,
571 // Return the value (register v0).
572 DCHECK(value_reg.is(a0));
574 __ Ret(USE_DELAY_SLOT);
579 void NamedStoreHandlerCompiler::GenerateStoreField(LookupResult* lookup,
582 DCHECK(lookup->representation().IsHeapObject());
583 __ JumpIfSmi(value_reg, miss_label);
584 HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
585 __ lw(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
589 // Do the CompareMap() directly within the Branch() functions.
590 current = it.Current();
593 __ Branch(miss_label, ne, scratch1(), Operand(current));
596 __ Branch(&do_store, eq, scratch1(), Operand(current));
600 StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
601 lookup->representation());
602 GenerateTailCall(masm(), stub.GetCode());
606 Register PropertyHandlerCompiler::CheckPrototypes(
607 Register object_reg, Register holder_reg, Register scratch1,
608 Register scratch2, Handle<Name> name, Label* miss,
609 PrototypeCheckType check) {
610 Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
612 // Make sure there's no overlap between holder and object registers.
613 DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
614 DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
615 && !scratch2.is(scratch1));
617 // Keep track of the current object in register reg.
618 Register reg = object_reg;
621 Handle<JSObject> current = Handle<JSObject>::null();
622 if (type()->IsConstant()) {
623 current = Handle<JSObject>::cast(type()->AsConstant()->Value());
625 Handle<JSObject> prototype = Handle<JSObject>::null();
626 Handle<Map> current_map = receiver_map;
627 Handle<Map> holder_map(holder()->map());
628 // Traverse the prototype chain and check the maps in the prototype chain for
629 // fast and global objects or do negative lookup for normal objects.
630 while (!current_map.is_identical_to(holder_map)) {
633 // Only global objects and objects that do not require access
634 // checks are allowed in stubs.
635 DCHECK(current_map->IsJSGlobalProxyMap() ||
636 !current_map->is_access_check_needed());
638 prototype = handle(JSObject::cast(current_map->prototype()));
639 if (current_map->is_dictionary_map() &&
640 !current_map->IsJSGlobalObjectMap()) {
641 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
642 if (!name->IsUniqueName()) {
643 DCHECK(name->IsString());
644 name = factory()->InternalizeString(Handle<String>::cast(name));
646 DCHECK(current.is_null() ||
647 current->property_dictionary()->FindEntry(name) ==
648 NameDictionary::kNotFound);
650 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
653 __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
654 reg = holder_reg; // From now on the object will be in holder_reg.
655 __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
657 Register map_reg = scratch1;
658 if (depth != 1 || check == CHECK_ALL_MAPS) {
659 // CheckMap implicitly loads the map of |reg| into |map_reg|.
660 __ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK);
662 __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
665 // Check access rights to the global object. This has to happen after
666 // the map check so that we know that the object is actually a global
668 // This allows us to install generated handlers for accesses to the
669 // global proxy (as opposed to using slow ICs). See corresponding code
670 // in LookupForRead().
671 if (current_map->IsJSGlobalProxyMap()) {
672 __ CheckAccessGlobalProxy(reg, scratch2, miss);
673 } else if (current_map->IsJSGlobalObjectMap()) {
674 GenerateCheckPropertyCell(
675 masm(), Handle<JSGlobalObject>::cast(current), name,
679 reg = holder_reg; // From now on the object will be in holder_reg.
681 // Two possible reasons for loading the prototype from the map:
682 // (1) Can't store references to new space in code.
683 // (2) Handler is shared for all receivers with the same prototype
684 // map (but not necessarily the same prototype instance).
685 bool load_prototype_from_map =
686 heap()->InNewSpace(*prototype) || depth == 1;
687 if (load_prototype_from_map) {
688 __ lw(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
690 __ li(reg, Operand(prototype));
694 // Go to the next object in the prototype chain.
696 current_map = handle(current->map());
699 // Log the check depth.
700 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
702 if (depth != 0 || check == CHECK_ALL_MAPS) {
703 // Check the holder map.
704 __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
707 // Perform security check for access to the global object.
708 DCHECK(current_map->IsJSGlobalProxyMap() ||
709 !current_map->is_access_check_needed());
710 if (current_map->IsJSGlobalProxyMap()) {
711 __ CheckAccessGlobalProxy(reg, scratch1, miss);
714 // Return the register containing the holder.
719 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
720 if (!miss->is_unused()) {
724 TailCallBuiltin(masm(), MissBuiltin(kind()));
730 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
731 if (!miss->is_unused()) {
734 GenerateRestoreName(miss, name);
735 TailCallBuiltin(masm(), MissBuiltin(kind()));
741 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
742 // Return the constant value.
748 void NamedLoadHandlerCompiler::GenerateLoadCallback(
749 Register reg, Handle<ExecutableAccessorInfo> callback) {
750 // Build AccessorInfo::args_ list on the stack and push property name below
751 // the exit frame to make GC aware of them and store pointers to them.
752 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
753 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
754 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
755 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
756 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
757 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
758 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
759 DCHECK(!scratch2().is(reg));
760 DCHECK(!scratch3().is(reg));
761 DCHECK(!scratch4().is(reg));
763 if (heap()->InNewSpace(callback->data())) {
764 __ li(scratch3(), callback);
765 __ lw(scratch3(), FieldMemOperand(scratch3(),
766 ExecutableAccessorInfo::kDataOffset));
768 __ li(scratch3(), Handle<Object>(callback->data(), isolate()));
770 __ Subu(sp, sp, 6 * kPointerSize);
771 __ sw(scratch3(), MemOperand(sp, 5 * kPointerSize));
772 __ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
773 __ sw(scratch3(), MemOperand(sp, 4 * kPointerSize));
774 __ sw(scratch3(), MemOperand(sp, 3 * kPointerSize));
776 Operand(ExternalReference::isolate_address(isolate())));
777 __ sw(scratch4(), MemOperand(sp, 2 * kPointerSize));
778 __ sw(reg, MemOperand(sp, 1 * kPointerSize));
779 __ sw(name(), MemOperand(sp, 0 * kPointerSize));
780 __ Addu(scratch2(), sp, 1 * kPointerSize);
782 __ mov(a2, scratch2()); // Saved in case scratch2 == a1.
783 // Abi for CallApiGetter.
784 Register getter_address_reg = a2;
786 Address getter_address = v8::ToCData<Address>(callback->getter());
787 ApiFunction fun(getter_address);
788 ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
789 ExternalReference ref = ExternalReference(&fun, type, isolate());
790 __ li(getter_address_reg, Operand(ref));
792 CallApiGetterStub stub(isolate());
793 __ TailCallStub(&stub);
797 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg,
798 LookupResult* lookup,
800 DCHECK(holder()->HasNamedInterceptor());
801 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
803 // So far the most popular follow ups for interceptor loads are FIELD
804 // and CALLBACKS, so inline only them, other cases may be added
806 bool compile_followup_inline = false;
807 if (lookup->IsFound() && lookup->IsCacheable()) {
808 if (lookup->IsField()) {
809 compile_followup_inline = true;
810 } else if (lookup->type() == CALLBACKS &&
811 lookup->GetCallbackObject()->IsExecutableAccessorInfo()) {
812 Handle<ExecutableAccessorInfo> callback(
813 ExecutableAccessorInfo::cast(lookup->GetCallbackObject()));
814 compile_followup_inline =
815 callback->getter() != NULL &&
816 ExecutableAccessorInfo::IsCompatibleReceiverType(isolate(), callback,
821 if (compile_followup_inline) {
822 // Compile the interceptor call, followed by inline code to load the
823 // property from further up the prototype chain if the call fails.
824 // Check that the maps haven't changed.
825 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
827 // Preserve the receiver register explicitly whenever it is different from
828 // the holder and it is needed should the interceptor return without any
829 // result. The CALLBACKS case needs the receiver to be passed into C++ code,
830 // the FIELD case might cause a miss during the prototype check.
831 bool must_perfrom_prototype_check = *holder() != lookup->holder();
832 bool must_preserve_receiver_reg = !receiver().is(holder_reg) &&
833 (lookup->type() == CALLBACKS || must_perfrom_prototype_check);
835 // Save necessary data before invoking an interceptor.
836 // Requires a frame to make GC aware of pushed pointers.
838 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
839 if (must_preserve_receiver_reg) {
840 __ Push(receiver(), holder_reg, this->name());
842 __ Push(holder_reg, this->name());
844 // Invoke an interceptor. Note: map checks from receiver to
845 // interceptor's holder has been compiled before (see a caller
847 CompileCallLoadPropertyWithInterceptor(
848 masm(), receiver(), holder_reg, this->name(), holder(),
849 IC::kLoadPropertyWithInterceptorOnly);
851 // Check if interceptor provided a value for property. If it's
852 // the case, return immediately.
853 Label interceptor_failed;
854 __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
855 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
856 frame_scope.GenerateLeaveFrame();
859 __ bind(&interceptor_failed);
860 __ pop(this->name());
862 if (must_preserve_receiver_reg) {
865 // Leave the internal frame.
867 GenerateLoadPostInterceptor(holder_reg, name, lookup);
868 } else { // !compile_followup_inline
869 // Call the runtime system to load the interceptor.
870 // Check that the maps haven't changed.
871 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
874 ExternalReference ref = ExternalReference(
875 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
876 __ TailCallExternalReference(
877 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
882 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
883 Handle<JSObject> object, Handle<Name> name,
884 Handle<ExecutableAccessorInfo> callback) {
885 Register holder_reg = Frontend(receiver(), name);
887 __ Push(receiver(), holder_reg); // Receiver.
888 __ li(at, Operand(callback)); // Callback info.
890 __ li(at, Operand(name));
891 __ Push(at, value());
893 // Do tail-call to the runtime system.
894 ExternalReference store_callback_property =
895 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
896 __ TailCallExternalReference(store_callback_property, 5, 1);
898 // Return the generated code.
899 return GetCode(kind(), Code::FAST, name);
904 #define __ ACCESS_MASM(masm)
907 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
908 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
909 Handle<JSFunction> setter) {
910 // ----------- S t a t e -------------
911 // -- ra : return address
912 // -----------------------------------
914 FrameScope scope(masm, StackFrame::INTERNAL);
916 // Save value register, so we can restore it later.
919 if (!setter.is_null()) {
920 // Call the JavaScript setter with receiver and value on the stack.
921 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
922 // Swap in the global receiver.
924 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
926 __ Push(receiver, value());
927 ParameterCount actual(1);
928 ParameterCount expected(setter);
929 __ InvokeFunction(setter, expected, actual,
930 CALL_FUNCTION, NullCallWrapper());
932 // If we generate a global code snippet for deoptimization only, remember
933 // the place to continue after deoptimization.
934 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
937 // We have to return the passed value, not the return value of the setter.
940 // Restore context register.
941 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
948 #define __ ACCESS_MASM(masm())
951 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
953 __ Push(receiver(), this->name(), value());
955 // Do tail-call to the runtime system.
956 ExternalReference store_ic_property = ExternalReference(
957 IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
958 __ TailCallExternalReference(store_ic_property, 3, 1);
960 // Return the generated code.
961 return GetCode(kind(), Code::FAST, name);
965 Register* PropertyAccessCompiler::load_calling_convention() {
966 // receiver, name, scratch1, scratch2, scratch3, scratch4.
967 Register receiver = LoadIC::ReceiverRegister();
968 Register name = LoadIC::NameRegister();
969 static Register registers[] = { receiver, name, a3, a0, t0, t1 };
974 Register* PropertyAccessCompiler::store_calling_convention() {
975 // receiver, name, scratch1, scratch2, scratch3.
976 Register receiver = StoreIC::ReceiverRegister();
977 Register name = StoreIC::NameRegister();
978 DCHECK(a3.is(KeyedStoreIC::MapRegister()));
979 static Register registers[] = { receiver, name, a3, t0, t1 };
984 Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
988 #define __ ACCESS_MASM(masm)
991 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
992 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
993 Handle<JSFunction> getter) {
994 // ----------- S t a t e -------------
997 // -- ra : return address
998 // -----------------------------------
1000 FrameScope scope(masm, StackFrame::INTERNAL);
1002 if (!getter.is_null()) {
1003 // Call the JavaScript getter with the receiver on the stack.
1004 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
1005 // Swap in the global receiver.
1007 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
1010 ParameterCount actual(0);
1011 ParameterCount expected(getter);
1012 __ InvokeFunction(getter, expected, actual,
1013 CALL_FUNCTION, NullCallWrapper());
1015 // If we generate a global code snippet for deoptimization only, remember
1016 // the place to continue after deoptimization.
1017 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
1020 // Restore context register.
1021 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1028 #define __ ACCESS_MASM(masm())
1031 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
1032 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
1035 FrontendHeader(receiver(), name, &miss);
1037 // Get the value from the cell.
1038 Register result = StoreIC::ValueRegister();
1039 __ li(result, Operand(cell));
1040 __ lw(result, FieldMemOperand(result, Cell::kValueOffset));
1042 // Check for deleted property if property can actually be deleted.
1043 if (is_configurable) {
1044 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
1045 __ Branch(&miss, eq, result, Operand(at));
1048 Counters* counters = isolate()->counters();
1049 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
1050 __ Ret(USE_DELAY_SLOT);
1053 FrontendFooter(name, &miss);
1055 // Return the generated code.
1056 return GetCode(kind(), Code::NORMAL, name);
1060 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
1061 CodeHandleList* handlers,
1063 Code::StubType type,
1064 IcCheckType check) {
1067 if (check == PROPERTY &&
1068 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) {
1069 // In case we are compiling an IC for dictionary loads and stores, just
1070 // check whether the name is unique.
1071 if (name.is_identical_to(isolate()->factory()->normal_ic_symbol())) {
1072 __ JumpIfNotUniqueName(this->name(), &miss);
1074 __ Branch(&miss, ne, this->name(), Operand(name));
1079 Register match = scratch2();
1080 Label* smi_target = IncludesNumberType(types) ? &number_case : &miss;
1081 __ JumpIfSmi(receiver(), smi_target, match); // Reg match is 0 if Smi.
1083 // Polymorphic keyed stores may use the map register
1084 Register map_reg = scratch1();
1085 DCHECK(kind() != Code::KEYED_STORE_IC ||
1086 map_reg.is(KeyedStoreIC::MapRegister()));
1088 int receiver_count = types->length();
1089 int number_of_handled_maps = 0;
1090 __ lw(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
1091 for (int current = 0; current < receiver_count; ++current) {
1092 Handle<HeapType> type = types->at(current);
1093 Handle<Map> map = IC::TypeToMap(*type, isolate());
1094 if (!map->is_deprecated()) {
1095 number_of_handled_maps++;
1096 // Check map and tail call if there's a match.
1097 // Separate compare from branch, to provide path for above JumpIfSmi().
1098 __ Subu(match, map_reg, Operand(map));
1099 if (type->Is(HeapType::Number())) {
1100 DCHECK(!number_case.is_unused());
1101 __ bind(&number_case);
1103 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET,
1104 eq, match, Operand(zero_reg));
1107 DCHECK(number_of_handled_maps != 0);
1110 TailCallBuiltin(masm(), MissBuiltin(kind()));
1112 // Return the generated code.
1113 InlineCacheState state =
1114 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC;
1115 return GetCode(kind(), type, name, state);
1119 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
1120 MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
1121 MapHandleList* transitioned_maps) {
1123 __ JumpIfSmi(receiver(), &miss);
1125 int receiver_count = receiver_maps->length();
1126 __ lw(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
1127 for (int i = 0; i < receiver_count; ++i) {
1128 if (transitioned_maps->at(i).is_null()) {
1129 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
1130 scratch1(), Operand(receiver_maps->at(i)));
1133 __ Branch(&next_map, ne, scratch1(), Operand(receiver_maps->at(i)));
1134 __ li(transition_map(), Operand(transitioned_maps->at(i)));
1135 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
1141 TailCallBuiltin(masm(), MissBuiltin(kind()));
1143 // Return the generated code.
1144 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
1149 #define __ ACCESS_MASM(masm)
1152 void ElementHandlerCompiler::GenerateLoadDictionaryElement(
1153 MacroAssembler* masm) {
1154 // The return address is in ra.
1157 Register key = LoadIC::NameRegister();
1158 Register receiver = LoadIC::ReceiverRegister();
1159 DCHECK(receiver.is(a1));
1162 __ UntagAndJumpIfNotSmi(t2, key, &miss);
1163 __ lw(t0, FieldMemOperand(receiver, JSObject::kElementsOffset));
1164 __ LoadFromNumberDictionary(&slow, t0, key, v0, t2, a3, t1);
1167 // Slow case, key and receiver still unmodified.
1169 __ IncrementCounter(
1170 masm->isolate()->counters()->keyed_load_external_array_slow(),
1173 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
1175 // Miss case, call the runtime.
1178 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
1184 } } // namespace v8::internal
1186 #endif // V8_TARGET_ARCH_MIPS