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