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

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

Powered by Google App Engine
This is Rietveld 408576698