93106ea0e15c8f0d6ac3f069c89938bed190d752
[platform/upstream/nodejs.git] / deps / v8 / src / ic / mips / handler-compiler-mips.cc
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_MIPS
8
9 #include "src/ic/call-optimization.h"
10 #include "src/ic/handler-compiler.h"
11 #include "src/ic/ic.h"
12
13 namespace v8 {
14 namespace internal {
15
16 #define __ ACCESS_MASM(masm)
17
18
19 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
20     MacroAssembler* masm, Handle<Map> map, Register receiver, Register holder,
21     int accessor_index, int expected_arguments, Register scratch) {
22   // ----------- S t a t e -------------
23   //  -- a0    : receiver
24   //  -- a2    : name
25   //  -- ra    : return address
26   // -----------------------------------
27   {
28     FrameScope scope(masm, StackFrame::INTERNAL);
29
30     if (accessor_index >= 0) {
31       DCHECK(!holder.is(scratch));
32       DCHECK(!receiver.is(scratch));
33       // Call the JavaScript getter with the receiver on the stack.
34       if (map->IsJSGlobalObjectMap()) {
35         // Swap in the global receiver.
36         __ lw(scratch,
37               FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
38         receiver = scratch;
39       }
40       __ push(receiver);
41       ParameterCount actual(0);
42       ParameterCount expected(expected_arguments);
43       __ LoadAccessor(a1, holder, accessor_index, ACCESSOR_GETTER);
44       __ InvokeFunction(a1, expected, actual, CALL_FUNCTION, NullCallWrapper());
45     } else {
46       // If we generate a global code snippet for deoptimization only, remember
47       // the place to continue after deoptimization.
48       masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
49     }
50
51     // Restore context register.
52     __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
53   }
54   __ Ret();
55 }
56
57
58 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
59     MacroAssembler* masm, Handle<Map> map, Register receiver, Register holder,
60     int accessor_index, int expected_arguments, Register scratch) {
61   // ----------- S t a t e -------------
62   //  -- ra    : return address
63   // -----------------------------------
64   {
65     FrameScope scope(masm, StackFrame::INTERNAL);
66
67     // Save value register, so we can restore it later.
68     __ push(value());
69
70     if (accessor_index >= 0) {
71       DCHECK(!holder.is(scratch));
72       DCHECK(!receiver.is(scratch));
73       DCHECK(!value().is(scratch));
74       // Call the JavaScript setter with receiver and value on the stack.
75       if (map->IsJSGlobalObjectMap()) {
76         // Swap in the global receiver.
77         __ lw(scratch,
78               FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
79         receiver = scratch;
80       }
81       __ Push(receiver, value());
82       ParameterCount actual(1);
83       ParameterCount expected(expected_arguments);
84       __ LoadAccessor(a1, holder, accessor_index, ACCESSOR_SETTER);
85       __ InvokeFunction(a1, expected, actual, CALL_FUNCTION, NullCallWrapper());
86     } else {
87       // If we generate a global code snippet for deoptimization only, remember
88       // the place to continue after deoptimization.
89       masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
90     }
91
92     // We have to return the passed value, not the return value of the setter.
93     __ pop(v0);
94
95     // Restore context register.
96     __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
97   }
98   __ Ret();
99 }
100
101
102 void PropertyHandlerCompiler::PushVectorAndSlot(Register vector,
103                                                 Register slot) {
104   MacroAssembler* masm = this->masm();
105   __ Push(vector, slot);
106 }
107
108
109 void PropertyHandlerCompiler::PopVectorAndSlot(Register vector, Register slot) {
110   MacroAssembler* masm = this->masm();
111   __ Pop(vector, slot);
112 }
113
114
115 void PropertyHandlerCompiler::DiscardVectorAndSlot() {
116   MacroAssembler* masm = this->masm();
117   // Remove vector and slot.
118   __ Addu(sp, sp, Operand(2 * kPointerSize));
119 }
120
121
122 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
123     MacroAssembler* masm, Label* miss_label, Register receiver,
124     Handle<Name> name, Register scratch0, Register scratch1) {
125   DCHECK(name->IsUniqueName());
126   DCHECK(!receiver.is(scratch0));
127   Counters* counters = masm->isolate()->counters();
128   __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
129   __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
130
131   Label done;
132
133   const int kInterceptorOrAccessCheckNeededMask =
134   (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
135
136   // Bail out if the receiver has a named interceptor or requires access checks.
137   Register map = scratch1;
138   __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
139   __ lbu(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
140   __ And(scratch0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
141   __ Branch(miss_label, ne, scratch0, Operand(zero_reg));
142
143   // Check that receiver is a JSObject.
144   __ lbu(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
145   __ Branch(miss_label, lt, scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
146
147   // Load properties array.
148   Register properties = scratch0;
149   __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
150   // Check that the properties array is a dictionary.
151   __ lw(map, FieldMemOperand(properties, HeapObject::kMapOffset));
152   Register tmp = properties;
153   __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
154   __ Branch(miss_label, ne, map, Operand(tmp));
155
156   // Restore the temporarily used register.
157   __ lw(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
158
159
160   NameDictionaryLookupStub::GenerateNegativeLookup(
161       masm, miss_label, &done, receiver, properties, name, scratch1);
162   __ bind(&done);
163   __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
164 }
165
166
167 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
168     MacroAssembler* masm, int index, Register result, Label* miss) {
169   const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
170   __ lw(result, MemOperand(cp, offset));
171   __ lw(result, FieldMemOperand(result, GlobalObject::kNativeContextOffset));
172   __ lw(result, MemOperand(result, Context::SlotOffset(index)));
173   // Load its initial map. The global functions all have initial maps.
174   __ lw(result,
175         FieldMemOperand(result, JSFunction::kPrototypeOrInitialMapOffset));
176   // Load the prototype from the initial map.
177   __ lw(result, FieldMemOperand(result, Map::kPrototypeOffset));
178 }
179
180
181 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
182     MacroAssembler* masm, Register receiver, Register scratch1,
183     Register scratch2, Label* miss_label) {
184   __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
185   __ Ret(USE_DELAY_SLOT);
186   __ mov(v0, scratch1);
187 }
188
189
190 // Generate code to check that a global property cell is empty. Create
191 // the property cell at compilation time if no cell exists for the
192 // property.
193 void PropertyHandlerCompiler::GenerateCheckPropertyCell(
194     MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
195     Register scratch, Label* miss) {
196   Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
197   DCHECK(cell->value()->IsTheHole());
198   Handle<WeakCell> weak_cell = masm->isolate()->factory()->NewWeakCell(cell);
199   __ LoadWeakValue(scratch, weak_cell, miss);
200   __ lw(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
201   __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
202   __ Branch(miss, ne, scratch, Operand(at));
203 }
204
205
206 static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
207                                      Register holder, Register name,
208                                      Handle<JSObject> holder_obj) {
209   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
210   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 1);
211   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 2);
212   STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 3);
213   __ Push(name, receiver, holder);
214 }
215
216
217 static void CompileCallLoadPropertyWithInterceptor(
218     MacroAssembler* masm, Register receiver, Register holder, Register name,
219     Handle<JSObject> holder_obj, IC::UtilityId id) {
220   PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
221   __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
222                            NamedLoadHandlerCompiler::kInterceptorArgsLength);
223 }
224
225
226 // Generate call to api function.
227 void PropertyHandlerCompiler::GenerateApiAccessorCall(
228     MacroAssembler* masm, const CallOptimization& optimization,
229     Handle<Map> receiver_map, Register receiver, Register scratch_in,
230     bool is_store, Register store_parameter, Register accessor_holder,
231     int accessor_index) {
232   DCHECK(!accessor_holder.is(scratch_in));
233   DCHECK(!receiver.is(scratch_in));
234   __ push(receiver);
235   // Write the arguments to stack frame.
236   if (is_store) {
237     DCHECK(!receiver.is(store_parameter));
238     DCHECK(!scratch_in.is(store_parameter));
239     __ push(store_parameter);
240   }
241   DCHECK(optimization.is_simple_api_call());
242
243   // Abi for CallApiFunctionStub.
244   Register callee = a0;
245   Register data = t0;
246   Register holder = a2;
247   Register api_function_address = a1;
248
249   // Put callee in place.
250   __ LoadAccessor(callee, accessor_holder, accessor_index,
251                   is_store ? ACCESSOR_SETTER : ACCESSOR_GETTER);
252
253   // Put holder in place.
254   CallOptimization::HolderLookup holder_lookup;
255   int holder_depth = 0;
256   optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup,
257                                           &holder_depth);
258   switch (holder_lookup) {
259     case CallOptimization::kHolderIsReceiver:
260       __ Move(holder, receiver);
261       break;
262     case CallOptimization::kHolderFound:
263       __ lw(holder, FieldMemOperand(receiver, HeapObject::kMapOffset));
264       __ lw(holder, FieldMemOperand(holder, Map::kPrototypeOffset));
265       for (int i = 1; i < holder_depth; i++) {
266         __ lw(holder, FieldMemOperand(holder, HeapObject::kMapOffset));
267         __ lw(holder, FieldMemOperand(holder, Map::kPrototypeOffset));
268       }
269       break;
270     case CallOptimization::kHolderNotFound:
271       UNREACHABLE();
272       break;
273   }
274
275   Isolate* isolate = masm->isolate();
276   Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
277   bool call_data_undefined = false;
278   // Put call data in place.
279   if (api_call_info->data()->IsUndefined()) {
280     call_data_undefined = true;
281     __ LoadRoot(data, Heap::kUndefinedValueRootIndex);
282   } else {
283     __ lw(data, FieldMemOperand(callee, JSFunction::kSharedFunctionInfoOffset));
284     __ lw(data, FieldMemOperand(data, SharedFunctionInfo::kFunctionDataOffset));
285     __ lw(data, FieldMemOperand(data, FunctionTemplateInfo::kCallCodeOffset));
286     __ lw(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
287   }
288   // Put api_function_address in place.
289   Address function_address = v8::ToCData<Address>(api_call_info->callback());
290   ApiFunction fun(function_address);
291   ExternalReference::Type type = ExternalReference::DIRECT_API_CALL;
292   ExternalReference ref = ExternalReference(&fun, type, masm->isolate());
293   __ li(api_function_address, Operand(ref));
294
295   // Jump to stub.
296   CallApiAccessorStub stub(isolate, is_store, call_data_undefined);
297   __ TailCallStub(&stub);
298 }
299
300
301 void NamedStoreHandlerCompiler::GenerateSlow(MacroAssembler* masm) {
302   // Push receiver, key and value for runtime call.
303   __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(),
304           StoreDescriptor::ValueRegister());
305
306   // The slow case calls into the runtime to complete the store without causing
307   // an IC miss that would otherwise cause a transition to the generic stub.
308   ExternalReference ref =
309       ExternalReference(IC_Utility(IC::kStoreIC_Slow), masm->isolate());
310   __ TailCallExternalReference(ref, 3, 1);
311 }
312
313
314 void ElementHandlerCompiler::GenerateStoreSlow(MacroAssembler* masm) {
315   // Push receiver, key and value for runtime call.
316   __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(),
317           StoreDescriptor::ValueRegister());
318
319   // The slow case calls into the runtime to complete the store without causing
320   // an IC miss that would otherwise cause a transition to the generic stub.
321   ExternalReference ref =
322       ExternalReference(IC_Utility(IC::kKeyedStoreIC_Slow), masm->isolate());
323   __ TailCallExternalReference(ref, 3, 1);
324 }
325
326
327 #undef __
328 #define __ ACCESS_MASM(masm())
329
330
331 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
332                                                     Handle<Name> name) {
333   if (!label->is_unused()) {
334     __ bind(label);
335     __ li(this->name(), Operand(name));
336   }
337 }
338
339
340 void NamedStoreHandlerCompiler::GenerateRestoreName(Handle<Name> name) {
341   __ li(this->name(), Operand(name));
342 }
343
344
345 void NamedStoreHandlerCompiler::GenerateRestoreMap(Handle<Map> transition,
346                                                    Register scratch,
347                                                    Label* miss) {
348   Handle<WeakCell> cell = Map::WeakCellForMap(transition);
349   Register map_reg = StoreTransitionDescriptor::MapRegister();
350   DCHECK(!map_reg.is(scratch));
351   __ LoadWeakValue(map_reg, cell, miss);
352   if (transition->CanBeDeprecated()) {
353     __ lw(scratch, FieldMemOperand(map_reg, Map::kBitField3Offset));
354     __ And(at, scratch, Operand(Map::Deprecated::kMask));
355     __ Branch(miss, ne, at, Operand(zero_reg));
356   }
357 }
358
359
360 void NamedStoreHandlerCompiler::GenerateConstantCheck(Register map_reg,
361                                                       int descriptor,
362                                                       Register value_reg,
363                                                       Register scratch,
364                                                       Label* miss_label) {
365   DCHECK(!map_reg.is(scratch));
366   DCHECK(!map_reg.is(value_reg));
367   DCHECK(!value_reg.is(scratch));
368   __ LoadInstanceDescriptors(map_reg, scratch);
369   __ lw(scratch,
370         FieldMemOperand(scratch, DescriptorArray::GetValueOffset(descriptor)));
371   __ Branch(miss_label, ne, value_reg, Operand(scratch));
372 }
373
374
375 void NamedStoreHandlerCompiler::GenerateFieldTypeChecks(HeapType* field_type,
376                                                         Register value_reg,
377                                                         Label* miss_label) {
378   Register map_reg = scratch1();
379   Register scratch = scratch2();
380   DCHECK(!value_reg.is(map_reg));
381   DCHECK(!value_reg.is(scratch));
382   __ JumpIfSmi(value_reg, miss_label);
383   HeapType::Iterator<Map> it = field_type->Classes();
384   if (!it.Done()) {
385     __ lw(map_reg, FieldMemOperand(value_reg, HeapObject::kMapOffset));
386     Label do_store;
387     while (true) {
388       // Compare map directly within the Branch() functions.
389       __ GetWeakValue(scratch, Map::WeakCellForMap(it.Current()));
390       it.Advance();
391       if (it.Done()) {
392         __ Branch(miss_label, ne, map_reg, Operand(scratch));
393         break;
394       }
395       __ Branch(&do_store, eq, map_reg, Operand(scratch));
396     }
397     __ bind(&do_store);
398   }
399 }
400
401
402 Register PropertyHandlerCompiler::CheckPrototypes(
403     Register object_reg, Register holder_reg, Register scratch1,
404     Register scratch2, Handle<Name> name, Label* miss,
405     PrototypeCheckType check) {
406   Handle<Map> receiver_map = map();
407
408   // Make sure there's no overlap between holder and object registers.
409   DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
410   DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
411          !scratch2.is(scratch1));
412
413   // Keep track of the current object in register reg.
414   Register reg = object_reg;
415   int depth = 0;
416
417   Handle<JSObject> current = Handle<JSObject>::null();
418   if (receiver_map->IsJSGlobalObjectMap()) {
419     current = isolate()->global_object();
420   }
421   Handle<JSObject> prototype = Handle<JSObject>::null();
422   Handle<Map> current_map = receiver_map;
423   Handle<Map> holder_map(holder()->map());
424   // Traverse the prototype chain and check the maps in the prototype chain for
425   // fast and global objects or do negative lookup for normal objects.
426   while (!current_map.is_identical_to(holder_map)) {
427     ++depth;
428
429     // Only global objects and objects that do not require access
430     // checks are allowed in stubs.
431     DCHECK(current_map->IsJSGlobalProxyMap() ||
432            !current_map->is_access_check_needed());
433
434     prototype = handle(JSObject::cast(current_map->prototype()));
435     if (current_map->is_dictionary_map() &&
436         !current_map->IsJSGlobalObjectMap()) {
437       DCHECK(!current_map->IsJSGlobalProxyMap());  // Proxy maps are fast.
438       if (!name->IsUniqueName()) {
439         DCHECK(name->IsString());
440         name = factory()->InternalizeString(Handle<String>::cast(name));
441       }
442       DCHECK(current.is_null() ||
443              current->property_dictionary()->FindEntry(name) ==
444                  NameDictionary::kNotFound);
445
446       GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
447                                        scratch2);
448
449       __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
450       reg = holder_reg;  // From now on the object will be in holder_reg.
451       __ lw(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
452     } else {
453       Register map_reg = scratch1;
454       __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
455       if (depth != 1 || check == CHECK_ALL_MAPS) {
456         Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
457         __ GetWeakValue(scratch2, cell);
458         __ Branch(miss, ne, scratch2, Operand(map_reg));
459       }
460
461       // Check access rights to the global object.  This has to happen after
462       // the map check so that we know that the object is actually a global
463       // object.
464       // This allows us to install generated handlers for accesses to the
465       // global proxy (as opposed to using slow ICs). See corresponding code
466       // in LookupForRead().
467       if (current_map->IsJSGlobalProxyMap()) {
468         __ CheckAccessGlobalProxy(reg, scratch2, miss);
469       } else if (current_map->IsJSGlobalObjectMap()) {
470         GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
471                                   name, scratch2, miss);
472       }
473
474       reg = holder_reg;  // From now on the object will be in holder_reg.
475
476       __ lw(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
477     }
478
479     // Go to the next object in the prototype chain.
480     current = prototype;
481     current_map = handle(current->map());
482   }
483
484   // Log the check depth.
485   LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
486
487   if (depth != 0 || check == CHECK_ALL_MAPS) {
488     // Check the holder map.
489     __ lw(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
490     Handle<WeakCell> cell = Map::WeakCellForMap(current_map);
491     __ GetWeakValue(scratch2, cell);
492     __ Branch(miss, ne, scratch2, Operand(scratch1));
493   }
494
495   // Perform security check for access to the global object.
496   DCHECK(current_map->IsJSGlobalProxyMap() ||
497          !current_map->is_access_check_needed());
498   if (current_map->IsJSGlobalProxyMap()) {
499     __ CheckAccessGlobalProxy(reg, scratch1, miss);
500   }
501
502   // Return the register containing the holder.
503   return reg;
504 }
505
506
507 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
508   if (!miss->is_unused()) {
509     Label success;
510     __ Branch(&success);
511     __ bind(miss);
512     if (IC::ICUseVector(kind())) {
513       DCHECK(kind() == Code::LOAD_IC);
514       PopVectorAndSlot();
515     }
516     TailCallBuiltin(masm(), MissBuiltin(kind()));
517     __ bind(&success);
518   }
519 }
520
521
522 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
523   if (!miss->is_unused()) {
524     Label success;
525     __ Branch(&success);
526     GenerateRestoreName(miss, name);
527     TailCallBuiltin(masm(), MissBuiltin(kind()));
528     __ bind(&success);
529   }
530 }
531
532
533 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
534   // Return the constant value.
535   __ li(v0, value);
536   __ Ret();
537 }
538
539
540 void NamedLoadHandlerCompiler::GenerateLoadCallback(
541     Register reg, Handle<ExecutableAccessorInfo> callback) {
542   // Build AccessorInfo::args_ list on the stack and push property name below
543   // the exit frame to make GC aware of them and store pointers to them.
544   STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
545   STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
546   STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
547   STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
548   STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
549   STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
550   STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
551   DCHECK(!scratch2().is(reg));
552   DCHECK(!scratch3().is(reg));
553   DCHECK(!scratch4().is(reg));
554   __ push(receiver());
555   Handle<Object> data(callback->data(), isolate());
556   if (data->IsUndefined() || data->IsSmi()) {
557     __ li(scratch3(), data);
558   } else {
559     Handle<WeakCell> cell =
560         isolate()->factory()->NewWeakCell(Handle<HeapObject>::cast(data));
561     // The callback is alive if this instruction is executed,
562     // so the weak cell is not cleared and points to data.
563     __ GetWeakValue(scratch3(), cell);
564   }
565   __ Subu(sp, sp, 6 * kPointerSize);
566   __ sw(scratch3(), MemOperand(sp, 5 * kPointerSize));
567   __ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
568   __ sw(scratch3(), MemOperand(sp, 4 * kPointerSize));
569   __ sw(scratch3(), MemOperand(sp, 3 * kPointerSize));
570   __ li(scratch4(), Operand(ExternalReference::isolate_address(isolate())));
571   __ sw(scratch4(), MemOperand(sp, 2 * kPointerSize));
572   __ sw(reg, MemOperand(sp, 1 * kPointerSize));
573   __ sw(name(), MemOperand(sp, 0 * kPointerSize));
574   __ Addu(scratch2(), sp, 1 * kPointerSize);
575
576   __ mov(a2, scratch2());  // Saved in case scratch2 == a1.
577   // Abi for CallApiGetter.
578   Register getter_address_reg = ApiGetterDescriptor::function_address();
579
580   Address getter_address = v8::ToCData<Address>(callback->getter());
581   ApiFunction fun(getter_address);
582   ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
583   ExternalReference ref = ExternalReference(&fun, type, isolate());
584   __ li(getter_address_reg, Operand(ref));
585
586   CallApiGetterStub stub(isolate());
587   __ TailCallStub(&stub);
588 }
589
590
591 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
592     LookupIterator* it, Register holder_reg) {
593   DCHECK(holder()->HasNamedInterceptor());
594   DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
595
596   // Compile the interceptor call, followed by inline code to load the
597   // property from further up the prototype chain if the call fails.
598   // Check that the maps haven't changed.
599   DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
600
601   // Preserve the receiver register explicitly whenever it is different from the
602   // holder and it is needed should the interceptor return without any result.
603   // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
604   // case might cause a miss during the prototype check.
605   bool must_perform_prototype_check =
606       !holder().is_identical_to(it->GetHolder<JSObject>());
607   bool must_preserve_receiver_reg =
608       !receiver().is(holder_reg) &&
609       (it->state() == LookupIterator::ACCESSOR || must_perform_prototype_check);
610
611   // Save necessary data before invoking an interceptor.
612   // Requires a frame to make GC aware of pushed pointers.
613   {
614     FrameScope frame_scope(masm(), StackFrame::INTERNAL);
615     if (must_preserve_receiver_reg) {
616       __ Push(receiver(), holder_reg, this->name());
617     } else {
618       __ Push(holder_reg, this->name());
619     }
620     InterceptorVectorSlotPush(holder_reg);
621     // Invoke an interceptor.  Note: map checks from receiver to
622     // interceptor's holder has been compiled before (see a caller
623     // of this method).
624     CompileCallLoadPropertyWithInterceptor(
625         masm(), receiver(), holder_reg, this->name(), holder(),
626         IC::kLoadPropertyWithInterceptorOnly);
627
628     // Check if interceptor provided a value for property.  If it's
629     // the case, return immediately.
630     Label interceptor_failed;
631     __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
632     __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
633     frame_scope.GenerateLeaveFrame();
634     __ Ret();
635
636     __ bind(&interceptor_failed);
637     InterceptorVectorSlotPop(holder_reg);
638     if (must_preserve_receiver_reg) {
639       __ Pop(receiver(), holder_reg, this->name());
640     } else {
641       __ Pop(holder_reg, this->name());
642     }
643     // Leave the internal frame.
644   }
645
646   GenerateLoadPostInterceptor(it, holder_reg);
647 }
648
649
650 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
651   // Call the runtime system to load the interceptor.
652   DCHECK(holder()->HasNamedInterceptor());
653   DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
654   PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
655                            holder());
656
657   ExternalReference ref = ExternalReference(
658       IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
659   __ TailCallExternalReference(
660       ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
661 }
662
663
664 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
665     Handle<JSObject> object, Handle<Name> name,
666     Handle<ExecutableAccessorInfo> callback) {
667   Register holder_reg = Frontend(name);
668
669   __ Push(receiver(), holder_reg);  // Receiver.
670   // If the callback cannot leak, then push the callback directly,
671   // otherwise wrap it in a weak cell.
672   if (callback->data()->IsUndefined() || callback->data()->IsSmi()) {
673     __ li(at, Operand(callback));
674   } else {
675     Handle<WeakCell> cell = isolate()->factory()->NewWeakCell(callback);
676     __ li(at, Operand(cell));
677   }
678   __ push(at);
679   __ li(at, Operand(name));
680   __ Push(at, value());
681
682   // Do tail-call to the runtime system.
683   ExternalReference store_callback_property =
684       ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
685   __ TailCallExternalReference(store_callback_property, 5, 1);
686
687   // Return the generated code.
688   return GetCode(kind(), Code::FAST, name);
689 }
690
691
692 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
693     Handle<Name> name) {
694   __ Push(receiver(), this->name(), value());
695
696   // Do tail-call to the runtime system.
697   ExternalReference store_ic_property = ExternalReference(
698       IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
699   __ TailCallExternalReference(store_ic_property, 3, 1);
700
701   // Return the generated code.
702   return GetCode(kind(), Code::FAST, name);
703 }
704
705
706 Register NamedStoreHandlerCompiler::value() {
707   return StoreDescriptor::ValueRegister();
708 }
709
710
711 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
712     Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
713   Label miss;
714   if (IC::ICUseVector(kind())) {
715     PushVectorAndSlot();
716   }
717
718   FrontendHeader(receiver(), name, &miss);
719
720   // Get the value from the cell.
721   Register result = StoreDescriptor::ValueRegister();
722   Handle<WeakCell> weak_cell = factory()->NewWeakCell(cell);
723   __ LoadWeakValue(result, weak_cell, &miss);
724   __ lw(result, FieldMemOperand(result, Cell::kValueOffset));
725
726   // Check for deleted property if property can actually be deleted.
727   if (is_configurable) {
728     __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
729     __ Branch(&miss, eq, result, Operand(at));
730   }
731
732   Counters* counters = isolate()->counters();
733   __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
734   if (IC::ICUseVector(kind())) {
735     DiscardVectorAndSlot();
736   }
737   __ Ret(USE_DELAY_SLOT);
738   __ mov(v0, result);
739
740   FrontendFooter(name, &miss);
741
742   // Return the generated code.
743   return GetCode(kind(), Code::NORMAL, name);
744 }
745
746
747 #undef __
748 }
749 }  // namespace v8::internal
750
751 #endif  // V8_TARGET_ARCH_MIPS