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

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: We still generated the arrays with feature flag off. Fixed. 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
« no previous file with comments | « src/arm/code-stubs-arm.h ('k') | src/arm/lithium-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
101 // register state 103 // register state
102 // r1 -- constructor function 104 // r0 -- number of arguments
103 // r2 -- type info cell with elements kind 105 // r2 -- type info cell with elements kind
104 // r0 -- number of arguments to the constructor function 106 static Register registers[] = { r2 };
105 static Register registers[] = { r1, r2 }; 107 descriptor->register_param_count_ = 1;
106 descriptor->register_param_count_ = 2; 108 if (constant_stack_parameter_count != 0) {
107 // stack param count needs (constructor pointer, and single argument) 109 // stack param count needs (constructor pointer, and single argument)
108 descriptor->stack_parameter_count_ = &r0; 110 descriptor->stack_parameter_count_ = &r0;
111 }
112 descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count;
109 descriptor->register_params_ = registers; 113 descriptor->register_params_ = registers;
110 descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; 114 descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
111 descriptor->deoptimization_handler_ = 115 descriptor->deoptimization_handler_ =
112 FUNCTION_ADDR(ArrayConstructor_StubFailure); 116 FUNCTION_ADDR(ArrayConstructor_StubFailure);
113 } 117 }
114 118
115 119
116 void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( 120 void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor(
117 Isolate* isolate, 121 Isolate* isolate,
118 CodeStubInterfaceDescriptor* descriptor) { 122 CodeStubInterfaceDescriptor* descriptor) {
119 InitializeArrayConstructorDescriptor(isolate, descriptor); 123 InitializeArrayConstructorDescriptor(isolate, descriptor, 0);
120 } 124 }
121 125
122 126
123 void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( 127 void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor(
124 Isolate* isolate, 128 Isolate* isolate,
125 CodeStubInterfaceDescriptor* descriptor) { 129 CodeStubInterfaceDescriptor* descriptor) {
126 InitializeArrayConstructorDescriptor(isolate, descriptor); 130 InitializeArrayConstructorDescriptor(isolate, descriptor, 1);
127 } 131 }
128 132
129 133
130 void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( 134 void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor(
131 Isolate* isolate, 135 Isolate* isolate,
132 CodeStubInterfaceDescriptor* descriptor) { 136 CodeStubInterfaceDescriptor* descriptor) {
133 InitializeArrayConstructorDescriptor(isolate, descriptor); 137 InitializeArrayConstructorDescriptor(isolate, descriptor, -1);
134 } 138 }
135 139
136 140
137 #define __ ACCESS_MASM(masm) 141 #define __ ACCESS_MASM(masm)
138 142
139 static void EmitIdenticalObjectComparison(MacroAssembler* masm, 143 static void EmitIdenticalObjectComparison(MacroAssembler* masm,
140 Label* slow, 144 Label* slow,
141 Condition cond); 145 Condition cond);
142 static void EmitSmiNonsmiComparison(MacroAssembler* masm, 146 static void EmitSmiNonsmiComparison(MacroAssembler* masm,
143 Register lhs, 147 Register lhs,
(...skipping 2859 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 result_size_ == 1; 3007 result_size_ == 1;
3004 } 3008 }
3005 3009
3006 3010
3007 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { 3011 void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
3008 CEntryStub::GenerateAheadOfTime(isolate); 3012 CEntryStub::GenerateAheadOfTime(isolate);
3009 WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate); 3013 WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate);
3010 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); 3014 StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
3011 StubFailureTrampolineStub::GenerateAheadOfTime(isolate); 3015 StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
3012 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); 3016 RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate);
3017 if (FLAG_optimize_constructed_arrays) {
3018 ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
3019 }
3013 } 3020 }
3014 3021
3015 3022
3016 void CodeStub::GenerateFPStubs(Isolate* isolate) { 3023 void CodeStub::GenerateFPStubs(Isolate* isolate) {
3017 SaveFPRegsMode mode = kSaveFPRegs; 3024 SaveFPRegsMode mode = kSaveFPRegs;
3018 CEntryStub save_doubles(1, mode); 3025 CEntryStub save_doubles(1, mode);
3019 StoreBufferOverflowStub stub(mode); 3026 StoreBufferOverflowStub stub(mode);
3020 // These stubs might already be in the snapshot, detect that and don't 3027 // These stubs might already be in the snapshot, detect that and don't
3021 // regenerate, which would lead to code stub initialization state being messed 3028 // regenerate, which would lead to code stub initialization state being messed
3022 // up. 3029 // up.
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
4707 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); 4714 __ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
4708 __ b(eq, &done); 4715 __ b(eq, &done);
4709 4716
4710 // Special handling of the Array() function, which caches not only the 4717 // Special handling of the Array() function, which caches not only the
4711 // monomorphic Array function but the initial ElementsKind with special 4718 // monomorphic Array function but the initial ElementsKind with special
4712 // sentinels 4719 // sentinels
4713 Handle<Object> terminal_kind_sentinel = 4720 Handle<Object> terminal_kind_sentinel =
4714 TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(), 4721 TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(),
4715 LAST_FAST_ELEMENTS_KIND); 4722 LAST_FAST_ELEMENTS_KIND);
4716 __ cmp(r3, Operand(terminal_kind_sentinel)); 4723 __ cmp(r3, Operand(terminal_kind_sentinel));
4717 __ b(ne, &miss); 4724 __ b(gt, &miss);
4718 // Make sure the function is the Array() function 4725 // Make sure the function is the Array() function
4719 __ LoadArrayFunction(r3); 4726 __ LoadArrayFunction(r3);
4720 __ cmp(r1, r3); 4727 __ cmp(r1, r3);
4721 __ b(ne, &megamorphic); 4728 __ b(ne, &megamorphic);
4722 __ jmp(&done); 4729 __ jmp(&done);
4723 4730
4724 __ bind(&miss); 4731 __ bind(&miss);
4725 4732
4726 // A monomorphic miss (i.e, here the cache is not uninitialized) goes 4733 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
4727 // megamorphic. 4734 // megamorphic.
(...skipping 2418 matching lines...) Expand 10 before | Expand all | Expand 10 after
7146 7153
7147 // Restore the stack pointer if needed. 7154 // Restore the stack pointer if needed.
7148 if (frame_alignment > kPointerSize) { 7155 if (frame_alignment > kPointerSize) {
7149 __ mov(sp, r5); 7156 __ mov(sp, r5);
7150 } 7157 }
7151 7158
7152 __ Pop(lr, r5, r1); 7159 __ Pop(lr, r5, r1);
7153 __ Ret(); 7160 __ Ret();
7154 } 7161 }
7155 7162
7163
7164 template<class T>
7165 static void CreateArrayDispatch(MacroAssembler* masm) {
7166 int last_index = GetSequenceIndexFromFastElementsKind(
7167 TERMINAL_FAST_ELEMENTS_KIND);
7168 for (int i = 0; i <= last_index; ++i) {
7169 Label next;
7170 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
7171 __ cmp(r3, Operand(kind));
7172 __ b(ne, &next);
7173 T stub(kind);
7174 __ TailCallStub(&stub);
7175 __ bind(&next);
7176 }
7177
7178 // If we reached this point there is a problem.
7179 __ Abort("Unexpected ElementsKind in array constructor");
7180 }
7181
7182
7183 static void CreateArrayDispatchOneArgument(MacroAssembler* masm) {
7184 // r2 - type info cell
7185 // r3 - kind
7186 // r0 - number of arguments
7187 // r1 - constructor?
7188 // sp[0] - last argument
7189 ASSERT(FAST_SMI_ELEMENTS == 0);
7190 ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
7191 ASSERT(FAST_ELEMENTS == 2);
7192 ASSERT(FAST_HOLEY_ELEMENTS == 3);
7193 ASSERT(FAST_DOUBLE_ELEMENTS == 4);
7194 ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
7195
7196 Handle<Object> undefined_sentinel(
7197 masm->isolate()->heap()->undefined_value(),
7198 masm->isolate());
7199
7200 // is the low bit set? If so, we are holey and that is good.
7201 __ tst(r3, Operand(1));
7202 Label normal_sequence;
7203 __ b(ne, &normal_sequence);
7204
7205 // look at the first argument
7206 __ ldr(r5, MemOperand(sp, 0));
7207 __ cmp(r5, Operand::Zero());
7208 __ b(eq, &normal_sequence);
7209
7210 // We are going to create a holey array, but our kind is non-holey.
7211 // Fix kind and retry
7212 __ add(r3, r3, Operand(1));
7213 __ cmp(r2, Operand(undefined_sentinel));
7214 __ b(eq, &normal_sequence);
7215
7216 // Save the resulting elements kind in type info
7217 __ SmiTag(r3);
7218 __ str(r3, FieldMemOperand(r2, kPointerSize));
7219 __ SmiUntag(r3);
7220
7221 __ bind(&normal_sequence);
7222 int last_index = GetSequenceIndexFromFastElementsKind(
7223 TERMINAL_FAST_ELEMENTS_KIND);
7224 for (int i = 0; i <= last_index; ++i) {
7225 Label next;
7226 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
7227 __ cmp(r3, Operand(kind));
7228 __ b(ne, &next);
7229 ArraySingleArgumentConstructorStub stub(kind);
7230 __ TailCallStub(&stub);
7231 __ bind(&next);
7232 }
7233
7234 // If we reached this point there is a problem.
7235 __ Abort("Unexpected ElementsKind in array constructor");
7236 }
7237
7238
7239 template<class T>
7240 static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
7241 int to_index = GetSequenceIndexFromFastElementsKind(
7242 TERMINAL_FAST_ELEMENTS_KIND);
7243 for (int i = 0; i <= to_index; ++i) {
7244 ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
7245 T stub(kind);
7246 stub.GetCode(isolate)->set_is_pregenerated(true);
7247 }
7248 }
7249
7250
7251 void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
7252 ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
7253 isolate);
7254 ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
7255 isolate);
7256 ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
7257 isolate);
7258 }
7259
7260
7261 void ArrayConstructorStub::Generate(MacroAssembler* masm) {
7262 // ----------- S t a t e -------------
7263 // -- r0 : argc (only if argument_count_ == ANY)
7264 // -- r1 : constructor
7265 // -- r2 : type info cell
7266 // -- sp[0] : return address
7267 // -- sp[4] : last argument
7268 // -----------------------------------
7269 Handle<Object> undefined_sentinel(
7270 masm->isolate()->heap()->undefined_value(),
7271 masm->isolate());
7272
7273 if (FLAG_debug_code) {
7274 // The array construct code is only set for the global and natives
7275 // builtin Array functions which always have maps.
7276
7277 // Initial map for the builtin Array function should be a map.
7278 __ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
7279 // Will both indicate a NULL and a Smi.
7280 __ tst(r3, Operand(kSmiTagMask));
7281 __ Assert(ne, "Unexpected initial map for Array function");
7282 __ CompareObjectType(r3, r3, r4, MAP_TYPE);
7283 __ Assert(eq, "Unexpected initial map for Array function");
7284
7285 // We should either have undefined in ebx or a valid jsglobalpropertycell
7286 Label okay_here;
7287 Handle<Map> global_property_cell_map(
7288 masm->isolate()->heap()->global_property_cell_map());
7289 __ cmp(r2, Operand(undefined_sentinel));
7290 __ b(eq, &okay_here);
7291 __ ldr(r3, FieldMemOperand(r2, 0));
7292 __ cmp(r3, Operand(global_property_cell_map));
7293 __ Assert(eq, "Expected property cell in register ebx");
7294 __ bind(&okay_here);
7295 }
7296
7297 if (FLAG_optimize_constructed_arrays) {
7298 Label no_info, switch_ready;
7299 // Get the elements kind and case on that.
7300 __ cmp(r2, Operand(undefined_sentinel));
7301 __ b(eq, &no_info);
7302 __ ldr(r3, FieldMemOperand(r2, kPointerSize));
7303
7304 // There is no info if the call site went megamorphic either
7305 // TODO(mvstanton): Really? I thought if it was the array function that
7306 // the cell wouldn't get stamped as megamorphic.
7307 __ cmp(r3,
7308 Operand(TypeFeedbackCells::MegamorphicSentinel(masm->isolate())));
7309 __ b(eq, &no_info);
7310 __ SmiUntag(r3);
7311 __ jmp(&switch_ready);
7312 __ bind(&no_info);
7313 __ mov(r3, Operand(GetInitialFastElementsKind()));
7314 __ bind(&switch_ready);
7315
7316 if (argument_count_ == ANY) {
7317 Label not_zero_case, not_one_case;
7318 __ tst(r0, r0);
7319 __ b(ne, &not_zero_case);
7320 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
7321
7322 __ bind(&not_zero_case);
7323 __ cmp(r0, Operand(1));
7324 __ b(gt, &not_one_case);
7325 CreateArrayDispatchOneArgument(masm);
7326
7327 __ bind(&not_one_case);
7328 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
7329 } else if (argument_count_ == NONE) {
7330 CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
7331 } else if (argument_count_ == ONE) {
7332 CreateArrayDispatchOneArgument(masm);
7333 } else if (argument_count_ == MORE_THAN_ONE) {
7334 CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
7335 } else {
7336 UNREACHABLE();
7337 }
7338 } else {
7339 Label generic_constructor;
7340 // Run the native code for the Array function called as a constructor.
7341 ArrayNativeCode(masm, &generic_constructor);
7342
7343 // Jump to the generic construct code in case the specialized code cannot
7344 // handle the construction.
7345 __ bind(&generic_constructor);
7346 Handle<Code> generic_construct_stub =
7347 masm->isolate()->builtins()->JSConstructStubGeneric();
7348 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
7349 }
7350 }
7351
7352
7156 #undef __ 7353 #undef __
7157 7354
7158 } } // namespace v8::internal 7355 } } // namespace v8::internal
7159 7356
7160 #endif // V8_TARGET_ARCH_ARM 7357 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « src/arm/code-stubs-arm.h ('k') | src/arm/lithium-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698