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

Side by Side Diff: src/arm/code-stubs-arm.cc

Issue 12385014: Hydrogen stubs for array constructors (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 7 years, 8 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 CodeStubInterfaceDescriptor* descriptor) { 89 CodeStubInterfaceDescriptor* descriptor) {
90 static Register registers[] = { r0, r1 }; 90 static Register registers[] = { r0, r1 };
91 descriptor->register_param_count_ = 2; 91 descriptor->register_param_count_ = 2;
92 descriptor->register_params_ = registers; 92 descriptor->register_params_ = registers;
93 Address entry = 93 Address entry =
94 Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; 94 Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry;
95 descriptor->deoptimization_handler_ = FUNCTION_ADDR(entry); 95 descriptor->deoptimization_handler_ = FUNCTION_ADDR(entry);
96 } 96 }
97 97
98 98
99 static void InitializeArrayConstructorDescriptor(Isolate* isolate, 99 static void InitializeArrayConstructorDescriptor(
100 CodeStubInterfaceDescriptor* descriptor) { 100 Isolate* isolate,
101 CodeStubInterfaceDescriptor* descriptor,
102 int constant_stack_parameter_count) {
Hannes Payer (out of office) 2013/04/23 11:42:50 can you describe the semantic of constant_stack_pa
101 // register state 103 // register state
102 // r1 -- constructor function
103 // r2 -- type info cell with elements kind 104 // r2 -- type info cell with elements kind
Hannes Payer (out of office) 2013/04/23 11:42:50 do you want to bring back the comment for r0? sinc
mvstanton 2013/04/23 14:19:58 good point, thx, done.
104 // r0 -- number of arguments to the constructor function 105 static Register registers[] = { r2 };
105 static Register registers[] = { r1, r2 }; 106 descriptor->register_param_count_ = 1;
106 descriptor->register_param_count_ = 2; 107 if (constant_stack_parameter_count != 0) {
107 // stack param count needs (constructor pointer, and single argument) 108 // stack param count needs (constructor pointer, and single argument)
108 descriptor->stack_parameter_count_ = &r0; 109 descriptor->stack_parameter_count_ = &r0;
110 }
111 descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count;
109 descriptor->register_params_ = registers; 112 descriptor->register_params_ = registers;
110 descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; 113 descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
111 descriptor->deoptimization_handler_ = 114 descriptor->deoptimization_handler_ =
112 FUNCTION_ADDR(ArrayConstructor_StubFailure); 115 FUNCTION_ADDR(ArrayConstructor_StubFailure);
113 } 116 }
114 117
115 118
116 void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( 119 void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor(
117 Isolate* isolate, 120 Isolate* isolate,
118 CodeStubInterfaceDescriptor* descriptor) { 121 CodeStubInterfaceDescriptor* descriptor) {
119 InitializeArrayConstructorDescriptor(isolate, descriptor); 122 InitializeArrayConstructorDescriptor(isolate, descriptor, 0);
120 } 123 }
121 124
122 125
123 void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( 126 void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor(
124 Isolate* isolate, 127 Isolate* isolate,
125 CodeStubInterfaceDescriptor* descriptor) { 128 CodeStubInterfaceDescriptor* descriptor) {
126 InitializeArrayConstructorDescriptor(isolate, descriptor); 129 InitializeArrayConstructorDescriptor(isolate, descriptor, 1);
127 } 130 }
128 131
129 132
130 void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( 133 void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor(
131 Isolate* isolate, 134 Isolate* isolate,
132 CodeStubInterfaceDescriptor* descriptor) { 135 CodeStubInterfaceDescriptor* descriptor) {
133 InitializeArrayConstructorDescriptor(isolate, descriptor); 136 InitializeArrayConstructorDescriptor(isolate, descriptor, -1);
134 } 137 }
135 138
136 139
137 #define __ ACCESS_MASM(masm) 140 #define __ ACCESS_MASM(masm)
138 141
139 static void EmitIdenticalObjectComparison(MacroAssembler* masm, 142 static void EmitIdenticalObjectComparison(MacroAssembler* masm,
140 Label* slow, 143 Label* slow,
141 Condition cond); 144 Condition cond);
142 static void EmitSmiNonsmiComparison(MacroAssembler* masm, 145 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
143 Register lhs, 146 Register lhs,
(...skipping 3243 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 result_size_ == 1; 3390 result_size_ == 1;
3388 } 3391 }
3389 3392
3390 3393
3391 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { 3394 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
3392 CEntryStub::GenerateAheadOfTime(isolate); 3395 CEntryStub::GenerateAheadOfTime(isolate);
3393 WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate); 3396 WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate);
3394 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); 3397 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
3395 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); 3398 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
3396 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); 3399 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate);
3400 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
3397 } 3401 }
3398 3402
3399 3403
3400 void CodeStub::GenerateFPStubs(Isolate* isolate) { 3404 void CodeStub::GenerateFPStubs(Isolate* isolate) {
3401 SaveFPRegsMode mode = kSaveFPRegs; 3405 SaveFPRegsMode mode = kSaveFPRegs;
3402 CEntryStub save_doubles(1, mode); 3406 CEntryStub save_doubles(1, mode);
3403 StoreBufferOverflowStub stub(mode); 3407 StoreBufferOverflowStub stub(mode);
3404 // These stubs might already be in the snapshot, detect that and don't 3408 // These stubs might already be in the snapshot, detect that and don't
3405 // regenerate, which would lead to code stub initialization state being messed 3409 // regenerate, which would lead to code stub initialization state being messed
3406 // up. 3410 // up.
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
5091 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); 5095 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
5092 __ b(eq, &done); 5096 __ b(eq, &done);
5093 5097
5094 // Special handling of the Array() function, which caches not only the 5098 // Special handling of the Array() function, which caches not only the
5095 // monomorphic Array function but the initial ElementsKind with special 5099 // monomorphic Array function but the initial ElementsKind with special
5096 // sentinels 5100 // sentinels
5097 Handle<Object> terminal_kind_sentinel = 5101 Handle<Object> terminal_kind_sentinel =
5098 TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(), 5102 TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(),
5099 LAST_FAST_ELEMENTS_KIND); 5103 LAST_FAST_ELEMENTS_KIND);
5100 __ cmp(r3, Operand(terminal_kind_sentinel)); 5104 __ cmp(r3, Operand(terminal_kind_sentinel));
5101 __ b(ne, &miss); 5105 __ b(gt, &miss);
5102 // Make sure the function is the Array() function 5106 // Make sure the function is the Array() function
5103 __ LoadArrayFunction(r3); 5107 __ LoadArrayFunction(r3);
5104 __ cmp(r1, r3); 5108 __ cmp(r1, r3);
5105 __ b(ne, &megamorphic); 5109 __ b(ne, &megamorphic);
5106 __ jmp(&done); 5110 __ jmp(&done);
5107 5111
5108 __ bind(&miss); 5112 __ bind(&miss);
5109 5113
5110 // A monomorphic miss (i.e, here the cache is not uninitialized) goes 5114 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
5111 // megamorphic. 5115 // megamorphic.
(...skipping 2059 matching lines...) Expand 10 before | Expand all | Expand 10 after
7171 return true; 7175 return true;
7172 } 7176 }
7173 } 7177 }
7174 return false; 7178 return false;
7175 } 7179 }
7176 7180
7177 7181
7178 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( 7182 void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
7179 Isolate* isolate) { 7183 Isolate* isolate) {
7180 StoreBufferOverflowStub stub1(kDontSaveFPRegs); 7184 StoreBufferOverflowStub stub1(kDontSaveFPRegs);
7181 stub1.GetCode(isolate)->set_is_pregenerated(true); 7185 stub1.GetCode(isolate)->set_is_pregenerated(true);
Hannes Payer (out of office) 2013/04/23 11:42:50 Why did you remove that comment?
mvstanton 2013/04/23 14:19:58 I guess text angers me. I have put it back! :)
7182 // Hydrogen code stubs need stub2 at snapshot time.
7183 StoreBufferOverflowStub stub2(kSaveFPRegs); 7186 StoreBufferOverflowStub stub2(kSaveFPRegs);
7184 stub2.GetCode(isolate)->set_is_pregenerated(true); 7187 stub2.GetCode(isolate)->set_is_pregenerated(true);
7185 } 7188 }
7186 7189
7187 7190
7188 void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { 7191 void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) {
7189 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; 7192 for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime;
7190 !entry->object.is(no_reg); 7193 !entry->object.is(no_reg);
7191 entry++) { 7194 entry++) {
7192 RecordWriteStub stub(entry->object, 7195 RecordWriteStub stub(entry->object,
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
7533 7536
7534 // Restore the stack pointer if needed. 7537 // Restore the stack pointer if needed.
7535 if (frame_alignment > kPointerSize) { 7538 if (frame_alignment > kPointerSize) {
7536 __ mov(sp, r5); 7539 __ mov(sp, r5);
7537 } 7540 }
7538 7541
7539 __ Pop(lr, r5, r1); 7542 __ Pop(lr, r5, r1);
7540 __ Ret(); 7543 __ Ret();
7541 } 7544 }
7542 7545
7546
7547 template<class T>
7548 static void CreateArrayDispatch(MacroAssembler* masm) {
7549 int last_index = GetSequenceIndexFromFastElementsKind(
7550 TERMINAL_FAST_ELEMENTS_KIND);
7551 for (int i = 0; i <= last_index; ++i) {
7552 Label next;
7553 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
7554 __ cmp(r3, Operand(kind));
7555 __ b(ne, &next);
7556 T stub(kind);
7557 __ TailCallStub(&stub);
7558 __ bind(&next);
7559 }
7560
7561 // If we reached this point there is a problem.
7562 __ Abort("Unexpected ElementsKind in array constructor");
7563 }
7564
7565
7566 static void CreateArrayDispatchOneArgument(MacroAssembler* masm) {
7567 // r2 - type info cell
7568 // r3 - kind
7569 // r0 - number of arguments
7570 // r1 - constructor?
7571 // sp[0] - last argument
7572 ASSERT(FAST_SMI_ELEMENTS == 0);
7573 ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
7574 ASSERT(FAST_ELEMENTS == 2);
7575 ASSERT(FAST_HOLEY_ELEMENTS == 3);
7576 ASSERT(FAST_DOUBLE_ELEMENTS == 4);
7577 ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
7578
7579 Handle<Object> undefined_sentinel(
7580 masm->isolate()->heap()->undefined_value(),
7581 masm->isolate());
7582
7583 // is the low bit set? If so, we are holey and that is good.
7584 __ tst(r3, Operand(1));
7585 Label normal_sequence;
7586 __ b(ne, &normal_sequence);
7587
7588 // look at the first argument
7589 __ ldr(r5, MemOperand(sp, 0));
7590 __ cmp(r5, Operand::Zero());
7591 __ b(eq, &normal_sequence);
7592
7593 // We are going to create a holey array, but our kind is non-holey.
7594 // Fix kind and retry
7595 __ add(r3, r3, Operand(1));
7596 __ cmp(r2, Operand(undefined_sentinel));
7597 __ b(eq, &normal_sequence);
7598
7599 // Save the resulting elements kind in type info
7600 __ SmiTag(r3);
7601 __ str(r3, FieldMemOperand(r2, kPointerSize));
7602 __ SmiUntag(r3);
7603
7604 __ bind(&normal_sequence);
7605 int last_index = GetSequenceIndexFromFastElementsKind(
7606 TERMINAL_FAST_ELEMENTS_KIND);
7607 for (int i = 0; i <= last_index; ++i) {
7608 Label next;
7609 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
7610 __ cmp(r3, Operand(kind));
7611 __ b(ne, &next);
7612 ArraySingleArgumentConstructorStub stub(kind);
7613 __ TailCallStub(&stub);
7614 __ bind(&next);
7615 }
7616
7617 // If we reached this point there is a problem.
7618 __ Abort("Unexpected ElementsKind in array constructor");
7619 }
7620
7621
7622 template<class T>
7623 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
7624 int to_index = GetSequenceIndexFromFastElementsKind(
7625 TERMINAL_FAST_ELEMENTS_KIND);
7626 for (int i = 0; i <= to_index; ++i) {
7627 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
7628 T stub(kind);
7629 stub.GetCode(isolate)->set_is_pregenerated(true);
7630 }
7631 }
7632
7633
7634 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
7635 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
7636 isolate);
7637 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
7638 isolate);
7639 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
7640 isolate);
7641 }
7642
7643
7644 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
7645 // ----------- S t a t e -------------
7646 // -- r0 : argc (only if argument_count_ == ANY)
7647 // -- r1 : constructor
7648 // -- r2 : type info cell
7649 // -- sp[0] : return address
7650 // -- sp[4] : last argument
7651 // -----------------------------------
7652 Handle<Object> undefined_sentinel(
7653 masm->isolate()->heap()->undefined_value(),
7654 masm->isolate());
7655
7656 if (FLAG_debug_code) {
7657 // The array construct code is only set for the global and natives
7658 // builtin Array functions which always have maps.
7659
7660 // Initial map for the builtin Array function should be a map.
7661 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
7662 // Will both indicate a NULL and a Smi.
7663 __ tst(r3, Operand(kSmiTagMask));
7664 __ Assert(ne, "Unexpected initial map for Array function");
7665 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
7666 __ Assert(eq, "Unexpected initial map for Array function");
7667
7668 // We should either have undefined in ebx or a valid jsglobalpropertycell
7669 Label okay_here;
7670 Handle<Map> global_property_cell_map(
7671 masm->isolate()->heap()->global_property_cell_map());
7672 __ cmp(r2, Operand(undefined_sentinel));
7673 __ b(eq, &okay_here);
7674 __ ldr(r3, FieldMemOperand(r2, 0));
7675 __ cmp(r3, Operand(global_property_cell_map));
7676 __ Assert(eq, "Expected property cell in register ebx");
7677 __ bind(&okay_here);
7678 }
7679
7680 if (FLAG_optimize_constructed_arrays) {
7681 Label no_info, switch_ready;
7682 // Get the elements kind and case on that.
7683 __ cmp(r2, Operand(undefined_sentinel));
7684 __ b(eq, &no_info);
7685 __ ldr(r3, FieldMemOperand(r2, kPointerSize));
7686
7687 // There is no info if the call site went megamorphic either
7688 // TODO(mvstanton): Really? I thought if it was the array function that
7689 // the cell wouldn't get stamped as megamorphic.
7690 __ cmp(r3,
7691 Operand(TypeFeedbackCells::MegamorphicSentinel(masm->isolate())));
7692 __ b(eq, &no_info);
7693 __ SmiUntag(r3);
7694 __ jmp(&switch_ready);
7695 __ bind(&no_info);
7696 __ mov(r3, Operand(GetInitialFastElementsKind()));
7697 __ bind(&switch_ready);
7698
7699 if (argument_count_ == ANY) {
7700 Label not_zero_case, not_one_case;
7701 __ tst(r0, r0);
7702 __ b(ne, &not_zero_case);
7703 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
7704
7705 __ bind(&not_zero_case);
7706 __ cmp(r0, Operand(1));
7707 __ b(gt, &not_one_case);
7708 CreateArrayDispatchOneArgument(masm);
7709
7710 __ bind(&not_one_case);
7711 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
7712 } else if (argument_count_ == NONE) {
7713 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
7714 } else if (argument_count_ == ONE) {
7715 CreateArrayDispatchOneArgument(masm);
7716 } else if (argument_count_ == MORE_THAN_ONE) {
7717 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
7718 } else {
7719 UNREACHABLE();
7720 }
7721 } else {
7722 Label generic_constructor;
7723 // Run the native code for the Array function called as a constructor.
7724 ArrayNativeCode(masm, &generic_constructor);
7725
7726 // Jump to the generic construct code in case the specialized code cannot
7727 // handle the construction.
7728 __ bind(&generic_constructor);
7729 Handle<Code> generic_construct_stub =
7730 masm->isolate()->builtins()->JSConstructStubGeneric();
7731 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
7732 }
7733 }
7734
7735
7543 #undef __ 7736 #undef __
7544 7737
7545 } } // namespace v8::internal 7738 } } // namespace v8::internal
7546 7739
7547 #endif // V8_TARGET_ARCH_ARM 7740 #endif // V8_TARGET_ARCH_ARM
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698