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

Side by Side Diff: src/mips64/stub-cache-mips64.cc

Issue 496393002: MIPS: Move IC code into a subdir and move ic-compilation related code from stub-cache into ic-compi… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix formatting Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mips64/lithium-codegen-mips64.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "src/v8.h"
6
7 #if V8_TARGET_ARCH_MIPS64
8
9 #include "src/codegen.h"
10 #include "src/ic-inl.h"
11 #include "src/stub-cache.h"
12
13 namespace v8 {
14 namespace internal {
15
16 #define __ ACCESS_MASM(masm)
17
18
19 static void ProbeTable(Isolate* isolate,
20 MacroAssembler* masm,
21 Code::Flags flags,
22 StubCache::Table table,
23 Register receiver,
24 Register name,
25 // Number of the cache entry, not scaled.
26 Register offset,
27 Register scratch,
28 Register scratch2,
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));
33
34 uint64_t key_off_addr = reinterpret_cast<uint64_t>(key_offset.address());
35 uint64_t value_off_addr = reinterpret_cast<uint64_t>(value_offset.address());
36 uint64_t map_off_addr = reinterpret_cast<uint64_t>(map_offset.address());
37
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));
45
46 Label miss;
47 Register base_addr = scratch;
48 scratch = no_reg;
49
50 // Multiply by 3 because there are 3 fields per entry (name, code, map).
51 __ dsll(offset_scratch, offset, 1);
52 __ Daddu(offset_scratch, offset_scratch, offset);
53
54 // Calculate the base address of the entry.
55 __ li(base_addr, Operand(key_offset));
56 __ dsll(at, offset_scratch, kPointerSizeLog2);
57 __ Daddu(base_addr, base_addr, at);
58
59 // Check that the key in the entry matches the name.
60 __ ld(at, MemOperand(base_addr, 0));
61 __ Branch(&miss, ne, name, Operand(at));
62
63 // Check the map matches.
64 __ ld(at, MemOperand(base_addr, map_off_addr - key_off_addr));
65 __ ld(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset));
66 __ Branch(&miss, ne, at, Operand(scratch2));
67
68 // Get the code entry from the cache.
69 Register code = scratch2;
70 scratch2 = no_reg;
71 __ ld(code, MemOperand(base_addr, value_off_addr - key_off_addr));
72
73 // Check that the flags match what we're looking for.
74 Register flags_reg = base_addr;
75 base_addr = no_reg;
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));
79
80 #ifdef DEBUG
81 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
82 __ jmp(&miss);
83 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
84 __ jmp(&miss);
85 }
86 #endif
87
88 // Jump to the first instruction in the code stub.
89 __ Daddu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag));
90 __ Jump(at);
91
92 // Miss: fall through.
93 __ bind(&miss);
94 }
95
96
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);
105
106 Label done;
107
108 const int kInterceptorOrAccessCheckNeededMask =
109 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
110
111 // Bail out if the receiver has a named interceptor or requires access checks.
112 Register map = scratch1;
113 __ ld(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));
117
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));
121
122 // Load properties array.
123 Register properties = scratch0;
124 __ ld(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
125 // Check that the properties array is a dictionary.
126 __ ld(map, FieldMemOperand(properties, HeapObject::kMapOffset));
127 Register tmp = properties;
128 __ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
129 __ Branch(miss_label, ne, map, Operand(tmp));
130
131 // Restore the temporarily used register.
132 __ ld(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
133
134
135 NameDictionaryLookupStub::GenerateNegativeLookup(masm,
136 miss_label,
137 &done,
138 receiver,
139 properties,
140 name,
141 scratch1);
142 __ bind(&done);
143 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
144 }
145
146
147 void StubCache::GenerateProbe(MacroAssembler* masm,
148 Code::Flags flags,
149 Register receiver,
150 Register name,
151 Register scratch,
152 Register extra,
153 Register extra2,
154 Register extra3) {
155 Isolate* isolate = masm->isolate();
156 Label miss;
157
158 // Make sure that code is valid. The multiplying code relies on the
159 // entry size being 12.
160 // DCHECK(sizeof(Entry) == 12);
161 // DCHECK(sizeof(Entry) == 3 * kPointerSize);
162
163 // Make sure the flags does not name a specific type.
164 DCHECK(Code::ExtractTypeFromFlags(flags) == 0);
165
166 // Make sure that there are no register conflicts.
167 DCHECK(!scratch.is(receiver));
168 DCHECK(!scratch.is(name));
169 DCHECK(!extra.is(receiver));
170 DCHECK(!extra.is(name));
171 DCHECK(!extra.is(scratch));
172 DCHECK(!extra2.is(receiver));
173 DCHECK(!extra2.is(name));
174 DCHECK(!extra2.is(scratch));
175 DCHECK(!extra2.is(extra));
176
177 // Check register validity.
178 DCHECK(!scratch.is(no_reg));
179 DCHECK(!extra.is(no_reg));
180 DCHECK(!extra2.is(no_reg));
181 DCHECK(!extra3.is(no_reg));
182
183 Counters* counters = masm->isolate()->counters();
184 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1,
185 extra2, extra3);
186
187 // Check that the receiver isn't a smi.
188 __ JumpIfSmi(receiver, &miss);
189
190 // Get the map of the receiver and compute the hash.
191 __ ld(scratch, FieldMemOperand(name, Name::kHashFieldOffset));
192 __ ld(at, FieldMemOperand(receiver, HeapObject::kMapOffset));
193 __ Daddu(scratch, scratch, at);
194 uint64_t mask = kPrimaryTableSize - 1;
195 // We shift out the last two bits because they are not part of the hash and
196 // they are always 01 for maps.
197 __ dsrl(scratch, scratch, kCacheIndexShift);
198 __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask));
199 __ And(scratch, scratch, Operand(mask));
200
201 // Probe the primary table.
202 ProbeTable(isolate,
203 masm,
204 flags,
205 kPrimary,
206 receiver,
207 name,
208 scratch,
209 extra,
210 extra2,
211 extra3);
212
213 // Primary miss: Compute hash for secondary probe.
214 __ dsrl(at, name, kCacheIndexShift);
215 __ Dsubu(scratch, scratch, at);
216 uint64_t mask2 = kSecondaryTableSize - 1;
217 __ Daddu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2));
218 __ And(scratch, scratch, Operand(mask2));
219
220 // Probe the secondary table.
221 ProbeTable(isolate,
222 masm,
223 flags,
224 kSecondary,
225 receiver,
226 name,
227 scratch,
228 extra,
229 extra2,
230 extra3);
231
232 // Cache miss: Fall-through and let caller handle the miss by
233 // entering the runtime system.
234 __ bind(&miss);
235 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1,
236 extra2, extra3);
237 }
238
239
240 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
241 MacroAssembler* masm, int index, Register prototype, Label* miss) {
242 Isolate* isolate = masm->isolate();
243 // Get the global function with the given index.
244 Handle<JSFunction> function(
245 JSFunction::cast(isolate->native_context()->get(index)));
246
247 // Check we're still in the same context.
248 Register scratch = prototype;
249 const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
250 __ ld(scratch, MemOperand(cp, offset));
251 __ ld(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
252 __ ld(scratch, MemOperand(scratch, Context::SlotOffset(index)));
253 __ li(at, function);
254 __ Branch(miss, ne, at, Operand(scratch));
255
256 // Load its initial map. The global functions all have initial maps.
257 __ li(prototype, Handle<Map>(function->initial_map()));
258 // Load the prototype from the initial map.
259 __ ld(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
260 }
261
262
263 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
264 MacroAssembler* masm, Register receiver, Register scratch1,
265 Register scratch2, Label* miss_label) {
266 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
267 __ Ret(USE_DELAY_SLOT);
268 __ mov(v0, scratch1);
269 }
270
271
272 void PropertyHandlerCompiler::GenerateCheckPropertyCell(
273 MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
274 Register scratch, Label* miss) {
275 Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
276 DCHECK(cell->value()->IsTheHole());
277 __ li(scratch, Operand(cell));
278 __ ld(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
279 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
280 __ Branch(miss, ne, scratch, Operand(at));
281 }
282
283
284 static void PushInterceptorArguments(MacroAssembler* masm,
285 Register receiver,
286 Register holder,
287 Register name,
288 Handle<JSObject> holder_obj) {
289 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
290 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
291 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
292 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
293 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
294 __ push(name);
295 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
296 DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
297 Register scratch = name;
298 __ li(scratch, Operand(interceptor));
299 __ Push(scratch, receiver, holder);
300 }
301
302
303 static void CompileCallLoadPropertyWithInterceptor(
304 MacroAssembler* masm,
305 Register receiver,
306 Register holder,
307 Register name,
308 Handle<JSObject> holder_obj,
309 IC::UtilityId id) {
310 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
311 __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
312 NamedLoadHandlerCompiler::kInterceptorArgsLength);
313 }
314
315
316 // Generate call to api function.
317 void PropertyHandlerCompiler::GenerateFastApiCall(
318 MacroAssembler* masm, const CallOptimization& optimization,
319 Handle<Map> receiver_map, Register receiver, Register scratch_in,
320 bool is_store, int argc, Register* values) {
321 DCHECK(!receiver.is(scratch_in));
322 // Preparing to push, adjust sp.
323 __ Dsubu(sp, sp, Operand((argc + 1) * kPointerSize));
324 __ sd(receiver, MemOperand(sp, argc * kPointerSize)); // Push receiver.
325 // Write the arguments to stack frame.
326 for (int i = 0; i < argc; i++) {
327 Register arg = values[argc-1-i];
328 DCHECK(!receiver.is(arg));
329 DCHECK(!scratch_in.is(arg));
330 __ sd(arg, MemOperand(sp, (argc-1-i) * kPointerSize)); // Push arg.
331 }
332 DCHECK(optimization.is_simple_api_call());
333
334 // Abi for CallApiFunctionStub.
335 Register callee = a0;
336 Register call_data = a4;
337 Register holder = a2;
338 Register api_function_address = a1;
339
340 // Put holder in place.
341 CallOptimization::HolderLookup holder_lookup;
342 Handle<JSObject> api_holder = optimization.LookupHolderOfExpectedType(
343 receiver_map,
344 &holder_lookup);
345 switch (holder_lookup) {
346 case CallOptimization::kHolderIsReceiver:
347 __ Move(holder, receiver);
348 break;
349 case CallOptimization::kHolderFound:
350 __ li(holder, api_holder);
351 break;
352 case CallOptimization::kHolderNotFound:
353 UNREACHABLE();
354 break;
355 }
356
357 Isolate* isolate = masm->isolate();
358 Handle<JSFunction> function = optimization.constant_function();
359 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
360 Handle<Object> call_data_obj(api_call_info->data(), isolate);
361
362 // Put callee in place.
363 __ li(callee, function);
364
365 bool call_data_undefined = false;
366 // Put call_data in place.
367 if (isolate->heap()->InNewSpace(*call_data_obj)) {
368 __ li(call_data, api_call_info);
369 __ ld(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
370 } else if (call_data_obj->IsUndefined()) {
371 call_data_undefined = true;
372 __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
373 } else {
374 __ li(call_data, call_data_obj);
375 }
376 // Put api_function_address in place.
377 Address function_address = v8::ToCData<Address>(api_call_info->callback());
378 ApiFunction fun(function_address);
379 ExternalReference::Type type = ExternalReference::DIRECT_API_CALL;
380 ExternalReference ref =
381 ExternalReference(&fun,
382 type,
383 masm->isolate());
384 __ li(api_function_address, Operand(ref));
385
386 // Jump to stub.
387 CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
388 __ TailCallStub(&stub);
389 }
390
391
392 void PropertyAccessCompiler::GenerateTailCall(MacroAssembler* masm,
393 Handle<Code> code) {
394 __ Jump(code, RelocInfo::CODE_TARGET);
395 }
396
397
398 #undef __
399 #define __ ACCESS_MASM(masm())
400
401
402 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
403 Handle<Name> name) {
404 if (!label->is_unused()) {
405 __ bind(label);
406 __ li(this->name(), Operand(name));
407 }
408 }
409
410
411 // Generate StoreTransition code, value is passed in a0 register.
412 // After executing generated code, the receiver_reg and name_reg
413 // may be clobbered.
414 void NamedStoreHandlerCompiler::GenerateStoreTransition(
415 Handle<Map> transition, Handle<Name> name, Register receiver_reg,
416 Register storage_reg, Register value_reg, Register scratch1,
417 Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
418 // a0 : value.
419 Label exit;
420
421 int descriptor = transition->LastAdded();
422 DescriptorArray* descriptors = transition->instance_descriptors();
423 PropertyDetails details = descriptors->GetDetails(descriptor);
424 Representation representation = details.representation();
425 DCHECK(!representation.IsNone());
426
427 if (details.type() == CONSTANT) {
428 Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
429 __ li(scratch1, constant);
430 __ Branch(miss_label, ne, value_reg, Operand(scratch1));
431 } else if (representation.IsSmi()) {
432 __ JumpIfNotSmi(value_reg, miss_label);
433 } else if (representation.IsHeapObject()) {
434 __ JumpIfSmi(value_reg, miss_label);
435 HeapType* field_type = descriptors->GetFieldType(descriptor);
436 HeapType::Iterator<Map> it = field_type->Classes();
437 Handle<Map> current;
438 if (!it.Done()) {
439 __ ld(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
440 Label do_store;
441 while (true) {
442 // Do the CompareMap() directly within the Branch() functions.
443 current = it.Current();
444 it.Advance();
445 if (it.Done()) {
446 __ Branch(miss_label, ne, scratch1, Operand(current));
447 break;
448 }
449 __ Branch(&do_store, eq, scratch1, Operand(current));
450 }
451 __ bind(&do_store);
452 }
453 } else if (representation.IsDouble()) {
454 Label do_store, heap_number;
455 __ LoadRoot(scratch3, Heap::kMutableHeapNumberMapRootIndex);
456 __ AllocateHeapNumber(storage_reg, scratch1, scratch2, scratch3, slow,
457 TAG_RESULT, MUTABLE);
458
459 __ JumpIfNotSmi(value_reg, &heap_number);
460 __ SmiUntag(scratch1, value_reg);
461 __ mtc1(scratch1, f6);
462 __ cvt_d_w(f4, f6);
463 __ jmp(&do_store);
464
465 __ bind(&heap_number);
466 __ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex,
467 miss_label, DONT_DO_SMI_CHECK);
468 __ ldc1(f4, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
469
470 __ bind(&do_store);
471 __ sdc1(f4, FieldMemOperand(storage_reg, HeapNumber::kValueOffset));
472 }
473
474 // Stub never generated for objects that require access checks.
475 DCHECK(!transition->is_access_check_needed());
476
477 // Perform map transition for the receiver if necessary.
478 if (details.type() == FIELD &&
479 Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
480 // The properties must be extended before we can store the value.
481 // We jump to a runtime call that extends the properties array.
482 __ push(receiver_reg);
483 __ li(a2, Operand(transition));
484 __ Push(a2, a0);
485 __ TailCallExternalReference(
486 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
487 isolate()),
488 3, 1);
489 return;
490 }
491
492 // Update the map of the object.
493 __ li(scratch1, Operand(transition));
494 __ sd(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
495
496 // Update the write barrier for the map field.
497 __ RecordWriteField(receiver_reg,
498 HeapObject::kMapOffset,
499 scratch1,
500 scratch2,
501 kRAHasNotBeenSaved,
502 kDontSaveFPRegs,
503 OMIT_REMEMBERED_SET,
504 OMIT_SMI_CHECK);
505
506 if (details.type() == CONSTANT) {
507 DCHECK(value_reg.is(a0));
508 __ Ret(USE_DELAY_SLOT);
509 __ mov(v0, a0);
510 return;
511 }
512
513 int index = transition->instance_descriptors()->GetFieldIndex(
514 transition->LastAdded());
515
516 // Adjust for the number of properties stored in the object. Even in the
517 // face of a transition we can use the old map here because the size of the
518 // object and the number of in-object properties is not going to change.
519 index -= transition->inobject_properties();
520
521 // TODO(verwaest): Share this code as a code stub.
522 SmiCheck smi_check = representation.IsTagged()
523 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
524 if (index < 0) {
525 // Set the property straight into the object.
526 int offset = transition->instance_size() + (index * kPointerSize);
527 if (representation.IsDouble()) {
528 __ sd(storage_reg, FieldMemOperand(receiver_reg, offset));
529 } else {
530 __ sd(value_reg, FieldMemOperand(receiver_reg, offset));
531 }
532
533 if (!representation.IsSmi()) {
534 // Update the write barrier for the array address.
535 if (!representation.IsDouble()) {
536 __ mov(storage_reg, value_reg);
537 }
538 __ RecordWriteField(receiver_reg,
539 offset,
540 storage_reg,
541 scratch1,
542 kRAHasNotBeenSaved,
543 kDontSaveFPRegs,
544 EMIT_REMEMBERED_SET,
545 smi_check);
546 }
547 } else {
548 // Write to the properties array.
549 int offset = index * kPointerSize + FixedArray::kHeaderSize;
550 // Get the properties array
551 __ ld(scratch1,
552 FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
553 if (representation.IsDouble()) {
554 __ sd(storage_reg, FieldMemOperand(scratch1, offset));
555 } else {
556 __ sd(value_reg, FieldMemOperand(scratch1, offset));
557 }
558
559 if (!representation.IsSmi()) {
560 // Update the write barrier for the array address.
561 if (!representation.IsDouble()) {
562 __ mov(storage_reg, value_reg);
563 }
564 __ RecordWriteField(scratch1,
565 offset,
566 storage_reg,
567 receiver_reg,
568 kRAHasNotBeenSaved,
569 kDontSaveFPRegs,
570 EMIT_REMEMBERED_SET,
571 smi_check);
572 }
573 }
574
575 // Return the value (register v0).
576 DCHECK(value_reg.is(a0));
577 __ bind(&exit);
578 __ Ret(USE_DELAY_SLOT);
579 __ mov(v0, a0);
580 }
581
582
583 void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
584 Register value_reg,
585 Label* miss_label) {
586 DCHECK(lookup->representation().IsHeapObject());
587 __ JumpIfSmi(value_reg, miss_label);
588 HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
589 __ ld(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
590 Label do_store;
591 Handle<Map> current;
592 while (true) {
593 // Do the CompareMap() directly within the Branch() functions.
594 current = it.Current();
595 it.Advance();
596 if (it.Done()) {
597 __ Branch(miss_label, ne, scratch1(), Operand(current));
598 break;
599 }
600 __ Branch(&do_store, eq, scratch1(), Operand(current));
601 }
602 __ bind(&do_store);
603
604 StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
605 lookup->representation());
606 GenerateTailCall(masm(), stub.GetCode());
607 }
608
609
610 Register PropertyHandlerCompiler::CheckPrototypes(
611 Register object_reg, Register holder_reg, Register scratch1,
612 Register scratch2, Handle<Name> name, Label* miss,
613 PrototypeCheckType check) {
614 Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
615
616 // Make sure there's no overlap between holder and object registers.
617 DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
618 DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg)
619 && !scratch2.is(scratch1));
620
621 // Keep track of the current object in register reg.
622 Register reg = object_reg;
623 int depth = 0;
624
625 Handle<JSObject> current = Handle<JSObject>::null();
626 if (type()->IsConstant()) {
627 current = Handle<JSObject>::cast(type()->AsConstant()->Value());
628 }
629 Handle<JSObject> prototype = Handle<JSObject>::null();
630 Handle<Map> current_map = receiver_map;
631 Handle<Map> holder_map(holder()->map());
632 // Traverse the prototype chain and check the maps in the prototype chain for
633 // fast and global objects or do negative lookup for normal objects.
634 while (!current_map.is_identical_to(holder_map)) {
635 ++depth;
636
637 // Only global objects and objects that do not require access
638 // checks are allowed in stubs.
639 DCHECK(current_map->IsJSGlobalProxyMap() ||
640 !current_map->is_access_check_needed());
641
642 prototype = handle(JSObject::cast(current_map->prototype()));
643 if (current_map->is_dictionary_map() &&
644 !current_map->IsJSGlobalObjectMap()) {
645 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
646 if (!name->IsUniqueName()) {
647 DCHECK(name->IsString());
648 name = factory()->InternalizeString(Handle<String>::cast(name));
649 }
650 DCHECK(current.is_null() ||
651 current->property_dictionary()->FindEntry(name) ==
652 NameDictionary::kNotFound);
653
654 GenerateDictionaryNegativeLookup(masm(), miss, reg, name,
655 scratch1, scratch2);
656
657 __ ld(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
658 reg = holder_reg; // From now on the object will be in holder_reg.
659 __ ld(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
660 } else {
661 // Two possible reasons for loading the prototype from the map:
662 // (1) Can't store references to new space in code.
663 // (2) Handler is shared for all receivers with the same prototype
664 // map (but not necessarily the same prototype instance).
665 bool load_prototype_from_map =
666 heap()->InNewSpace(*prototype) || depth == 1;
667 Register map_reg = scratch1;
668 if (depth != 1 || check == CHECK_ALL_MAPS) {
669 // CheckMap implicitly loads the map of |reg| into |map_reg|.
670 __ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK);
671 } else {
672 __ ld(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
673 }
674
675 // Check access rights to the global object. This has to happen after
676 // the map check so that we know that the object is actually a global
677 // object.
678 // This allows us to install generated handlers for accesses to the
679 // global proxy (as opposed to using slow ICs). See corresponding code
680 // in LookupForRead().
681 if (current_map->IsJSGlobalProxyMap()) {
682 __ CheckAccessGlobalProxy(reg, scratch2, miss);
683 } else if (current_map->IsJSGlobalObjectMap()) {
684 GenerateCheckPropertyCell(
685 masm(), Handle<JSGlobalObject>::cast(current), name,
686 scratch2, miss);
687 }
688
689 reg = holder_reg; // From now on the object will be in holder_reg.
690
691 if (load_prototype_from_map) {
692 __ ld(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
693 } else {
694 __ li(reg, Operand(prototype));
695 }
696 }
697
698 // Go to the next object in the prototype chain.
699 current = prototype;
700 current_map = handle(current->map());
701 }
702
703 // Log the check depth.
704 LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
705
706 if (depth != 0 || check == CHECK_ALL_MAPS) {
707 // Check the holder map.
708 __ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
709 }
710
711 // Perform security check for access to the global object.
712 DCHECK(current_map->IsJSGlobalProxyMap() ||
713 !current_map->is_access_check_needed());
714 if (current_map->IsJSGlobalProxyMap()) {
715 __ CheckAccessGlobalProxy(reg, scratch1, miss);
716 }
717
718 // Return the register containing the holder.
719 return reg;
720 }
721
722
723 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
724 if (!miss->is_unused()) {
725 Label success;
726 __ Branch(&success);
727 __ bind(miss);
728 TailCallBuiltin(masm(), MissBuiltin(kind()));
729 __ bind(&success);
730 }
731 }
732
733
734 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
735 if (!miss->is_unused()) {
736 Label success;
737 __ Branch(&success);
738 GenerateRestoreName(miss, name);
739 TailCallBuiltin(masm(), MissBuiltin(kind()));
740 __ bind(&success);
741 }
742 }
743
744
745 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
746 // Return the constant value.
747 __ li(v0, value);
748 __ Ret();
749 }
750
751
752 void NamedLoadHandlerCompiler::GenerateLoadCallback(
753 Register reg, Handle<ExecutableAccessorInfo> callback) {
754 // Build AccessorInfo::args_ list on the stack and push property name below
755 // the exit frame to make GC aware of them and store pointers to them.
756 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
757 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
758 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
759 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
760 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
761 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
762 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
763 DCHECK(!scratch2().is(reg));
764 DCHECK(!scratch3().is(reg));
765 DCHECK(!scratch4().is(reg));
766 __ push(receiver());
767 if (heap()->InNewSpace(callback->data())) {
768 __ li(scratch3(), callback);
769 __ ld(scratch3(), FieldMemOperand(scratch3(),
770 ExecutableAccessorInfo::kDataOffset));
771 } else {
772 __ li(scratch3(), Handle<Object>(callback->data(), isolate()));
773 }
774 __ Dsubu(sp, sp, 6 * kPointerSize);
775 __ sd(scratch3(), MemOperand(sp, 5 * kPointerSize));
776 __ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
777 __ sd(scratch3(), MemOperand(sp, 4 * kPointerSize));
778 __ sd(scratch3(), MemOperand(sp, 3 * kPointerSize));
779 __ li(scratch4(),
780 Operand(ExternalReference::isolate_address(isolate())));
781 __ sd(scratch4(), MemOperand(sp, 2 * kPointerSize));
782 __ sd(reg, MemOperand(sp, 1 * kPointerSize));
783 __ sd(name(), MemOperand(sp, 0 * kPointerSize));
784 __ Daddu(scratch2(), sp, 1 * kPointerSize);
785
786 __ mov(a2, scratch2()); // Saved in case scratch2 == a1.
787 // Abi for CallApiGetter.
788 Register getter_address_reg = a2;
789
790 Address getter_address = v8::ToCData<Address>(callback->getter());
791 ApiFunction fun(getter_address);
792 ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
793 ExternalReference ref = ExternalReference(&fun, type, isolate());
794 __ li(getter_address_reg, Operand(ref));
795
796 CallApiGetterStub stub(isolate());
797 __ TailCallStub(&stub);
798 }
799
800
801 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
802 LookupIterator* it, Register holder_reg) {
803 DCHECK(holder()->HasNamedInterceptor());
804 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
805
806 // Compile the interceptor call, followed by inline code to load the
807 // property from further up the prototype chain if the call fails.
808 // Check that the maps haven't changed.
809 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
810
811 // Preserve the receiver register explicitly whenever it is different from the
812 // holder and it is needed should the interceptor return without any result.
813 // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
814 // case might cause a miss during the prototype check.
815 bool must_perform_prototype_check =
816 !holder().is_identical_to(it->GetHolder<JSObject>());
817 bool must_preserve_receiver_reg =
818 !receiver().is(holder_reg) &&
819 (it->property_kind() == LookupIterator::ACCESSOR ||
820 must_perform_prototype_check);
821
822 // Save necessary data before invoking an interceptor.
823 // Requires a frame to make GC aware of pushed pointers.
824 {
825 FrameScope frame_scope(masm(), StackFrame::INTERNAL);
826 if (must_preserve_receiver_reg) {
827 __ Push(receiver(), holder_reg, this->name());
828 } else {
829 __ Push(holder_reg, this->name());
830 }
831 // Invoke an interceptor. Note: map checks from receiver to
832 // interceptor's holder has been compiled before (see a caller
833 // of this method).
834 CompileCallLoadPropertyWithInterceptor(
835 masm(), receiver(), holder_reg, this->name(), holder(),
836 IC::kLoadPropertyWithInterceptorOnly);
837
838 // Check if interceptor provided a value for property. If it's
839 // the case, return immediately.
840 Label interceptor_failed;
841 __ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
842 __ Branch(&interceptor_failed, eq, v0, Operand(scratch1()));
843 frame_scope.GenerateLeaveFrame();
844 __ Ret();
845
846 __ bind(&interceptor_failed);
847 if (must_preserve_receiver_reg) {
848 __ Pop(receiver(), holder_reg, this->name());
849 } else {
850 __ Pop(holder_reg, this->name());
851 }
852 // Leave the internal frame.
853 }
854
855 GenerateLoadPostInterceptor(it, holder_reg);
856 }
857
858
859 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
860 // Call the runtime system to load the interceptor.
861 DCHECK(holder()->HasNamedInterceptor());
862 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
863 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
864 holder());
865
866 ExternalReference ref = ExternalReference(
867 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
868 __ TailCallExternalReference(
869 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
870 }
871
872
873 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
874 Handle<JSObject> object, Handle<Name> name,
875 Handle<ExecutableAccessorInfo> callback) {
876 Register holder_reg = Frontend(receiver(), name);
877
878 __ Push(receiver(), holder_reg); // Receiver.
879 __ li(at, Operand(callback)); // Callback info.
880 __ push(at);
881 __ li(at, Operand(name));
882 __ Push(at, value());
883
884 // Do tail-call to the runtime system.
885 ExternalReference store_callback_property =
886 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
887 __ TailCallExternalReference(store_callback_property, 5, 1);
888
889 // Return the generated code.
890 return GetCode(kind(), Code::FAST, name);
891 }
892
893
894 #undef __
895 #define __ ACCESS_MASM(masm)
896
897
898 void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
899 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
900 Handle<JSFunction> setter) {
901 // ----------- S t a t e -------------
902 // -- ra : return address
903 // -----------------------------------
904 {
905 FrameScope scope(masm, StackFrame::INTERNAL);
906
907 // Save value register, so we can restore it later.
908 __ push(value());
909
910 if (!setter.is_null()) {
911 // Call the JavaScript setter with receiver and value on the stack.
912 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
913 // Swap in the global receiver.
914 __ ld(receiver,
915 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
916 }
917 __ Push(receiver, value());
918 ParameterCount actual(1);
919 ParameterCount expected(setter);
920 __ InvokeFunction(setter, expected, actual,
921 CALL_FUNCTION, NullCallWrapper());
922 } else {
923 // If we generate a global code snippet for deoptimization only, remember
924 // the place to continue after deoptimization.
925 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
926 }
927
928 // We have to return the passed value, not the return value of the setter.
929 __ pop(v0);
930
931 // Restore context register.
932 __ ld(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
933 }
934 __ Ret();
935 }
936
937
938 #undef __
939 #define __ ACCESS_MASM(masm())
940
941
942 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
943 Handle<Name> name) {
944 __ Push(receiver(), this->name(), value());
945
946 // Do tail-call to the runtime system.
947 ExternalReference store_ic_property = ExternalReference(
948 IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
949 __ TailCallExternalReference(store_ic_property, 3, 1);
950
951 // Return the generated code.
952 return GetCode(kind(), Code::FAST, name);
953 }
954
955
956 Register* PropertyAccessCompiler::load_calling_convention() {
957 // receiver, name, scratch1, scratch2, scratch3, scratch4.
958 Register receiver = LoadIC::ReceiverRegister();
959 Register name = LoadIC::NameRegister();
960 static Register registers[] = { receiver, name, a3, a0, a4, a5 };
961 return registers;
962 }
963
964
965 Register* PropertyAccessCompiler::store_calling_convention() {
966 // receiver, name, scratch1, scratch2, scratch3.
967 Register receiver = StoreIC::ReceiverRegister();
968 Register name = StoreIC::NameRegister();
969 DCHECK(a3.is(KeyedStoreIC::MapRegister()));
970 static Register registers[] = { receiver, name, a3, a4, a5 };
971 return registers;
972 }
973
974
975 Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
976
977
978 #undef __
979 #define __ ACCESS_MASM(masm)
980
981
982 void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
983 MacroAssembler* masm, Handle<HeapType> type, Register receiver,
984 Handle<JSFunction> getter) {
985 // ----------- S t a t e -------------
986 // -- a0 : receiver
987 // -- a2 : name
988 // -- ra : return address
989 // -----------------------------------
990 {
991 FrameScope scope(masm, StackFrame::INTERNAL);
992
993 if (!getter.is_null()) {
994 // Call the JavaScript getter with the receiver on the stack.
995 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
996 // Swap in the global receiver.
997 __ ld(receiver,
998 FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
999 }
1000 __ push(receiver);
1001 ParameterCount actual(0);
1002 ParameterCount expected(getter);
1003 __ InvokeFunction(getter, expected, actual,
1004 CALL_FUNCTION, NullCallWrapper());
1005 } else {
1006 // If we generate a global code snippet for deoptimization only, remember
1007 // the place to continue after deoptimization.
1008 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
1009 }
1010
1011 // Restore context register.
1012 __ ld(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
1013 }
1014 __ Ret();
1015 }
1016
1017
1018 #undef __
1019 #define __ ACCESS_MASM(masm())
1020
1021
1022 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
1023 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
1024 Label miss;
1025
1026 FrontendHeader(receiver(), name, &miss);
1027
1028 // Get the value from the cell.
1029 Register result = StoreIC::ValueRegister();
1030 __ li(result, Operand(cell));
1031 __ ld(result, FieldMemOperand(result, Cell::kValueOffset));
1032
1033 // Check for deleted property if property can actually be deleted.
1034 if (is_configurable) {
1035 __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
1036 __ Branch(&miss, eq, result, Operand(at));
1037 }
1038
1039 Counters* counters = isolate()->counters();
1040 __ IncrementCounter(counters->named_load_global_stub(), 1, a1, a3);
1041 __ Ret(USE_DELAY_SLOT);
1042 __ mov(v0, result);
1043
1044 FrontendFooter(name, &miss);
1045
1046 // Return the generated code.
1047 return GetCode(kind(), Code::NORMAL, name);
1048 }
1049
1050
1051 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
1052 CodeHandleList* handlers,
1053 Handle<Name> name,
1054 Code::StubType type,
1055 IcCheckType check) {
1056 Label miss;
1057
1058 if (check == PROPERTY &&
1059 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) {
1060 // In case we are compiling an IC for dictionary loads and stores, just
1061 // check whether the name is unique.
1062 if (name.is_identical_to(isolate()->factory()->normal_ic_symbol())) {
1063 __ JumpIfNotUniqueName(this->name(), &miss);
1064 } else {
1065 __ Branch(&miss, ne, this->name(), Operand(name));
1066 }
1067 }
1068
1069 Label number_case;
1070 Register match = scratch2();
1071 Label* smi_target = IncludesNumberType(types) ? &number_case : &miss;
1072 __ JumpIfSmi(receiver(), smi_target, match); // Reg match is 0 if Smi.
1073
1074 // Polymorphic keyed stores may use the map register
1075 Register map_reg = scratch1();
1076 DCHECK(kind() != Code::KEYED_STORE_IC ||
1077 map_reg.is(KeyedStoreIC::MapRegister()));
1078
1079 int receiver_count = types->length();
1080 int number_of_handled_maps = 0;
1081 __ ld(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
1082 for (int current = 0; current < receiver_count; ++current) {
1083 Handle<HeapType> type = types->at(current);
1084 Handle<Map> map = IC::TypeToMap(*type, isolate());
1085 if (!map->is_deprecated()) {
1086 number_of_handled_maps++;
1087 // Check map and tail call if there's a match.
1088 // Separate compare from branch, to provide path for above JumpIfSmi().
1089 __ Dsubu(match, map_reg, Operand(map));
1090 if (type->Is(HeapType::Number())) {
1091 DCHECK(!number_case.is_unused());
1092 __ bind(&number_case);
1093 }
1094 __ Jump(handlers->at(current), RelocInfo::CODE_TARGET,
1095 eq, match, Operand(zero_reg));
1096 }
1097 }
1098 DCHECK(number_of_handled_maps != 0);
1099
1100 __ bind(&miss);
1101 TailCallBuiltin(masm(), MissBuiltin(kind()));
1102
1103 // Return the generated code.
1104 InlineCacheState state =
1105 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC;
1106 return GetCode(kind(), type, name, state);
1107 }
1108
1109
1110 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
1111 MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
1112 MapHandleList* transitioned_maps) {
1113 Label miss;
1114 __ JumpIfSmi(receiver(), &miss);
1115
1116 int receiver_count = receiver_maps->length();
1117 __ ld(scratch1(), FieldMemOperand(receiver(), HeapObject::kMapOffset));
1118 for (int i = 0; i < receiver_count; ++i) {
1119 if (transitioned_maps->at(i).is_null()) {
1120 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq,
1121 scratch1(), Operand(receiver_maps->at(i)));
1122 } else {
1123 Label next_map;
1124 __ Branch(&next_map, ne, scratch1(), Operand(receiver_maps->at(i)));
1125 __ li(transition_map(), Operand(transitioned_maps->at(i)));
1126 __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
1127 __ bind(&next_map);
1128 }
1129 }
1130
1131 __ bind(&miss);
1132 TailCallBuiltin(masm(), MissBuiltin(kind()));
1133
1134 // Return the generated code.
1135 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
1136 }
1137
1138
1139 #undef __
1140 #define __ ACCESS_MASM(masm)
1141
1142
1143 void ElementHandlerCompiler::GenerateLoadDictionaryElement(
1144 MacroAssembler* masm) {
1145 // The return address is in ra
1146 Label slow, miss;
1147
1148 Register key = LoadIC::NameRegister();
1149 Register receiver = LoadIC::ReceiverRegister();
1150 DCHECK(receiver.is(a1));
1151 DCHECK(key.is(a2));
1152
1153 __ UntagAndJumpIfNotSmi(a6, key, &miss);
1154 __ ld(a4, FieldMemOperand(receiver, JSObject::kElementsOffset));
1155 DCHECK(kSmiTagSize + kSmiShiftSize == 32);
1156 __ LoadFromNumberDictionary(&slow, a4, key, v0, a6, a3, a5);
1157 __ Ret();
1158
1159 // Slow case, key and receiver still unmodified.
1160 __ bind(&slow);
1161 __ IncrementCounter(
1162 masm->isolate()->counters()->keyed_load_external_array_slow(),
1163 1, a2, a3);
1164
1165 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
1166
1167 // Miss case, call the runtime.
1168 __ bind(&miss);
1169
1170 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
1171 }
1172
1173
1174 #undef __
1175
1176 } } // namespace v8::internal
1177
1178 #endif // V8_TARGET_ARCH_MIPS64
OLDNEW
« no previous file with comments | « src/mips64/lithium-codegen-mips64.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698