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

Side by Side Diff: src/a64/full-codegen-a64.cc

Issue 185653004: Experimental parser: merge to r19637 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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/a64/frames-a64.cc ('k') | src/a64/ic-a64.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 2013 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #if V8_TARGET_ARCH_ARM 30 #if V8_TARGET_ARCH_A64
31 31
32 #include "code-stubs.h" 32 #include "code-stubs.h"
33 #include "codegen.h" 33 #include "codegen.h"
34 #include "compiler.h" 34 #include "compiler.h"
35 #include "debug.h" 35 #include "debug.h"
36 #include "full-codegen.h" 36 #include "full-codegen.h"
37 #include "isolate-inl.h" 37 #include "isolate-inl.h"
38 #include "parser.h" 38 #include "parser.h"
39 #include "scopes.h" 39 #include "scopes.h"
40 #include "stub-cache.h" 40 #include "stub-cache.h"
41 41
42 #include "arm/code-stubs-arm.h" 42 #include "a64/code-stubs-a64.h"
43 #include "arm/macro-assembler-arm.h" 43 #include "a64/macro-assembler-a64.h"
44 44
45 namespace v8 { 45 namespace v8 {
46 namespace internal { 46 namespace internal {
47 47
48 #define __ ACCESS_MASM(masm_) 48 #define __ ACCESS_MASM(masm_)
49 49
50
51 // A patch site is a location in the code which it is possible to patch. This
52 // class has a number of methods to emit the code which is patchable and the
53 // method EmitPatchInfo to record a marker back to the patchable code. This
54 // marker is a cmp rx, #yyy instruction, and x * 0x00000fff + yyy (raw 12 bit
55 // immediate value is used) is the delta from the pc to the first instruction of
56 // the patchable code.
57 class JumpPatchSite BASE_EMBEDDED { 50 class JumpPatchSite BASE_EMBEDDED {
58 public: 51 public:
59 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { 52 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm), reg_(NoReg) {
60 #ifdef DEBUG 53 #ifdef DEBUG
61 info_emitted_ = false; 54 info_emitted_ = false;
62 #endif 55 #endif
63 } 56 }
64 57
65 ~JumpPatchSite() { 58 ~JumpPatchSite() {
66 ASSERT(patch_site_.is_bound() == info_emitted_); 59 if (patch_site_.is_bound()) {
60 ASSERT(info_emitted_);
61 } else {
62 ASSERT(reg_.IsNone());
63 }
67 } 64 }
68 65
69 // When initially emitting this ensure that a jump is always generated to skip
70 // the inlined smi code.
71 void EmitJumpIfNotSmi(Register reg, Label* target) { 66 void EmitJumpIfNotSmi(Register reg, Label* target) {
72 ASSERT(!patch_site_.is_bound() && !info_emitted_); 67 // This code will be patched by PatchInlinedSmiCode, in ic-a64.cc.
73 Assembler::BlockConstPoolScope block_const_pool(masm_); 68 InstructionAccurateScope scope(masm_, 1);
69 ASSERT(!info_emitted_);
70 ASSERT(reg.Is64Bits());
71 ASSERT(!reg.Is(csp));
72 reg_ = reg;
74 __ bind(&patch_site_); 73 __ bind(&patch_site_);
75 __ cmp(reg, Operand(reg)); 74 __ tbz(xzr, 0, target); // Always taken before patched.
76 __ b(eq, target); // Always taken before patched.
77 } 75 }
78 76
79 // When initially emitting this ensure that a jump is never generated to skip
80 // the inlined smi code.
81 void EmitJumpIfSmi(Register reg, Label* target) { 77 void EmitJumpIfSmi(Register reg, Label* target) {
82 ASSERT(!patch_site_.is_bound() && !info_emitted_); 78 // This code will be patched by PatchInlinedSmiCode, in ic-a64.cc.
83 Assembler::BlockConstPoolScope block_const_pool(masm_); 79 InstructionAccurateScope scope(masm_, 1);
80 ASSERT(!info_emitted_);
81 ASSERT(reg.Is64Bits());
82 ASSERT(!reg.Is(csp));
83 reg_ = reg;
84 __ bind(&patch_site_); 84 __ bind(&patch_site_);
85 __ cmp(reg, Operand(reg)); 85 __ tbnz(xzr, 0, target); // Never taken before patched.
86 __ b(ne, target); // Never taken before patched. 86 }
87
88 void EmitJumpIfEitherNotSmi(Register reg1, Register reg2, Label* target) {
89 // We need to use ip0, so don't allow access to the MacroAssembler.
90 InstructionAccurateScope scope(masm_);
91 __ orr(ip0, reg1, reg2);
92 EmitJumpIfNotSmi(ip0, target);
87 } 93 }
88 94
89 void EmitPatchInfo() { 95 void EmitPatchInfo() {
90 // Block literal pool emission whilst recording patch site information. 96 Assembler::BlockConstPoolScope scope(masm_);
91 Assembler::BlockConstPoolScope block_const_pool(masm_); 97 InlineSmiCheckInfo::Emit(masm_, reg_, &patch_site_);
92 if (patch_site_.is_bound()) {
93 int delta_to_patch_site = masm_->InstructionsGeneratedSince(&patch_site_);
94 Register reg;
95 reg.set_code(delta_to_patch_site / kOff12Mask);
96 __ cmp_raw_immediate(reg, delta_to_patch_site % kOff12Mask);
97 #ifdef DEBUG 98 #ifdef DEBUG
98 info_emitted_ = true; 99 info_emitted_ = true;
99 #endif 100 #endif
100 } else {
101 __ nop(); // Signals no inlined code.
102 }
103 } 101 }
104 102
105 private: 103 private:
106 MacroAssembler* masm_; 104 MacroAssembler* masm_;
107 Label patch_site_; 105 Label patch_site_;
106 Register reg_;
108 #ifdef DEBUG 107 #ifdef DEBUG
109 bool info_emitted_; 108 bool info_emitted_;
110 #endif 109 #endif
111 }; 110 };
112 111
113 112
114 // Generate code for a JS function. On entry to the function the receiver 113 // Generate code for a JS function. On entry to the function the receiver
115 // and arguments have been pushed on the stack left to right. The actual 114 // and arguments have been pushed on the stack left to right. The actual
116 // argument count matches the formal parameter count expected by the 115 // argument count matches the formal parameter count expected by the
117 // function. 116 // function.
118 // 117 //
119 // The live registers are: 118 // The live registers are:
120 // o r1: the JS function object being called (i.e., ourselves) 119 // - x1: the JS function object being called (i.e. ourselves).
121 // o cp: our context 120 // - cp: our context.
122 // o pp: our caller's constant pool pointer (if FLAG_enable_ool_constant_pool) 121 // - fp: our caller's frame pointer.
123 // o fp: our caller's frame pointer 122 // - jssp: stack pointer.
124 // o sp: stack pointer 123 // - lr: return address.
125 // o lr: return address
126 // 124 //
127 // The function builds a JS frame. Please see JavaScriptFrameConstants in 125 // The function builds a JS frame. See JavaScriptFrameConstants in
128 // frames-arm.h for its layout. 126 // frames-arm.h for its layout.
129 void FullCodeGenerator::Generate() { 127 void FullCodeGenerator::Generate() {
130 CompilationInfo* info = info_; 128 CompilationInfo* info = info_;
131 handler_table_ = 129 handler_table_ =
132 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); 130 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED);
131
132 InitializeFeedbackVector();
133
133 profiling_counter_ = isolate()->factory()->NewCell( 134 profiling_counter_ = isolate()->factory()->NewCell(
134 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); 135 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate()));
135 SetFunctionPosition(function()); 136 SetFunctionPosition(function());
136 Comment cmnt(masm_, "[ function compiled by full code generator"); 137 Comment cmnt(masm_, "[ Function compiled by full code generator");
137 138
138 ProfileEntryHookStub::MaybeCallEntryHook(masm_); 139 ProfileEntryHookStub::MaybeCallEntryHook(masm_);
139 140
140 #ifdef DEBUG 141 #ifdef DEBUG
141 if (strlen(FLAG_stop_at) > 0 && 142 if (strlen(FLAG_stop_at) > 0 &&
142 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { 143 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
143 __ stop("stop-at"); 144 __ Debug("stop-at", __LINE__, BREAK);
144 } 145 }
145 #endif 146 #endif
146 147
147 // Classic mode functions and builtins need to replace the receiver with the 148 // Classic mode functions and builtins need to replace the receiver with the
148 // global proxy when called as functions (without an explicit receiver 149 // global proxy when called as functions (without an explicit receiver
149 // object). 150 // object).
150 if (info->is_classic_mode() && !info->is_native()) { 151 if (info->is_classic_mode() && !info->is_native()) {
151 Label ok; 152 Label ok;
152 int receiver_offset = info->scope()->num_parameters() * kPointerSize; 153 int receiver_offset = info->scope()->num_parameters() * kXRegSizeInBytes;
153 __ ldr(r2, MemOperand(sp, receiver_offset)); 154 __ Peek(x10, receiver_offset);
154 __ CompareRoot(r2, Heap::kUndefinedValueRootIndex); 155 __ JumpIfNotRoot(x10, Heap::kUndefinedValueRootIndex, &ok);
155 __ b(ne, &ok);
156 156
157 __ ldr(r2, GlobalObjectOperand()); 157 __ Ldr(x10, GlobalObjectMemOperand());
158 __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalReceiverOffset)); 158 __ Ldr(x10, FieldMemOperand(x10, GlobalObject::kGlobalReceiverOffset));
159 __ Poke(x10, receiver_offset);
159 160
160 __ str(r2, MemOperand(sp, receiver_offset)); 161 __ Bind(&ok);
161
162 __ bind(&ok);
163 } 162 }
164 163
165 // Open a frame scope to indicate that there is a frame on the stack. The 164
166 // MANUAL indicates that the scope shouldn't actually generate code to set up 165 // Open a frame scope to indicate that there is a frame on the stack.
167 // the frame (that is done below). 166 // The MANUAL indicates that the scope shouldn't actually generate code
167 // to set up the frame because we do it manually below.
168 FrameScope frame_scope(masm_, StackFrame::MANUAL); 168 FrameScope frame_scope(masm_, StackFrame::MANUAL);
169 169
170 // This call emits the following sequence in a way that can be patched for
171 // code ageing support:
172 // Push(lr, fp, cp, x1);
173 // Add(fp, jssp, 2 * kPointerSize);
170 info->set_prologue_offset(masm_->pc_offset()); 174 info->set_prologue_offset(masm_->pc_offset());
171 __ Prologue(BUILD_FUNCTION_FRAME); 175 __ Prologue(BUILD_FUNCTION_FRAME);
172 info->AddNoFrameRange(0, masm_->pc_offset()); 176 info->AddNoFrameRange(0, masm_->pc_offset());
173 __ LoadConstantPoolPointerRegister();
174 177
178 // Reserve space on the stack for locals.
175 { Comment cmnt(masm_, "[ Allocate locals"); 179 { Comment cmnt(masm_, "[ Allocate locals");
176 int locals_count = info->scope()->num_stack_slots(); 180 int locals_count = info->scope()->num_stack_slots();
177 // Generators allocate locals, if any, in context slots. 181 // Generators allocate locals, if any, in context slots.
178 ASSERT(!info->function()->is_generator() || locals_count == 0); 182 ASSERT(!info->function()->is_generator() || locals_count == 0);
183
179 if (locals_count > 0) { 184 if (locals_count > 0) {
180 // Emit a loop to initialize stack cells for locals when optimizing for 185 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex);
181 // size. Otherwise, unroll the loop for maximum performance. 186 __ PushMultipleTimes(x10, locals_count);
182 __ LoadRoot(r9, Heap::kUndefinedValueRootIndex);
183 if (FLAG_optimize_for_size && locals_count > 4) {
184 Label loop;
185 __ mov(r2, Operand(locals_count));
186 __ bind(&loop);
187 __ sub(r2, r2, Operand(1), SetCC);
188 __ push(r9);
189 __ b(&loop, ne);
190 } else {
191 for (int i = 0; i < locals_count; i++) {
192 __ push(r9);
193 }
194 }
195 } 187 }
196 } 188 }
197 189
198 bool function_in_register = true; 190 bool function_in_register_x1 = true;
199 191
200 // Possibly allocate a local context.
201 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; 192 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
202 if (heap_slots > 0) { 193 if (heap_slots > 0) {
203 // Argument to NewContext is the function, which is still in r1. 194 // Argument to NewContext is the function, which is still in x1.
204 Comment cmnt(masm_, "[ Allocate context"); 195 Comment cmnt(masm_, "[ Allocate context");
205 __ push(r1);
206 if (FLAG_harmony_scoping && info->scope()->is_global_scope()) { 196 if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
207 __ Push(info->scope()->GetScopeInfo()); 197 __ Mov(x10, Operand(info->scope()->GetScopeInfo()));
198 __ Push(x1, x10);
208 __ CallRuntime(Runtime::kNewGlobalContext, 2); 199 __ CallRuntime(Runtime::kNewGlobalContext, 2);
209 } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { 200 } else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
210 FastNewContextStub stub(heap_slots); 201 FastNewContextStub stub(heap_slots);
211 __ CallStub(&stub); 202 __ CallStub(&stub);
212 } else { 203 } else {
204 __ Push(x1);
213 __ CallRuntime(Runtime::kNewFunctionContext, 1); 205 __ CallRuntime(Runtime::kNewFunctionContext, 1);
214 } 206 }
215 function_in_register = false; 207 function_in_register_x1 = false;
216 // Context is returned in both r0 and cp. It replaces the context 208 // Context is returned in x0. It replaces the context passed to us.
217 // passed to us. It's saved in the stack and kept live in cp. 209 // It's saved in the stack and kept live in cp.
218 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 210 __ Mov(cp, x0);
211 __ Str(x0, MemOperand(fp, StandardFrameConstants::kContextOffset));
219 // Copy any necessary parameters into the context. 212 // Copy any necessary parameters into the context.
220 int num_parameters = info->scope()->num_parameters(); 213 int num_parameters = info->scope()->num_parameters();
221 for (int i = 0; i < num_parameters; i++) { 214 for (int i = 0; i < num_parameters; i++) {
222 Variable* var = scope()->parameter(i); 215 Variable* var = scope()->parameter(i);
223 if (var->IsContextSlot()) { 216 if (var->IsContextSlot()) {
224 int parameter_offset = StandardFrameConstants::kCallerSPOffset + 217 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
225 (num_parameters - 1 - i) * kPointerSize; 218 (num_parameters - 1 - i) * kPointerSize;
226 // Load parameter from stack. 219 // Load parameter from stack.
227 __ ldr(r0, MemOperand(fp, parameter_offset)); 220 __ Ldr(x10, MemOperand(fp, parameter_offset));
228 // Store it in the context. 221 // Store it in the context.
229 MemOperand target = ContextOperand(cp, var->index()); 222 MemOperand target = ContextMemOperand(cp, var->index());
230 __ str(r0, target); 223 __ Str(x10, target);
231 224
232 // Update the write barrier. 225 // Update the write barrier.
233 __ RecordWriteContextSlot( 226 __ RecordWriteContextSlot(
234 cp, target.offset(), r0, r3, kLRHasBeenSaved, kDontSaveFPRegs); 227 cp, target.offset(), x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
235 } 228 }
236 } 229 }
237 } 230 }
238 231
239 Variable* arguments = scope()->arguments(); 232 Variable* arguments = scope()->arguments();
240 if (arguments != NULL) { 233 if (arguments != NULL) {
241 // Function uses arguments object. 234 // Function uses arguments object.
242 Comment cmnt(masm_, "[ Allocate arguments object"); 235 Comment cmnt(masm_, "[ Allocate arguments object");
243 if (!function_in_register) { 236 if (!function_in_register_x1) {
244 // Load this again, if it's used by the local context below. 237 // Load this again, if it's used by the local context below.
245 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 238 __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
246 } else { 239 } else {
247 __ mov(r3, r1); 240 __ Mov(x3, x1);
248 } 241 }
249 // Receiver is just before the parameters on the caller's stack. 242 // Receiver is just before the parameters on the caller's stack.
250 int num_parameters = info->scope()->num_parameters(); 243 int num_parameters = info->scope()->num_parameters();
251 int offset = num_parameters * kPointerSize; 244 int offset = num_parameters * kPointerSize;
252 __ add(r2, fp, 245 __ Add(x2, fp, StandardFrameConstants::kCallerSPOffset + offset);
253 Operand(StandardFrameConstants::kCallerSPOffset + offset)); 246 __ Mov(x1, Operand(Smi::FromInt(num_parameters)));
254 __ mov(r1, Operand(Smi::FromInt(num_parameters))); 247 __ Push(x3, x2, x1);
255 __ Push(r3, r2, r1);
256 248
257 // Arguments to ArgumentsAccessStub: 249 // Arguments to ArgumentsAccessStub:
258 // function, receiver address, parameter count. 250 // function, receiver address, parameter count.
259 // The stub will rewrite receiever and parameter count if the previous 251 // The stub will rewrite receiver and parameter count if the previous
260 // stack frame was an arguments adapter frame. 252 // stack frame was an arguments adapter frame.
261 ArgumentsAccessStub::Type type; 253 ArgumentsAccessStub::Type type;
262 if (!is_classic_mode()) { 254 if (!is_classic_mode()) {
263 type = ArgumentsAccessStub::NEW_STRICT; 255 type = ArgumentsAccessStub::NEW_STRICT;
264 } else if (function()->has_duplicate_parameters()) { 256 } else if (function()->has_duplicate_parameters()) {
265 type = ArgumentsAccessStub::NEW_NON_STRICT_SLOW; 257 type = ArgumentsAccessStub::NEW_NON_STRICT_SLOW;
266 } else { 258 } else {
267 type = ArgumentsAccessStub::NEW_NON_STRICT_FAST; 259 type = ArgumentsAccessStub::NEW_NON_STRICT_FAST;
268 } 260 }
269 ArgumentsAccessStub stub(type); 261 ArgumentsAccessStub stub(type);
270 __ CallStub(&stub); 262 __ CallStub(&stub);
271 263
272 SetVar(arguments, r0, r1, r2); 264 SetVar(arguments, x0, x1, x2);
273 } 265 }
274 266
275 if (FLAG_trace) { 267 if (FLAG_trace) {
276 __ CallRuntime(Runtime::kTraceEnter, 0); 268 __ CallRuntime(Runtime::kTraceEnter, 0);
277 } 269 }
278 270
271
279 // Visit the declarations and body unless there is an illegal 272 // Visit the declarations and body unless there is an illegal
280 // redeclaration. 273 // redeclaration.
281 if (scope()->HasIllegalRedeclaration()) { 274 if (scope()->HasIllegalRedeclaration()) {
282 Comment cmnt(masm_, "[ Declarations"); 275 Comment cmnt(masm_, "[ Declarations");
283 scope()->VisitIllegalRedeclaration(this); 276 scope()->VisitIllegalRedeclaration(this);
284 277
285 } else { 278 } else {
286 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); 279 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
287 { Comment cmnt(masm_, "[ Declarations"); 280 { Comment cmnt(masm_, "[ Declarations");
288 // For named function expressions, declare the function name as a
289 // constant.
290 if (scope()->is_function_scope() && scope()->function() != NULL) { 281 if (scope()->is_function_scope() && scope()->function() != NULL) {
291 VariableDeclaration* function = scope()->function(); 282 VariableDeclaration* function = scope()->function();
292 ASSERT(function->proxy()->var()->mode() == CONST || 283 ASSERT(function->proxy()->var()->mode() == CONST ||
293 function->proxy()->var()->mode() == CONST_HARMONY); 284 function->proxy()->var()->mode() == CONST_HARMONY);
294 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); 285 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED);
295 VisitVariableDeclaration(function); 286 VisitVariableDeclaration(function);
296 } 287 }
297 VisitDeclarations(scope()->declarations()); 288 VisitDeclarations(scope()->declarations());
298 } 289 }
290 }
299 291
300 { Comment cmnt(masm_, "[ Stack check"); 292 { Comment cmnt(masm_, "[ Stack check");
301 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); 293 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS);
302 Label ok; 294 Label ok;
303 __ LoadRoot(ip, Heap::kStackLimitRootIndex); 295 ASSERT(jssp.Is(__ StackPointer()));
304 __ cmp(sp, Operand(ip)); 296 __ CompareRoot(jssp, Heap::kStackLimitRootIndex);
305 __ b(hs, &ok); 297 __ B(hs, &ok);
306 PredictableCodeSizeScope predictable(masm_, 2 * Assembler::kInstrSize); 298 PredictableCodeSizeScope predictable(masm_,
307 __ Call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); 299 Assembler::kCallSizeWithRelocation);
308 __ bind(&ok); 300 __ Call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET);
309 } 301 __ Bind(&ok);
302 }
310 303
311 { Comment cmnt(masm_, "[ Body"); 304 { Comment cmnt(masm_, "[ Body");
312 ASSERT(loop_depth() == 0); 305 ASSERT(loop_depth() == 0);
313 VisitStatements(function()->body()); 306 VisitStatements(function()->body());
314 ASSERT(loop_depth() == 0); 307 ASSERT(loop_depth() == 0);
315 }
316 } 308 }
317 309
318 // Always emit a 'return undefined' in case control fell off the end of 310 // Always emit a 'return undefined' in case control fell off the end of
319 // the body. 311 // the body.
320 { Comment cmnt(masm_, "[ return <undefined>;"); 312 { Comment cmnt(masm_, "[ return <undefined>;");
321 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); 313 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
322 } 314 }
323 EmitReturnSequence(); 315 EmitReturnSequence();
324 316
325 // Force emit the constant pool, so it doesn't get emitted in the middle 317 // Force emit the constant pool, so it doesn't get emitted in the middle
326 // of the back edge table. 318 // of the back edge table.
327 masm()->CheckConstPool(true, false); 319 masm()->CheckConstPool(true, false);
328 } 320 }
329 321
330 322
331 void FullCodeGenerator::ClearAccumulator() { 323 void FullCodeGenerator::ClearAccumulator() {
332 __ mov(r0, Operand(Smi::FromInt(0))); 324 __ Mov(x0, Operand(Smi::FromInt(0)));
333 } 325 }
334 326
335 327
336 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { 328 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) {
337 __ mov(r2, Operand(profiling_counter_)); 329 __ Mov(x2, Operand(profiling_counter_));
338 __ ldr(r3, FieldMemOperand(r2, Cell::kValueOffset)); 330 __ Ldr(x3, FieldMemOperand(x2, Cell::kValueOffset));
339 __ sub(r3, r3, Operand(Smi::FromInt(delta)), SetCC); 331 __ Subs(x3, x3, Operand(Smi::FromInt(delta)));
340 __ str(r3, FieldMemOperand(r2, Cell::kValueOffset)); 332 __ Str(x3, FieldMemOperand(x2, Cell::kValueOffset));
341 } 333 }
342 334
343 335
344 void FullCodeGenerator::EmitProfilingCounterReset() { 336 void FullCodeGenerator::EmitProfilingCounterReset() {
345 int reset_value = FLAG_interrupt_budget; 337 int reset_value = FLAG_interrupt_budget;
346 if (isolate()->IsDebuggerActive()) { 338 if (isolate()->IsDebuggerActive()) {
347 // Detect debug break requests as soon as possible. 339 // Detect debug break requests as soon as possible.
348 reset_value = FLAG_interrupt_budget >> 4; 340 reset_value = FLAG_interrupt_budget >> 4;
349 } 341 }
350 __ mov(r2, Operand(profiling_counter_)); 342 __ Mov(x2, Operand(profiling_counter_));
351 __ mov(r3, Operand(Smi::FromInt(reset_value))); 343 __ Mov(x3, Operand(Smi::FromInt(reset_value)));
352 __ str(r3, FieldMemOperand(r2, Cell::kValueOffset)); 344 __ Str(x3, FieldMemOperand(x2, Cell::kValueOffset));
353 } 345 }
354 346
355 347
356 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, 348 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt,
357 Label* back_edge_target) { 349 Label* back_edge_target) {
350 ASSERT(jssp.Is(__ StackPointer()));
358 Comment cmnt(masm_, "[ Back edge bookkeeping"); 351 Comment cmnt(masm_, "[ Back edge bookkeeping");
359 // Block literal pools whilst emitting back edge code. 352 // Block literal pools whilst emitting back edge code.
360 Assembler::BlockConstPoolScope block_const_pool(masm_); 353 Assembler::BlockConstPoolScope block_const_pool(masm_);
361 Label ok; 354 Label ok;
362 355
363 ASSERT(back_edge_target->is_bound()); 356 ASSERT(back_edge_target->is_bound());
364 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); 357 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target);
365 int weight = Min(kMaxBackEdgeWeight, 358 int weight = Min(kMaxBackEdgeWeight,
366 Max(1, distance / kCodeSizeMultiplier)); 359 Max(1, distance / kCodeSizeMultiplier));
367 EmitProfilingCounterDecrement(weight); 360 EmitProfilingCounterDecrement(weight);
368 __ b(pl, &ok); 361 __ B(pl, &ok);
369 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); 362 __ Call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
370 363
371 // Record a mapping of this PC offset to the OSR id. This is used to find 364 // Record a mapping of this PC offset to the OSR id. This is used to find
372 // the AST id from the unoptimized code in order to use it as a key into 365 // the AST id from the unoptimized code in order to use it as a key into
373 // the deoptimization input data found in the optimized code. 366 // the deoptimization input data found in the optimized code.
374 RecordBackEdge(stmt->OsrEntryId()); 367 RecordBackEdge(stmt->OsrEntryId());
375 368
376 EmitProfilingCounterReset(); 369 EmitProfilingCounterReset();
377 370
378 __ bind(&ok); 371 __ Bind(&ok);
379 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); 372 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
380 // Record a mapping of the OSR id to this PC. This is used if the OSR 373 // Record a mapping of the OSR id to this PC. This is used if the OSR
381 // entry becomes the target of a bailout. We don't expect it to be, but 374 // entry becomes the target of a bailout. We don't expect it to be, but
382 // we want it to work if it is. 375 // we want it to work if it is.
383 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); 376 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
384 } 377 }
385 378
386 379
387 void FullCodeGenerator::EmitReturnSequence() { 380 void FullCodeGenerator::EmitReturnSequence() {
388 Comment cmnt(masm_, "[ Return sequence"); 381 Comment cmnt(masm_, "[ Return sequence");
382
389 if (return_label_.is_bound()) { 383 if (return_label_.is_bound()) {
390 __ b(&return_label_); 384 __ B(&return_label_);
385
391 } else { 386 } else {
392 __ bind(&return_label_); 387 __ Bind(&return_label_);
393 if (FLAG_trace) { 388 if (FLAG_trace) {
394 // Push the return value on the stack as the parameter. 389 // Push the return value on the stack as the parameter.
395 // Runtime::TraceExit returns its parameter in r0. 390 // Runtime::TraceExit returns its parameter in x0.
396 __ push(r0); 391 __ Push(result_register());
397 __ CallRuntime(Runtime::kTraceExit, 1); 392 __ CallRuntime(Runtime::kTraceExit, 1);
393 ASSERT(x0.Is(result_register()));
398 } 394 }
399 // Pretend that the exit is a backwards jump to the entry. 395 // Pretend that the exit is a backwards jump to the entry.
400 int weight = 1; 396 int weight = 1;
401 if (info_->ShouldSelfOptimize()) { 397 if (info_->ShouldSelfOptimize()) {
402 weight = FLAG_interrupt_budget / FLAG_self_opt_count; 398 weight = FLAG_interrupt_budget / FLAG_self_opt_count;
403 } else { 399 } else {
404 int distance = masm_->pc_offset(); 400 int distance = masm_->pc_offset();
405 weight = Min(kMaxBackEdgeWeight, 401 weight = Min(kMaxBackEdgeWeight,
406 Max(1, distance / kCodeSizeMultiplier)); 402 Max(1, distance / kCodeSizeMultiplier));
407 } 403 }
408 EmitProfilingCounterDecrement(weight); 404 EmitProfilingCounterDecrement(weight);
409 Label ok; 405 Label ok;
410 __ b(pl, &ok); 406 __ B(pl, &ok);
411 __ push(r0); 407 __ Push(x0);
412 __ Call(isolate()->builtins()->InterruptCheck(), 408 __ Call(isolate()->builtins()->InterruptCheck(),
413 RelocInfo::CODE_TARGET); 409 RelocInfo::CODE_TARGET);
414 __ pop(r0); 410 __ Pop(x0);
415 EmitProfilingCounterReset(); 411 EmitProfilingCounterReset();
416 __ bind(&ok); 412 __ Bind(&ok);
417 413
418 #ifdef DEBUG
419 // Add a label for checking the size of the code used for returning.
420 Label check_exit_codesize;
421 __ bind(&check_exit_codesize);
422 #endif
423 // Make sure that the constant pool is not emitted inside of the return 414 // Make sure that the constant pool is not emitted inside of the return
424 // sequence. 415 // sequence. This sequence can get patched when the debugger is used. See
425 { Assembler::BlockConstPoolScope block_const_pool(masm_); 416 // debug-a64.cc:BreakLocationIterator::SetDebugBreakAtReturn().
426 int32_t sp_delta = (info_->scope()->num_parameters() + 1) * kPointerSize; 417 {
418 InstructionAccurateScope scope(masm_,
419 Assembler::kJSRetSequenceInstructions);
427 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); 420 CodeGenerator::RecordPositions(masm_, function()->end_position() - 1);
428 // TODO(svenpanne) The code below is sometimes 4 words, sometimes 5!
429 PredictableCodeSizeScope predictable(masm_, -1);
430 __ RecordJSReturn(); 421 __ RecordJSReturn();
431 int no_frame_start = __ LeaveFrame(StackFrame::JAVA_SCRIPT); 422 // This code is generated using Assembler methods rather than Macro
432 __ add(sp, sp, Operand(sp_delta)); 423 // Assembler methods because it will be patched later on, and so the size
433 __ Jump(lr); 424 // of the generated code must be consistent.
425 const Register& current_sp = __ StackPointer();
426 // Nothing ensures 16 bytes alignment here.
427 ASSERT(!current_sp.Is(csp));
428 __ mov(current_sp, fp);
429 int no_frame_start = masm_->pc_offset();
430 __ ldp(fp, lr, MemOperand(current_sp, 2 * kXRegSizeInBytes, PostIndex));
431 // Drop the arguments and receiver and return.
432 // TODO(all): This implementation is overkill as it supports 2**31+1
433 // arguments, consider how to improve it without creating a security
434 // hole.
435 __ LoadLiteral(ip0, 3 * kInstructionSize);
436 __ add(current_sp, current_sp, ip0);
437 __ ret();
438 __ dc64(kXRegSizeInBytes * (info_->scope()->num_parameters() + 1));
434 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); 439 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
435 } 440 }
436
437 #ifdef DEBUG
438 // Check that the size of the code used for returning is large enough
439 // for the debugger's requirements.
440 ASSERT(Assembler::kJSReturnSequenceInstructions <=
441 masm_->InstructionsGeneratedSince(&check_exit_codesize));
442 #endif
443 } 441 }
444 } 442 }
445 443
446 444
447 void FullCodeGenerator::EffectContext::Plug(Variable* var) const { 445 void FullCodeGenerator::EffectContext::Plug(Variable* var) const {
448 ASSERT(var->IsStackAllocated() || var->IsContextSlot()); 446 ASSERT(var->IsStackAllocated() || var->IsContextSlot());
449 } 447 }
450 448
451 449
452 void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { 450 void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const {
453 ASSERT(var->IsStackAllocated() || var->IsContextSlot()); 451 ASSERT(var->IsStackAllocated() || var->IsContextSlot());
454 codegen()->GetVar(result_register(), var); 452 codegen()->GetVar(result_register(), var);
455 } 453 }
456 454
457 455
458 void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { 456 void FullCodeGenerator::StackValueContext::Plug(Variable* var) const {
459 ASSERT(var->IsStackAllocated() || var->IsContextSlot()); 457 ASSERT(var->IsStackAllocated() || var->IsContextSlot());
460 codegen()->GetVar(result_register(), var); 458 codegen()->GetVar(result_register(), var);
461 __ push(result_register()); 459 __ Push(result_register());
462 } 460 }
463 461
464 462
465 void FullCodeGenerator::TestContext::Plug(Variable* var) const { 463 void FullCodeGenerator::TestContext::Plug(Variable* var) const {
466 ASSERT(var->IsStackAllocated() || var->IsContextSlot()); 464 ASSERT(var->IsStackAllocated() || var->IsContextSlot());
467 // For simplicity we always test the accumulator register. 465 // For simplicity we always test the accumulator register.
468 codegen()->GetVar(result_register(), var); 466 codegen()->GetVar(result_register(), var);
469 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); 467 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
470 codegen()->DoTest(this); 468 codegen()->DoTest(this);
471 } 469 }
472 470
473 471
474 void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { 472 void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const {
473 // Root values have no side effects.
475 } 474 }
476 475
477 476
478 void FullCodeGenerator::AccumulatorValueContext::Plug( 477 void FullCodeGenerator::AccumulatorValueContext::Plug(
479 Heap::RootListIndex index) const { 478 Heap::RootListIndex index) const {
480 __ LoadRoot(result_register(), index); 479 __ LoadRoot(result_register(), index);
481 } 480 }
482 481
483 482
484 void FullCodeGenerator::StackValueContext::Plug( 483 void FullCodeGenerator::StackValueContext::Plug(
485 Heap::RootListIndex index) const { 484 Heap::RootListIndex index) const {
486 __ LoadRoot(result_register(), index); 485 __ LoadRoot(result_register(), index);
487 __ push(result_register()); 486 __ Push(result_register());
488 } 487 }
489 488
490 489
491 void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { 490 void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const {
492 codegen()->PrepareForBailoutBeforeSplit(condition(), 491 codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
493 true,
494 true_label_,
495 false_label_); 492 false_label_);
496 if (index == Heap::kUndefinedValueRootIndex || 493 if (index == Heap::kUndefinedValueRootIndex ||
497 index == Heap::kNullValueRootIndex || 494 index == Heap::kNullValueRootIndex ||
498 index == Heap::kFalseValueRootIndex) { 495 index == Heap::kFalseValueRootIndex) {
499 if (false_label_ != fall_through_) __ b(false_label_); 496 if (false_label_ != fall_through_) __ B(false_label_);
500 } else if (index == Heap::kTrueValueRootIndex) { 497 } else if (index == Heap::kTrueValueRootIndex) {
501 if (true_label_ != fall_through_) __ b(true_label_); 498 if (true_label_ != fall_through_) __ B(true_label_);
502 } else { 499 } else {
503 __ LoadRoot(result_register(), index); 500 __ LoadRoot(result_register(), index);
504 codegen()->DoTest(this); 501 codegen()->DoTest(this);
505 } 502 }
506 } 503 }
507 504
508 505
509 void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { 506 void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {
510 } 507 }
511 508
512 509
513 void FullCodeGenerator::AccumulatorValueContext::Plug( 510 void FullCodeGenerator::AccumulatorValueContext::Plug(
514 Handle<Object> lit) const { 511 Handle<Object> lit) const {
515 __ mov(result_register(), Operand(lit)); 512 __ Mov(result_register(), Operand(lit));
516 } 513 }
517 514
518 515
519 void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { 516 void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
520 // Immediates cannot be pushed directly. 517 // Immediates cannot be pushed directly.
521 __ mov(result_register(), Operand(lit)); 518 __ Mov(result_register(), Operand(lit));
522 __ push(result_register()); 519 __ Push(result_register());
523 } 520 }
524 521
525 522
526 void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { 523 void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
527 codegen()->PrepareForBailoutBeforeSplit(condition(), 524 codegen()->PrepareForBailoutBeforeSplit(condition(),
528 true, 525 true,
529 true_label_, 526 true_label_,
530 false_label_); 527 false_label_);
531 ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. 528 ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals.
532 if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { 529 if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) {
533 if (false_label_ != fall_through_) __ b(false_label_); 530 if (false_label_ != fall_through_) __ B(false_label_);
534 } else if (lit->IsTrue() || lit->IsJSObject()) { 531 } else if (lit->IsTrue() || lit->IsJSObject()) {
535 if (true_label_ != fall_through_) __ b(true_label_); 532 if (true_label_ != fall_through_) __ B(true_label_);
536 } else if (lit->IsString()) { 533 } else if (lit->IsString()) {
537 if (String::cast(*lit)->length() == 0) { 534 if (String::cast(*lit)->length() == 0) {
538 if (false_label_ != fall_through_) __ b(false_label_); 535 if (false_label_ != fall_through_) __ B(false_label_);
539 } else { 536 } else {
540 if (true_label_ != fall_through_) __ b(true_label_); 537 if (true_label_ != fall_through_) __ B(true_label_);
541 } 538 }
542 } else if (lit->IsSmi()) { 539 } else if (lit->IsSmi()) {
543 if (Smi::cast(*lit)->value() == 0) { 540 if (Smi::cast(*lit)->value() == 0) {
544 if (false_label_ != fall_through_) __ b(false_label_); 541 if (false_label_ != fall_through_) __ B(false_label_);
545 } else { 542 } else {
546 if (true_label_ != fall_through_) __ b(true_label_); 543 if (true_label_ != fall_through_) __ B(true_label_);
547 } 544 }
548 } else { 545 } else {
549 // For simplicity we always test the accumulator register. 546 // For simplicity we always test the accumulator register.
550 __ mov(result_register(), Operand(lit)); 547 __ Mov(result_register(), Operand(lit));
551 codegen()->DoTest(this); 548 codegen()->DoTest(this);
552 } 549 }
553 } 550 }
554 551
555 552
556 void FullCodeGenerator::EffectContext::DropAndPlug(int count, 553 void FullCodeGenerator::EffectContext::DropAndPlug(int count,
557 Register reg) const { 554 Register reg) const {
558 ASSERT(count > 0); 555 ASSERT(count > 0);
559 __ Drop(count); 556 __ Drop(count);
560 } 557 }
561 558
562 559
563 void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( 560 void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
564 int count, 561 int count,
565 Register reg) const { 562 Register reg) const {
566 ASSERT(count > 0); 563 ASSERT(count > 0);
567 __ Drop(count); 564 __ Drop(count);
568 __ Move(result_register(), reg); 565 __ Move(result_register(), reg);
569 } 566 }
570 567
571 568
572 void FullCodeGenerator::StackValueContext::DropAndPlug(int count, 569 void FullCodeGenerator::StackValueContext::DropAndPlug(int count,
573 Register reg) const { 570 Register reg) const {
574 ASSERT(count > 0); 571 ASSERT(count > 0);
575 if (count > 1) __ Drop(count - 1); 572 if (count > 1) __ Drop(count - 1);
576 __ str(reg, MemOperand(sp, 0)); 573 __ Poke(reg, 0);
577 } 574 }
578 575
579 576
580 void FullCodeGenerator::TestContext::DropAndPlug(int count, 577 void FullCodeGenerator::TestContext::DropAndPlug(int count,
581 Register reg) const { 578 Register reg) const {
582 ASSERT(count > 0); 579 ASSERT(count > 0);
583 // For simplicity we always test the accumulator register. 580 // For simplicity we always test the accumulator register.
584 __ Drop(count); 581 __ Drop(count);
585 __ Move(result_register(), reg); 582 __ Mov(result_register(), reg);
586 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); 583 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
587 codegen()->DoTest(this); 584 codegen()->DoTest(this);
588 } 585 }
589 586
590 587
591 void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, 588 void FullCodeGenerator::EffectContext::Plug(Label* materialize_true,
592 Label* materialize_false) const { 589 Label* materialize_false) const {
593 ASSERT(materialize_true == materialize_false); 590 ASSERT(materialize_true == materialize_false);
594 __ bind(materialize_true); 591 __ Bind(materialize_true);
595 } 592 }
596 593
597 594
598 void FullCodeGenerator::AccumulatorValueContext::Plug( 595 void FullCodeGenerator::AccumulatorValueContext::Plug(
599 Label* materialize_true, 596 Label* materialize_true,
600 Label* materialize_false) const { 597 Label* materialize_false) const {
601 Label done; 598 Label done;
602 __ bind(materialize_true); 599 __ Bind(materialize_true);
603 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex); 600 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
604 __ jmp(&done); 601 __ B(&done);
605 __ bind(materialize_false); 602 __ Bind(materialize_false);
606 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex); 603 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
607 __ bind(&done); 604 __ Bind(&done);
608 } 605 }
609 606
610 607
611 void FullCodeGenerator::StackValueContext::Plug( 608 void FullCodeGenerator::StackValueContext::Plug(
612 Label* materialize_true, 609 Label* materialize_true,
613 Label* materialize_false) const { 610 Label* materialize_false) const {
614 Label done; 611 Label done;
615 __ bind(materialize_true); 612 __ Bind(materialize_true);
616 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 613 __ LoadRoot(x10, Heap::kTrueValueRootIndex);
617 __ jmp(&done); 614 __ B(&done);
618 __ bind(materialize_false); 615 __ Bind(materialize_false);
619 __ LoadRoot(ip, Heap::kFalseValueRootIndex); 616 __ LoadRoot(x10, Heap::kFalseValueRootIndex);
620 __ bind(&done); 617 __ Bind(&done);
621 __ push(ip); 618 __ Push(x10);
622 } 619 }
623 620
624 621
625 void FullCodeGenerator::TestContext::Plug(Label* materialize_true, 622 void FullCodeGenerator::TestContext::Plug(Label* materialize_true,
626 Label* materialize_false) const { 623 Label* materialize_false) const {
627 ASSERT(materialize_true == true_label_); 624 ASSERT(materialize_true == true_label_);
628 ASSERT(materialize_false == false_label_); 625 ASSERT(materialize_false == false_label_);
629 } 626 }
630 627
631 628
632 void FullCodeGenerator::EffectContext::Plug(bool flag) const { 629 void FullCodeGenerator::EffectContext::Plug(bool flag) const {
633 } 630 }
634 631
635 632
636 void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { 633 void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const {
637 Heap::RootListIndex value_root_index = 634 Heap::RootListIndex value_root_index =
638 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; 635 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
639 __ LoadRoot(result_register(), value_root_index); 636 __ LoadRoot(result_register(), value_root_index);
640 } 637 }
641 638
642 639
643 void FullCodeGenerator::StackValueContext::Plug(bool flag) const { 640 void FullCodeGenerator::StackValueContext::Plug(bool flag) const {
644 Heap::RootListIndex value_root_index = 641 Heap::RootListIndex value_root_index =
645 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; 642 flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
646 __ LoadRoot(ip, value_root_index); 643 __ LoadRoot(x10, value_root_index);
647 __ push(ip); 644 __ Push(x10);
648 } 645 }
649 646
650 647
651 void FullCodeGenerator::TestContext::Plug(bool flag) const { 648 void FullCodeGenerator::TestContext::Plug(bool flag) const {
652 codegen()->PrepareForBailoutBeforeSplit(condition(), 649 codegen()->PrepareForBailoutBeforeSplit(condition(),
653 true, 650 true,
654 true_label_, 651 true_label_,
655 false_label_); 652 false_label_);
656 if (flag) { 653 if (flag) {
657 if (true_label_ != fall_through_) __ b(true_label_); 654 if (true_label_ != fall_through_) {
655 __ B(true_label_);
656 }
658 } else { 657 } else {
659 if (false_label_ != fall_through_) __ b(false_label_); 658 if (false_label_ != fall_through_) {
659 __ B(false_label_);
660 }
660 } 661 }
661 } 662 }
662 663
663 664
664 void FullCodeGenerator::DoTest(Expression* condition, 665 void FullCodeGenerator::DoTest(Expression* condition,
665 Label* if_true, 666 Label* if_true,
666 Label* if_false, 667 Label* if_false,
667 Label* fall_through) { 668 Label* fall_through) {
668 Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); 669 Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate());
669 CallIC(ic, NOT_CONTEXTUAL, condition->test_id()); 670 CallIC(ic, condition->test_id());
670 __ tst(result_register(), result_register()); 671 __ CompareAndSplit(result_register(), 0, ne, if_true, if_false, fall_through);
671 Split(ne, if_true, if_false, fall_through);
672 } 672 }
673 673
674 674
675 // If (cond), branch to if_true.
676 // If (!cond), branch to if_false.
677 // fall_through is used as an optimization in cases where only one branch
678 // instruction is necessary.
675 void FullCodeGenerator::Split(Condition cond, 679 void FullCodeGenerator::Split(Condition cond,
676 Label* if_true, 680 Label* if_true,
677 Label* if_false, 681 Label* if_false,
678 Label* fall_through) { 682 Label* fall_through) {
679 if (if_false == fall_through) { 683 if (if_false == fall_through) {
680 __ b(cond, if_true); 684 __ B(cond, if_true);
681 } else if (if_true == fall_through) { 685 } else if (if_true == fall_through) {
682 __ b(NegateCondition(cond), if_false); 686 ASSERT(if_false != fall_through);
687 __ B(InvertCondition(cond), if_false);
683 } else { 688 } else {
684 __ b(cond, if_true); 689 __ B(cond, if_true);
685 __ b(if_false); 690 __ B(if_false);
686 } 691 }
687 } 692 }
688 693
689 694
690 MemOperand FullCodeGenerator::StackOperand(Variable* var) { 695 MemOperand FullCodeGenerator::StackOperand(Variable* var) {
691 ASSERT(var->IsStackAllocated());
692 // Offset is negative because higher indexes are at lower addresses. 696 // Offset is negative because higher indexes are at lower addresses.
693 int offset = -var->index() * kPointerSize; 697 int offset = -var->index() * kXRegSizeInBytes;
694 // Adjust by a (parameter or local) base offset. 698 // Adjust by a (parameter or local) base offset.
695 if (var->IsParameter()) { 699 if (var->IsParameter()) {
696 offset += (info_->scope()->num_parameters() + 1) * kPointerSize; 700 offset += (info_->scope()->num_parameters() + 1) * kPointerSize;
697 } else { 701 } else {
698 offset += JavaScriptFrameConstants::kLocal0Offset; 702 offset += JavaScriptFrameConstants::kLocal0Offset;
699 } 703 }
700 return MemOperand(fp, offset); 704 return MemOperand(fp, offset);
701 } 705 }
702 706
703 707
704 MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { 708 MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) {
705 ASSERT(var->IsContextSlot() || var->IsStackAllocated()); 709 ASSERT(var->IsContextSlot() || var->IsStackAllocated());
706 if (var->IsContextSlot()) { 710 if (var->IsContextSlot()) {
707 int context_chain_length = scope()->ContextChainLength(var->scope()); 711 int context_chain_length = scope()->ContextChainLength(var->scope());
708 __ LoadContext(scratch, context_chain_length); 712 __ LoadContext(scratch, context_chain_length);
709 return ContextOperand(scratch, var->index()); 713 return ContextMemOperand(scratch, var->index());
710 } else { 714 } else {
711 return StackOperand(var); 715 return StackOperand(var);
712 } 716 }
713 } 717 }
714 718
715 719
716 void FullCodeGenerator::GetVar(Register dest, Variable* var) { 720 void FullCodeGenerator::GetVar(Register dest, Variable* var) {
717 // Use destination as scratch. 721 // Use destination as scratch.
718 MemOperand location = VarOperand(var, dest); 722 MemOperand location = VarOperand(var, dest);
719 __ ldr(dest, location); 723 __ Ldr(dest, location);
720 } 724 }
721 725
722 726
723 void FullCodeGenerator::SetVar(Variable* var, 727 void FullCodeGenerator::SetVar(Variable* var,
724 Register src, 728 Register src,
725 Register scratch0, 729 Register scratch0,
726 Register scratch1) { 730 Register scratch1) {
727 ASSERT(var->IsContextSlot() || var->IsStackAllocated()); 731 ASSERT(var->IsContextSlot() || var->IsStackAllocated());
728 ASSERT(!scratch0.is(src)); 732 ASSERT(!AreAliased(src, scratch0, scratch1));
729 ASSERT(!scratch0.is(scratch1));
730 ASSERT(!scratch1.is(src));
731 MemOperand location = VarOperand(var, scratch0); 733 MemOperand location = VarOperand(var, scratch0);
732 __ str(src, location); 734 __ Str(src, location);
733 735
734 // Emit the write barrier code if the location is in the heap. 736 // Emit the write barrier code if the location is in the heap.
735 if (var->IsContextSlot()) { 737 if (var->IsContextSlot()) {
738 // scratch0 contains the correct context.
736 __ RecordWriteContextSlot(scratch0, 739 __ RecordWriteContextSlot(scratch0,
737 location.offset(), 740 location.offset(),
738 src, 741 src,
739 scratch1, 742 scratch1,
740 kLRHasBeenSaved, 743 kLRHasBeenSaved,
741 kDontSaveFPRegs); 744 kDontSaveFPRegs);
742 } 745 }
743 } 746 }
744 747
745 748
746 void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, 749 void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr,
747 bool should_normalize, 750 bool should_normalize,
748 Label* if_true, 751 Label* if_true,
749 Label* if_false) { 752 Label* if_false) {
750 // Only prepare for bailouts before splits if we're in a test 753 // Only prepare for bailouts before splits if we're in a test
751 // context. Otherwise, we let the Visit function deal with the 754 // context. Otherwise, we let the Visit function deal with the
752 // preparation to avoid preparing with the same AST id twice. 755 // preparation to avoid preparing with the same AST id twice.
753 if (!context()->IsTest() || !info_->IsOptimizable()) return; 756 if (!context()->IsTest() || !info_->IsOptimizable()) return;
754 757
758 // TODO(all): Investigate to see if there is something to work on here.
755 Label skip; 759 Label skip;
756 if (should_normalize) __ b(&skip); 760 if (should_normalize) {
761 __ B(&skip);
762 }
757 PrepareForBailout(expr, TOS_REG); 763 PrepareForBailout(expr, TOS_REG);
758 if (should_normalize) { 764 if (should_normalize) {
759 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 765 __ CompareRoot(x0, Heap::kTrueValueRootIndex);
760 __ cmp(r0, ip);
761 Split(eq, if_true, if_false, NULL); 766 Split(eq, if_true, if_false, NULL);
762 __ bind(&skip); 767 __ Bind(&skip);
763 } 768 }
764 } 769 }
765 770
766 771
767 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { 772 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) {
768 // The variable in the declaration always resides in the current function 773 // The variable in the declaration always resides in the current function
769 // context. 774 // context.
770 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); 775 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope()));
771 if (generate_debug_code_) { 776 if (generate_debug_code_) {
772 // Check that we're not inside a with or catch context. 777 // Check that we're not inside a with or catch context.
773 __ ldr(r1, FieldMemOperand(cp, HeapObject::kMapOffset)); 778 __ Ldr(x1, FieldMemOperand(cp, HeapObject::kMapOffset));
774 __ CompareRoot(r1, Heap::kWithContextMapRootIndex); 779 __ CompareRoot(x1, Heap::kWithContextMapRootIndex);
775 __ Check(ne, kDeclarationInWithContext); 780 __ Check(ne, kDeclarationInWithContext);
776 __ CompareRoot(r1, Heap::kCatchContextMapRootIndex); 781 __ CompareRoot(x1, Heap::kCatchContextMapRootIndex);
777 __ Check(ne, kDeclarationInCatchContext); 782 __ Check(ne, kDeclarationInCatchContext);
778 } 783 }
779 } 784 }
780 785
781 786
782 void FullCodeGenerator::VisitVariableDeclaration( 787 void FullCodeGenerator::VisitVariableDeclaration(
783 VariableDeclaration* declaration) { 788 VariableDeclaration* declaration) {
784 // If it was not possible to allocate the variable at compile time, we 789 // If it was not possible to allocate the variable at compile time, we
785 // need to "declare" it at runtime to make sure it actually exists in the 790 // need to "declare" it at runtime to make sure it actually exists in the
786 // local context. 791 // local context.
787 VariableProxy* proxy = declaration->proxy(); 792 VariableProxy* proxy = declaration->proxy();
788 VariableMode mode = declaration->mode(); 793 VariableMode mode = declaration->mode();
789 Variable* variable = proxy->var(); 794 Variable* variable = proxy->var();
790 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; 795 bool hole_init = (mode == CONST) || (mode == CONST_HARMONY) || (mode == LET);
796
791 switch (variable->location()) { 797 switch (variable->location()) {
792 case Variable::UNALLOCATED: 798 case Variable::UNALLOCATED:
793 globals_->Add(variable->name(), zone()); 799 globals_->Add(variable->name(), zone());
794 globals_->Add(variable->binding_needs_init() 800 globals_->Add(variable->binding_needs_init()
795 ? isolate()->factory()->the_hole_value() 801 ? isolate()->factory()->the_hole_value()
796 : isolate()->factory()->undefined_value(), 802 : isolate()->factory()->undefined_value(),
797 zone()); 803 zone());
798 break; 804 break;
799 805
800 case Variable::PARAMETER: 806 case Variable::PARAMETER:
801 case Variable::LOCAL: 807 case Variable::LOCAL:
802 if (hole_init) { 808 if (hole_init) {
803 Comment cmnt(masm_, "[ VariableDeclaration"); 809 Comment cmnt(masm_, "[ VariableDeclaration");
804 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); 810 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex);
805 __ str(ip, StackOperand(variable)); 811 __ Str(x10, StackOperand(variable));
806 } 812 }
807 break; 813 break;
808 814
809 case Variable::CONTEXT: 815 case Variable::CONTEXT:
810 if (hole_init) { 816 if (hole_init) {
811 Comment cmnt(masm_, "[ VariableDeclaration"); 817 Comment cmnt(masm_, "[ VariableDeclaration");
812 EmitDebugCheckDeclarationContext(variable); 818 EmitDebugCheckDeclarationContext(variable);
813 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); 819 __ LoadRoot(x10, Heap::kTheHoleValueRootIndex);
814 __ str(ip, ContextOperand(cp, variable->index())); 820 __ Str(x10, ContextMemOperand(cp, variable->index()));
815 // No write barrier since the_hole_value is in old space. 821 // No write barrier since the_hole_value is in old space.
816 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); 822 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
817 } 823 }
818 break; 824 break;
819 825
820 case Variable::LOOKUP: { 826 case Variable::LOOKUP: {
821 Comment cmnt(masm_, "[ VariableDeclaration"); 827 Comment cmnt(masm_, "[ VariableDeclaration");
822 __ mov(r2, Operand(variable->name())); 828 __ Mov(x2, Operand(variable->name()));
823 // Declaration nodes are always introduced in one of four modes. 829 // Declaration nodes are always introduced in one of four modes.
824 ASSERT(IsDeclaredVariableMode(mode)); 830 ASSERT(IsDeclaredVariableMode(mode));
825 PropertyAttributes attr = 831 PropertyAttributes attr = IsImmutableVariableMode(mode) ? READ_ONLY
826 IsImmutableVariableMode(mode) ? READ_ONLY : NONE; 832 : NONE;
827 __ mov(r1, Operand(Smi::FromInt(attr))); 833 __ Mov(x1, Operand(Smi::FromInt(attr)));
828 // Push initial value, if any. 834 // Push initial value, if any.
829 // Note: For variables we must not push an initial value (such as 835 // Note: For variables we must not push an initial value (such as
830 // 'undefined') because we may have a (legal) redeclaration and we 836 // 'undefined') because we may have a (legal) redeclaration and we
831 // must not destroy the current value. 837 // must not destroy the current value.
832 if (hole_init) { 838 if (hole_init) {
833 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); 839 __ LoadRoot(x0, Heap::kTheHoleValueRootIndex);
834 __ Push(cp, r2, r1, r0); 840 __ Push(cp, x2, x1, x0);
835 } else { 841 } else {
836 __ mov(r0, Operand(Smi::FromInt(0))); // Indicates no initial value. 842 // Pushing 0 (xzr) indicates no initial value.
837 __ Push(cp, r2, r1, r0); 843 __ Push(cp, x2, x1, xzr);
838 } 844 }
839 __ CallRuntime(Runtime::kDeclareContextSlot, 4); 845 __ CallRuntime(Runtime::kDeclareContextSlot, 4);
840 break; 846 break;
841 } 847 }
842 } 848 }
843 } 849 }
844 850
845 851
846 void FullCodeGenerator::VisitFunctionDeclaration( 852 void FullCodeGenerator::VisitFunctionDeclaration(
847 FunctionDeclaration* declaration) { 853 FunctionDeclaration* declaration) {
848 VariableProxy* proxy = declaration->proxy(); 854 VariableProxy* proxy = declaration->proxy();
849 Variable* variable = proxy->var(); 855 Variable* variable = proxy->var();
850 switch (variable->location()) { 856 switch (variable->location()) {
851 case Variable::UNALLOCATED: { 857 case Variable::UNALLOCATED: {
852 globals_->Add(variable->name(), zone()); 858 globals_->Add(variable->name(), zone());
853 Handle<SharedFunctionInfo> function = 859 Handle<SharedFunctionInfo> function =
854 Compiler::BuildFunctionInfo(declaration->fun(), script()); 860 Compiler::BuildFunctionInfo(declaration->fun(), script());
855 // Check for stack-overflow exception. 861 // Check for stack overflow exception.
856 if (function.is_null()) return SetStackOverflow(); 862 if (function.is_null()) return SetStackOverflow();
857 globals_->Add(function, zone()); 863 globals_->Add(function, zone());
858 break; 864 break;
859 } 865 }
860 866
861 case Variable::PARAMETER: 867 case Variable::PARAMETER:
862 case Variable::LOCAL: { 868 case Variable::LOCAL: {
863 Comment cmnt(masm_, "[ FunctionDeclaration"); 869 Comment cmnt(masm_, "[ Function Declaration");
864 VisitForAccumulatorValue(declaration->fun()); 870 VisitForAccumulatorValue(declaration->fun());
865 __ str(result_register(), StackOperand(variable)); 871 __ Str(result_register(), StackOperand(variable));
866 break; 872 break;
867 } 873 }
868 874
869 case Variable::CONTEXT: { 875 case Variable::CONTEXT: {
870 Comment cmnt(masm_, "[ FunctionDeclaration"); 876 Comment cmnt(masm_, "[ Function Declaration");
871 EmitDebugCheckDeclarationContext(variable); 877 EmitDebugCheckDeclarationContext(variable);
872 VisitForAccumulatorValue(declaration->fun()); 878 VisitForAccumulatorValue(declaration->fun());
873 __ str(result_register(), ContextOperand(cp, variable->index())); 879 __ Str(result_register(), ContextMemOperand(cp, variable->index()));
874 int offset = Context::SlotOffset(variable->index()); 880 int offset = Context::SlotOffset(variable->index());
875 // We know that we have written a function, which is not a smi. 881 // We know that we have written a function, which is not a smi.
876 __ RecordWriteContextSlot(cp, 882 __ RecordWriteContextSlot(cp,
877 offset, 883 offset,
878 result_register(), 884 result_register(),
879 r2, 885 x2,
880 kLRHasBeenSaved, 886 kLRHasBeenSaved,
881 kDontSaveFPRegs, 887 kDontSaveFPRegs,
882 EMIT_REMEMBERED_SET, 888 EMIT_REMEMBERED_SET,
883 OMIT_SMI_CHECK); 889 OMIT_SMI_CHECK);
884 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); 890 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
885 break; 891 break;
886 } 892 }
887 893
888 case Variable::LOOKUP: { 894 case Variable::LOOKUP: {
889 Comment cmnt(masm_, "[ FunctionDeclaration"); 895 Comment cmnt(masm_, "[ Function Declaration");
890 __ mov(r2, Operand(variable->name())); 896 __ Mov(x2, Operand(variable->name()));
891 __ mov(r1, Operand(Smi::FromInt(NONE))); 897 __ Mov(x1, Operand(Smi::FromInt(NONE)));
892 __ Push(cp, r2, r1); 898 __ Push(cp, x2, x1);
893 // Push initial value for function declaration. 899 // Push initial value for function declaration.
894 VisitForStackValue(declaration->fun()); 900 VisitForStackValue(declaration->fun());
895 __ CallRuntime(Runtime::kDeclareContextSlot, 4); 901 __ CallRuntime(Runtime::kDeclareContextSlot, 4);
896 break; 902 break;
897 } 903 }
898 } 904 }
899 } 905 }
900 906
901 907
902 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { 908 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) {
903 Variable* variable = declaration->proxy()->var(); 909 Variable* variable = declaration->proxy()->var();
904 ASSERT(variable->location() == Variable::CONTEXT); 910 ASSERT(variable->location() == Variable::CONTEXT);
905 ASSERT(variable->interface()->IsFrozen()); 911 ASSERT(variable->interface()->IsFrozen());
906 912
907 Comment cmnt(masm_, "[ ModuleDeclaration"); 913 Comment cmnt(masm_, "[ ModuleDeclaration");
908 EmitDebugCheckDeclarationContext(variable); 914 EmitDebugCheckDeclarationContext(variable);
909 915
910 // Load instance object. 916 // Load instance object.
911 __ LoadContext(r1, scope_->ContextChainLength(scope_->GlobalScope())); 917 __ LoadContext(x1, scope_->ContextChainLength(scope_->GlobalScope()));
912 __ ldr(r1, ContextOperand(r1, variable->interface()->Index())); 918 __ Ldr(x1, ContextMemOperand(x1, variable->interface()->Index()));
913 __ ldr(r1, ContextOperand(r1, Context::EXTENSION_INDEX)); 919 __ Ldr(x1, ContextMemOperand(x1, Context::EXTENSION_INDEX));
914 920
915 // Assign it. 921 // Assign it.
916 __ str(r1, ContextOperand(cp, variable->index())); 922 __ Str(x1, ContextMemOperand(cp, variable->index()));
917 // We know that we have written a module, which is not a smi. 923 // We know that we have written a module, which is not a smi.
918 __ RecordWriteContextSlot(cp, 924 __ RecordWriteContextSlot(cp,
919 Context::SlotOffset(variable->index()), 925 Context::SlotOffset(variable->index()),
920 r1, 926 x1,
921 r3, 927 x3,
922 kLRHasBeenSaved, 928 kLRHasBeenSaved,
923 kDontSaveFPRegs, 929 kDontSaveFPRegs,
924 EMIT_REMEMBERED_SET, 930 EMIT_REMEMBERED_SET,
925 OMIT_SMI_CHECK); 931 OMIT_SMI_CHECK);
926 PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); 932 PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS);
927 933
928 // Traverse into body. 934 // Traverse info body.
929 Visit(declaration->module()); 935 Visit(declaration->module());
930 } 936 }
931 937
932 938
933 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { 939 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) {
934 VariableProxy* proxy = declaration->proxy(); 940 VariableProxy* proxy = declaration->proxy();
935 Variable* variable = proxy->var(); 941 Variable* variable = proxy->var();
936 switch (variable->location()) { 942 switch (variable->location()) {
937 case Variable::UNALLOCATED: 943 case Variable::UNALLOCATED:
938 // TODO(rossberg) 944 // TODO(rossberg)
(...skipping 14 matching lines...) Expand all
953 } 959 }
954 960
955 961
956 void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { 962 void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) {
957 // TODO(rossberg) 963 // TODO(rossberg)
958 } 964 }
959 965
960 966
961 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { 967 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
962 // Call the runtime to declare the globals. 968 // Call the runtime to declare the globals.
963 // The context is the first argument. 969 __ Mov(x11, Operand(pairs));
964 __ mov(r1, Operand(pairs)); 970 Register flags = xzr;
965 __ mov(r0, Operand(Smi::FromInt(DeclareGlobalsFlags()))); 971 if (Smi::FromInt(DeclareGlobalsFlags())) {
966 __ Push(cp, r1, r0); 972 flags = x10;
973 __ Mov(flags, Operand(Smi::FromInt(DeclareGlobalsFlags())));
974 }
975 __ Push(cp, x11, flags);
967 __ CallRuntime(Runtime::kDeclareGlobals, 3); 976 __ CallRuntime(Runtime::kDeclareGlobals, 3);
968 // Return value is ignored. 977 // Return value is ignored.
969 } 978 }
970 979
971 980
972 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { 981 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) {
973 // Call the runtime to declare the modules. 982 // Call the runtime to declare the modules.
974 __ Push(descriptions); 983 __ Push(descriptions);
975 __ CallRuntime(Runtime::kDeclareModules, 1); 984 __ CallRuntime(Runtime::kDeclareModules, 1);
976 // Return value is ignored. 985 // Return value is ignored.
977 } 986 }
978 987
979 988
980 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { 989 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
990 ASM_LOCATION("FullCodeGenerator::VisitSwitchStatement");
981 Comment cmnt(masm_, "[ SwitchStatement"); 991 Comment cmnt(masm_, "[ SwitchStatement");
982 Breakable nested_statement(this, stmt); 992 Breakable nested_statement(this, stmt);
983 SetStatementPosition(stmt); 993 SetStatementPosition(stmt);
984 994
985 // Keep the switch value on the stack until a case matches. 995 // Keep the switch value on the stack until a case matches.
986 VisitForStackValue(stmt->tag()); 996 VisitForStackValue(stmt->tag());
987 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); 997 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
988 998
989 ZoneList<CaseClause*>* clauses = stmt->cases(); 999 ZoneList<CaseClause*>* clauses = stmt->cases();
990 CaseClause* default_clause = NULL; // Can occur anywhere in the list. 1000 CaseClause* default_clause = NULL; // Can occur anywhere in the list.
991 1001
992 Label next_test; // Recycled for each test. 1002 Label next_test; // Recycled for each test.
993 // Compile all the tests with branches to their bodies. 1003 // Compile all the tests with branches to their bodies.
994 for (int i = 0; i < clauses->length(); i++) { 1004 for (int i = 0; i < clauses->length(); i++) {
995 CaseClause* clause = clauses->at(i); 1005 CaseClause* clause = clauses->at(i);
996 clause->body_target()->Unuse(); 1006 clause->body_target()->Unuse();
997 1007
998 // The default is not a test, but remember it as final fall through. 1008 // The default is not a test, but remember it as final fall through.
999 if (clause->is_default()) { 1009 if (clause->is_default()) {
1000 default_clause = clause; 1010 default_clause = clause;
1001 continue; 1011 continue;
1002 } 1012 }
1003 1013
1004 Comment cmnt(masm_, "[ Case comparison"); 1014 Comment cmnt(masm_, "[ Case comparison");
1005 __ bind(&next_test); 1015 __ Bind(&next_test);
1006 next_test.Unuse(); 1016 next_test.Unuse();
1007 1017
1008 // Compile the label expression. 1018 // Compile the label expression.
1009 VisitForAccumulatorValue(clause->label()); 1019 VisitForAccumulatorValue(clause->label());
1010 1020
1011 // Perform the comparison as if via '==='. 1021 // Perform the comparison as if via '==='.
1012 __ ldr(r1, MemOperand(sp, 0)); // Switch value. 1022 __ Peek(x1, 0); // Switch value.
1013 bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); 1023
1014 JumpPatchSite patch_site(masm_); 1024 JumpPatchSite patch_site(masm_);
1015 if (inline_smi_code) { 1025 if (ShouldInlineSmiCase(Token::EQ_STRICT)) {
1016 Label slow_case; 1026 Label slow_case;
1017 __ orr(r2, r1, r0); 1027 patch_site.EmitJumpIfEitherNotSmi(x0, x1, &slow_case);
1018 patch_site.EmitJumpIfNotSmi(r2, &slow_case); 1028 __ Cmp(x1, x0);
1019 1029 __ B(ne, &next_test);
1020 __ cmp(r1, r0);
1021 __ b(ne, &next_test);
1022 __ Drop(1); // Switch value is no longer needed. 1030 __ Drop(1); // Switch value is no longer needed.
1023 __ b(clause->body_target()); 1031 __ B(clause->body_target());
1024 __ bind(&slow_case); 1032 __ Bind(&slow_case);
1025 } 1033 }
1026 1034
1027 // Record position before stub call for type feedback. 1035 // Record position before stub call for type feedback.
1028 SetSourcePosition(clause->position()); 1036 SetSourcePosition(clause->position());
1029 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); 1037 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT);
1030 CallIC(ic, NOT_CONTEXTUAL, clause->CompareId()); 1038 CallIC(ic, clause->CompareId());
1031 patch_site.EmitPatchInfo(); 1039 patch_site.EmitPatchInfo();
1032 1040
1033 Label skip; 1041 Label skip;
1034 __ b(&skip); 1042 __ B(&skip);
1035 PrepareForBailout(clause, TOS_REG); 1043 PrepareForBailout(clause, TOS_REG);
1036 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 1044 __ JumpIfNotRoot(x0, Heap::kTrueValueRootIndex, &next_test);
1037 __ cmp(r0, ip);
1038 __ b(ne, &next_test);
1039 __ Drop(1); 1045 __ Drop(1);
1040 __ jmp(clause->body_target()); 1046 __ B(clause->body_target());
1041 __ bind(&skip); 1047 __ Bind(&skip);
1042 1048
1043 __ cmp(r0, Operand::Zero()); 1049 __ Cbnz(x0, &next_test);
1044 __ b(ne, &next_test);
1045 __ Drop(1); // Switch value is no longer needed. 1050 __ Drop(1); // Switch value is no longer needed.
1046 __ b(clause->body_target()); 1051 __ B(clause->body_target());
1047 } 1052 }
1048 1053
1049 // Discard the test value and jump to the default if present, otherwise to 1054 // Discard the test value and jump to the default if present, otherwise to
1050 // the end of the statement. 1055 // the end of the statement.
1051 __ bind(&next_test); 1056 __ Bind(&next_test);
1052 __ Drop(1); // Switch value is no longer needed. 1057 __ Drop(1); // Switch value is no longer needed.
1053 if (default_clause == NULL) { 1058 if (default_clause == NULL) {
1054 __ b(nested_statement.break_label()); 1059 __ B(nested_statement.break_label());
1055 } else { 1060 } else {
1056 __ b(default_clause->body_target()); 1061 __ B(default_clause->body_target());
1057 } 1062 }
1058 1063
1059 // Compile all the case bodies. 1064 // Compile all the case bodies.
1060 for (int i = 0; i < clauses->length(); i++) { 1065 for (int i = 0; i < clauses->length(); i++) {
1061 Comment cmnt(masm_, "[ Case body"); 1066 Comment cmnt(masm_, "[ Case body");
1062 CaseClause* clause = clauses->at(i); 1067 CaseClause* clause = clauses->at(i);
1063 __ bind(clause->body_target()); 1068 __ Bind(clause->body_target());
1064 PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); 1069 PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS);
1065 VisitStatements(clause->statements()); 1070 VisitStatements(clause->statements());
1066 } 1071 }
1067 1072
1068 __ bind(nested_statement.break_label()); 1073 __ Bind(nested_statement.break_label());
1069 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); 1074 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1070 } 1075 }
1071 1076
1072 1077
1073 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { 1078 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
1079 ASM_LOCATION("FullCodeGenerator::VisitForInStatement");
1074 Comment cmnt(masm_, "[ ForInStatement"); 1080 Comment cmnt(masm_, "[ ForInStatement");
1081 int slot = stmt->ForInFeedbackSlot();
1082 // TODO(all): This visitor probably needs better comments and a revisit.
1075 SetStatementPosition(stmt); 1083 SetStatementPosition(stmt);
1076 1084
1077 Label loop, exit; 1085 Label loop, exit;
1078 ForIn loop_statement(this, stmt); 1086 ForIn loop_statement(this, stmt);
1079 increment_loop_depth(); 1087 increment_loop_depth();
1080 1088
1081 // Get the object to enumerate over. If the object is null or undefined, skip 1089 // Get the object to enumerate over. If the object is null or undefined, skip
1082 // over the loop. See ECMA-262 version 5, section 12.6.4. 1090 // over the loop. See ECMA-262 version 5, section 12.6.4.
1083 VisitForAccumulatorValue(stmt->enumerable()); 1091 VisitForAccumulatorValue(stmt->enumerable());
1084 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); 1092 __ JumpIfRoot(x0, Heap::kUndefinedValueRootIndex, &exit);
1085 __ cmp(r0, ip); 1093 Register null_value = x15;
1086 __ b(eq, &exit);
1087 Register null_value = r5;
1088 __ LoadRoot(null_value, Heap::kNullValueRootIndex); 1094 __ LoadRoot(null_value, Heap::kNullValueRootIndex);
1089 __ cmp(r0, null_value); 1095 __ Cmp(x0, null_value);
1090 __ b(eq, &exit); 1096 __ B(eq, &exit);
1091 1097
1092 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); 1098 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG);
1093 1099
1094 // Convert the object to a JS object. 1100 // Convert the object to a JS object.
1095 Label convert, done_convert; 1101 Label convert, done_convert;
1096 __ JumpIfSmi(r0, &convert); 1102 __ JumpIfSmi(x0, &convert);
1097 __ CompareObjectType(r0, r1, r1, FIRST_SPEC_OBJECT_TYPE); 1103 __ JumpIfObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE, &done_convert, ge);
1098 __ b(ge, &done_convert); 1104 __ Bind(&convert);
1099 __ bind(&convert); 1105 __ Push(x0);
1100 __ push(r0);
1101 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); 1106 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
1102 __ bind(&done_convert); 1107 __ Bind(&done_convert);
1103 __ push(r0); 1108 __ Push(x0);
1104 1109
1105 // Check for proxies. 1110 // Check for proxies.
1106 Label call_runtime; 1111 Label call_runtime;
1107 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); 1112 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1108 __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE); 1113 __ JumpIfObjectType(x0, x10, x11, LAST_JS_PROXY_TYPE, &call_runtime, le);
1109 __ b(le, &call_runtime);
1110 1114
1111 // Check cache validity in generated code. This is a fast case for 1115 // Check cache validity in generated code. This is a fast case for
1112 // the JSObject::IsSimpleEnum cache validity checks. If we cannot 1116 // the JSObject::IsSimpleEnum cache validity checks. If we cannot
1113 // guarantee cache validity, call the runtime system to check cache 1117 // guarantee cache validity, call the runtime system to check cache
1114 // validity or get the property names in a fixed array. 1118 // validity or get the property names in a fixed array.
1115 __ CheckEnumCache(null_value, &call_runtime); 1119 __ CheckEnumCache(x0, null_value, x10, x11, x12, x13, &call_runtime);
1116 1120
1117 // The enum cache is valid. Load the map of the object being 1121 // The enum cache is valid. Load the map of the object being
1118 // iterated over and use the cache for the iteration. 1122 // iterated over and use the cache for the iteration.
1119 Label use_cache; 1123 Label use_cache;
1120 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); 1124 __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset));
1121 __ b(&use_cache); 1125 __ B(&use_cache);
1122 1126
1123 // Get the set of properties to enumerate. 1127 // Get the set of properties to enumerate.
1124 __ bind(&call_runtime); 1128 __ Bind(&call_runtime);
1125 __ push(r0); // Duplicate the enumerable object on the stack. 1129 __ Push(x0); // Duplicate the enumerable object on the stack.
1126 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); 1130 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1);
1127 1131
1128 // If we got a map from the runtime call, we can do a fast 1132 // If we got a map from the runtime call, we can do a fast
1129 // modification check. Otherwise, we got a fixed array, and we have 1133 // modification check. Otherwise, we got a fixed array, and we have
1130 // to do a slow check. 1134 // to do a slow check.
1131 Label fixed_array; 1135 Label fixed_array, no_descriptors;
1132 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); 1136 __ Ldr(x2, FieldMemOperand(x0, HeapObject::kMapOffset));
1133 __ LoadRoot(ip, Heap::kMetaMapRootIndex); 1137 __ JumpIfNotRoot(x2, Heap::kMetaMapRootIndex, &fixed_array);
1134 __ cmp(r2, ip);
1135 __ b(ne, &fixed_array);
1136 1138
1137 // We got a map in register r0. Get the enumeration cache from it. 1139 // We got a map in register x0. Get the enumeration cache from it.
1138 Label no_descriptors; 1140 __ Bind(&use_cache);
1139 __ bind(&use_cache);
1140 1141
1141 __ EnumLength(r1, r0); 1142 __ EnumLengthUntagged(x1, x0);
1142 __ cmp(r1, Operand(Smi::FromInt(0))); 1143 __ Cbz(x1, &no_descriptors);
1143 __ b(eq, &no_descriptors);
1144 1144
1145 __ LoadInstanceDescriptors(r0, r2); 1145 __ LoadInstanceDescriptors(x0, x2);
1146 __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheOffset)); 1146 __ Ldr(x2, FieldMemOperand(x2, DescriptorArray::kEnumCacheOffset));
1147 __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheBridgeCacheOffset)); 1147 __ Ldr(x2,
1148 FieldMemOperand(x2, DescriptorArray::kEnumCacheBridgeCacheOffset));
1148 1149
1149 // Set up the four remaining stack slots. 1150 // Set up the four remaining stack slots.
1150 __ push(r0); // Map. 1151 __ Push(x0); // Map.
1151 __ mov(r0, Operand(Smi::FromInt(0))); 1152 __ Mov(x0, Operand(Smi::FromInt(0)));
1152 // Push enumeration cache, enumeration cache length (as smi) and zero. 1153 // Push enumeration cache, enumeration cache length (as smi) and zero.
1153 __ Push(r2, r1, r0); 1154 __ SmiTag(x1);
1154 __ jmp(&loop); 1155 __ Push(x2, x1, x0);
1156 __ B(&loop);
1155 1157
1156 __ bind(&no_descriptors); 1158 __ Bind(&no_descriptors);
1157 __ Drop(1); 1159 __ Drop(1);
1158 __ jmp(&exit); 1160 __ B(&exit);
1159 1161
1160 // We got a fixed array in register r0. Iterate through that. 1162 // We got a fixed array in register x0. Iterate through that.
1161 Label non_proxy; 1163 __ Bind(&fixed_array);
1162 __ bind(&fixed_array);
1163 1164
1164 Handle<Cell> cell = isolate()->factory()->NewCell( 1165 Handle<Object> feedback = Handle<Object>(
1165 Handle<Object>(Smi::FromInt(TypeFeedbackCells::kForInFastCaseMarker), 1166 Smi::FromInt(TypeFeedbackInfo::kForInFastCaseMarker),
1166 isolate())); 1167 isolate());
1167 RecordTypeFeedbackCell(stmt->ForInFeedbackId(), cell); 1168 StoreFeedbackVectorSlot(slot, feedback);
1168 __ Move(r1, cell); 1169 __ LoadObject(x1, FeedbackVector());
1169 __ mov(r2, Operand(Smi::FromInt(TypeFeedbackCells::kForInSlowCaseMarker))); 1170 __ Mov(x10, Operand(Smi::FromInt(TypeFeedbackInfo::kForInSlowCaseMarker)));
1170 __ str(r2, FieldMemOperand(r1, Cell::kValueOffset)); 1171 __ Str(x10, FieldMemOperand(x1, FixedArray::OffsetOfElementAt(slot)));
1171 1172
1172 __ mov(r1, Operand(Smi::FromInt(1))); // Smi indicates slow check 1173 __ Mov(x1, Operand(Smi::FromInt(1))); // Smi indicates slow check.
1173 __ ldr(r2, MemOperand(sp, 0 * kPointerSize)); // Get enumerated object 1174 __ Peek(x10, 0); // Get enumerated object.
1174 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); 1175 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
1175 __ CompareObjectType(r2, r3, r3, LAST_JS_PROXY_TYPE); 1176 // TODO(all): similar check was done already. Can we avoid it here?
1176 __ b(gt, &non_proxy); 1177 __ CompareObjectType(x10, x11, x12, LAST_JS_PROXY_TYPE);
1177 __ mov(r1, Operand(Smi::FromInt(0))); // Zero indicates proxy 1178 ASSERT(Smi::FromInt(0) == 0);
1178 __ bind(&non_proxy); 1179 __ CzeroX(x1, le); // Zero indicates proxy.
1179 __ Push(r1, r0); // Smi and array 1180 __ Push(x1, x0); // Smi and array
1180 __ ldr(r1, FieldMemOperand(r0, FixedArray::kLengthOffset)); 1181 __ Ldr(x1, FieldMemOperand(x0, FixedArray::kLengthOffset));
1181 __ mov(r0, Operand(Smi::FromInt(0))); 1182 __ Push(x1, xzr); // Fixed array length (as smi) and initial index.
1182 __ Push(r1, r0); // Fixed array length (as smi) and initial index.
1183 1183
1184 // Generate code for doing the condition check. 1184 // Generate code for doing the condition check.
1185 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); 1185 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
1186 __ bind(&loop); 1186 __ Bind(&loop);
1187 // Load the current count to r0, load the length to r1. 1187 // Load the current count to x0, load the length to x1.
1188 __ Ldrd(r0, r1, MemOperand(sp, 0 * kPointerSize)); 1188 __ PeekPair(x0, x1, 0);
1189 __ cmp(r0, r1); // Compare to the array length. 1189 __ Cmp(x0, x1); // Compare to the array length.
1190 __ b(hs, loop_statement.break_label()); 1190 __ B(hs, loop_statement.break_label());
1191 1191
1192 // Get the current entry of the array into register r3. 1192 // Get the current entry of the array into register r3.
1193 __ ldr(r2, MemOperand(sp, 2 * kPointerSize)); 1193 __ Peek(x10, 2 * kXRegSizeInBytes);
1194 __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); 1194 __ Add(x10, x10, Operand::UntagSmiAndScale(x0, kPointerSizeLog2));
1195 __ ldr(r3, MemOperand::PointerAddressFromSmiKey(r2, r0)); 1195 __ Ldr(x3, MemOperand(x10, FixedArray::kHeaderSize - kHeapObjectTag));
1196 1196
1197 // Get the expected map from the stack or a smi in the 1197 // Get the expected map from the stack or a smi in the
1198 // permanent slow case into register r2. 1198 // permanent slow case into register x10.
1199 __ ldr(r2, MemOperand(sp, 3 * kPointerSize)); 1199 __ Peek(x2, 3 * kXRegSizeInBytes);
1200 1200
1201 // Check if the expected map still matches that of the enumerable. 1201 // Check if the expected map still matches that of the enumerable.
1202 // If not, we may have to filter the key. 1202 // If not, we may have to filter the key.
1203 Label update_each; 1203 Label update_each;
1204 __ ldr(r1, MemOperand(sp, 4 * kPointerSize)); 1204 __ Peek(x1, 4 * kXRegSizeInBytes);
1205 __ ldr(r4, FieldMemOperand(r1, HeapObject::kMapOffset)); 1205 __ Ldr(x11, FieldMemOperand(x1, HeapObject::kMapOffset));
1206 __ cmp(r4, Operand(r2)); 1206 __ Cmp(x11, x2);
1207 __ b(eq, &update_each); 1207 __ B(eq, &update_each);
1208 1208
1209 // For proxies, no filtering is done. 1209 // For proxies, no filtering is done.
1210 // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. 1210 // TODO(rossberg): What if only a prototype is a proxy? Not specified yet.
1211 __ cmp(r2, Operand(Smi::FromInt(0))); 1211 STATIC_ASSERT(kSmiTag == 0);
1212 __ b(eq, &update_each); 1212 __ Cbz(x2, &update_each);
1213 1213
1214 // Convert the entry to a string or (smi) 0 if it isn't a property 1214 // Convert the entry to a string or (smi) 0 if it isn't a property
1215 // any more. If the property has been removed while iterating, we 1215 // any more. If the property has been removed while iterating, we
1216 // just skip it. 1216 // just skip it.
1217 __ push(r1); // Enumerable. 1217 __ Push(x1, x3);
1218 __ push(r3); // Current entry.
1219 __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); 1218 __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION);
1220 __ mov(r3, Operand(r0), SetCC); 1219 __ Mov(x3, x0);
1221 __ b(eq, loop_statement.continue_label()); 1220 __ Cbz(x0, loop_statement.continue_label());
1222 1221
1223 // Update the 'each' property or variable from the possibly filtered 1222 // Update the 'each' property or variable from the possibly filtered
1224 // entry in register r3. 1223 // entry in register x3.
1225 __ bind(&update_each); 1224 __ Bind(&update_each);
1226 __ mov(result_register(), r3); 1225 __ Mov(result_register(), x3);
1227 // Perform the assignment as if via '='. 1226 // Perform the assignment as if via '='.
1228 { EffectContext context(this); 1227 { EffectContext context(this);
1229 EmitAssignment(stmt->each()); 1228 EmitAssignment(stmt->each());
1230 } 1229 }
1231 1230
1232 // Generate code for the body of the loop. 1231 // Generate code for the body of the loop.
1233 Visit(stmt->body()); 1232 Visit(stmt->body());
1234 1233
1235 // Generate code for the going to the next element by incrementing 1234 // Generate code for going to the next element by incrementing
1236 // the index (smi) stored on top of the stack. 1235 // the index (smi) stored on top of the stack.
1237 __ bind(loop_statement.continue_label()); 1236 __ Bind(loop_statement.continue_label());
1238 __ pop(r0); 1237 // TODO(all): We could use a callee saved register to avoid popping.
1239 __ add(r0, r0, Operand(Smi::FromInt(1))); 1238 __ Pop(x0);
1240 __ push(r0); 1239 __ Add(x0, x0, Operand(Smi::FromInt(1)));
1240 __ Push(x0);
1241 1241
1242 EmitBackEdgeBookkeeping(stmt, &loop); 1242 EmitBackEdgeBookkeeping(stmt, &loop);
1243 __ b(&loop); 1243 __ B(&loop);
1244 1244
1245 // Remove the pointers stored on the stack. 1245 // Remove the pointers stored on the stack.
1246 __ bind(loop_statement.break_label()); 1246 __ Bind(loop_statement.break_label());
1247 __ Drop(5); 1247 __ Drop(5);
1248 1248
1249 // Exit and decrement the loop depth. 1249 // Exit and decrement the loop depth.
1250 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); 1250 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1251 __ bind(&exit); 1251 __ Bind(&exit);
1252 decrement_loop_depth(); 1252 decrement_loop_depth();
1253 } 1253 }
1254 1254
1255 1255
1256 void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { 1256 void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) {
1257 Comment cmnt(masm_, "[ ForOfStatement"); 1257 Comment cmnt(masm_, "[ ForOfStatement");
1258 SetStatementPosition(stmt); 1258 SetStatementPosition(stmt);
1259 1259
1260 Iteration loop_statement(this, stmt); 1260 Iteration loop_statement(this, stmt);
1261 increment_loop_depth(); 1261 increment_loop_depth();
1262 1262
1263 // var iterator = iterable[@@iterator]() 1263 // var iterator = iterable[@@iterator]()
1264 VisitForAccumulatorValue(stmt->assign_iterator()); 1264 VisitForAccumulatorValue(stmt->assign_iterator());
1265 1265
1266 // As with for-in, skip the loop if the iterator is null or undefined. 1266 // As with for-in, skip the loop if the iterator is null or undefined.
1267 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex); 1267 Register iterator = x0;
1268 __ b(eq, loop_statement.break_label()); 1268 __ JumpIfRoot(iterator, Heap::kUndefinedValueRootIndex,
1269 __ CompareRoot(r0, Heap::kNullValueRootIndex); 1269 loop_statement.break_label());
1270 __ b(eq, loop_statement.break_label()); 1270 __ JumpIfRoot(iterator, Heap::kNullValueRootIndex,
1271 loop_statement.break_label());
1271 1272
1272 // Convert the iterator to a JS object. 1273 // Convert the iterator to a JS object.
1273 Label convert, done_convert; 1274 Label convert, done_convert;
1274 __ JumpIfSmi(r0, &convert); 1275 __ JumpIfSmi(iterator, &convert);
1275 __ CompareObjectType(r0, r1, r1, FIRST_SPEC_OBJECT_TYPE); 1276 __ CompareObjectType(iterator, x1, x1, FIRST_SPEC_OBJECT_TYPE);
1276 __ b(ge, &done_convert); 1277 __ B(ge, &done_convert);
1277 __ bind(&convert); 1278 __ Bind(&convert);
1278 __ push(r0); 1279 __ Push(iterator);
1279 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); 1280 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
1280 __ bind(&done_convert); 1281 __ Bind(&done_convert);
1281 __ push(r0); 1282 __ Push(iterator);
1282 1283
1283 // Loop entry. 1284 // Loop entry.
1284 __ bind(loop_statement.continue_label()); 1285 __ Bind(loop_statement.continue_label());
1285 1286
1286 // result = iterator.next() 1287 // result = iterator.next()
1287 VisitForEffect(stmt->next_result()); 1288 VisitForEffect(stmt->next_result());
1288 1289
1289 // if (result.done) break; 1290 // if (result.done) break;
1290 Label result_not_done; 1291 Label result_not_done;
1291 VisitForControl(stmt->result_done(), 1292 VisitForControl(stmt->result_done(),
1292 loop_statement.break_label(), 1293 loop_statement.break_label(),
1293 &result_not_done, 1294 &result_not_done,
1294 &result_not_done); 1295 &result_not_done);
1295 __ bind(&result_not_done); 1296 __ Bind(&result_not_done);
1296 1297
1297 // each = result.value 1298 // each = result.value
1298 VisitForEffect(stmt->assign_each()); 1299 VisitForEffect(stmt->assign_each());
1299 1300
1300 // Generate code for the body of the loop. 1301 // Generate code for the body of the loop.
1301 Visit(stmt->body()); 1302 Visit(stmt->body());
1302 1303
1303 // Check stack before looping. 1304 // Check stack before looping.
1304 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); 1305 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS);
1305 EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label()); 1306 EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label());
1306 __ jmp(loop_statement.continue_label()); 1307 __ B(loop_statement.continue_label());
1307 1308
1308 // Exit and decrement the loop depth. 1309 // Exit and decrement the loop depth.
1309 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); 1310 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1310 __ bind(loop_statement.break_label()); 1311 __ Bind(loop_statement.break_label());
1311 decrement_loop_depth(); 1312 decrement_loop_depth();
1312 } 1313 }
1313 1314
1314 1315
1315 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, 1316 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1316 bool pretenure) { 1317 bool pretenure) {
1317 // Use the fast case closure allocation code that allocates in new 1318 // Use the fast case closure allocation code that allocates in new space for
1318 // space for nested functions that don't need literals cloning. If 1319 // nested functions that don't need literals cloning. If we're running with
1319 // we're running with the --always-opt or the --prepare-always-opt 1320 // the --always-opt or the --prepare-always-opt flag, we need to use the
1320 // flag, we need to use the runtime function so that the new function 1321 // runtime function so that the new function we are creating here gets a
1321 // we are creating here gets a chance to have its code optimized and 1322 // chance to have its code optimized and doesn't just get a copy of the
1322 // doesn't just get a copy of the existing unoptimized code. 1323 // existing unoptimized code.
1323 if (!FLAG_always_opt && 1324 if (!FLAG_always_opt &&
1324 !FLAG_prepare_always_opt && 1325 !FLAG_prepare_always_opt &&
1325 !pretenure && 1326 !pretenure &&
1326 scope()->is_function_scope() && 1327 scope()->is_function_scope() &&
1327 info->num_literals() == 0) { 1328 info->num_literals() == 0) {
1328 FastNewClosureStub stub(info->language_mode(), info->is_generator()); 1329 FastNewClosureStub stub(info->language_mode(), info->is_generator());
1329 __ mov(r2, Operand(info)); 1330 __ Mov(x2, Operand(info));
1330 __ CallStub(&stub); 1331 __ CallStub(&stub);
1331 } else { 1332 } else {
1332 __ mov(r0, Operand(info)); 1333 __ Mov(x11, Operand(info));
1333 __ LoadRoot(r1, pretenure ? Heap::kTrueValueRootIndex 1334 __ LoadRoot(x10, pretenure ? Heap::kTrueValueRootIndex
1334 : Heap::kFalseValueRootIndex); 1335 : Heap::kFalseValueRootIndex);
1335 __ Push(cp, r0, r1); 1336 __ Push(cp, x11, x10);
1336 __ CallRuntime(Runtime::kNewClosure, 3); 1337 __ CallRuntime(Runtime::kNewClosure, 3);
1337 } 1338 }
1338 context()->Plug(r0); 1339 context()->Plug(x0);
1339 } 1340 }
1340 1341
1341 1342
1342 void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { 1343 void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
1343 Comment cmnt(masm_, "[ VariableProxy"); 1344 Comment cmnt(masm_, "[ VariableProxy");
1344 EmitVariableLoad(expr); 1345 EmitVariableLoad(expr);
1345 } 1346 }
1346 1347
1347 1348
1348 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var, 1349 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var,
1349 TypeofState typeof_state, 1350 TypeofState typeof_state,
1350 Label* slow) { 1351 Label* slow) {
1351 Register current = cp; 1352 Register current = cp;
1352 Register next = r1; 1353 Register next = x10;
1353 Register temp = r2; 1354 Register temp = x11;
1354 1355
1355 Scope* s = scope(); 1356 Scope* s = scope();
1356 while (s != NULL) { 1357 while (s != NULL) {
1357 if (s->num_heap_slots() > 0) { 1358 if (s->num_heap_slots() > 0) {
1358 if (s->calls_non_strict_eval()) { 1359 if (s->calls_non_strict_eval()) {
1359 // Check that extension is NULL. 1360 // Check that extension is NULL.
1360 __ ldr(temp, ContextOperand(current, Context::EXTENSION_INDEX)); 1361 __ Ldr(temp, ContextMemOperand(current, Context::EXTENSION_INDEX));
1361 __ tst(temp, temp); 1362 __ Cbnz(temp, slow);
1362 __ b(ne, slow);
1363 } 1363 }
1364 // Load next context in chain. 1364 // Load next context in chain.
1365 __ ldr(next, ContextOperand(current, Context::PREVIOUS_INDEX)); 1365 __ Ldr(next, ContextMemOperand(current, Context::PREVIOUS_INDEX));
1366 // Walk the rest of the chain without clobbering cp. 1366 // Walk the rest of the chain without clobbering cp.
1367 current = next; 1367 current = next;
1368 } 1368 }
1369 // If no outer scope calls eval, we do not need to check more 1369 // If no outer scope calls eval, we do not need to check more
1370 // context extensions. 1370 // context extensions.
1371 if (!s->outer_scope_calls_non_strict_eval() || s->is_eval_scope()) break; 1371 if (!s->outer_scope_calls_non_strict_eval() || s->is_eval_scope()) break;
1372 s = s->outer_scope(); 1372 s = s->outer_scope();
1373 } 1373 }
1374 1374
1375 if (s->is_eval_scope()) { 1375 if (s->is_eval_scope()) {
1376 Label loop, fast; 1376 Label loop, fast;
1377 if (!current.is(next)) { 1377 __ Mov(next, current);
1378 __ Move(next, current); 1378
1379 } 1379 __ Bind(&loop);
1380 __ bind(&loop);
1381 // Terminate at native context. 1380 // Terminate at native context.
1382 __ ldr(temp, FieldMemOperand(next, HeapObject::kMapOffset)); 1381 __ Ldr(temp, FieldMemOperand(next, HeapObject::kMapOffset));
1383 __ LoadRoot(ip, Heap::kNativeContextMapRootIndex); 1382 __ JumpIfRoot(temp, Heap::kNativeContextMapRootIndex, &fast);
1384 __ cmp(temp, ip);
1385 __ b(eq, &fast);
1386 // Check that extension is NULL. 1383 // Check that extension is NULL.
1387 __ ldr(temp, ContextOperand(next, Context::EXTENSION_INDEX)); 1384 __ Ldr(temp, ContextMemOperand(next, Context::EXTENSION_INDEX));
1388 __ tst(temp, temp); 1385 __ Cbnz(temp, slow);
1389 __ b(ne, slow);
1390 // Load next context in chain. 1386 // Load next context in chain.
1391 __ ldr(next, ContextOperand(next, Context::PREVIOUS_INDEX)); 1387 __ Ldr(next, ContextMemOperand(next, Context::PREVIOUS_INDEX));
1392 __ b(&loop); 1388 __ B(&loop);
1393 __ bind(&fast); 1389 __ Bind(&fast);
1394 } 1390 }
1395 1391
1396 __ ldr(r0, GlobalObjectOperand()); 1392 __ Ldr(x0, GlobalObjectMemOperand());
1397 __ mov(r2, Operand(var->name())); 1393 __ Mov(x2, Operand(var->name()));
1398 ContextualMode mode = (typeof_state == INSIDE_TYPEOF) 1394 ContextualMode mode = (typeof_state == INSIDE_TYPEOF) ? NOT_CONTEXTUAL
1399 ? NOT_CONTEXTUAL 1395 : CONTEXTUAL;
1400 : CONTEXTUAL;
1401 CallLoadIC(mode); 1396 CallLoadIC(mode);
1402 } 1397 }
1403 1398
1404 1399
1405 MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, 1400 MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var,
1406 Label* slow) { 1401 Label* slow) {
1407 ASSERT(var->IsContextSlot()); 1402 ASSERT(var->IsContextSlot());
1408 Register context = cp; 1403 Register context = cp;
1409 Register next = r3; 1404 Register next = x10;
1410 Register temp = r4; 1405 Register temp = x11;
1411 1406
1412 for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { 1407 for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) {
1413 if (s->num_heap_slots() > 0) { 1408 if (s->num_heap_slots() > 0) {
1414 if (s->calls_non_strict_eval()) { 1409 if (s->calls_non_strict_eval()) {
1415 // Check that extension is NULL. 1410 // Check that extension is NULL.
1416 __ ldr(temp, ContextOperand(context, Context::EXTENSION_INDEX)); 1411 __ Ldr(temp, ContextMemOperand(context, Context::EXTENSION_INDEX));
1417 __ tst(temp, temp); 1412 __ Cbnz(temp, slow);
1418 __ b(ne, slow);
1419 } 1413 }
1420 __ ldr(next, ContextOperand(context, Context::PREVIOUS_INDEX)); 1414 __ Ldr(next, ContextMemOperand(context, Context::PREVIOUS_INDEX));
1421 // Walk the rest of the chain without clobbering cp. 1415 // Walk the rest of the chain without clobbering cp.
1422 context = next; 1416 context = next;
1423 } 1417 }
1424 } 1418 }
1425 // Check that last extension is NULL. 1419 // Check that last extension is NULL.
1426 __ ldr(temp, ContextOperand(context, Context::EXTENSION_INDEX)); 1420 __ Ldr(temp, ContextMemOperand(context, Context::EXTENSION_INDEX));
1427 __ tst(temp, temp); 1421 __ Cbnz(temp, slow);
1428 __ b(ne, slow);
1429 1422
1430 // This function is used only for loads, not stores, so it's safe to 1423 // This function is used only for loads, not stores, so it's safe to
1431 // return an cp-based operand (the write barrier cannot be allowed to 1424 // return an cp-based operand (the write barrier cannot be allowed to
1432 // destroy the cp register). 1425 // destroy the cp register).
1433 return ContextOperand(context, var->index()); 1426 return ContextMemOperand(context, var->index());
1434 } 1427 }
1435 1428
1436 1429
1437 void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, 1430 void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var,
1438 TypeofState typeof_state, 1431 TypeofState typeof_state,
1439 Label* slow, 1432 Label* slow,
1440 Label* done) { 1433 Label* done) {
1441 // Generate fast-case code for variables that might be shadowed by 1434 // Generate fast-case code for variables that might be shadowed by
1442 // eval-introduced variables. Eval is used a lot without 1435 // eval-introduced variables. Eval is used a lot without
1443 // introducing variables. In those cases, we do not want to 1436 // introducing variables. In those cases, we do not want to
1444 // perform a runtime call for all variables in the scope 1437 // perform a runtime call for all variables in the scope
1445 // containing the eval. 1438 // containing the eval.
1446 if (var->mode() == DYNAMIC_GLOBAL) { 1439 if (var->mode() == DYNAMIC_GLOBAL) {
1447 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); 1440 EmitLoadGlobalCheckExtensions(var, typeof_state, slow);
1448 __ jmp(done); 1441 __ B(done);
1449 } else if (var->mode() == DYNAMIC_LOCAL) { 1442 } else if (var->mode() == DYNAMIC_LOCAL) {
1450 Variable* local = var->local_if_not_shadowed(); 1443 Variable* local = var->local_if_not_shadowed();
1451 __ ldr(r0, ContextSlotOperandCheckExtensions(local, slow)); 1444 __ Ldr(x0, ContextSlotOperandCheckExtensions(local, slow));
1452 if (local->mode() == LET || 1445 if (local->mode() == LET ||
1453 local->mode() == CONST || 1446 local->mode() == CONST ||
1454 local->mode() == CONST_HARMONY) { 1447 local->mode() == CONST_HARMONY) {
1455 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); 1448 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, done);
1456 if (local->mode() == CONST) { 1449 if (local->mode() == CONST) {
1457 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); 1450 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
1458 } else { // LET || CONST_HARMONY 1451 } else { // LET || CONST_HARMONY
1459 __ b(ne, done); 1452 __ Mov(x0, Operand(var->name()));
1460 __ mov(r0, Operand(var->name())); 1453 __ Push(x0);
1461 __ push(r0);
1462 __ CallRuntime(Runtime::kThrowReferenceError, 1); 1454 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1463 } 1455 }
1464 } 1456 }
1465 __ jmp(done); 1457 __ B(done);
1466 } 1458 }
1467 } 1459 }
1468 1460
1469 1461
1470 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { 1462 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
1471 // Record position before possible IC call. 1463 // Record position before possible IC call.
1472 SetSourcePosition(proxy->position()); 1464 SetSourcePosition(proxy->position());
1473 Variable* var = proxy->var(); 1465 Variable* var = proxy->var();
1474 1466
1475 // Three cases: global variables, lookup variables, and all other types of 1467 // Three cases: global variables, lookup variables, and all other types of
1476 // variables. 1468 // variables.
1477 switch (var->location()) { 1469 switch (var->location()) {
1478 case Variable::UNALLOCATED: { 1470 case Variable::UNALLOCATED: {
1479 Comment cmnt(masm_, "Global variable"); 1471 Comment cmnt(masm_, "Global variable");
1480 // Use inline caching. Variable name is passed in r2 and the global 1472 // Use inline caching. Variable name is passed in x2 and the global
1481 // object (receiver) in r0. 1473 // object (receiver) in x0.
1482 __ ldr(r0, GlobalObjectOperand()); 1474 __ Ldr(x0, GlobalObjectMemOperand());
1483 __ mov(r2, Operand(var->name())); 1475 __ Mov(x2, Operand(var->name()));
1484 CallLoadIC(CONTEXTUAL); 1476 CallLoadIC(CONTEXTUAL);
1485 context()->Plug(r0); 1477 context()->Plug(x0);
1486 break; 1478 break;
1487 } 1479 }
1488 1480
1489 case Variable::PARAMETER: 1481 case Variable::PARAMETER:
1490 case Variable::LOCAL: 1482 case Variable::LOCAL:
1491 case Variable::CONTEXT: { 1483 case Variable::CONTEXT: {
1492 Comment cmnt(masm_, var->IsContextSlot() 1484 Comment cmnt(masm_, var->IsContextSlot()
1493 ? "Context variable" 1485 ? "Context variable"
1494 : "Stack variable"); 1486 : "Stack variable");
1495 if (var->binding_needs_init()) { 1487 if (var->binding_needs_init()) {
(...skipping 26 matching lines...) Expand all
1522 } else { 1514 } else {
1523 // Check that we always have valid source position. 1515 // Check that we always have valid source position.
1524 ASSERT(var->initializer_position() != RelocInfo::kNoPosition); 1516 ASSERT(var->initializer_position() != RelocInfo::kNoPosition);
1525 ASSERT(proxy->position() != RelocInfo::kNoPosition); 1517 ASSERT(proxy->position() != RelocInfo::kNoPosition);
1526 skip_init_check = var->mode() != CONST && 1518 skip_init_check = var->mode() != CONST &&
1527 var->initializer_position() < proxy->position(); 1519 var->initializer_position() < proxy->position();
1528 } 1520 }
1529 1521
1530 if (!skip_init_check) { 1522 if (!skip_init_check) {
1531 // Let and const need a read barrier. 1523 // Let and const need a read barrier.
1532 GetVar(r0, var); 1524 GetVar(x0, var);
1533 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); 1525 Label done;
1526 __ JumpIfNotRoot(x0, Heap::kTheHoleValueRootIndex, &done);
1534 if (var->mode() == LET || var->mode() == CONST_HARMONY) { 1527 if (var->mode() == LET || var->mode() == CONST_HARMONY) {
1535 // Throw a reference error when using an uninitialized let/const 1528 // Throw a reference error when using an uninitialized let/const
1536 // binding in harmony mode. 1529 // binding in harmony mode.
1537 Label done; 1530 __ Mov(x0, Operand(var->name()));
1538 __ b(ne, &done); 1531 __ Push(x0);
1539 __ mov(r0, Operand(var->name()));
1540 __ push(r0);
1541 __ CallRuntime(Runtime::kThrowReferenceError, 1); 1532 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1542 __ bind(&done); 1533 __ Bind(&done);
1543 } else { 1534 } else {
1544 // Uninitalized const bindings outside of harmony mode are unholed. 1535 // Uninitalized const bindings outside of harmony mode are unholed.
1545 ASSERT(var->mode() == CONST); 1536 ASSERT(var->mode() == CONST);
1546 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); 1537 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
1538 __ Bind(&done);
1547 } 1539 }
1548 context()->Plug(r0); 1540 context()->Plug(x0);
1549 break; 1541 break;
1550 } 1542 }
1551 } 1543 }
1552 context()->Plug(var); 1544 context()->Plug(var);
1553 break; 1545 break;
1554 } 1546 }
1555 1547
1556 case Variable::LOOKUP: { 1548 case Variable::LOOKUP: {
1557 Label done, slow; 1549 Label done, slow;
1558 // Generate code for loading from variables potentially shadowed 1550 // Generate code for loading from variables potentially shadowed by
1559 // by eval-introduced variables. 1551 // eval-introduced variables.
1560 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); 1552 EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done);
1561 __ bind(&slow); 1553 __ Bind(&slow);
1562 Comment cmnt(masm_, "Lookup variable"); 1554 Comment cmnt(masm_, "Lookup variable");
1563 __ mov(r1, Operand(var->name())); 1555 __ Mov(x1, Operand(var->name()));
1564 __ Push(cp, r1); // Context and name. 1556 __ Push(cp, x1); // Context and name.
1565 __ CallRuntime(Runtime::kLoadContextSlot, 2); 1557 __ CallRuntime(Runtime::kLoadContextSlot, 2);
1566 __ bind(&done); 1558 __ Bind(&done);
1567 context()->Plug(r0); 1559 context()->Plug(x0);
1560 break;
1568 } 1561 }
1569 } 1562 }
1570 } 1563 }
1571 1564
1572 1565
1573 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { 1566 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1574 Comment cmnt(masm_, "[ RegExpLiteral"); 1567 Comment cmnt(masm_, "[ RegExpLiteral");
1575 Label materialized; 1568 Label materialized;
1576 // Registers will be used as follows: 1569 // Registers will be used as follows:
1577 // r5 = materialized value (RegExp literal) 1570 // x5 = materialized value (RegExp literal)
1578 // r4 = JS function, literals array 1571 // x4 = JS function, literals array
1579 // r3 = literal index 1572 // x3 = literal index
1580 // r2 = RegExp pattern 1573 // x2 = RegExp pattern
1581 // r1 = RegExp flags 1574 // x1 = RegExp flags
1582 // r0 = RegExp literal clone 1575 // x0 = RegExp literal clone
1583 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 1576 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1584 __ ldr(r4, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); 1577 __ Ldr(x4, FieldMemOperand(x10, JSFunction::kLiteralsOffset));
1585 int literal_offset = 1578 int literal_offset =
1586 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; 1579 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
1587 __ ldr(r5, FieldMemOperand(r4, literal_offset)); 1580 __ Ldr(x5, FieldMemOperand(x4, literal_offset));
1588 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); 1581 __ JumpIfNotRoot(x5, Heap::kUndefinedValueRootIndex, &materialized);
1589 __ cmp(r5, ip);
1590 __ b(ne, &materialized);
1591 1582
1592 // Create regexp literal using runtime function. 1583 // Create regexp literal using runtime function.
1593 // Result will be in r0. 1584 // Result will be in x0.
1594 __ mov(r3, Operand(Smi::FromInt(expr->literal_index()))); 1585 __ Mov(x3, Operand(Smi::FromInt(expr->literal_index())));
1595 __ mov(r2, Operand(expr->pattern())); 1586 __ Mov(x2, Operand(expr->pattern()));
1596 __ mov(r1, Operand(expr->flags())); 1587 __ Mov(x1, Operand(expr->flags()));
1597 __ Push(r4, r3, r2, r1); 1588 __ Push(x4, x3, x2, x1);
1598 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); 1589 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1599 __ mov(r5, r0); 1590 __ Mov(x5, x0);
1600 1591
1601 __ bind(&materialized); 1592 __ Bind(&materialized);
1602 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; 1593 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1603 Label allocated, runtime_allocate; 1594 Label allocated, runtime_allocate;
1604 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); 1595 __ Allocate(size, x0, x2, x3, &runtime_allocate, TAG_OBJECT);
1605 __ jmp(&allocated); 1596 __ B(&allocated);
1606 1597
1607 __ bind(&runtime_allocate); 1598 __ Bind(&runtime_allocate);
1608 __ mov(r0, Operand(Smi::FromInt(size))); 1599 __ Mov(x10, Operand(Smi::FromInt(size)));
1609 __ Push(r5, r0); 1600 __ Push(x5, x10);
1610 __ CallRuntime(Runtime::kAllocateInNewSpace, 1); 1601 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1611 __ pop(r5); 1602 __ Pop(x5);
1612 1603
1613 __ bind(&allocated); 1604 __ Bind(&allocated);
1614 // After this, registers are used as follows: 1605 // After this, registers are used as follows:
1615 // r0: Newly allocated regexp. 1606 // x0: Newly allocated regexp.
1616 // r5: Materialized regexp. 1607 // x5: Materialized regexp.
1617 // r2: temp. 1608 // x10, x11, x12: temps.
1618 __ CopyFields(r0, r5, d0, size / kPointerSize); 1609 __ CopyFields(x0, x5, CPURegList(x10, x11, x12), size / kPointerSize);
1619 context()->Plug(r0); 1610 context()->Plug(x0);
1620 } 1611 }
1621 1612
1622 1613
1623 void FullCodeGenerator::EmitAccessor(Expression* expression) { 1614 void FullCodeGenerator::EmitAccessor(Expression* expression) {
1624 if (expression == NULL) { 1615 if (expression == NULL) {
1625 __ LoadRoot(r1, Heap::kNullValueRootIndex); 1616 __ LoadRoot(x10, Heap::kNullValueRootIndex);
1626 __ push(r1); 1617 __ Push(x10);
1627 } else { 1618 } else {
1628 VisitForStackValue(expression); 1619 VisitForStackValue(expression);
1629 } 1620 }
1630 } 1621 }
1631 1622
1632 1623
1633 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { 1624 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1634 Comment cmnt(masm_, "[ ObjectLiteral"); 1625 Comment cmnt(masm_, "[ ObjectLiteral");
1635 1626
1636 expr->BuildConstantProperties(isolate()); 1627 expr->BuildConstantProperties(isolate());
1637 Handle<FixedArray> constant_properties = expr->constant_properties(); 1628 Handle<FixedArray> constant_properties = expr->constant_properties();
1638 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 1629 __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1639 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); 1630 __ Ldr(x3, FieldMemOperand(x3, JSFunction::kLiteralsOffset));
1640 __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); 1631 __ Mov(x2, Operand(Smi::FromInt(expr->literal_index())));
1641 __ mov(r1, Operand(constant_properties)); 1632 __ Mov(x1, Operand(constant_properties));
1642 int flags = expr->fast_elements() 1633 int flags = expr->fast_elements()
1643 ? ObjectLiteral::kFastElements 1634 ? ObjectLiteral::kFastElements
1644 : ObjectLiteral::kNoFlags; 1635 : ObjectLiteral::kNoFlags;
1645 flags |= expr->has_function() 1636 flags |= expr->has_function()
1646 ? ObjectLiteral::kHasFunction 1637 ? ObjectLiteral::kHasFunction
1647 : ObjectLiteral::kNoFlags; 1638 : ObjectLiteral::kNoFlags;
1648 __ mov(r0, Operand(Smi::FromInt(flags))); 1639 __ Mov(x0, Operand(Smi::FromInt(flags)));
1649 int properties_count = constant_properties->length() / 2; 1640 int properties_count = constant_properties->length() / 2;
1641 const int max_cloned_properties =
1642 FastCloneShallowObjectStub::kMaximumClonedProperties;
1650 if ((FLAG_track_double_fields && expr->may_store_doubles()) || 1643 if ((FLAG_track_double_fields && expr->may_store_doubles()) ||
1651 expr->depth() > 1 || Serializer::enabled() || 1644 (expr->depth() > 1) || Serializer::enabled() ||
1652 flags != ObjectLiteral::kFastElements || 1645 (flags != ObjectLiteral::kFastElements) ||
1653 properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { 1646 (properties_count > max_cloned_properties)) {
1654 __ Push(r3, r2, r1, r0); 1647 __ Push(x3, x2, x1, x0);
1655 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); 1648 __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1656 } else { 1649 } else {
1657 FastCloneShallowObjectStub stub(properties_count); 1650 FastCloneShallowObjectStub stub(properties_count);
1658 __ CallStub(&stub); 1651 __ CallStub(&stub);
1659 } 1652 }
1660 1653
1661 // If result_saved is true the result is on top of the stack. If 1654 // If result_saved is true the result is on top of the stack. If
1662 // result_saved is false the result is in r0. 1655 // result_saved is false the result is in x0.
1663 bool result_saved = false; 1656 bool result_saved = false;
1664 1657
1665 // Mark all computed expressions that are bound to a key that 1658 // Mark all computed expressions that are bound to a key that
1666 // is shadowed by a later occurrence of the same key. For the 1659 // is shadowed by a later occurrence of the same key. For the
1667 // marked expressions, no store code is emitted. 1660 // marked expressions, no store code is emitted.
1668 expr->CalculateEmitStore(zone()); 1661 expr->CalculateEmitStore(zone());
1669 1662
1670 AccessorTable accessor_table(zone()); 1663 AccessorTable accessor_table(zone());
1671 for (int i = 0; i < expr->properties()->length(); i++) { 1664 for (int i = 0; i < expr->properties()->length(); i++) {
1672 ObjectLiteral::Property* property = expr->properties()->at(i); 1665 ObjectLiteral::Property* property = expr->properties()->at(i);
1673 if (property->IsCompileTimeValue()) continue; 1666 if (property->IsCompileTimeValue()) continue;
1674 1667
1675 Literal* key = property->key(); 1668 Literal* key = property->key();
1676 Expression* value = property->value(); 1669 Expression* value = property->value();
1677 if (!result_saved) { 1670 if (!result_saved) {
1678 __ push(r0); // Save result on stack 1671 __ Push(x0); // Save result on stack
1679 result_saved = true; 1672 result_saved = true;
1680 } 1673 }
1681 switch (property->kind()) { 1674 switch (property->kind()) {
1682 case ObjectLiteral::Property::CONSTANT: 1675 case ObjectLiteral::Property::CONSTANT:
1683 UNREACHABLE(); 1676 UNREACHABLE();
1684 case ObjectLiteral::Property::MATERIALIZED_LITERAL: 1677 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1685 ASSERT(!CompileTimeValue::IsCompileTimeValue(property->value())); 1678 ASSERT(!CompileTimeValue::IsCompileTimeValue(property->value()));
1686 // Fall through. 1679 // Fall through.
1687 case ObjectLiteral::Property::COMPUTED: 1680 case ObjectLiteral::Property::COMPUTED:
1688 if (key->value()->IsInternalizedString()) { 1681 if (key->value()->IsInternalizedString()) {
1689 if (property->emit_store()) { 1682 if (property->emit_store()) {
1690 VisitForAccumulatorValue(value); 1683 VisitForAccumulatorValue(value);
1691 __ mov(r2, Operand(key->value())); 1684 __ Mov(x2, Operand(key->value()));
1692 __ ldr(r1, MemOperand(sp)); 1685 __ Peek(x1, 0);
1693 CallStoreIC(NOT_CONTEXTUAL, key->LiteralFeedbackId()); 1686 CallStoreIC(key->LiteralFeedbackId());
1694 PrepareForBailoutForId(key->id(), NO_REGISTERS); 1687 PrepareForBailoutForId(key->id(), NO_REGISTERS);
1695 } else { 1688 } else {
1696 VisitForEffect(value); 1689 VisitForEffect(value);
1697 } 1690 }
1698 break; 1691 break;
1699 } 1692 }
1700 // Duplicate receiver on stack. 1693 // Duplicate receiver on stack.
1701 __ ldr(r0, MemOperand(sp)); 1694 __ Peek(x0, 0);
1702 __ push(r0); 1695 __ Push(x0);
1703 VisitForStackValue(key); 1696 VisitForStackValue(key);
1704 VisitForStackValue(value); 1697 VisitForStackValue(value);
1705 if (property->emit_store()) { 1698 if (property->emit_store()) {
1706 __ mov(r0, Operand(Smi::FromInt(NONE))); // PropertyAttributes 1699 __ Mov(x0, Operand(Smi::FromInt(NONE))); // PropertyAttributes
1707 __ push(r0); 1700 __ Push(x0);
1708 __ CallRuntime(Runtime::kSetProperty, 4); 1701 __ CallRuntime(Runtime::kSetProperty, 4);
1709 } else { 1702 } else {
1710 __ Drop(3); 1703 __ Drop(3);
1711 } 1704 }
1712 break; 1705 break;
1713 case ObjectLiteral::Property::PROTOTYPE: 1706 case ObjectLiteral::Property::PROTOTYPE:
1714 // Duplicate receiver on stack. 1707 // Duplicate receiver on stack.
1715 __ ldr(r0, MemOperand(sp)); 1708 __ Peek(x0, 0);
1716 __ push(r0); 1709 // TODO(jbramley): This push shouldn't be necessary if we don't call the
1710 // runtime below. In that case, skip it.
1711 __ Push(x0);
1717 VisitForStackValue(value); 1712 VisitForStackValue(value);
1718 if (property->emit_store()) { 1713 if (property->emit_store()) {
1719 __ CallRuntime(Runtime::kSetPrototype, 2); 1714 __ CallRuntime(Runtime::kSetPrototype, 2);
1720 } else { 1715 } else {
1721 __ Drop(2); 1716 __ Drop(2);
1722 } 1717 }
1723 break; 1718 break;
1724
1725 case ObjectLiteral::Property::GETTER: 1719 case ObjectLiteral::Property::GETTER:
1726 accessor_table.lookup(key)->second->getter = value; 1720 accessor_table.lookup(key)->second->getter = value;
1727 break; 1721 break;
1728 case ObjectLiteral::Property::SETTER: 1722 case ObjectLiteral::Property::SETTER:
1729 accessor_table.lookup(key)->second->setter = value; 1723 accessor_table.lookup(key)->second->setter = value;
1730 break; 1724 break;
1731 } 1725 }
1732 } 1726 }
1733 1727
1734 // Emit code to define accessors, using only a single call to the runtime for 1728 // Emit code to define accessors, using only a single call to the runtime for
1735 // each pair of corresponding getters and setters. 1729 // each pair of corresponding getters and setters.
1736 for (AccessorTable::Iterator it = accessor_table.begin(); 1730 for (AccessorTable::Iterator it = accessor_table.begin();
1737 it != accessor_table.end(); 1731 it != accessor_table.end();
1738 ++it) { 1732 ++it) {
1739 __ ldr(r0, MemOperand(sp)); // Duplicate receiver. 1733 __ Peek(x10, 0); // Duplicate receiver.
1740 __ push(r0); 1734 __ Push(x10);
1741 VisitForStackValue(it->first); 1735 VisitForStackValue(it->first);
1742 EmitAccessor(it->second->getter); 1736 EmitAccessor(it->second->getter);
1743 EmitAccessor(it->second->setter); 1737 EmitAccessor(it->second->setter);
1744 __ mov(r0, Operand(Smi::FromInt(NONE))); 1738 __ Mov(x10, Operand(Smi::FromInt(NONE)));
1745 __ push(r0); 1739 __ Push(x10);
1746 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); 1740 __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5);
1747 } 1741 }
1748 1742
1749 if (expr->has_function()) { 1743 if (expr->has_function()) {
1750 ASSERT(result_saved); 1744 ASSERT(result_saved);
1751 __ ldr(r0, MemOperand(sp)); 1745 __ Peek(x0, 0);
1752 __ push(r0); 1746 __ Push(x0);
1753 __ CallRuntime(Runtime::kToFastProperties, 1); 1747 __ CallRuntime(Runtime::kToFastProperties, 1);
1754 } 1748 }
1755 1749
1756 if (result_saved) { 1750 if (result_saved) {
1757 context()->PlugTOS(); 1751 context()->PlugTOS();
1758 } else { 1752 } else {
1759 context()->Plug(r0); 1753 context()->Plug(x0);
1760 } 1754 }
1761 } 1755 }
1762 1756
1763 1757
1764 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { 1758 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1765 Comment cmnt(masm_, "[ ArrayLiteral"); 1759 Comment cmnt(masm_, "[ ArrayLiteral");
1766 1760
1767 expr->BuildConstantElements(isolate()); 1761 expr->BuildConstantElements(isolate());
1768 int flags = expr->depth() == 1 1762 int flags = (expr->depth() == 1) ? ArrayLiteral::kShallowElements
1769 ? ArrayLiteral::kShallowElements 1763 : ArrayLiteral::kNoFlags;
1770 : ArrayLiteral::kNoFlags;
1771 1764
1772 ZoneList<Expression*>* subexprs = expr->values(); 1765 ZoneList<Expression*>* subexprs = expr->values();
1773 int length = subexprs->length(); 1766 int length = subexprs->length();
1774 Handle<FixedArray> constant_elements = expr->constant_elements(); 1767 Handle<FixedArray> constant_elements = expr->constant_elements();
1775 ASSERT_EQ(2, constant_elements->length()); 1768 ASSERT_EQ(2, constant_elements->length());
1776 ElementsKind constant_elements_kind = 1769 ElementsKind constant_elements_kind =
1777 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); 1770 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value());
1778 bool has_fast_elements = IsFastObjectElementsKind(constant_elements_kind); 1771 bool has_fast_elements = IsFastObjectElementsKind(constant_elements_kind);
1779 Handle<FixedArrayBase> constant_elements_values( 1772 Handle<FixedArrayBase> constant_elements_values(
1780 FixedArrayBase::cast(constant_elements->get(1))); 1773 FixedArrayBase::cast(constant_elements->get(1)));
1781 1774
1782 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; 1775 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE;
1783 if (has_fast_elements && !FLAG_allocation_site_pretenuring) { 1776 if (has_fast_elements && !FLAG_allocation_site_pretenuring) {
1784 // If the only customer of allocation sites is transitioning, then 1777 // If the only customer of allocation sites is transitioning, then
1785 // we can turn it off if we don't have anywhere else to transition to. 1778 // we can turn it off if we don't have anywhere else to transition to.
1786 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; 1779 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE;
1787 } 1780 }
1788 1781
1789 __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 1782 __ Ldr(x3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1790 __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); 1783 __ Ldr(x3, FieldMemOperand(x3, JSFunction::kLiteralsOffset));
1791 __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); 1784 // TODO(jbramley): Can these Operand constructors be implicit?
1792 __ mov(r1, Operand(constant_elements)); 1785 __ Mov(x2, Operand(Smi::FromInt(expr->literal_index())));
1786 __ Mov(x1, Operand(constant_elements));
1793 if (has_fast_elements && constant_elements_values->map() == 1787 if (has_fast_elements && constant_elements_values->map() ==
1794 isolate()->heap()->fixed_cow_array_map()) { 1788 isolate()->heap()->fixed_cow_array_map()) {
1795 FastCloneShallowArrayStub stub( 1789 FastCloneShallowArrayStub stub(
1796 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, 1790 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS,
1797 allocation_site_mode, 1791 allocation_site_mode,
1798 length); 1792 length);
1799 __ CallStub(&stub); 1793 __ CallStub(&stub);
1800 __ IncrementCounter( 1794 __ IncrementCounter(
1801 isolate()->counters()->cow_arrays_created_stub(), 1, r1, r2); 1795 isolate()->counters()->cow_arrays_created_stub(), 1, x10, x11);
1802 } else if (expr->depth() > 1 || Serializer::enabled() || 1796 } else if ((expr->depth() > 1) || Serializer::enabled() ||
1803 length > FastCloneShallowArrayStub::kMaximumClonedLength) { 1797 length > FastCloneShallowArrayStub::kMaximumClonedLength) {
1804 __ mov(r0, Operand(Smi::FromInt(flags))); 1798 __ Mov(x0, Operand(Smi::FromInt(flags)));
1805 __ Push(r3, r2, r1, r0); 1799 __ Push(x3, x2, x1, x0);
1806 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); 1800 __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
1807 } else { 1801 } else {
1808 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || 1802 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) ||
1809 FLAG_smi_only_arrays); 1803 FLAG_smi_only_arrays);
1810 FastCloneShallowArrayStub::Mode mode = 1804 FastCloneShallowArrayStub::Mode mode =
1811 FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; 1805 FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS;
1812 1806
1813 if (has_fast_elements) { 1807 if (has_fast_elements) {
1814 mode = FastCloneShallowArrayStub::CLONE_ELEMENTS; 1808 mode = FastCloneShallowArrayStub::CLONE_ELEMENTS;
1815 } 1809 }
1816 1810
1817 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); 1811 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length);
1818 __ CallStub(&stub); 1812 __ CallStub(&stub);
1819 } 1813 }
1820 1814
1821 bool result_saved = false; // Is the result saved to the stack? 1815 bool result_saved = false; // Is the result saved to the stack?
1822 1816
1823 // Emit code to evaluate all the non-constant subexpressions and to store 1817 // Emit code to evaluate all the non-constant subexpressions and to store
1824 // them into the newly cloned array. 1818 // them into the newly cloned array.
1825 for (int i = 0; i < length; i++) { 1819 for (int i = 0; i < length; i++) {
1826 Expression* subexpr = subexprs->at(i); 1820 Expression* subexpr = subexprs->at(i);
1827 // If the subexpression is a literal or a simple materialized literal it 1821 // If the subexpression is a literal or a simple materialized literal it
1828 // is already set in the cloned array. 1822 // is already set in the cloned array.
1829 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; 1823 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1830 1824
1831 if (!result_saved) { 1825 if (!result_saved) {
1832 __ push(r0); 1826 __ Push(x0);
1833 __ Push(Smi::FromInt(expr->literal_index())); 1827 __ Push(Smi::FromInt(expr->literal_index()));
1834 result_saved = true; 1828 result_saved = true;
1835 } 1829 }
1836 VisitForAccumulatorValue(subexpr); 1830 VisitForAccumulatorValue(subexpr);
1837 1831
1838 if (IsFastObjectElementsKind(constant_elements_kind)) { 1832 if (IsFastObjectElementsKind(constant_elements_kind)) {
1839 int offset = FixedArray::kHeaderSize + (i * kPointerSize); 1833 int offset = FixedArray::kHeaderSize + (i * kPointerSize);
1840 __ ldr(r6, MemOperand(sp, kPointerSize)); // Copy of array literal. 1834 __ Peek(x6, kPointerSize); // Copy of array literal.
1841 __ ldr(r1, FieldMemOperand(r6, JSObject::kElementsOffset)); 1835 __ Ldr(x1, FieldMemOperand(x6, JSObject::kElementsOffset));
1842 __ str(result_register(), FieldMemOperand(r1, offset)); 1836 __ Str(result_register(), FieldMemOperand(x1, offset));
1843 // Update the write barrier for the array store. 1837 // Update the write barrier for the array store.
1844 __ RecordWriteField(r1, offset, result_register(), r2, 1838 __ RecordWriteField(x1, offset, result_register(), x10,
1845 kLRHasBeenSaved, kDontSaveFPRegs, 1839 kLRHasBeenSaved, kDontSaveFPRegs,
1846 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); 1840 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK);
1847 } else { 1841 } else {
1848 __ mov(r3, Operand(Smi::FromInt(i))); 1842 __ Mov(x3, Operand(Smi::FromInt(i)));
1849 StoreArrayLiteralElementStub stub; 1843 StoreArrayLiteralElementStub stub;
1850 __ CallStub(&stub); 1844 __ CallStub(&stub);
1851 } 1845 }
1852 1846
1853 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); 1847 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);
1854 } 1848 }
1855 1849
1856 if (result_saved) { 1850 if (result_saved) {
1857 __ pop(); // literal index 1851 __ Drop(1); // literal index
1858 context()->PlugTOS(); 1852 context()->PlugTOS();
1859 } else { 1853 } else {
1860 context()->Plug(r0); 1854 context()->Plug(x0);
1861 } 1855 }
1862 } 1856 }
1863 1857
1864 1858
1865 void FullCodeGenerator::VisitAssignment(Assignment* expr) { 1859 void FullCodeGenerator::VisitAssignment(Assignment* expr) {
1866 Comment cmnt(masm_, "[ Assignment"); 1860 Comment cmnt(masm_, "[ Assignment");
1867 // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' 1861 // Invalid left-hand sides are rewritten to have a 'throw ReferenceError'
1868 // on the left-hand side. 1862 // on the left-hand side.
1869 if (!expr->target()->IsValidLeftHandSide()) { 1863 if (!expr->target()->IsValidLeftHandSide()) {
1870 VisitForEffect(expr->target()); 1864 VisitForEffect(expr->target());
(...skipping 13 matching lines...) Expand all
1884 1878
1885 // Evaluate LHS expression. 1879 // Evaluate LHS expression.
1886 switch (assign_type) { 1880 switch (assign_type) {
1887 case VARIABLE: 1881 case VARIABLE:
1888 // Nothing to do here. 1882 // Nothing to do here.
1889 break; 1883 break;
1890 case NAMED_PROPERTY: 1884 case NAMED_PROPERTY:
1891 if (expr->is_compound()) { 1885 if (expr->is_compound()) {
1892 // We need the receiver both on the stack and in the accumulator. 1886 // We need the receiver both on the stack and in the accumulator.
1893 VisitForAccumulatorValue(property->obj()); 1887 VisitForAccumulatorValue(property->obj());
1894 __ push(result_register()); 1888 __ Push(result_register());
1895 } else { 1889 } else {
1896 VisitForStackValue(property->obj()); 1890 VisitForStackValue(property->obj());
1897 } 1891 }
1898 break; 1892 break;
1899 case KEYED_PROPERTY: 1893 case KEYED_PROPERTY:
1900 if (expr->is_compound()) { 1894 if (expr->is_compound()) {
1901 VisitForStackValue(property->obj()); 1895 VisitForStackValue(property->obj());
1902 VisitForAccumulatorValue(property->key()); 1896 VisitForAccumulatorValue(property->key());
1903 __ ldr(r1, MemOperand(sp, 0)); 1897 __ Peek(x1, 0);
1904 __ push(r0); 1898 __ Push(x0);
1905 } else { 1899 } else {
1906 VisitForStackValue(property->obj()); 1900 VisitForStackValue(property->obj());
1907 VisitForStackValue(property->key()); 1901 VisitForStackValue(property->key());
1908 } 1902 }
1909 break; 1903 break;
1910 } 1904 }
1911 1905
1912 // For compound assignments we need another deoptimization point after the 1906 // For compound assignments we need another deoptimization point after the
1913 // variable/property load. 1907 // variable/property load.
1914 if (expr->is_compound()) { 1908 if (expr->is_compound()) {
1915 { AccumulatorValueContext context(this); 1909 { AccumulatorValueContext context(this);
1916 switch (assign_type) { 1910 switch (assign_type) {
1917 case VARIABLE: 1911 case VARIABLE:
1918 EmitVariableLoad(expr->target()->AsVariableProxy()); 1912 EmitVariableLoad(expr->target()->AsVariableProxy());
1919 PrepareForBailout(expr->target(), TOS_REG); 1913 PrepareForBailout(expr->target(), TOS_REG);
1920 break; 1914 break;
1921 case NAMED_PROPERTY: 1915 case NAMED_PROPERTY:
1922 EmitNamedPropertyLoad(property); 1916 EmitNamedPropertyLoad(property);
1923 PrepareForBailoutForId(property->LoadId(), TOS_REG); 1917 PrepareForBailoutForId(property->LoadId(), TOS_REG);
1924 break; 1918 break;
1925 case KEYED_PROPERTY: 1919 case KEYED_PROPERTY:
1926 EmitKeyedPropertyLoad(property); 1920 EmitKeyedPropertyLoad(property);
1927 PrepareForBailoutForId(property->LoadId(), TOS_REG); 1921 PrepareForBailoutForId(property->LoadId(), TOS_REG);
1928 break; 1922 break;
1929 } 1923 }
1930 } 1924 }
1931 1925
1932 Token::Value op = expr->binary_op(); 1926 Token::Value op = expr->binary_op();
1933 __ push(r0); // Left operand goes on the stack. 1927 __ Push(x0); // Left operand goes on the stack.
1934 VisitForAccumulatorValue(expr->value()); 1928 VisitForAccumulatorValue(expr->value());
1935 1929
1936 OverwriteMode mode = expr->value()->ResultOverwriteAllowed() 1930 OverwriteMode mode = expr->value()->ResultOverwriteAllowed()
1937 ? OVERWRITE_RIGHT 1931 ? OVERWRITE_RIGHT
1938 : NO_OVERWRITE; 1932 : NO_OVERWRITE;
1939 SetSourcePosition(expr->position() + 1); 1933 SetSourcePosition(expr->position() + 1);
1940 AccumulatorValueContext context(this); 1934 AccumulatorValueContext context(this);
1941 if (ShouldInlineSmiCase(op)) { 1935 if (ShouldInlineSmiCase(op)) {
1942 EmitInlineSmiBinaryOp(expr->binary_operation(), 1936 EmitInlineSmiBinaryOp(expr->binary_operation(),
1943 op, 1937 op,
(...skipping 12 matching lines...) Expand all
1956 1950
1957 // Record source position before possible IC call. 1951 // Record source position before possible IC call.
1958 SetSourcePosition(expr->position()); 1952 SetSourcePosition(expr->position());
1959 1953
1960 // Store the value. 1954 // Store the value.
1961 switch (assign_type) { 1955 switch (assign_type) {
1962 case VARIABLE: 1956 case VARIABLE:
1963 EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), 1957 EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
1964 expr->op()); 1958 expr->op());
1965 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); 1959 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
1966 context()->Plug(r0); 1960 context()->Plug(x0);
1967 break; 1961 break;
1968 case NAMED_PROPERTY: 1962 case NAMED_PROPERTY:
1969 EmitNamedPropertyAssignment(expr); 1963 EmitNamedPropertyAssignment(expr);
1970 break; 1964 break;
1971 case KEYED_PROPERTY: 1965 case KEYED_PROPERTY:
1972 EmitKeyedPropertyAssignment(expr); 1966 EmitKeyedPropertyAssignment(expr);
1973 break; 1967 break;
1974 } 1968 }
1975 } 1969 }
1976 1970
1977 1971
1978 void FullCodeGenerator::VisitYield(Yield* expr) {
1979 Comment cmnt(masm_, "[ Yield");
1980 // Evaluate yielded value first; the initial iterator definition depends on
1981 // this. It stays on the stack while we update the iterator.
1982 VisitForStackValue(expr->expression());
1983
1984 switch (expr->yield_kind()) {
1985 case Yield::SUSPEND:
1986 // Pop value from top-of-stack slot; box result into result register.
1987 EmitCreateIteratorResult(false);
1988 __ push(result_register());
1989 // Fall through.
1990 case Yield::INITIAL: {
1991 Label suspend, continuation, post_runtime, resume;
1992
1993 __ jmp(&suspend);
1994
1995 __ bind(&continuation);
1996 __ jmp(&resume);
1997
1998 __ bind(&suspend);
1999 VisitForAccumulatorValue(expr->generator_object());
2000 ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
2001 __ mov(r1, Operand(Smi::FromInt(continuation.pos())));
2002 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset));
2003 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset));
2004 __ mov(r1, cp);
2005 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2,
2006 kLRHasBeenSaved, kDontSaveFPRegs);
2007 __ add(r1, fp, Operand(StandardFrameConstants::kExpressionsOffset));
2008 __ cmp(sp, r1);
2009 __ b(eq, &post_runtime);
2010 __ push(r0); // generator object
2011 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2012 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2013 __ bind(&post_runtime);
2014 __ pop(result_register());
2015 EmitReturnSequence();
2016
2017 __ bind(&resume);
2018 context()->Plug(result_register());
2019 break;
2020 }
2021
2022 case Yield::FINAL: {
2023 VisitForAccumulatorValue(expr->generator_object());
2024 __ mov(r1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
2025 __ str(r1, FieldMemOperand(result_register(),
2026 JSGeneratorObject::kContinuationOffset));
2027 // Pop value from top-of-stack slot, box result into result register.
2028 EmitCreateIteratorResult(true);
2029 EmitUnwindBeforeReturn();
2030 EmitReturnSequence();
2031 break;
2032 }
2033
2034 case Yield::DELEGATING: {
2035 VisitForStackValue(expr->generator_object());
2036
2037 // Initial stack layout is as follows:
2038 // [sp + 1 * kPointerSize] iter
2039 // [sp + 0 * kPointerSize] g
2040
2041 Label l_catch, l_try, l_suspend, l_continuation, l_resume;
2042 Label l_next, l_call, l_loop;
2043 // Initial send value is undefined.
2044 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
2045 __ b(&l_next);
2046
2047 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
2048 __ bind(&l_catch);
2049 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
2050 __ LoadRoot(r2, Heap::kthrow_stringRootIndex); // "throw"
2051 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
2052 __ Push(r3, r0); // iter, exception
2053 __ jmp(&l_call);
2054
2055 // try { received = %yield result }
2056 // Shuffle the received result above a try handler and yield it without
2057 // re-boxing.
2058 __ bind(&l_try);
2059 __ pop(r0); // result
2060 __ PushTryHandler(StackHandler::CATCH, expr->index());
2061 const int handler_size = StackHandlerConstants::kSize;
2062 __ push(r0); // result
2063 __ jmp(&l_suspend);
2064 __ bind(&l_continuation);
2065 __ jmp(&l_resume);
2066 __ bind(&l_suspend);
2067 const int generator_object_depth = kPointerSize + handler_size;
2068 __ ldr(r0, MemOperand(sp, generator_object_depth));
2069 __ push(r0); // g
2070 ASSERT(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
2071 __ mov(r1, Operand(Smi::FromInt(l_continuation.pos())));
2072 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset));
2073 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset));
2074 __ mov(r1, cp);
2075 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2,
2076 kLRHasBeenSaved, kDontSaveFPRegs);
2077 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2078 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2079 __ pop(r0); // result
2080 EmitReturnSequence();
2081 __ bind(&l_resume); // received in r0
2082 __ PopTryHandler();
2083
2084 // receiver = iter; f = 'next'; arg = received;
2085 __ bind(&l_next);
2086 __ LoadRoot(r2, Heap::knext_stringRootIndex); // "next"
2087 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
2088 __ Push(r3, r0); // iter, received
2089
2090 // result = receiver[f](arg);
2091 __ bind(&l_call);
2092 Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize(1);
2093 CallIC(ic);
2094 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2095
2096 // if (!result.done) goto l_try;
2097 __ bind(&l_loop);
2098 __ push(r0); // save result
2099 __ LoadRoot(r2, Heap::kdone_stringRootIndex); // "done"
2100 CallLoadIC(NOT_CONTEXTUAL); // result.done in r0
2101 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate());
2102 CallIC(bool_ic);
2103 __ cmp(r0, Operand(0));
2104 __ b(eq, &l_try);
2105
2106 // result.value
2107 __ pop(r0); // result
2108 __ LoadRoot(r2, Heap::kvalue_stringRootIndex); // "value"
2109 CallLoadIC(NOT_CONTEXTUAL); // result.value in r0
2110 context()->DropAndPlug(2, r0); // drop iter and g
2111 break;
2112 }
2113 }
2114 }
2115
2116
2117 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
2118 Expression *value,
2119 JSGeneratorObject::ResumeMode resume_mode) {
2120 // The value stays in r0, and is ultimately read by the resumed generator, as
2121 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
2122 // is read to throw the value when the resumed generator is already closed.
2123 // r1 will hold the generator object until the activation has been resumed.
2124 VisitForStackValue(generator);
2125 VisitForAccumulatorValue(value);
2126 __ pop(r1);
2127
2128 // Check generator state.
2129 Label wrong_state, closed_state, done;
2130 __ ldr(r3, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset));
2131 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0);
2132 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0);
2133 __ cmp(r3, Operand(Smi::FromInt(0)));
2134 __ b(eq, &closed_state);
2135 __ b(lt, &wrong_state);
2136
2137 // Load suspended function and context.
2138 __ ldr(cp, FieldMemOperand(r1, JSGeneratorObject::kContextOffset));
2139 __ ldr(r4, FieldMemOperand(r1, JSGeneratorObject::kFunctionOffset));
2140
2141 // Load receiver and store as the first argument.
2142 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kReceiverOffset));
2143 __ push(r2);
2144
2145 // Push holes for the rest of the arguments to the generator function.
2146 __ ldr(r3, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
2147 __ ldr(r3,
2148 FieldMemOperand(r3, SharedFunctionInfo::kFormalParameterCountOffset));
2149 __ LoadRoot(r2, Heap::kTheHoleValueRootIndex);
2150 Label push_argument_holes, push_frame;
2151 __ bind(&push_argument_holes);
2152 __ sub(r3, r3, Operand(Smi::FromInt(1)), SetCC);
2153 __ b(mi, &push_frame);
2154 __ push(r2);
2155 __ jmp(&push_argument_holes);
2156
2157 // Enter a new JavaScript frame, and initialize its slots as they were when
2158 // the generator was suspended.
2159 Label resume_frame;
2160 __ bind(&push_frame);
2161 __ bl(&resume_frame);
2162 __ jmp(&done);
2163 __ bind(&resume_frame);
2164 // lr = return address.
2165 // fp = caller's frame pointer.
2166 // pp = caller's constant pool (if FLAG_enable_ool_constant_pool),
2167 // cp = callee's context,
2168 // r4 = callee's JS function.
2169 __ PushFixedFrame(r4);
2170 // Adjust FP to point to saved FP.
2171 __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
2172
2173 // Load the operand stack size.
2174 __ ldr(r3, FieldMemOperand(r1, JSGeneratorObject::kOperandStackOffset));
2175 __ ldr(r3, FieldMemOperand(r3, FixedArray::kLengthOffset));
2176 __ SmiUntag(r3);
2177
2178 // If we are sending a value and there is no operand stack, we can jump back
2179 // in directly.
2180 if (resume_mode == JSGeneratorObject::NEXT) {
2181 Label slow_resume;
2182 __ cmp(r3, Operand(0));
2183 __ b(ne, &slow_resume);
2184 __ ldr(r3, FieldMemOperand(r4, JSFunction::kCodeEntryOffset));
2185 __ ldr(r2, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset));
2186 __ SmiUntag(r2);
2187 __ add(r3, r3, r2);
2188 __ mov(r2, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)));
2189 __ str(r2, FieldMemOperand(r1, JSGeneratorObject::kContinuationOffset));
2190 __ Jump(r3);
2191 __ bind(&slow_resume);
2192 }
2193
2194 // Otherwise, we push holes for the operand stack and call the runtime to fix
2195 // up the stack and the handlers.
2196 Label push_operand_holes, call_resume;
2197 __ bind(&push_operand_holes);
2198 __ sub(r3, r3, Operand(1), SetCC);
2199 __ b(mi, &call_resume);
2200 __ push(r2);
2201 __ b(&push_operand_holes);
2202 __ bind(&call_resume);
2203 ASSERT(!result_register().is(r1));
2204 __ Push(r1, result_register());
2205 __ Push(Smi::FromInt(resume_mode));
2206 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
2207 // Not reached: the runtime call returns elsewhere.
2208 __ stop("not-reached");
2209
2210 // Reach here when generator is closed.
2211 __ bind(&closed_state);
2212 if (resume_mode == JSGeneratorObject::NEXT) {
2213 // Return completed iterator result when generator is closed.
2214 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
2215 __ push(r2);
2216 // Pop value from top-of-stack slot; box result into result register.
2217 EmitCreateIteratorResult(true);
2218 } else {
2219 // Throw the provided value.
2220 __ push(r0);
2221 __ CallRuntime(Runtime::kThrow, 1);
2222 }
2223 __ jmp(&done);
2224
2225 // Throw error if we attempt to operate on a running generator.
2226 __ bind(&wrong_state);
2227 __ push(r1);
2228 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1);
2229
2230 __ bind(&done);
2231 context()->Plug(result_register());
2232 }
2233
2234
2235 void FullCodeGenerator::EmitCreateIteratorResult(bool done) {
2236 Label gc_required;
2237 Label allocated;
2238
2239 Handle<Map> map(isolate()->native_context()->generator_result_map());
2240
2241 __ Allocate(map->instance_size(), r0, r2, r3, &gc_required, TAG_OBJECT);
2242 __ jmp(&allocated);
2243
2244 __ bind(&gc_required);
2245 __ Push(Smi::FromInt(map->instance_size()));
2246 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
2247 __ ldr(context_register(),
2248 MemOperand(fp, StandardFrameConstants::kContextOffset));
2249
2250 __ bind(&allocated);
2251 __ mov(r1, Operand(map));
2252 __ pop(r2);
2253 __ mov(r3, Operand(isolate()->factory()->ToBoolean(done)));
2254 __ mov(r4, Operand(isolate()->factory()->empty_fixed_array()));
2255 ASSERT_EQ(map->instance_size(), 5 * kPointerSize);
2256 __ str(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
2257 __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset));
2258 __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
2259 __ str(r2,
2260 FieldMemOperand(r0, JSGeneratorObject::kResultValuePropertyOffset));
2261 __ str(r3,
2262 FieldMemOperand(r0, JSGeneratorObject::kResultDonePropertyOffset));
2263
2264 // Only the value field needs a write barrier, as the other values are in the
2265 // root set.
2266 __ RecordWriteField(r0, JSGeneratorObject::kResultValuePropertyOffset,
2267 r2, r3, kLRHasBeenSaved, kDontSaveFPRegs);
2268 }
2269
2270
2271 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { 1972 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
2272 SetSourcePosition(prop->position()); 1973 SetSourcePosition(prop->position());
2273 Literal* key = prop->key()->AsLiteral(); 1974 Literal* key = prop->key()->AsLiteral();
2274 __ mov(r2, Operand(key->value())); 1975 __ Mov(x2, Operand(key->value()));
2275 // Call load IC. It has arguments receiver and property name r0 and r2. 1976 // Call load IC. It has arguments receiver and property name x0 and x2.
2276 CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId()); 1977 CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId());
2277 } 1978 }
2278 1979
2279 1980
2280 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { 1981 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
2281 SetSourcePosition(prop->position()); 1982 SetSourcePosition(prop->position());
2282 // Call keyed load IC. It has arguments key and receiver in r0 and r1. 1983 // Call keyed load IC. It has arguments key and receiver in r0 and r1.
2283 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); 1984 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
2284 CallIC(ic, NOT_CONTEXTUAL, prop->PropertyFeedbackId()); 1985 CallIC(ic, prop->PropertyFeedbackId());
2285 } 1986 }
2286 1987
2287 1988
2288 void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, 1989 void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr,
2289 Token::Value op, 1990 Token::Value op,
2290 OverwriteMode mode, 1991 OverwriteMode mode,
2291 Expression* left_expr, 1992 Expression* left_expr,
2292 Expression* right_expr) { 1993 Expression* right_expr) {
2293 Label done, smi_case, stub_call; 1994 Label done, both_smis, stub_call;
2294
2295 Register scratch1 = r2;
2296 Register scratch2 = r3;
2297 1995
2298 // Get the arguments. 1996 // Get the arguments.
2299 Register left = r1; 1997 Register left = x1;
2300 Register right = r0; 1998 Register right = x0;
2301 __ pop(left); 1999 Register result = x0;
2000 __ Pop(left);
2302 2001
2303 // Perform combined smi check on both operands. 2002 // Perform combined smi check on both operands.
2304 __ orr(scratch1, left, Operand(right)); 2003 __ Orr(x10, left, right);
2305 STATIC_ASSERT(kSmiTag == 0);
2306 JumpPatchSite patch_site(masm_); 2004 JumpPatchSite patch_site(masm_);
2307 patch_site.EmitJumpIfSmi(scratch1, &smi_case); 2005 patch_site.EmitJumpIfSmi(x10, &both_smis);
2308 2006
2309 __ bind(&stub_call); 2007 __ Bind(&stub_call);
2310 BinaryOpICStub stub(op, mode); 2008 BinaryOpICStub stub(op, mode);
2311 CallIC(stub.GetCode(isolate()), NOT_CONTEXTUAL, 2009 {
2312 expr->BinaryOperationFeedbackId()); 2010 Assembler::BlockConstPoolScope scope(masm_);
2313 patch_site.EmitPatchInfo(); 2011 CallIC(stub.GetCode(isolate()), expr->BinaryOperationFeedbackId());
2314 __ jmp(&done); 2012 patch_site.EmitPatchInfo();
2013 }
2014 __ B(&done);
2315 2015
2316 __ bind(&smi_case); 2016 __ Bind(&both_smis);
2317 // Smi case. This code works the same way as the smi-smi case in the type 2017 // Smi case. This code works in the same way as the smi-smi case in the type
2318 // recording binary operation stub, see 2018 // recording binary operation stub, see
2019 // BinaryOpStub::GenerateSmiSmiOperation for comments.
2020 // TODO(all): That doesn't exist any more. Where are the comments?
2021 //
2022 // The set of operations that needs to be supported here is controlled by
2023 // FullCodeGenerator::ShouldInlineSmiCase().
2319 switch (op) { 2024 switch (op) {
2320 case Token::SAR: 2025 case Token::SAR:
2321 __ GetLeastBitsFromSmi(scratch1, right, 5); 2026 __ Ubfx(right, right, kSmiShift, 5);
2322 __ mov(right, Operand(left, ASR, scratch1)); 2027 __ Asr(result, left, right);
2323 __ bic(right, right, Operand(kSmiTagMask)); 2028 __ Bic(result, result, kSmiShiftMask);
2324 break; 2029 break;
2325 case Token::SHL: { 2030 case Token::SHL:
2326 __ SmiUntag(scratch1, left); 2031 __ Ubfx(right, right, kSmiShift, 5);
2327 __ GetLeastBitsFromSmi(scratch2, right, 5); 2032 __ Lsl(result, left, right);
2328 __ mov(scratch1, Operand(scratch1, LSL, scratch2));
2329 __ TrySmiTag(right, scratch1, &stub_call);
2330 break; 2033 break;
2331 }
2332 case Token::SHR: { 2034 case Token::SHR: {
2333 __ SmiUntag(scratch1, left); 2035 Label right_not_zero;
2334 __ GetLeastBitsFromSmi(scratch2, right, 5); 2036 __ Cbnz(right, &right_not_zero);
2335 __ mov(scratch1, Operand(scratch1, LSR, scratch2)); 2037 __ Tbnz(left, kXSignBit, &stub_call);
2336 __ tst(scratch1, Operand(0xc0000000)); 2038 __ Bind(&right_not_zero);
2337 __ b(ne, &stub_call); 2039 __ Ubfx(right, right, kSmiShift, 5);
2338 __ SmiTag(right, scratch1); 2040 __ Lsr(result, left, right);
2041 __ Bic(result, result, kSmiShiftMask);
2339 break; 2042 break;
2340 } 2043 }
2341 case Token::ADD: 2044 case Token::ADD:
2342 __ add(scratch1, left, Operand(right), SetCC); 2045 __ Adds(x10, left, right);
2343 __ b(vs, &stub_call); 2046 __ B(vs, &stub_call);
2344 __ mov(right, scratch1); 2047 __ Mov(result, x10);
2345 break; 2048 break;
2346 case Token::SUB: 2049 case Token::SUB:
2347 __ sub(scratch1, left, Operand(right), SetCC); 2050 __ Subs(x10, left, right);
2348 __ b(vs, &stub_call); 2051 __ B(vs, &stub_call);
2349 __ mov(right, scratch1); 2052 __ Mov(result, x10);
2350 break; 2053 break;
2351 case Token::MUL: { 2054 case Token::MUL: {
2352 __ SmiUntag(ip, right); 2055 Label not_minus_zero, done;
2353 __ smull(scratch1, scratch2, left, ip); 2056 __ Smulh(x10, left, right);
2354 __ mov(ip, Operand(scratch1, ASR, 31)); 2057 __ Cbnz(x10, &not_minus_zero);
2355 __ cmp(ip, Operand(scratch2)); 2058 __ Eor(x11, left, right);
2356 __ b(ne, &stub_call); 2059 __ Tbnz(x11, kXSignBit, &stub_call);
2357 __ cmp(scratch1, Operand::Zero()); 2060 STATIC_ASSERT(kSmiTag == 0);
2358 __ mov(right, Operand(scratch1), LeaveCC, ne); 2061 __ Mov(result, x10);
2359 __ b(ne, &done); 2062 __ B(&done);
2360 __ add(scratch2, right, Operand(left), SetCC); 2063 __ Bind(&not_minus_zero);
2361 __ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl); 2064 __ Cls(x11, x10);
2362 __ b(mi, &stub_call); 2065 __ Cmp(x11, kXRegSize - kSmiShift);
2066 __ B(lt, &stub_call);
2067 __ SmiTag(result, x10);
2068 __ Bind(&done);
2363 break; 2069 break;
2364 } 2070 }
2365 case Token::BIT_OR: 2071 case Token::BIT_OR:
2366 __ orr(right, left, Operand(right)); 2072 __ Orr(result, left, right);
2367 break; 2073 break;
2368 case Token::BIT_AND: 2074 case Token::BIT_AND:
2369 __ and_(right, left, Operand(right)); 2075 __ And(result, left, right);
2370 break; 2076 break;
2371 case Token::BIT_XOR: 2077 case Token::BIT_XOR:
2372 __ eor(right, left, Operand(right)); 2078 __ Eor(result, left, right);
2373 break; 2079 break;
2374 default: 2080 default:
2375 UNREACHABLE(); 2081 UNREACHABLE();
2376 } 2082 }
2377 2083
2378 __ bind(&done); 2084 __ Bind(&done);
2379 context()->Plug(r0); 2085 context()->Plug(x0);
2380 } 2086 }
2381 2087
2382 2088
2383 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, 2089 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr,
2384 Token::Value op, 2090 Token::Value op,
2385 OverwriteMode mode) { 2091 OverwriteMode mode) {
2386 __ pop(r1); 2092 __ Pop(x1);
2387 BinaryOpICStub stub(op, mode); 2093 BinaryOpICStub stub(op, mode);
2388 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. 2094 JumpPatchSite patch_site(masm_); // Unbound, signals no inlined smi code.
2389 CallIC(stub.GetCode(isolate()), NOT_CONTEXTUAL, 2095 {
2390 expr->BinaryOperationFeedbackId()); 2096 Assembler::BlockConstPoolScope scope(masm_);
2391 patch_site.EmitPatchInfo(); 2097 CallIC(stub.GetCode(isolate()), expr->BinaryOperationFeedbackId());
2392 context()->Plug(r0); 2098 patch_site.EmitPatchInfo();
2099 }
2100 context()->Plug(x0);
2393 } 2101 }
2394 2102
2395 2103
2396 void FullCodeGenerator::EmitAssignment(Expression* expr) { 2104 void FullCodeGenerator::EmitAssignment(Expression* expr) {
2397 // Invalid left-hand sides are rewritten by the parser to have a 'throw 2105 // Invalid left-hand sides are rewritten to have a 'throw
2398 // ReferenceError' on the left-hand side. 2106 // ReferenceError' on the left-hand side.
2399 if (!expr->IsValidLeftHandSide()) { 2107 if (!expr->IsValidLeftHandSide()) {
2400 VisitForEffect(expr); 2108 VisitForEffect(expr);
2401 return; 2109 return;
2402 } 2110 }
2403 2111
2404 // Left-hand side can only be a property, a global or a (parameter or local) 2112 // Left-hand side can only be a property, a global or a (parameter or local)
2405 // slot. 2113 // slot.
2406 enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; 2114 enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
2407 LhsKind assign_type = VARIABLE; 2115 LhsKind assign_type = VARIABLE;
2408 Property* prop = expr->AsProperty(); 2116 Property* prop = expr->AsProperty();
2409 if (prop != NULL) { 2117 if (prop != NULL) {
2410 assign_type = (prop->key()->IsPropertyName()) 2118 assign_type = (prop->key()->IsPropertyName())
2411 ? NAMED_PROPERTY 2119 ? NAMED_PROPERTY
2412 : KEYED_PROPERTY; 2120 : KEYED_PROPERTY;
2413 } 2121 }
2414 2122
2415 switch (assign_type) { 2123 switch (assign_type) {
2416 case VARIABLE: { 2124 case VARIABLE: {
2417 Variable* var = expr->AsVariableProxy()->var(); 2125 Variable* var = expr->AsVariableProxy()->var();
2418 EffectContext context(this); 2126 EffectContext context(this);
2419 EmitVariableAssignment(var, Token::ASSIGN); 2127 EmitVariableAssignment(var, Token::ASSIGN);
2420 break; 2128 break;
2421 } 2129 }
2422 case NAMED_PROPERTY: { 2130 case NAMED_PROPERTY: {
2423 __ push(r0); // Preserve value. 2131 __ Push(x0); // Preserve value.
2424 VisitForAccumulatorValue(prop->obj()); 2132 VisitForAccumulatorValue(prop->obj());
2425 __ mov(r1, r0); 2133 // TODO(all): We could introduce a VisitForRegValue(reg, expr) to avoid
2426 __ pop(r0); // Restore value. 2134 // this copy.
2427 __ mov(r2, Operand(prop->key()->AsLiteral()->value())); 2135 __ Mov(x1, x0);
2428 CallStoreIC(NOT_CONTEXTUAL); 2136 __ Pop(x0); // Restore value.
2137 __ Mov(x2, Operand(prop->key()->AsLiteral()->value()));
2138 CallStoreIC();
2429 break; 2139 break;
2430 } 2140 }
2431 case KEYED_PROPERTY: { 2141 case KEYED_PROPERTY: {
2432 __ push(r0); // Preserve value. 2142 __ Push(x0); // Preserve value.
2433 VisitForStackValue(prop->obj()); 2143 VisitForStackValue(prop->obj());
2434 VisitForAccumulatorValue(prop->key()); 2144 VisitForAccumulatorValue(prop->key());
2435 __ mov(r1, r0); 2145 __ Mov(x1, x0);
2436 __ Pop(r0, r2); // r0 = restored value. 2146 __ Pop(x2, x0);
2437 Handle<Code> ic = is_classic_mode() 2147 Handle<Code> ic = is_classic_mode()
2438 ? isolate()->builtins()->KeyedStoreIC_Initialize() 2148 ? isolate()->builtins()->KeyedStoreIC_Initialize()
2439 : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); 2149 : isolate()->builtins()->KeyedStoreIC_Initialize_Strict();
2440 CallIC(ic); 2150 CallIC(ic);
2441 break; 2151 break;
2442 } 2152 }
2443 } 2153 }
2444 context()->Plug(r0); 2154 context()->Plug(x0);
2155 }
2156
2157
2158 void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
2159 Variable* var, MemOperand location) {
2160 __ Str(result_register(), location);
2161 if (var->IsContextSlot()) {
2162 // RecordWrite may destroy all its register arguments.
2163 __ Mov(x10, result_register());
2164 int offset = Context::SlotOffset(var->index());
2165 __ RecordWriteContextSlot(
2166 x1, offset, x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
2167 }
2168 }
2169
2170
2171 void FullCodeGenerator::EmitCallStoreContextSlot(
2172 Handle<String> name, LanguageMode mode) {
2173 __ Mov(x11, Operand(name));
2174 __ Mov(x10, Operand(Smi::FromInt(mode)));
2175 // jssp[0] : mode.
2176 // jssp[8] : name.
2177 // jssp[16] : context.
2178 // jssp[24] : value.
2179 __ Push(x0, cp, x11, x10);
2180 __ CallRuntime(Runtime::kStoreContextSlot, 4);
2445 } 2181 }
2446 2182
2447 2183
2448 void FullCodeGenerator::EmitVariableAssignment(Variable* var, 2184 void FullCodeGenerator::EmitVariableAssignment(Variable* var,
2449 Token::Value op) { 2185 Token::Value op) {
2186 ASM_LOCATION("FullCodeGenerator::EmitVariableAssignment");
2450 if (var->IsUnallocated()) { 2187 if (var->IsUnallocated()) {
2451 // Global var, const, or let. 2188 // Global var, const, or let.
2452 __ mov(r2, Operand(var->name())); 2189 __ Mov(x2, Operand(var->name()));
2453 __ ldr(r1, GlobalObjectOperand()); 2190 __ Ldr(x1, GlobalObjectMemOperand());
2454 CallStoreIC(CONTEXTUAL); 2191 CallStoreIC();
2192
2455 } else if (op == Token::INIT_CONST) { 2193 } else if (op == Token::INIT_CONST) {
2456 // Const initializers need a write barrier. 2194 // Const initializers need a write barrier.
2457 ASSERT(!var->IsParameter()); // No const parameters. 2195 ASSERT(!var->IsParameter()); // No const parameters.
2458 if (var->IsStackLocal()) { 2196 if (var->IsLookupSlot()) {
2459 __ ldr(r1, StackOperand(var)); 2197 __ Push(x0);
2460 __ CompareRoot(r1, Heap::kTheHoleValueRootIndex); 2198 __ Mov(x0, Operand(var->name()));
2461 __ str(result_register(), StackOperand(var), eq); 2199 __ Push(cp, x0); // Context and name.
2200 __ CallRuntime(Runtime::kInitializeConstContextSlot, 3);
2462 } else { 2201 } else {
2463 ASSERT(var->IsContextSlot() || var->IsLookupSlot()); 2202 ASSERT(var->IsStackLocal() || var->IsContextSlot());
2464 // Like var declarations, const declarations are hoisted to function 2203 Label skip;
2465 // scope. However, unlike var initializers, const initializers are 2204 MemOperand location = VarOperand(var, x1);
2466 // able to drill a hole to that function context, even from inside a 2205 __ Ldr(x10, location);
2467 // 'with' context. We thus bypass the normal static scope lookup for 2206 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &skip);
2468 // var->IsContextSlot(). 2207 EmitStoreToStackLocalOrContextSlot(var, location);
2469 __ push(r0); 2208 __ Bind(&skip);
2470 __ mov(r0, Operand(var->name()));
2471 __ Push(cp, r0); // Context and name.
2472 __ CallRuntime(Runtime::kInitializeConstContextSlot, 3);
2473 } 2209 }
2474 2210
2475 } else if (var->mode() == LET && op != Token::INIT_LET) { 2211 } else if (var->mode() == LET && op != Token::INIT_LET) {
2476 // Non-initializing assignment to let variable needs a write barrier. 2212 // Non-initializing assignment to let variable needs a write barrier.
2477 if (var->IsLookupSlot()) { 2213 if (var->IsLookupSlot()) {
2478 __ push(r0); // Value. 2214 EmitCallStoreContextSlot(var->name(), language_mode());
2479 __ mov(r1, Operand(var->name()));
2480 __ mov(r0, Operand(Smi::FromInt(language_mode())));
2481 __ Push(cp, r1, r0); // Context, name, strict mode.
2482 __ CallRuntime(Runtime::kStoreContextSlot, 4);
2483 } else { 2215 } else {
2484 ASSERT(var->IsStackAllocated() || var->IsContextSlot()); 2216 ASSERT(var->IsStackAllocated() || var->IsContextSlot());
2485 Label assign; 2217 Label assign;
2486 MemOperand location = VarOperand(var, r1); 2218 MemOperand location = VarOperand(var, x1);
2487 __ ldr(r3, location); 2219 __ Ldr(x10, location);
2488 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); 2220 __ JumpIfNotRoot(x10, Heap::kTheHoleValueRootIndex, &assign);
2489 __ b(ne, &assign); 2221 __ Mov(x10, Operand(var->name()));
2490 __ mov(r3, Operand(var->name())); 2222 __ Push(x10);
2491 __ push(r3);
2492 __ CallRuntime(Runtime::kThrowReferenceError, 1); 2223 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2493 // Perform the assignment. 2224 // Perform the assignment.
2494 __ bind(&assign); 2225 __ Bind(&assign);
2495 __ str(result_register(), location); 2226 EmitStoreToStackLocalOrContextSlot(var, location);
2496 if (var->IsContextSlot()) {
2497 // RecordWrite may destroy all its register arguments.
2498 __ mov(r3, result_register());
2499 int offset = Context::SlotOffset(var->index());
2500 __ RecordWriteContextSlot(
2501 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs);
2502 }
2503 } 2227 }
2504 2228
2505 } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { 2229 } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) {
2506 // Assignment to var or initializing assignment to let/const 2230 // Assignment to var or initializing assignment to let/const
2507 // in harmony mode. 2231 // in harmony mode.
2508 if (var->IsStackAllocated() || var->IsContextSlot()) { 2232 if (var->IsLookupSlot()) {
2509 MemOperand location = VarOperand(var, r1); 2233 EmitCallStoreContextSlot(var->name(), language_mode());
2510 if (generate_debug_code_ && op == Token::INIT_LET) { 2234 } else {
2511 // Check for an uninitialized let binding. 2235 ASSERT(var->IsStackAllocated() || var->IsContextSlot());
2512 __ ldr(r2, location); 2236 MemOperand location = VarOperand(var, x1);
2513 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex); 2237 if (FLAG_debug_code && op == Token::INIT_LET) {
2238 __ Ldr(x10, location);
2239 __ CompareRoot(x10, Heap::kTheHoleValueRootIndex);
2514 __ Check(eq, kLetBindingReInitialization); 2240 __ Check(eq, kLetBindingReInitialization);
2515 } 2241 }
2516 // Perform the assignment. 2242 EmitStoreToStackLocalOrContextSlot(var, location);
2517 __ str(r0, location);
2518 if (var->IsContextSlot()) {
2519 __ mov(r3, r0);
2520 int offset = Context::SlotOffset(var->index());
2521 __ RecordWriteContextSlot(
2522 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs);
2523 }
2524 } else {
2525 ASSERT(var->IsLookupSlot());
2526 __ push(r0); // Value.
2527 __ mov(r1, Operand(var->name()));
2528 __ mov(r0, Operand(Smi::FromInt(language_mode())));
2529 __ Push(cp, r1, r0); // Context, name, strict mode.
2530 __ CallRuntime(Runtime::kStoreContextSlot, 4);
2531 } 2243 }
2532 } 2244 }
2533 // Non-initializing assignments to consts are ignored. 2245 // Non-initializing assignments to consts are ignored.
2534 } 2246 }
2535 2247
2536 2248
2537 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { 2249 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
2250 ASM_LOCATION("FullCodeGenerator::EmitNamedPropertyAssignment");
2538 // Assignment to a property, using a named store IC. 2251 // Assignment to a property, using a named store IC.
2539 Property* prop = expr->target()->AsProperty(); 2252 Property* prop = expr->target()->AsProperty();
2540 ASSERT(prop != NULL); 2253 ASSERT(prop != NULL);
2541 ASSERT(prop->key()->AsLiteral() != NULL); 2254 ASSERT(prop->key()->AsLiteral() != NULL);
2542 2255
2543 // Record source code position before IC call. 2256 // Record source code position before IC call.
2544 SetSourcePosition(expr->position()); 2257 SetSourcePosition(expr->position());
2545 __ mov(r2, Operand(prop->key()->AsLiteral()->value())); 2258 __ Mov(x2, Operand(prop->key()->AsLiteral()->value()));
2546 __ pop(r1); 2259 __ Pop(x1);
2547 2260
2548 CallStoreIC(NOT_CONTEXTUAL, expr->AssignmentFeedbackId()); 2261 CallStoreIC(expr->AssignmentFeedbackId());
2549 2262
2550 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); 2263 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2551 context()->Plug(r0); 2264 context()->Plug(x0);
2552 } 2265 }
2553 2266
2554 2267
2555 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { 2268 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) {
2269 ASM_LOCATION("FullCodeGenerator::EmitKeyedPropertyAssignment");
2556 // Assignment to a property, using a keyed store IC. 2270 // Assignment to a property, using a keyed store IC.
2557 2271
2558 // Record source code position before IC call. 2272 // Record source code position before IC call.
2559 SetSourcePosition(expr->position()); 2273 SetSourcePosition(expr->position());
2560 __ Pop(r2, r1); // r1 = key. 2274 // TODO(all): Could we pass this in registers rather than on the stack?
2275 __ Pop(x1, x2); // Key and object holding the property.
2561 2276
2562 Handle<Code> ic = is_classic_mode() 2277 Handle<Code> ic = is_classic_mode()
2563 ? isolate()->builtins()->KeyedStoreIC_Initialize() 2278 ? isolate()->builtins()->KeyedStoreIC_Initialize()
2564 : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); 2279 : isolate()->builtins()->KeyedStoreIC_Initialize_Strict();
2565 CallIC(ic, NOT_CONTEXTUAL, expr->AssignmentFeedbackId()); 2280 CallIC(ic, expr->AssignmentFeedbackId());
2566 2281
2567 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); 2282 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2568 context()->Plug(r0); 2283 context()->Plug(x0);
2569 } 2284 }
2570 2285
2571 2286
2572 void FullCodeGenerator::VisitProperty(Property* expr) { 2287 void FullCodeGenerator::VisitProperty(Property* expr) {
2573 Comment cmnt(masm_, "[ Property"); 2288 Comment cmnt(masm_, "[ Property");
2574 Expression* key = expr->key(); 2289 Expression* key = expr->key();
2575 2290
2576 if (key->IsPropertyName()) { 2291 if (key->IsPropertyName()) {
2577 VisitForAccumulatorValue(expr->obj()); 2292 VisitForAccumulatorValue(expr->obj());
2578 EmitNamedPropertyLoad(expr); 2293 EmitNamedPropertyLoad(expr);
2579 PrepareForBailoutForId(expr->LoadId(), TOS_REG); 2294 PrepareForBailoutForId(expr->LoadId(), TOS_REG);
2580 context()->Plug(r0); 2295 context()->Plug(x0);
2581 } else { 2296 } else {
2582 VisitForStackValue(expr->obj()); 2297 VisitForStackValue(expr->obj());
2583 VisitForAccumulatorValue(expr->key()); 2298 VisitForAccumulatorValue(expr->key());
2584 __ pop(r1); 2299 __ Pop(x1);
2585 EmitKeyedPropertyLoad(expr); 2300 EmitKeyedPropertyLoad(expr);
2586 context()->Plug(r0); 2301 context()->Plug(x0);
2587 } 2302 }
2588 } 2303 }
2589 2304
2590 2305
2591 void FullCodeGenerator::CallIC(Handle<Code> code, 2306 void FullCodeGenerator::CallIC(Handle<Code> code,
2592 ContextualMode mode,
2593 TypeFeedbackId ast_id) { 2307 TypeFeedbackId ast_id) {
2594 ic_total_count_++; 2308 ic_total_count_++;
2595 // All calls must have a predictable size in full-codegen code to ensure that 2309 // All calls must have a predictable size in full-codegen code to ensure that
2596 // the debugger can patch them correctly. 2310 // the debugger can patch them correctly.
2597 ASSERT(mode != CONTEXTUAL || ast_id.IsNone()); 2311 __ Call(code, RelocInfo::CODE_TARGET, ast_id);
2598 __ Call(code, RelocInfo::CODE_TARGET, ast_id, al,
2599 NEVER_INLINE_TARGET_ADDRESS);
2600 } 2312 }
2601 2313
2602 void FullCodeGenerator::EmitCallWithIC(Call* expr, 2314
2603 Handle<Object> name, 2315 // Code common for calls using the IC.
2604 ContextualMode mode) { 2316 void FullCodeGenerator::EmitCallWithIC(Call* expr) {
2605 // Code common for calls using the IC. 2317 ASM_LOCATION("EmitCallWithIC");
2318
2319 Expression* callee = expr->expression();
2606 ZoneList<Expression*>* args = expr->arguments(); 2320 ZoneList<Expression*>* args = expr->arguments();
2607 int arg_count = args->length(); 2321 int arg_count = args->length();
2322
2323 CallFunctionFlags flags;
2324 // Get the target function.
2325 if (callee->IsVariableProxy()) {
2326 { StackValueContext context(this);
2327 EmitVariableLoad(callee->AsVariableProxy());
2328 PrepareForBailout(callee, NO_REGISTERS);
2329 }
2330 // Push undefined as receiver. This is patched in the method prologue if it
2331 // is a classic mode method.
2332 __ Push(isolate()->factory()->undefined_value());
2333 flags = NO_CALL_FUNCTION_FLAGS;
2334 } else {
2335 // Load the function from the receiver.
2336 ASSERT(callee->IsProperty());
2337 __ Peek(x0, 0);
2338 EmitNamedPropertyLoad(callee->AsProperty());
2339 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2340 // Push the target function under the receiver.
2341 __ Pop(x10);
2342 __ Push(x0, x10);
2343 flags = CALL_AS_METHOD;
2344 }
2345
2346 // Load the arguments.
2608 { PreservePositionScope scope(masm()->positions_recorder()); 2347 { PreservePositionScope scope(masm()->positions_recorder());
2609 for (int i = 0; i < arg_count; i++) { 2348 for (int i = 0; i < arg_count; i++) {
2610 VisitForStackValue(args->at(i)); 2349 VisitForStackValue(args->at(i));
2611 } 2350 }
2612 __ mov(r2, Operand(name));
2613 } 2351 }
2352
2614 // Record source position for debugger. 2353 // Record source position for debugger.
2615 SetSourcePosition(expr->position()); 2354 SetSourcePosition(expr->position());
2616 // Call the IC initialization code. 2355 CallFunctionStub stub(arg_count, flags);
2617 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize(arg_count); 2356 __ Peek(x1, (arg_count + 1) * kPointerSize);
2618 TypeFeedbackId ast_id = mode == CONTEXTUAL 2357 __ CallStub(&stub);
2619 ? TypeFeedbackId::None() 2358
2620 : expr->CallFeedbackId();
2621 CallIC(ic, mode, ast_id);
2622 RecordJSReturnSite(expr); 2359 RecordJSReturnSite(expr);
2360
2623 // Restore context register. 2361 // Restore context register.
2624 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 2362 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2625 context()->Plug(r0); 2363
2364 context()->DropAndPlug(1, x0);
2626 } 2365 }
2627 2366
2628 2367
2368 // Code common for calls using the IC.
2629 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, 2369 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
2630 Expression* key) { 2370 Expression* key) {
2631 // Load the key. 2371 // Load the key.
2632 VisitForAccumulatorValue(key); 2372 VisitForAccumulatorValue(key);
2633 2373
2634 // Swap the name of the function and the receiver on the stack to follow 2374 Expression* callee = expr->expression();
2635 // the calling convention for call ICs.
2636 __ pop(r1);
2637 __ push(r0);
2638 __ push(r1);
2639
2640 // Code common for calls using the IC.
2641 ZoneList<Expression*>* args = expr->arguments(); 2375 ZoneList<Expression*>* args = expr->arguments();
2642 int arg_count = args->length(); 2376 int arg_count = args->length();
2377
2378 // Load the function from the receiver.
2379 ASSERT(callee->IsProperty());
2380 __ Peek(x1, 0);
2381 EmitKeyedPropertyLoad(callee->AsProperty());
2382 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG);
2383
2384 // Push the target function under the receiver.
2385 __ Pop(x10);
2386 __ Push(x0, x10);
2387
2643 { PreservePositionScope scope(masm()->positions_recorder()); 2388 { PreservePositionScope scope(masm()->positions_recorder());
2644 for (int i = 0; i < arg_count; i++) { 2389 for (int i = 0; i < arg_count; i++) {
2645 VisitForStackValue(args->at(i)); 2390 VisitForStackValue(args->at(i));
2646 } 2391 }
2647 } 2392 }
2393
2648 // Record source position for debugger. 2394 // Record source position for debugger.
2649 SetSourcePosition(expr->position()); 2395 SetSourcePosition(expr->position());
2650 // Call the IC initialization code. 2396 CallFunctionStub stub(arg_count, CALL_AS_METHOD);
2651 Handle<Code> ic = 2397 __ Peek(x1, (arg_count + 1) * kPointerSize);
2652 isolate()->stub_cache()->ComputeKeyedCallInitialize(arg_count); 2398 __ CallStub(&stub);
2653 __ ldr(r2, MemOperand(sp, (arg_count + 1) * kPointerSize)); // Key. 2399
2654 CallIC(ic, NOT_CONTEXTUAL, expr->CallFeedbackId());
2655 RecordJSReturnSite(expr); 2400 RecordJSReturnSite(expr);
2656 // Restore context register. 2401 // Restore context register.
2657 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 2402 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2658 context()->DropAndPlug(1, r0); // Drop the key still on the stack. 2403
2404 context()->DropAndPlug(1, x0);
2659 } 2405 }
2660 2406
2661 2407
2662 void FullCodeGenerator::EmitCallWithStub(Call* expr) { 2408 void FullCodeGenerator::EmitCallWithStub(Call* expr) {
2663 // Code common for calls using the call stub. 2409 // Code common for calls using the call stub.
2664 ZoneList<Expression*>* args = expr->arguments(); 2410 ZoneList<Expression*>* args = expr->arguments();
2665 int arg_count = args->length(); 2411 int arg_count = args->length();
2666 { PreservePositionScope scope(masm()->positions_recorder()); 2412 { PreservePositionScope scope(masm()->positions_recorder());
2667 for (int i = 0; i < arg_count; i++) { 2413 for (int i = 0; i < arg_count; i++) {
2668 VisitForStackValue(args->at(i)); 2414 VisitForStackValue(args->at(i));
2669 } 2415 }
2670 } 2416 }
2671 // Record source position for debugger. 2417 // Record source position for debugger.
2672 SetSourcePosition(expr->position()); 2418 SetSourcePosition(expr->position());
2673 2419
2674 Handle<Object> uninitialized = 2420 Handle<Object> uninitialized =
2675 TypeFeedbackCells::UninitializedSentinel(isolate()); 2421 TypeFeedbackInfo::UninitializedSentinel(isolate());
2676 Handle<Cell> cell = isolate()->factory()->NewCell(uninitialized); 2422 StoreFeedbackVectorSlot(expr->CallFeedbackSlot(), uninitialized);
2677 RecordTypeFeedbackCell(expr->CallFeedbackId(), cell); 2423 __ LoadObject(x2, FeedbackVector());
2678 __ mov(r2, Operand(cell)); 2424 __ Mov(x3, Operand(Smi::FromInt(expr->CallFeedbackSlot())));
2679 2425
2680 // Record call targets in unoptimized code. 2426 // Record call targets in unoptimized code.
2681 CallFunctionStub stub(arg_count, RECORD_CALL_TARGET); 2427 CallFunctionStub stub(arg_count, RECORD_CALL_TARGET);
2682 __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); 2428 __ Peek(x1, (arg_count + 1) * kXRegSizeInBytes);
2683 __ CallStub(&stub, expr->CallFeedbackId()); 2429 __ CallStub(&stub);
2684 RecordJSReturnSite(expr); 2430 RecordJSReturnSite(expr);
2685 // Restore context register. 2431 // Restore context register.
2686 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 2432 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2687 context()->DropAndPlug(1, r0); 2433 context()->DropAndPlug(1, x0);
2688 } 2434 }
2689 2435
2690 2436
2691 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { 2437 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
2692 // r4: copy of the first argument or undefined if it doesn't exist. 2438 ASM_LOCATION("FullCodeGenerator::EmitResolvePossiblyDirectEval");
2439 // Prepare to push a copy of the first argument or undefined if it doesn't
2440 // exist.
2693 if (arg_count > 0) { 2441 if (arg_count > 0) {
2694 __ ldr(r4, MemOperand(sp, arg_count * kPointerSize)); 2442 __ Peek(x10, arg_count * kXRegSizeInBytes);
2695 } else { 2443 } else {
2696 __ LoadRoot(r4, Heap::kUndefinedValueRootIndex); 2444 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex);
2697 } 2445 }
2698 2446
2699 // r3: the receiver of the enclosing function. 2447 // Prepare to push the receiver of the enclosing function.
2700 int receiver_offset = 2 + info_->scope()->num_parameters(); 2448 int receiver_offset = 2 + info_->scope()->num_parameters();
2701 __ ldr(r3, MemOperand(fp, receiver_offset * kPointerSize)); 2449 __ Ldr(x11, MemOperand(fp, receiver_offset * kPointerSize));
2702 2450
2703 // r2: the language mode. 2451 // Push.
2704 __ mov(r2, Operand(Smi::FromInt(language_mode()))); 2452 __ Push(x10, x11);
2705 2453
2706 // r1: the start position of the scope the calls resides in. 2454 // Prepare to push the language mode.
2707 __ mov(r1, Operand(Smi::FromInt(scope()->start_position()))); 2455 __ Mov(x10, Operand(Smi::FromInt(language_mode())));
2456 // Prepare to push the start position of the scope the calls resides in.
2457 __ Mov(x11, Operand(Smi::FromInt(scope()->start_position())));
2458
2459 // Push.
2460 __ Push(x10, x11);
2708 2461
2709 // Do the runtime call. 2462 // Do the runtime call.
2710 __ Push(r4, r3, r2, r1);
2711 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5); 2463 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5);
2712 } 2464 }
2713 2465
2714 2466
2715 void FullCodeGenerator::VisitCall(Call* expr) { 2467 void FullCodeGenerator::VisitCall(Call* expr) {
2716 #ifdef DEBUG 2468 #ifdef DEBUG
2717 // We want to verify that RecordJSReturnSite gets called on all paths 2469 // We want to verify that RecordJSReturnSite gets called on all paths
2718 // through this function. Avoid early returns. 2470 // through this function. Avoid early returns.
2719 expr->return_is_recorded_ = false; 2471 expr->return_is_recorded_ = false;
2720 #endif 2472 #endif
2721 2473
2722 Comment cmnt(masm_, "[ Call"); 2474 Comment cmnt(masm_, "[ Call");
2723 Expression* callee = expr->expression(); 2475 Expression* callee = expr->expression();
2724 Call::CallType call_type = expr->GetCallType(isolate()); 2476 Call::CallType call_type = expr->GetCallType(isolate());
2725 2477
2726 if (call_type == Call::POSSIBLY_EVAL_CALL) { 2478 if (call_type == Call::POSSIBLY_EVAL_CALL) {
2727 // In a call to eval, we first call %ResolvePossiblyDirectEval to 2479 // In a call to eval, we first call %ResolvePossiblyDirectEval to
2728 // resolve the function we need to call and the receiver of the 2480 // resolve the function we need to call and the receiver of the
2729 // call. Then we call the resolved function using the given 2481 // call. Then we call the resolved function using the given
2730 // arguments. 2482 // arguments.
2731 ZoneList<Expression*>* args = expr->arguments(); 2483 ZoneList<Expression*>* args = expr->arguments();
2732 int arg_count = args->length(); 2484 int arg_count = args->length();
2733 2485
2734 { PreservePositionScope pos_scope(masm()->positions_recorder()); 2486 {
2487 PreservePositionScope pos_scope(masm()->positions_recorder());
2735 VisitForStackValue(callee); 2488 VisitForStackValue(callee);
2736 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); 2489 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex);
2737 __ push(r2); // Reserved receiver slot. 2490 __ Push(x10); // Reserved receiver slot.
2738 2491
2739 // Push the arguments. 2492 // Push the arguments.
2740 for (int i = 0; i < arg_count; i++) { 2493 for (int i = 0; i < arg_count; i++) {
2741 VisitForStackValue(args->at(i)); 2494 VisitForStackValue(args->at(i));
2742 } 2495 }
2743 2496
2744 // Push a copy of the function (found below the arguments) and 2497 // Push a copy of the function (found below the arguments) and
2745 // resolve eval. 2498 // resolve eval.
2746 __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); 2499 __ Peek(x10, (arg_count + 1) * kPointerSize);
2747 __ push(r1); 2500 __ Push(x10);
2748 EmitResolvePossiblyDirectEval(arg_count); 2501 EmitResolvePossiblyDirectEval(arg_count);
2749 2502
2750 // The runtime call returns a pair of values in r0 (function) and 2503 // The runtime call returns a pair of values in x0 (function) and
2751 // r1 (receiver). Touch up the stack with the right values. 2504 // x1 (receiver). Touch up the stack with the right values.
2752 __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); 2505 __ PokePair(x1, x0, arg_count * kPointerSize);
2753 __ str(r1, MemOperand(sp, arg_count * kPointerSize));
2754 } 2506 }
2755 2507
2756 // Record source position for debugger. 2508 // Record source position for debugger.
2757 SetSourcePosition(expr->position()); 2509 SetSourcePosition(expr->position());
2510
2511 // Call the evaluated function.
2758 CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); 2512 CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS);
2759 __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); 2513 __ Peek(x1, (arg_count + 1) * kXRegSizeInBytes);
2760 __ CallStub(&stub); 2514 __ CallStub(&stub);
2761 RecordJSReturnSite(expr); 2515 RecordJSReturnSite(expr);
2762 // Restore context register. 2516 // Restore context register.
2763 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 2517 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2764 context()->DropAndPlug(1, r0); 2518 context()->DropAndPlug(1, x0);
2519
2765 } else if (call_type == Call::GLOBAL_CALL) { 2520 } else if (call_type == Call::GLOBAL_CALL) {
2766 // Push global object as receiver for the call IC. 2521 EmitCallWithIC(expr);
2767 __ ldr(r0, GlobalObjectOperand()); 2522
2768 __ push(r0);
2769 VariableProxy* proxy = callee->AsVariableProxy();
2770 EmitCallWithIC(expr, proxy->name(), CONTEXTUAL);
2771 } else if (call_type == Call::LOOKUP_SLOT_CALL) { 2523 } else if (call_type == Call::LOOKUP_SLOT_CALL) {
2772 // Call to a lookup slot (dynamically introduced variable). 2524 // Call to a lookup slot (dynamically introduced variable).
2773 VariableProxy* proxy = callee->AsVariableProxy(); 2525 VariableProxy* proxy = callee->AsVariableProxy();
2774 Label slow, done; 2526 Label slow, done;
2775 2527
2776 { PreservePositionScope scope(masm()->positions_recorder()); 2528 { PreservePositionScope scope(masm()->positions_recorder());
2777 // Generate code for loading from variables potentially shadowed 2529 // Generate code for loading from variables potentially shadowed
2778 // by eval-introduced variables. 2530 // by eval-introduced variables.
2779 EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); 2531 EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done);
2780 } 2532 }
2781 2533
2782 __ bind(&slow); 2534 __ Bind(&slow);
2783 // Call the runtime to find the function to call (returned in r0) 2535 // Call the runtime to find the function to call (returned in x0)
2784 // and the object holding it (returned in edx). 2536 // and the object holding it (returned in x1).
2785 ASSERT(!context_register().is(r2)); 2537 __ Push(context_register());
2786 __ mov(r2, Operand(proxy->name())); 2538 __ Mov(x10, Operand(proxy->name()));
2787 __ Push(context_register(), r2); 2539 __ Push(x10);
2788 __ CallRuntime(Runtime::kLoadContextSlot, 2); 2540 __ CallRuntime(Runtime::kLoadContextSlot, 2);
2789 __ Push(r0, r1); // Function, receiver. 2541 __ Push(x0, x1); // Receiver, function.
2790 2542
2791 // If fast case code has been generated, emit code to push the 2543 // If fast case code has been generated, emit code to push the
2792 // function and receiver and have the slow path jump around this 2544 // function and receiver and have the slow path jump around this
2793 // code. 2545 // code.
2794 if (done.is_linked()) { 2546 if (done.is_linked()) {
2795 Label call; 2547 Label call;
2796 __ b(&call); 2548 __ B(&call);
2797 __ bind(&done); 2549 __ Bind(&done);
2798 // Push function. 2550 // Push function.
2799 __ push(r0); 2551 __ Push(x0);
2800 // The receiver is implicitly the global receiver. Indicate this 2552 // The receiver is implicitly the global receiver. Indicate this
2801 // by passing the hole to the call function stub. 2553 // by passing the undefined to the call function stub.
2802 __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); 2554 __ LoadRoot(x1, Heap::kUndefinedValueRootIndex);
2803 __ push(r1); 2555 __ Push(x1);
2804 __ bind(&call); 2556 __ Bind(&call);
2805 } 2557 }
2806 2558
2807 // The receiver is either the global receiver or an object found 2559 // The receiver is either the global receiver or an object found
2808 // by LoadContextSlot. 2560 // by LoadContextSlot.
2809 EmitCallWithStub(expr); 2561 EmitCallWithStub(expr);
2810 } else if (call_type == Call::PROPERTY_CALL) { 2562 } else if (call_type == Call::PROPERTY_CALL) {
2811 Property* property = callee->AsProperty(); 2563 Property* property = callee->AsProperty();
2812 { PreservePositionScope scope(masm()->positions_recorder()); 2564 { PreservePositionScope scope(masm()->positions_recorder());
2813 VisitForStackValue(property->obj()); 2565 VisitForStackValue(property->obj());
2814 } 2566 }
2815 if (property->key()->IsPropertyName()) { 2567 if (property->key()->IsPropertyName()) {
2816 EmitCallWithIC(expr, 2568 EmitCallWithIC(expr);
2817 property->key()->AsLiteral()->value(),
2818 NOT_CONTEXTUAL);
2819 } else { 2569 } else {
2820 EmitKeyedCallWithIC(expr, property->key()); 2570 EmitKeyedCallWithIC(expr, property->key());
2821 } 2571 }
2572
2822 } else { 2573 } else {
2823 ASSERT(call_type == Call::OTHER_CALL); 2574 ASSERT(call_type == Call::OTHER_CALL);
2824 // Call to an arbitrary expression not handled specially above. 2575 // Call to an arbitrary expression not handled specially above.
2825 { PreservePositionScope scope(masm()->positions_recorder()); 2576 { PreservePositionScope scope(masm()->positions_recorder());
2826 VisitForStackValue(callee); 2577 VisitForStackValue(callee);
2827 } 2578 }
2828 __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); 2579 __ LoadRoot(x1, Heap::kUndefinedValueRootIndex);
2829 __ push(r1); 2580 __ Push(x1);
2830 // Emit function call. 2581 // Emit function call.
2831 EmitCallWithStub(expr); 2582 EmitCallWithStub(expr);
2832 } 2583 }
2833 2584
2834 #ifdef DEBUG 2585 #ifdef DEBUG
2835 // RecordJSReturnSite should have been called. 2586 // RecordJSReturnSite should have been called.
2836 ASSERT(expr->return_is_recorded_); 2587 ASSERT(expr->return_is_recorded_);
2837 #endif 2588 #endif
2838 } 2589 }
2839 2590
(...skipping 13 matching lines...) Expand all
2853 ZoneList<Expression*>* args = expr->arguments(); 2604 ZoneList<Expression*>* args = expr->arguments();
2854 int arg_count = args->length(); 2605 int arg_count = args->length();
2855 for (int i = 0; i < arg_count; i++) { 2606 for (int i = 0; i < arg_count; i++) {
2856 VisitForStackValue(args->at(i)); 2607 VisitForStackValue(args->at(i));
2857 } 2608 }
2858 2609
2859 // Call the construct call builtin that handles allocation and 2610 // Call the construct call builtin that handles allocation and
2860 // constructor invocation. 2611 // constructor invocation.
2861 SetSourcePosition(expr->position()); 2612 SetSourcePosition(expr->position());
2862 2613
2863 // Load function and argument count into r1 and r0. 2614 // Load function and argument count into x1 and x0.
2864 __ mov(r0, Operand(arg_count)); 2615 __ Mov(x0, arg_count);
2865 __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); 2616 __ Peek(x1, arg_count * kXRegSizeInBytes);
2866 2617
2867 // Record call targets in unoptimized code. 2618 // Record call targets in unoptimized code.
2868 Handle<Object> uninitialized = 2619 Handle<Object> uninitialized =
2869 TypeFeedbackCells::UninitializedSentinel(isolate()); 2620 TypeFeedbackInfo::UninitializedSentinel(isolate());
2870 Handle<Cell> cell = isolate()->factory()->NewCell(uninitialized); 2621 StoreFeedbackVectorSlot(expr->CallNewFeedbackSlot(), uninitialized);
2871 RecordTypeFeedbackCell(expr->CallNewFeedbackId(), cell); 2622 __ LoadObject(x2, FeedbackVector());
2872 __ mov(r2, Operand(cell)); 2623 __ Mov(x3, Operand(Smi::FromInt(expr->CallNewFeedbackSlot())));
2873 2624
2874 CallConstructStub stub(RECORD_CALL_TARGET); 2625 CallConstructStub stub(RECORD_CALL_TARGET);
2875 __ Call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); 2626 __ Call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL);
2876 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); 2627 PrepareForBailoutForId(expr->ReturnId(), TOS_REG);
2877 context()->Plug(r0); 2628 context()->Plug(x0);
2878 } 2629 }
2879 2630
2880 2631
2881 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { 2632 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) {
2882 ZoneList<Expression*>* args = expr->arguments(); 2633 ZoneList<Expression*>* args = expr->arguments();
2883 ASSERT(args->length() == 1); 2634 ASSERT(args->length() == 1);
2884 2635
2885 VisitForAccumulatorValue(args->at(0)); 2636 VisitForAccumulatorValue(args->at(0));
2886 2637
2887 Label materialize_true, materialize_false; 2638 Label materialize_true, materialize_false;
2888 Label* if_true = NULL; 2639 Label* if_true = NULL;
2889 Label* if_false = NULL; 2640 Label* if_false = NULL;
2890 Label* fall_through = NULL; 2641 Label* fall_through = NULL;
2891 context()->PrepareTest(&materialize_true, &materialize_false, 2642 context()->PrepareTest(&materialize_true, &materialize_false,
2892 &if_true, &if_false, &fall_through); 2643 &if_true, &if_false, &fall_through);
2893 2644
2894 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2645 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
2895 __ SmiTst(r0); 2646 __ TestAndSplit(x0, kSmiTagMask, if_true, if_false, fall_through);
2896 Split(eq, if_true, if_false, fall_through);
2897 2647
2898 context()->Plug(if_true, if_false); 2648 context()->Plug(if_true, if_false);
2899 } 2649 }
2900 2650
2901 2651
2902 void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { 2652 void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) {
2903 ZoneList<Expression*>* args = expr->arguments(); 2653 ZoneList<Expression*>* args = expr->arguments();
2904 ASSERT(args->length() == 1); 2654 ASSERT(args->length() == 1);
2905 2655
2906 VisitForAccumulatorValue(args->at(0)); 2656 VisitForAccumulatorValue(args->at(0));
2907 2657
2908 Label materialize_true, materialize_false; 2658 Label materialize_true, materialize_false;
2909 Label* if_true = NULL; 2659 Label* if_true = NULL;
2910 Label* if_false = NULL; 2660 Label* if_false = NULL;
2911 Label* fall_through = NULL; 2661 Label* fall_through = NULL;
2912 context()->PrepareTest(&materialize_true, &materialize_false, 2662 context()->PrepareTest(&materialize_true, &materialize_false,
2913 &if_true, &if_false, &fall_through); 2663 &if_true, &if_false, &fall_through);
2914 2664
2915 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2665 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
2916 __ NonNegativeSmiTst(r0); 2666 __ TestAndSplit(x0, kSmiTagMask | (0x80000000UL << kSmiShift), if_true,
2917 Split(eq, if_true, if_false, fall_through); 2667 if_false, fall_through);
2918 2668
2919 context()->Plug(if_true, if_false); 2669 context()->Plug(if_true, if_false);
2920 } 2670 }
2921 2671
2922 2672
2923 void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { 2673 void FullCodeGenerator::EmitIsObject(CallRuntime* expr) {
2924 ZoneList<Expression*>* args = expr->arguments(); 2674 ZoneList<Expression*>* args = expr->arguments();
2925 ASSERT(args->length() == 1); 2675 ASSERT(args->length() == 1);
2926 2676
2927 VisitForAccumulatorValue(args->at(0)); 2677 VisitForAccumulatorValue(args->at(0));
2928 2678
2929 Label materialize_true, materialize_false; 2679 Label materialize_true, materialize_false;
2930 Label* if_true = NULL; 2680 Label* if_true = NULL;
2931 Label* if_false = NULL; 2681 Label* if_false = NULL;
2932 Label* fall_through = NULL; 2682 Label* fall_through = NULL;
2933 context()->PrepareTest(&materialize_true, &materialize_false, 2683 context()->PrepareTest(&materialize_true, &materialize_false,
2934 &if_true, &if_false, &fall_through); 2684 &if_true, &if_false, &fall_through);
2935 2685
2936 __ JumpIfSmi(r0, if_false); 2686 __ JumpIfSmi(x0, if_false);
2937 __ LoadRoot(ip, Heap::kNullValueRootIndex); 2687 __ JumpIfRoot(x0, Heap::kNullValueRootIndex, if_true);
2938 __ cmp(r0, ip); 2688 __ Ldr(x10, FieldMemOperand(x0, HeapObject::kMapOffset));
2939 __ b(eq, if_true);
2940 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
2941 // Undetectable objects behave like undefined when tested with typeof. 2689 // Undetectable objects behave like undefined when tested with typeof.
2942 __ ldrb(r1, FieldMemOperand(r2, Map::kBitFieldOffset)); 2690 __ Ldrb(x11, FieldMemOperand(x10, Map::kBitFieldOffset));
2943 __ tst(r1, Operand(1 << Map::kIsUndetectable)); 2691 __ Tbnz(x11, Map::kIsUndetectable, if_false);
2944 __ b(ne, if_false); 2692 __ Ldrb(x12, FieldMemOperand(x10, Map::kInstanceTypeOffset));
2945 __ ldrb(r1, FieldMemOperand(r2, Map::kInstanceTypeOffset)); 2693 __ Cmp(x12, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE);
2946 __ cmp(r1, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); 2694 __ B(lt, if_false);
2947 __ b(lt, if_false); 2695 __ Cmp(x12, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
2948 __ cmp(r1, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE));
2949 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2696 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
2950 Split(le, if_true, if_false, fall_through); 2697 Split(le, if_true, if_false, fall_through);
2951 2698
2952 context()->Plug(if_true, if_false); 2699 context()->Plug(if_true, if_false);
2953 } 2700 }
2954 2701
2955 2702
2956 void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { 2703 void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) {
2957 ZoneList<Expression*>* args = expr->arguments(); 2704 ZoneList<Expression*>* args = expr->arguments();
2958 ASSERT(args->length() == 1); 2705 ASSERT(args->length() == 1);
2959 2706
2960 VisitForAccumulatorValue(args->at(0)); 2707 VisitForAccumulatorValue(args->at(0));
2961 2708
2962 Label materialize_true, materialize_false; 2709 Label materialize_true, materialize_false;
2963 Label* if_true = NULL; 2710 Label* if_true = NULL;
2964 Label* if_false = NULL; 2711 Label* if_false = NULL;
2965 Label* fall_through = NULL; 2712 Label* fall_through = NULL;
2966 context()->PrepareTest(&materialize_true, &materialize_false, 2713 context()->PrepareTest(&materialize_true, &materialize_false,
2967 &if_true, &if_false, &fall_through); 2714 &if_true, &if_false, &fall_through);
2968 2715
2969 __ JumpIfSmi(r0, if_false); 2716 __ JumpIfSmi(x0, if_false);
2970 __ CompareObjectType(r0, r1, r1, FIRST_SPEC_OBJECT_TYPE); 2717 __ CompareObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE);
2971 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2718 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
2972 Split(ge, if_true, if_false, fall_through); 2719 Split(ge, if_true, if_false, fall_through);
2973 2720
2974 context()->Plug(if_true, if_false); 2721 context()->Plug(if_true, if_false);
2975 } 2722 }
2976 2723
2977 2724
2978 void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { 2725 void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) {
2726 ASM_LOCATION("FullCodeGenerator::EmitIsUndetectableObject");
2979 ZoneList<Expression*>* args = expr->arguments(); 2727 ZoneList<Expression*>* args = expr->arguments();
2980 ASSERT(args->length() == 1); 2728 ASSERT(args->length() == 1);
2981 2729
2982 VisitForAccumulatorValue(args->at(0)); 2730 VisitForAccumulatorValue(args->at(0));
2983 2731
2984 Label materialize_true, materialize_false; 2732 Label materialize_true, materialize_false;
2985 Label* if_true = NULL; 2733 Label* if_true = NULL;
2986 Label* if_false = NULL; 2734 Label* if_false = NULL;
2987 Label* fall_through = NULL; 2735 Label* fall_through = NULL;
2988 context()->PrepareTest(&materialize_true, &materialize_false, 2736 context()->PrepareTest(&materialize_true, &materialize_false,
2989 &if_true, &if_false, &fall_through); 2737 &if_true, &if_false, &fall_through);
2990 2738
2991 __ JumpIfSmi(r0, if_false); 2739 __ JumpIfSmi(x0, if_false);
2992 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); 2740 __ Ldr(x10, FieldMemOperand(x0, HeapObject::kMapOffset));
2993 __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset)); 2741 __ Ldrb(x11, FieldMemOperand(x10, Map::kBitFieldOffset));
2994 __ tst(r1, Operand(1 << Map::kIsUndetectable)); 2742 __ Tst(x11, 1 << Map::kIsUndetectable);
2995 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2743 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
2996 Split(ne, if_true, if_false, fall_through); 2744 Split(ne, if_true, if_false, fall_through);
2997 2745
2998 context()->Plug(if_true, if_false); 2746 context()->Plug(if_true, if_false);
2999 } 2747 }
3000 2748
3001 2749
3002 void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( 2750 void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf(
3003 CallRuntime* expr) { 2751 CallRuntime* expr) {
3004 ZoneList<Expression*>* args = expr->arguments(); 2752 ZoneList<Expression*>* args = expr->arguments();
3005 ASSERT(args->length() == 1); 2753 ASSERT(args->length() == 1);
3006
3007 VisitForAccumulatorValue(args->at(0)); 2754 VisitForAccumulatorValue(args->at(0));
3008 2755
3009 Label materialize_true, materialize_false, skip_lookup; 2756 Label materialize_true, materialize_false, skip_lookup;
3010 Label* if_true = NULL; 2757 Label* if_true = NULL;
3011 Label* if_false = NULL; 2758 Label* if_false = NULL;
3012 Label* fall_through = NULL; 2759 Label* fall_through = NULL;
3013 context()->PrepareTest(&materialize_true, &materialize_false, 2760 context()->PrepareTest(&materialize_true, &materialize_false,
3014 &if_true, &if_false, &fall_through); 2761 &if_true, &if_false, &fall_through);
3015 2762
3016 __ AssertNotSmi(r0); 2763 Register object = x0;
2764 __ AssertNotSmi(object);
3017 2765
3018 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); 2766 Register map = x10;
3019 __ ldrb(ip, FieldMemOperand(r1, Map::kBitField2Offset)); 2767 Register bitfield2 = x11;
3020 __ tst(ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); 2768 __ Ldr(map, FieldMemOperand(object, HeapObject::kMapOffset));
3021 __ b(ne, &skip_lookup); 2769 __ Ldrb(bitfield2, FieldMemOperand(map, Map::kBitField2Offset));
2770 __ Tbnz(bitfield2, Map::kStringWrapperSafeForDefaultValueOf, &skip_lookup);
3022 2771
3023 // Check for fast case object. Generate false result for slow case object. 2772 // Check for fast case object. Generate false result for slow case object.
3024 __ ldr(r2, FieldMemOperand(r0, JSObject::kPropertiesOffset)); 2773 Register props = x12;
3025 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset)); 2774 Register props_map = x12;
3026 __ LoadRoot(ip, Heap::kHashTableMapRootIndex); 2775 Register hash_table_map = x13;
3027 __ cmp(r2, ip); 2776 __ Ldr(props, FieldMemOperand(object, JSObject::kPropertiesOffset));
3028 __ b(eq, if_false); 2777 __ Ldr(props_map, FieldMemOperand(props, HeapObject::kMapOffset));
2778 __ LoadRoot(hash_table_map, Heap::kHashTableMapRootIndex);
2779 __ Cmp(props_map, hash_table_map);
2780 __ B(eq, if_false);
3029 2781
3030 // Look for valueOf name in the descriptor array, and indicate false if 2782 // Look for valueOf name in the descriptor array, and indicate false if found.
3031 // found. Since we omit an enumeration index check, if it is added via a 2783 // Since we omit an enumeration index check, if it is added via a transition
3032 // transition that shares its descriptor array, this is a false positive. 2784 // that shares its descriptor array, this is a false positive.
3033 Label entry, loop, done; 2785 Label loop, done;
3034 2786
3035 // Skip loop if no descriptors are valid. 2787 // Skip loop if no descriptors are valid.
3036 __ NumberOfOwnDescriptors(r3, r1); 2788 Register descriptors = x12;
3037 __ cmp(r3, Operand::Zero()); 2789 Register descriptors_length = x13;
3038 __ b(eq, &done); 2790 __ NumberOfOwnDescriptors(descriptors_length, map);
2791 __ Cbz(descriptors_length, &done);
3039 2792
3040 __ LoadInstanceDescriptors(r1, r4); 2793 __ LoadInstanceDescriptors(map, descriptors);
3041 // r4: descriptor array. 2794
3042 // r3: valid entries in the descriptor array. 2795 // Calculate the end of the descriptor array.
3043 __ mov(ip, Operand(DescriptorArray::kDescriptorSize)); 2796 Register descriptors_end = x14;
3044 __ mul(r3, r3, ip); 2797 __ Mov(x15, DescriptorArray::kDescriptorSize);
2798 __ Mul(descriptors_length, descriptors_length, x15);
3045 // Calculate location of the first key name. 2799 // Calculate location of the first key name.
3046 __ add(r4, r4, Operand(DescriptorArray::kFirstOffset - kHeapObjectTag)); 2800 __ Add(descriptors, descriptors,
2801 DescriptorArray::kFirstOffset - kHeapObjectTag);
3047 // Calculate the end of the descriptor array. 2802 // Calculate the end of the descriptor array.
3048 __ mov(r2, r4); 2803 __ Add(descriptors_end, descriptors,
3049 __ add(r2, r2, Operand::PointerOffsetFromSmiKey(r3)); 2804 Operand(descriptors_length, LSL, kPointerSizeLog2));
3050 2805
3051 // Loop through all the keys in the descriptor array. If one of these is the 2806 // Loop through all the keys in the descriptor array. If one of these is the
3052 // string "valueOf" the result is false. 2807 // string "valueOf" the result is false.
3053 // The use of ip to store the valueOf string assumes that it is not otherwise 2808 Register valueof_string = x1;
3054 // used in the loop below. 2809 int descriptor_size = DescriptorArray::kDescriptorSize * kPointerSize;
3055 __ mov(ip, Operand(isolate()->factory()->value_of_string())); 2810 __ Mov(valueof_string, Operand(isolate()->factory()->value_of_string()));
3056 __ jmp(&entry); 2811 __ Bind(&loop);
3057 __ bind(&loop); 2812 __ Ldr(x15, MemOperand(descriptors, descriptor_size, PostIndex));
3058 __ ldr(r3, MemOperand(r4, 0)); 2813 __ Cmp(x15, valueof_string);
3059 __ cmp(r3, ip); 2814 __ B(eq, if_false);
3060 __ b(eq, if_false); 2815 __ Cmp(descriptors, descriptors_end);
3061 __ add(r4, r4, Operand(DescriptorArray::kDescriptorSize * kPointerSize)); 2816 __ B(ne, &loop);
3062 __ bind(&entry);
3063 __ cmp(r4, Operand(r2));
3064 __ b(ne, &loop);
3065 2817
3066 __ bind(&done); 2818 __ Bind(&done);
3067 2819
3068 // Set the bit in the map to indicate that there is no local valueOf field. 2820 // Set the bit in the map to indicate that there is no local valueOf field.
3069 __ ldrb(r2, FieldMemOperand(r1, Map::kBitField2Offset)); 2821 __ Ldrb(x2, FieldMemOperand(map, Map::kBitField2Offset));
3070 __ orr(r2, r2, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); 2822 __ Orr(x2, x2, 1 << Map::kStringWrapperSafeForDefaultValueOf);
3071 __ strb(r2, FieldMemOperand(r1, Map::kBitField2Offset)); 2823 __ Strb(x2, FieldMemOperand(map, Map::kBitField2Offset));
3072 2824
3073 __ bind(&skip_lookup); 2825 __ Bind(&skip_lookup);
3074 2826
3075 // If a valueOf property is not found on the object check that its 2827 // If a valueOf property is not found on the object check that its prototype
3076 // prototype is the un-modified String prototype. If not result is false. 2828 // is the unmodified String prototype. If not result is false.
3077 __ ldr(r2, FieldMemOperand(r1, Map::kPrototypeOffset)); 2829 Register prototype = x1;
3078 __ JumpIfSmi(r2, if_false); 2830 Register global_idx = x2;
3079 __ ldr(r2, FieldMemOperand(r2, HeapObject::kMapOffset)); 2831 Register native_context = x2;
3080 __ ldr(r3, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); 2832 Register string_proto = x3;
3081 __ ldr(r3, FieldMemOperand(r3, GlobalObject::kNativeContextOffset)); 2833 Register proto_map = x4;
3082 __ ldr(r3, ContextOperand(r3, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); 2834 __ Ldr(prototype, FieldMemOperand(map, Map::kPrototypeOffset));
3083 __ cmp(r2, r3); 2835 __ JumpIfSmi(prototype, if_false);
2836 __ Ldr(proto_map, FieldMemOperand(prototype, HeapObject::kMapOffset));
2837 __ Ldr(global_idx, GlobalObjectMemOperand());
2838 __ Ldr(native_context,
2839 FieldMemOperand(global_idx, GlobalObject::kNativeContextOffset));
2840 __ Ldr(string_proto,
2841 ContextMemOperand(native_context,
2842 Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
2843 __ Cmp(proto_map, string_proto);
2844
3084 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2845 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3085 Split(eq, if_true, if_false, fall_through); 2846 Split(eq, if_true, if_false, fall_through);
3086 2847
3087 context()->Plug(if_true, if_false); 2848 context()->Plug(if_true, if_false);
3088 } 2849 }
3089 2850
3090 2851
3091 void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { 2852 void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) {
3092 ZoneList<Expression*>* args = expr->arguments(); 2853 ZoneList<Expression*>* args = expr->arguments();
3093 ASSERT(args->length() == 1); 2854 ASSERT(args->length() == 1);
3094 2855
3095 VisitForAccumulatorValue(args->at(0)); 2856 VisitForAccumulatorValue(args->at(0));
3096 2857
3097 Label materialize_true, materialize_false; 2858 Label materialize_true, materialize_false;
3098 Label* if_true = NULL; 2859 Label* if_true = NULL;
3099 Label* if_false = NULL; 2860 Label* if_false = NULL;
3100 Label* fall_through = NULL; 2861 Label* fall_through = NULL;
3101 context()->PrepareTest(&materialize_true, &materialize_false, 2862 context()->PrepareTest(&materialize_true, &materialize_false,
3102 &if_true, &if_false, &fall_through); 2863 &if_true, &if_false, &fall_through);
3103 2864
3104 __ JumpIfSmi(r0, if_false); 2865 __ JumpIfSmi(x0, if_false);
3105 __ CompareObjectType(r0, r1, r2, JS_FUNCTION_TYPE); 2866 __ CompareObjectType(x0, x10, x11, JS_FUNCTION_TYPE);
3106 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2867 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3107 Split(eq, if_true, if_false, fall_through); 2868 Split(eq, if_true, if_false, fall_through);
3108 2869
3109 context()->Plug(if_true, if_false); 2870 context()->Plug(if_true, if_false);
3110 } 2871 }
3111 2872
3112 2873
3113 void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { 2874 void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) {
3114 ZoneList<Expression*>* args = expr->arguments(); 2875 ZoneList<Expression*>* args = expr->arguments();
3115 ASSERT(args->length() == 1); 2876 ASSERT(args->length() == 1);
3116 2877
3117 VisitForAccumulatorValue(args->at(0)); 2878 VisitForAccumulatorValue(args->at(0));
3118 2879
3119 Label materialize_true, materialize_false; 2880 Label materialize_true, materialize_false;
3120 Label* if_true = NULL; 2881 Label* if_true = NULL;
3121 Label* if_false = NULL; 2882 Label* if_false = NULL;
3122 Label* fall_through = NULL; 2883 Label* fall_through = NULL;
3123 context()->PrepareTest(&materialize_true, &materialize_false, 2884 context()->PrepareTest(&materialize_true, &materialize_false,
3124 &if_true, &if_false, &fall_through); 2885 &if_true, &if_false, &fall_through);
3125 2886
3126 __ CheckMap(r0, r1, Heap::kHeapNumberMapRootIndex, if_false, DO_SMI_CHECK); 2887 // Only a HeapNumber can be -0.0, so return false if we have something else.
3127 __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); 2888 __ CheckMap(x0, x1, Heap::kHeapNumberMapRootIndex, if_false, DO_SMI_CHECK);
3128 __ ldr(r1, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); 2889
3129 __ cmp(r2, Operand(0x80000000)); 2890 // Test the bit pattern.
3130 __ cmp(r1, Operand(0x00000000), eq); 2891 __ Ldr(x10, FieldMemOperand(x0, HeapNumber::kValueOffset));
2892 __ Cmp(x10, 1); // Set V on 0x8000000000000000.
3131 2893
3132 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2894 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3133 Split(eq, if_true, if_false, fall_through); 2895 Split(vs, if_true, if_false, fall_through);
3134 2896
3135 context()->Plug(if_true, if_false); 2897 context()->Plug(if_true, if_false);
3136 } 2898 }
3137 2899
3138 2900
3139 void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { 2901 void FullCodeGenerator::EmitIsArray(CallRuntime* expr) {
3140 ZoneList<Expression*>* args = expr->arguments(); 2902 ZoneList<Expression*>* args = expr->arguments();
3141 ASSERT(args->length() == 1); 2903 ASSERT(args->length() == 1);
3142 2904
3143 VisitForAccumulatorValue(args->at(0)); 2905 VisitForAccumulatorValue(args->at(0));
3144 2906
3145 Label materialize_true, materialize_false; 2907 Label materialize_true, materialize_false;
3146 Label* if_true = NULL; 2908 Label* if_true = NULL;
3147 Label* if_false = NULL; 2909 Label* if_false = NULL;
3148 Label* fall_through = NULL; 2910 Label* fall_through = NULL;
3149 context()->PrepareTest(&materialize_true, &materialize_false, 2911 context()->PrepareTest(&materialize_true, &materialize_false,
3150 &if_true, &if_false, &fall_through); 2912 &if_true, &if_false, &fall_through);
3151 2913
3152 __ JumpIfSmi(r0, if_false); 2914 __ JumpIfSmi(x0, if_false);
3153 __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); 2915 __ CompareObjectType(x0, x10, x11, JS_ARRAY_TYPE);
3154 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2916 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3155 Split(eq, if_true, if_false, fall_through); 2917 Split(eq, if_true, if_false, fall_through);
3156 2918
3157 context()->Plug(if_true, if_false); 2919 context()->Plug(if_true, if_false);
3158 } 2920 }
3159 2921
3160 2922
3161 void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { 2923 void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) {
3162 ZoneList<Expression*>* args = expr->arguments(); 2924 ZoneList<Expression*>* args = expr->arguments();
3163 ASSERT(args->length() == 1); 2925 ASSERT(args->length() == 1);
3164 2926
3165 VisitForAccumulatorValue(args->at(0)); 2927 VisitForAccumulatorValue(args->at(0));
3166 2928
3167 Label materialize_true, materialize_false; 2929 Label materialize_true, materialize_false;
3168 Label* if_true = NULL; 2930 Label* if_true = NULL;
3169 Label* if_false = NULL; 2931 Label* if_false = NULL;
3170 Label* fall_through = NULL; 2932 Label* fall_through = NULL;
3171 context()->PrepareTest(&materialize_true, &materialize_false, 2933 context()->PrepareTest(&materialize_true, &materialize_false,
3172 &if_true, &if_false, &fall_through); 2934 &if_true, &if_false, &fall_through);
3173 2935
3174 __ JumpIfSmi(r0, if_false); 2936 __ JumpIfSmi(x0, if_false);
3175 __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); 2937 __ CompareObjectType(x0, x10, x11, JS_REGEXP_TYPE);
3176 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2938 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3177 Split(eq, if_true, if_false, fall_through); 2939 Split(eq, if_true, if_false, fall_through);
3178 2940
3179 context()->Plug(if_true, if_false); 2941 context()->Plug(if_true, if_false);
3180 } 2942 }
3181 2943
3182 2944
3183 2945
3184 void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { 2946 void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) {
3185 ASSERT(expr->arguments()->length() == 0); 2947 ASSERT(expr->arguments()->length() == 0);
3186 2948
3187 Label materialize_true, materialize_false; 2949 Label materialize_true, materialize_false;
3188 Label* if_true = NULL; 2950 Label* if_true = NULL;
3189 Label* if_false = NULL; 2951 Label* if_false = NULL;
3190 Label* fall_through = NULL; 2952 Label* fall_through = NULL;
3191 context()->PrepareTest(&materialize_true, &materialize_false, 2953 context()->PrepareTest(&materialize_true, &materialize_false,
3192 &if_true, &if_false, &fall_through); 2954 &if_true, &if_false, &fall_through);
3193 2955
3194 // Get the frame pointer for the calling frame. 2956 // Get the frame pointer for the calling frame.
3195 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); 2957 __ Ldr(x2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3196 2958
3197 // Skip the arguments adaptor frame if it exists. 2959 // Skip the arguments adaptor frame if it exists.
3198 __ ldr(r1, MemOperand(r2, StandardFrameConstants::kContextOffset)); 2960 Label check_frame_marker;
3199 __ cmp(r1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); 2961 __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kContextOffset));
3200 __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset), eq); 2962 __ Cmp(x1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2963 __ B(ne, &check_frame_marker);
2964 __ Ldr(x2, MemOperand(x2, StandardFrameConstants::kCallerFPOffset));
3201 2965
3202 // Check the marker in the calling frame. 2966 // Check the marker in the calling frame.
3203 __ ldr(r1, MemOperand(r2, StandardFrameConstants::kMarkerOffset)); 2967 __ Bind(&check_frame_marker);
3204 __ cmp(r1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); 2968 __ Ldr(x1, MemOperand(x2, StandardFrameConstants::kMarkerOffset));
2969 __ Cmp(x1, Operand(Smi::FromInt(StackFrame::CONSTRUCT)));
3205 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2970 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3206 Split(eq, if_true, if_false, fall_through); 2971 Split(eq, if_true, if_false, fall_through);
3207 2972
3208 context()->Plug(if_true, if_false); 2973 context()->Plug(if_true, if_false);
3209 } 2974 }
3210 2975
3211 2976
3212 void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { 2977 void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) {
3213 ZoneList<Expression*>* args = expr->arguments(); 2978 ZoneList<Expression*>* args = expr->arguments();
3214 ASSERT(args->length() == 2); 2979 ASSERT(args->length() == 2);
3215 2980
3216 // Load the two objects into registers and perform the comparison. 2981 // Load the two objects into registers and perform the comparison.
3217 VisitForStackValue(args->at(0)); 2982 VisitForStackValue(args->at(0));
3218 VisitForAccumulatorValue(args->at(1)); 2983 VisitForAccumulatorValue(args->at(1));
3219 2984
3220 Label materialize_true, materialize_false; 2985 Label materialize_true, materialize_false;
3221 Label* if_true = NULL; 2986 Label* if_true = NULL;
3222 Label* if_false = NULL; 2987 Label* if_false = NULL;
3223 Label* fall_through = NULL; 2988 Label* fall_through = NULL;
3224 context()->PrepareTest(&materialize_true, &materialize_false, 2989 context()->PrepareTest(&materialize_true, &materialize_false,
3225 &if_true, &if_false, &fall_through); 2990 &if_true, &if_false, &fall_through);
3226 2991
3227 __ pop(r1); 2992 __ Pop(x1);
3228 __ cmp(r0, r1); 2993 __ Cmp(x0, x1);
3229 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 2994 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3230 Split(eq, if_true, if_false, fall_through); 2995 Split(eq, if_true, if_false, fall_through);
3231 2996
3232 context()->Plug(if_true, if_false); 2997 context()->Plug(if_true, if_false);
3233 } 2998 }
3234 2999
3235 3000
3236 void FullCodeGenerator::EmitArguments(CallRuntime* expr) { 3001 void FullCodeGenerator::EmitArguments(CallRuntime* expr) {
3237 ZoneList<Expression*>* args = expr->arguments(); 3002 ZoneList<Expression*>* args = expr->arguments();
3238 ASSERT(args->length() == 1); 3003 ASSERT(args->length() == 1);
3239 3004
3240 // ArgumentsAccessStub expects the key in edx and the formal 3005 // ArgumentsAccessStub expects the key in x1.
3241 // parameter count in r0.
3242 VisitForAccumulatorValue(args->at(0)); 3006 VisitForAccumulatorValue(args->at(0));
3243 __ mov(r1, r0); 3007 __ Mov(x1, x0);
3244 __ mov(r0, Operand(Smi::FromInt(info_->scope()->num_parameters()))); 3008 __ Mov(x0, Operand(Smi::FromInt(info_->scope()->num_parameters())));
3245 ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); 3009 ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT);
3246 __ CallStub(&stub); 3010 __ CallStub(&stub);
3247 context()->Plug(r0); 3011 context()->Plug(x0);
3248 } 3012 }
3249 3013
3250 3014
3251 void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { 3015 void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) {
3252 ASSERT(expr->arguments()->length() == 0); 3016 ASSERT(expr->arguments()->length() == 0);
3253 3017 Label exit;
3254 // Get the number of formal parameters. 3018 // Get the number of formal parameters.
3255 __ mov(r0, Operand(Smi::FromInt(info_->scope()->num_parameters()))); 3019 __ Mov(x0, Operand(Smi::FromInt(info_->scope()->num_parameters())));
3256 3020
3257 // Check if the calling frame is an arguments adaptor frame. 3021 // Check if the calling frame is an arguments adaptor frame.
3258 __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); 3022 __ Ldr(x12, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
3259 __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); 3023 __ Ldr(x13, MemOperand(x12, StandardFrameConstants::kContextOffset));
3260 __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); 3024 __ Cmp(x13, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
3025 __ B(ne, &exit);
3261 3026
3262 // Arguments adaptor case: Read the arguments length from the 3027 // Arguments adaptor case: Read the arguments length from the
3263 // adaptor frame. 3028 // adaptor frame.
3264 __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset), eq); 3029 __ Ldr(x0, MemOperand(x12, ArgumentsAdaptorFrameConstants::kLengthOffset));
3265 3030
3266 context()->Plug(r0); 3031 __ Bind(&exit);
3032 context()->Plug(x0);
3267 } 3033 }
3268 3034
3269 3035
3270 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { 3036 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) {
3037 ASM_LOCATION("FullCodeGenerator::EmitClassOf");
3271 ZoneList<Expression*>* args = expr->arguments(); 3038 ZoneList<Expression*>* args = expr->arguments();
3272 ASSERT(args->length() == 1); 3039 ASSERT(args->length() == 1);
3273 Label done, null, function, non_function_constructor; 3040 Label done, null, function, non_function_constructor;
3274 3041
3275 VisitForAccumulatorValue(args->at(0)); 3042 VisitForAccumulatorValue(args->at(0));
3276 3043
3277 // If the object is a smi, we return null. 3044 // If the object is a smi, we return null.
3278 __ JumpIfSmi(r0, &null); 3045 __ JumpIfSmi(x0, &null);
3279 3046
3280 // Check that the object is a JS object but take special care of JS 3047 // Check that the object is a JS object but take special care of JS
3281 // functions to make sure they have 'Function' as their class. 3048 // functions to make sure they have 'Function' as their class.
3282 // Assume that there are only two callable types, and one of them is at 3049 // Assume that there are only two callable types, and one of them is at
3283 // either end of the type range for JS object types. Saves extra comparisons. 3050 // either end of the type range for JS object types. Saves extra comparisons.
3284 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); 3051 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
3285 __ CompareObjectType(r0, r0, r1, FIRST_SPEC_OBJECT_TYPE); 3052 __ CompareObjectType(x0, x10, x11, FIRST_SPEC_OBJECT_TYPE);
3286 // Map is now in r0. 3053 // x10: object's map.
3287 __ b(lt, &null); 3054 // x11: object's type.
3055 __ B(lt, &null);
3288 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == 3056 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3289 FIRST_SPEC_OBJECT_TYPE + 1); 3057 FIRST_SPEC_OBJECT_TYPE + 1);
3290 __ b(eq, &function); 3058 __ B(eq, &function);
3291 3059
3292 __ cmp(r1, Operand(LAST_SPEC_OBJECT_TYPE)); 3060 __ Cmp(x11, LAST_SPEC_OBJECT_TYPE);
3293 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == 3061 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3294 LAST_SPEC_OBJECT_TYPE - 1); 3062 LAST_SPEC_OBJECT_TYPE - 1);
3295 __ b(eq, &function); 3063 __ B(eq, &function);
3296 // Assume that there is no larger type. 3064 // Assume that there is no larger type.
3297 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); 3065 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1);
3298 3066
3299 // Check if the constructor in the map is a JS function. 3067 // Check if the constructor in the map is a JS function.
3300 __ ldr(r0, FieldMemOperand(r0, Map::kConstructorOffset)); 3068 __ Ldr(x12, FieldMemOperand(x10, Map::kConstructorOffset));
3301 __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); 3069 __ JumpIfNotObjectType(x12, x13, x14, JS_FUNCTION_TYPE,
3302 __ b(ne, &non_function_constructor); 3070 &non_function_constructor);
3303 3071
3304 // r0 now contains the constructor function. Grab the 3072 // x12 now contains the constructor function. Grab the
3305 // instance class name from there. 3073 // instance class name from there.
3306 __ ldr(r0, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); 3074 __ Ldr(x13, FieldMemOperand(x12, JSFunction::kSharedFunctionInfoOffset));
3307 __ ldr(r0, FieldMemOperand(r0, SharedFunctionInfo::kInstanceClassNameOffset)); 3075 __ Ldr(x0,
3308 __ b(&done); 3076 FieldMemOperand(x13, SharedFunctionInfo::kInstanceClassNameOffset));
3077 __ B(&done);
3309 3078
3310 // Functions have class 'Function'. 3079 // Functions have class 'Function'.
3311 __ bind(&function); 3080 __ Bind(&function);
3312 __ LoadRoot(r0, Heap::kfunction_class_stringRootIndex); 3081 __ LoadRoot(x0, Heap::kfunction_class_stringRootIndex);
3313 __ jmp(&done); 3082 __ B(&done);
3314 3083
3315 // Objects with a non-function constructor have class 'Object'. 3084 // Objects with a non-function constructor have class 'Object'.
3316 __ bind(&non_function_constructor); 3085 __ Bind(&non_function_constructor);
3317 __ LoadRoot(r0, Heap::kObject_stringRootIndex); 3086 __ LoadRoot(x0, Heap::kObject_stringRootIndex);
3318 __ jmp(&done); 3087 __ B(&done);
3319 3088
3320 // Non-JS objects have class null. 3089 // Non-JS objects have class null.
3321 __ bind(&null); 3090 __ Bind(&null);
3322 __ LoadRoot(r0, Heap::kNullValueRootIndex); 3091 __ LoadRoot(x0, Heap::kNullValueRootIndex);
3323 3092
3324 // All done. 3093 // All done.
3325 __ bind(&done); 3094 __ Bind(&done);
3326 3095
3327 context()->Plug(r0); 3096 context()->Plug(x0);
3328 } 3097 }
3329 3098
3330 3099
3331 void FullCodeGenerator::EmitLog(CallRuntime* expr) { 3100 void FullCodeGenerator::EmitLog(CallRuntime* expr) {
3332 // Conditionally generate a log call. 3101 // Conditionally generate a log call.
3333 // Args: 3102 // Args:
3334 // 0 (literal string): The type of logging (corresponds to the flags). 3103 // 0 (literal string): The type of logging (corresponds to the flags).
3335 // This is used to determine whether or not to generate the log call. 3104 // This is used to determine whether or not to generate the log call.
3336 // 1 (string): Format string. Access the string at argument index 2 3105 // 1 (string): Format string. Access the string at argument index 2
3337 // with '%2s' (see Logger::LogRuntime for all the formats). 3106 // with '%2s' (see Logger::LogRuntime for all the formats).
3338 // 2 (array): Arguments to the format string. 3107 // 2 (array): Arguments to the format string.
3339 ZoneList<Expression*>* args = expr->arguments(); 3108 ZoneList<Expression*>* args = expr->arguments();
3340 ASSERT_EQ(args->length(), 3); 3109 ASSERT_EQ(args->length(), 3);
3341 if (CodeGenerator::ShouldGenerateLog(isolate(), args->at(0))) { 3110 if (CodeGenerator::ShouldGenerateLog(isolate(), args->at(0))) {
3342 VisitForStackValue(args->at(1)); 3111 VisitForStackValue(args->at(1));
3343 VisitForStackValue(args->at(2)); 3112 VisitForStackValue(args->at(2));
3344 __ CallRuntime(Runtime::kLog, 2); 3113 __ CallRuntime(Runtime::kLog, 2);
3345 } 3114 }
3346 3115
3347 // Finally, we're expected to leave a value on the top of the stack. 3116 // Finally, we're expected to leave a value on the top of the stack.
3348 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); 3117 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
3349 context()->Plug(r0); 3118 context()->Plug(x0);
3350 } 3119 }
3351 3120
3352 3121
3353 void FullCodeGenerator::EmitSubString(CallRuntime* expr) { 3122 void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
3354 // Load the arguments on the stack and call the stub. 3123 // Load the arguments on the stack and call the stub.
3355 SubStringStub stub; 3124 SubStringStub stub;
3356 ZoneList<Expression*>* args = expr->arguments(); 3125 ZoneList<Expression*>* args = expr->arguments();
3357 ASSERT(args->length() == 3); 3126 ASSERT(args->length() == 3);
3358 VisitForStackValue(args->at(0)); 3127 VisitForStackValue(args->at(0));
3359 VisitForStackValue(args->at(1)); 3128 VisitForStackValue(args->at(1));
3360 VisitForStackValue(args->at(2)); 3129 VisitForStackValue(args->at(2));
3361 __ CallStub(&stub); 3130 __ CallStub(&stub);
3362 context()->Plug(r0); 3131 context()->Plug(x0);
3363 } 3132 }
3364 3133
3365 3134
3366 void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { 3135 void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) {
3367 // Load the arguments on the stack and call the stub. 3136 // Load the arguments on the stack and call the stub.
3368 RegExpExecStub stub; 3137 RegExpExecStub stub;
3369 ZoneList<Expression*>* args = expr->arguments(); 3138 ZoneList<Expression*>* args = expr->arguments();
3370 ASSERT(args->length() == 4); 3139 ASSERT(args->length() == 4);
3371 VisitForStackValue(args->at(0)); 3140 VisitForStackValue(args->at(0));
3372 VisitForStackValue(args->at(1)); 3141 VisitForStackValue(args->at(1));
3373 VisitForStackValue(args->at(2)); 3142 VisitForStackValue(args->at(2));
3374 VisitForStackValue(args->at(3)); 3143 VisitForStackValue(args->at(3));
3375 __ CallStub(&stub); 3144 __ CallStub(&stub);
3376 context()->Plug(r0); 3145 context()->Plug(x0);
3377 } 3146 }
3378 3147
3379 3148
3380 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { 3149 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) {
3150 ASM_LOCATION("FullCodeGenerator::EmitValueOf");
3381 ZoneList<Expression*>* args = expr->arguments(); 3151 ZoneList<Expression*>* args = expr->arguments();
3382 ASSERT(args->length() == 1); 3152 ASSERT(args->length() == 1);
3383 VisitForAccumulatorValue(args->at(0)); // Load the object. 3153 VisitForAccumulatorValue(args->at(0)); // Load the object.
3384 3154
3385 Label done; 3155 Label done;
3386 // If the object is a smi return the object. 3156 // If the object is a smi return the object.
3387 __ JumpIfSmi(r0, &done); 3157 __ JumpIfSmi(x0, &done);
3388 // If the object is not a value type, return the object. 3158 // If the object is not a value type, return the object.
3389 __ CompareObjectType(r0, r1, r1, JS_VALUE_TYPE); 3159 __ JumpIfNotObjectType(x0, x10, x11, JS_VALUE_TYPE, &done);
3390 __ ldr(r0, FieldMemOperand(r0, JSValue::kValueOffset), eq); 3160 __ Ldr(x0, FieldMemOperand(x0, JSValue::kValueOffset));
3391 3161
3392 __ bind(&done); 3162 __ Bind(&done);
3393 context()->Plug(r0); 3163 context()->Plug(x0);
3394 } 3164 }
3395 3165
3396 3166
3397 void FullCodeGenerator::EmitDateField(CallRuntime* expr) { 3167 void FullCodeGenerator::EmitDateField(CallRuntime* expr) {
3398 ZoneList<Expression*>* args = expr->arguments(); 3168 ZoneList<Expression*>* args = expr->arguments();
3399 ASSERT(args->length() == 2); 3169 ASSERT(args->length() == 2);
3400 ASSERT_NE(NULL, args->at(1)->AsLiteral()); 3170 ASSERT_NE(NULL, args->at(1)->AsLiteral());
3401 Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); 3171 Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value()));
3402 3172
3403 VisitForAccumulatorValue(args->at(0)); // Load the object. 3173 VisitForAccumulatorValue(args->at(0)); // Load the object.
3404 3174
3405 Label runtime, done, not_date_object; 3175 Label runtime, done, not_date_object;
3406 Register object = r0; 3176 Register object = x0;
3407 Register result = r0; 3177 Register result = x0;
3408 Register scratch0 = r9; 3178 Register stamp_addr = x10;
3409 Register scratch1 = r1; 3179 Register stamp_cache = x11;
3410 3180
3411 __ JumpIfSmi(object, &not_date_object); 3181 __ JumpIfSmi(object, &not_date_object);
3412 __ CompareObjectType(object, scratch1, scratch1, JS_DATE_TYPE); 3182 __ JumpIfNotObjectType(object, x10, x10, JS_DATE_TYPE, &not_date_object);
3413 __ b(ne, &not_date_object);
3414 3183
3415 if (index->value() == 0) { 3184 if (index->value() == 0) {
3416 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset)); 3185 __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset));
3417 __ jmp(&done); 3186 __ B(&done);
3418 } else { 3187 } else {
3419 if (index->value() < JSDate::kFirstUncachedField) { 3188 if (index->value() < JSDate::kFirstUncachedField) {
3420 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); 3189 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
3421 __ mov(scratch1, Operand(stamp)); 3190 __ Mov(x10, Operand(stamp));
3422 __ ldr(scratch1, MemOperand(scratch1)); 3191 __ Ldr(stamp_addr, MemOperand(x10));
3423 __ ldr(scratch0, FieldMemOperand(object, JSDate::kCacheStampOffset)); 3192 __ Ldr(stamp_cache, FieldMemOperand(object, JSDate::kCacheStampOffset));
3424 __ cmp(scratch1, scratch0); 3193 __ Cmp(stamp_addr, stamp_cache);
3425 __ b(ne, &runtime); 3194 __ B(ne, &runtime);
3426 __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset + 3195 __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset +
3427 kPointerSize * index->value())); 3196 kPointerSize * index->value()));
3428 __ jmp(&done); 3197 __ B(&done);
3429 } 3198 }
3430 __ bind(&runtime); 3199
3431 __ PrepareCallCFunction(2, scratch1); 3200 __ Bind(&runtime);
3432 __ mov(r1, Operand(index)); 3201 __ Mov(x1, Operand(index));
3433 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); 3202 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
3434 __ jmp(&done); 3203 __ B(&done);
3435 } 3204 }
3436 3205
3437 __ bind(&not_date_object); 3206 __ Bind(&not_date_object);
3438 __ CallRuntime(Runtime::kThrowNotDateError, 0); 3207 __ CallRuntime(Runtime::kThrowNotDateError, 0);
3439 __ bind(&done); 3208 __ Bind(&done);
3440 context()->Plug(r0); 3209 context()->Plug(x0);
3441 } 3210 }
3442 3211
3443 3212
3444 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { 3213 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) {
3445 ZoneList<Expression*>* args = expr->arguments(); 3214 ZoneList<Expression*>* args = expr->arguments();
3446 ASSERT_EQ(3, args->length()); 3215 ASSERT_EQ(3, args->length());
3447 3216
3448 Register string = r0; 3217 Register string = x0;
3449 Register index = r1; 3218 Register index = x1;
3450 Register value = r2; 3219 Register value = x2;
3220 Register scratch = x10;
3451 3221
3452 VisitForStackValue(args->at(1)); // index 3222 VisitForStackValue(args->at(1)); // index
3453 VisitForStackValue(args->at(2)); // value 3223 VisitForStackValue(args->at(2)); // value
3454 VisitForAccumulatorValue(args->at(0)); // string 3224 VisitForAccumulatorValue(args->at(0)); // string
3455 __ Pop(index, value); 3225 __ Pop(value, index);
3456 3226
3457 if (FLAG_debug_code) { 3227 if (FLAG_debug_code) {
3458 __ SmiTst(value); 3228 __ AssertSmi(value, kNonSmiValue);
3459 __ ThrowIf(ne, kNonSmiValue); 3229 __ AssertSmi(index, kNonSmiIndex);
3460 __ SmiTst(index);
3461 __ ThrowIf(ne, kNonSmiIndex);
3462 __ SmiUntag(index, index);
3463 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; 3230 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
3464 __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); 3231 __ EmitSeqStringSetCharCheck(string, index, kIndexIsSmi, scratch,
3465 __ SmiTag(index, index); 3232 one_byte_seq_type);
3466 } 3233 }
3467 3234
3468 __ SmiUntag(value, value); 3235 __ Add(scratch, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
3469 __ add(ip, 3236 __ SmiUntag(value);
3470 string, 3237 __ SmiUntag(index);
3471 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); 3238 __ Strb(value, MemOperand(scratch, index));
3472 __ strb(value, MemOperand(ip, index, LSR, kSmiTagSize));
3473 context()->Plug(string); 3239 context()->Plug(string);
3474 } 3240 }
3475 3241
3476 3242
3477 void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { 3243 void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) {
3478 ZoneList<Expression*>* args = expr->arguments(); 3244 ZoneList<Expression*>* args = expr->arguments();
3479 ASSERT_EQ(3, args->length()); 3245 ASSERT_EQ(3, args->length());
3480 3246
3481 Register string = r0; 3247 Register string = x0;
3482 Register index = r1; 3248 Register index = x1;
3483 Register value = r2; 3249 Register value = x2;
3250 Register scratch = x10;
3484 3251
3485 VisitForStackValue(args->at(1)); // index 3252 VisitForStackValue(args->at(1)); // index
3486 VisitForStackValue(args->at(2)); // value 3253 VisitForStackValue(args->at(2)); // value
3487 VisitForAccumulatorValue(args->at(0)); // string 3254 VisitForAccumulatorValue(args->at(0)); // string
3488 __ Pop(index, value); 3255 __ Pop(value, index);
3489 3256
3490 if (FLAG_debug_code) { 3257 if (FLAG_debug_code) {
3491 __ SmiTst(value); 3258 __ AssertSmi(value, kNonSmiValue);
3492 __ ThrowIf(ne, kNonSmiValue); 3259 __ AssertSmi(index, kNonSmiIndex);
3493 __ SmiTst(index);
3494 __ ThrowIf(ne, kNonSmiIndex);
3495 __ SmiUntag(index, index);
3496 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; 3260 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
3497 __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); 3261 __ EmitSeqStringSetCharCheck(string, index, kIndexIsSmi, scratch,
3498 __ SmiTag(index, index); 3262 two_byte_seq_type);
3499 } 3263 }
3500 3264
3501 __ SmiUntag(value, value); 3265 __ Add(scratch, string, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
3502 __ add(ip, 3266 __ SmiUntag(value);
3503 string, 3267 __ SmiUntag(index);
3504 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); 3268 __ Strh(value, MemOperand(scratch, index, LSL, 1));
3505 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
3506 __ strh(value, MemOperand(ip, index));
3507 context()->Plug(string); 3269 context()->Plug(string);
3508 } 3270 }
3509 3271
3510 3272
3511
3512 void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { 3273 void FullCodeGenerator::EmitMathPow(CallRuntime* expr) {
3513 // Load the arguments on the stack and call the runtime function. 3274 // Load the arguments on the stack and call the MathPow stub.
3514 ZoneList<Expression*>* args = expr->arguments(); 3275 ZoneList<Expression*>* args = expr->arguments();
3515 ASSERT(args->length() == 2); 3276 ASSERT(args->length() == 2);
3516 VisitForStackValue(args->at(0)); 3277 VisitForStackValue(args->at(0));
3517 VisitForStackValue(args->at(1)); 3278 VisitForStackValue(args->at(1));
3518 MathPowStub stub(MathPowStub::ON_STACK); 3279 MathPowStub stub(MathPowStub::ON_STACK);
3519 __ CallStub(&stub); 3280 __ CallStub(&stub);
3520 context()->Plug(r0); 3281 context()->Plug(x0);
3521 } 3282 }
3522 3283
3523 3284
3524 void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { 3285 void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) {
3525 ZoneList<Expression*>* args = expr->arguments(); 3286 ZoneList<Expression*>* args = expr->arguments();
3526 ASSERT(args->length() == 2); 3287 ASSERT(args->length() == 2);
3527 VisitForStackValue(args->at(0)); // Load the object. 3288 VisitForStackValue(args->at(0)); // Load the object.
3528 VisitForAccumulatorValue(args->at(1)); // Load the value. 3289 VisitForAccumulatorValue(args->at(1)); // Load the value.
3529 __ pop(r1); // r0 = value. r1 = object. 3290 __ Pop(x1);
3291 // x0 = value.
3292 // x1 = object.
3530 3293
3531 Label done; 3294 Label done;
3532 // If the object is a smi, return the value. 3295 // If the object is a smi, return the value.
3533 __ JumpIfSmi(r1, &done); 3296 __ JumpIfSmi(x1, &done);
3534 3297
3535 // If the object is not a value type, return the value. 3298 // If the object is not a value type, return the value.
3536 __ CompareObjectType(r1, r2, r2, JS_VALUE_TYPE); 3299 __ JumpIfNotObjectType(x1, x10, x11, JS_VALUE_TYPE, &done);
3537 __ b(ne, &done);
3538 3300
3539 // Store the value. 3301 // Store the value.
3540 __ str(r0, FieldMemOperand(r1, JSValue::kValueOffset)); 3302 __ Str(x0, FieldMemOperand(x1, JSValue::kValueOffset));
3541 // Update the write barrier. Save the value as it will be 3303 // Update the write barrier. Save the value as it will be
3542 // overwritten by the write barrier code and is needed afterward. 3304 // overwritten by the write barrier code and is needed afterward.
3543 __ mov(r2, r0); 3305 __ Mov(x10, x0);
3544 __ RecordWriteField( 3306 __ RecordWriteField(
3545 r1, JSValue::kValueOffset, r2, r3, kLRHasBeenSaved, kDontSaveFPRegs); 3307 x1, JSValue::kValueOffset, x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
3546 3308
3547 __ bind(&done); 3309 __ Bind(&done);
3548 context()->Plug(r0); 3310 context()->Plug(x0);
3549 } 3311 }
3550 3312
3551 3313
3552 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { 3314 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
3553 ZoneList<Expression*>* args = expr->arguments(); 3315 ZoneList<Expression*>* args = expr->arguments();
3554 ASSERT_EQ(args->length(), 1); 3316 ASSERT_EQ(args->length(), 1);
3555 // Load the argument into r0 and call the stub. 3317
3318 // Load the argument into x0 and call the stub.
3556 VisitForAccumulatorValue(args->at(0)); 3319 VisitForAccumulatorValue(args->at(0));
3557 3320
3558 NumberToStringStub stub; 3321 NumberToStringStub stub;
3559 __ CallStub(&stub); 3322 __ CallStub(&stub);
3560 context()->Plug(r0); 3323 context()->Plug(x0);
3561 } 3324 }
3562 3325
3563 3326
3564 void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { 3327 void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) {
3565 ZoneList<Expression*>* args = expr->arguments(); 3328 ZoneList<Expression*>* args = expr->arguments();
3566 ASSERT(args->length() == 1); 3329 ASSERT(args->length() == 1);
3330
3567 VisitForAccumulatorValue(args->at(0)); 3331 VisitForAccumulatorValue(args->at(0));
3568 3332
3569 Label done; 3333 Label done;
3570 StringCharFromCodeGenerator generator(r0, r1); 3334 Register code = x0;
3335 Register result = x1;
3336
3337 StringCharFromCodeGenerator generator(code, result);
3571 generator.GenerateFast(masm_); 3338 generator.GenerateFast(masm_);
3572 __ jmp(&done); 3339 __ B(&done);
3573 3340
3574 NopRuntimeCallHelper call_helper; 3341 NopRuntimeCallHelper call_helper;
3575 generator.GenerateSlow(masm_, call_helper); 3342 generator.GenerateSlow(masm_, call_helper);
3576 3343
3577 __ bind(&done); 3344 __ Bind(&done);
3578 context()->Plug(r1); 3345 context()->Plug(result);
3579 } 3346 }
3580 3347
3581 3348
3582 void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { 3349 void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) {
3583 ZoneList<Expression*>* args = expr->arguments(); 3350 ZoneList<Expression*>* args = expr->arguments();
3584 ASSERT(args->length() == 2); 3351 ASSERT(args->length() == 2);
3352
3585 VisitForStackValue(args->at(0)); 3353 VisitForStackValue(args->at(0));
3586 VisitForAccumulatorValue(args->at(1)); 3354 VisitForAccumulatorValue(args->at(1));
3587 3355
3588 Register object = r1; 3356 Register object = x1;
3589 Register index = r0; 3357 Register index = x0;
3590 Register result = r3; 3358 Register result = x3;
3591 3359
3592 __ pop(object); 3360 __ Pop(object);
3593 3361
3594 Label need_conversion; 3362 Label need_conversion;
3595 Label index_out_of_range; 3363 Label index_out_of_range;
3596 Label done; 3364 Label done;
3597 StringCharCodeAtGenerator generator(object, 3365 StringCharCodeAtGenerator generator(object,
3598 index, 3366 index,
3599 result, 3367 result,
3600 &need_conversion, 3368 &need_conversion,
3601 &need_conversion, 3369 &need_conversion,
3602 &index_out_of_range, 3370 &index_out_of_range,
3603 STRING_INDEX_IS_NUMBER); 3371 STRING_INDEX_IS_NUMBER);
3604 generator.GenerateFast(masm_); 3372 generator.GenerateFast(masm_);
3605 __ jmp(&done); 3373 __ B(&done);
3606 3374
3607 __ bind(&index_out_of_range); 3375 __ Bind(&index_out_of_range);
3608 // When the index is out of range, the spec requires us to return 3376 // When the index is out of range, the spec requires us to return NaN.
3609 // NaN.
3610 __ LoadRoot(result, Heap::kNanValueRootIndex); 3377 __ LoadRoot(result, Heap::kNanValueRootIndex);
3611 __ jmp(&done); 3378 __ B(&done);
3612 3379
3613 __ bind(&need_conversion); 3380 __ Bind(&need_conversion);
3614 // Load the undefined value into the result register, which will 3381 // Load the undefined value into the result register, which will
3615 // trigger conversion. 3382 // trigger conversion.
3616 __ LoadRoot(result, Heap::kUndefinedValueRootIndex); 3383 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
3617 __ jmp(&done); 3384 __ B(&done);
3618 3385
3619 NopRuntimeCallHelper call_helper; 3386 NopRuntimeCallHelper call_helper;
3620 generator.GenerateSlow(masm_, call_helper); 3387 generator.GenerateSlow(masm_, call_helper);
3621 3388
3622 __ bind(&done); 3389 __ Bind(&done);
3623 context()->Plug(result); 3390 context()->Plug(result);
3624 } 3391 }
3625 3392
3626 3393
3627 void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { 3394 void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) {
3628 ZoneList<Expression*>* args = expr->arguments(); 3395 ZoneList<Expression*>* args = expr->arguments();
3629 ASSERT(args->length() == 2); 3396 ASSERT(args->length() == 2);
3397
3630 VisitForStackValue(args->at(0)); 3398 VisitForStackValue(args->at(0));
3631 VisitForAccumulatorValue(args->at(1)); 3399 VisitForAccumulatorValue(args->at(1));
3632 3400
3633 Register object = r1; 3401 Register object = x1;
3634 Register index = r0; 3402 Register index = x0;
3635 Register scratch = r3; 3403 Register result = x0;
3636 Register result = r0;
3637 3404
3638 __ pop(object); 3405 __ Pop(object);
3639 3406
3640 Label need_conversion; 3407 Label need_conversion;
3641 Label index_out_of_range; 3408 Label index_out_of_range;
3642 Label done; 3409 Label done;
3643 StringCharAtGenerator generator(object, 3410 StringCharAtGenerator generator(object,
3644 index, 3411 index,
3645 scratch, 3412 x3,
3646 result, 3413 result,
3647 &need_conversion, 3414 &need_conversion,
3648 &need_conversion, 3415 &need_conversion,
3649 &index_out_of_range, 3416 &index_out_of_range,
3650 STRING_INDEX_IS_NUMBER); 3417 STRING_INDEX_IS_NUMBER);
3651 generator.GenerateFast(masm_); 3418 generator.GenerateFast(masm_);
3652 __ jmp(&done); 3419 __ B(&done);
3653 3420
3654 __ bind(&index_out_of_range); 3421 __ Bind(&index_out_of_range);
3655 // When the index is out of range, the spec requires us to return 3422 // When the index is out of range, the spec requires us to return
3656 // the empty string. 3423 // the empty string.
3657 __ LoadRoot(result, Heap::kempty_stringRootIndex); 3424 __ LoadRoot(result, Heap::kempty_stringRootIndex);
3658 __ jmp(&done); 3425 __ B(&done);
3659 3426
3660 __ bind(&need_conversion); 3427 __ Bind(&need_conversion);
3661 // Move smi zero into the result register, which will trigger 3428 // Move smi zero into the result register, which will trigger conversion.
3662 // conversion. 3429 __ Mov(result, Operand(Smi::FromInt(0)));
3663 __ mov(result, Operand(Smi::FromInt(0))); 3430 __ B(&done);
3664 __ jmp(&done);
3665 3431
3666 NopRuntimeCallHelper call_helper; 3432 NopRuntimeCallHelper call_helper;
3667 generator.GenerateSlow(masm_, call_helper); 3433 generator.GenerateSlow(masm_, call_helper);
3668 3434
3669 __ bind(&done); 3435 __ Bind(&done);
3670 context()->Plug(result); 3436 context()->Plug(result);
3671 } 3437 }
3672 3438
3673 3439
3674 void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { 3440 void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
3441 ASM_LOCATION("FullCodeGenerator::EmitStringAdd");
3675 ZoneList<Expression*>* args = expr->arguments(); 3442 ZoneList<Expression*>* args = expr->arguments();
3676 ASSERT_EQ(2, args->length()); 3443 ASSERT_EQ(2, args->length());
3677 3444
3678 if (FLAG_new_string_add) { 3445 VisitForStackValue(args->at(0));
3679 VisitForStackValue(args->at(0)); 3446 VisitForAccumulatorValue(args->at(1));
3680 VisitForAccumulatorValue(args->at(1));
3681 3447
3682 __ pop(r1); 3448 __ Pop(x1);
3683 NewStringAddStub stub(STRING_ADD_CHECK_BOTH, NOT_TENURED); 3449 StringAddStub stub(STRING_ADD_CHECK_BOTH, NOT_TENURED);
3684 __ CallStub(&stub); 3450 __ CallStub(&stub);
3685 } else {
3686 VisitForStackValue(args->at(0));
3687 VisitForStackValue(args->at(1));
3688 3451
3689 StringAddStub stub(STRING_ADD_CHECK_BOTH); 3452 context()->Plug(x0);
3690 __ CallStub(&stub);
3691 }
3692 context()->Plug(r0);
3693 } 3453 }
3694 3454
3695 3455
3696 void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { 3456 void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) {
3697 ZoneList<Expression*>* args = expr->arguments(); 3457 ZoneList<Expression*>* args = expr->arguments();
3698 ASSERT_EQ(2, args->length()); 3458 ASSERT_EQ(2, args->length());
3699 VisitForStackValue(args->at(0)); 3459 VisitForStackValue(args->at(0));
3700 VisitForStackValue(args->at(1)); 3460 VisitForStackValue(args->at(1));
3701 3461
3702 StringCompareStub stub; 3462 StringCompareStub stub;
3703 __ CallStub(&stub); 3463 __ CallStub(&stub);
3704 context()->Plug(r0); 3464 context()->Plug(x0);
3705 } 3465 }
3706 3466
3707 3467
3708 void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { 3468 void FullCodeGenerator::EmitMathLog(CallRuntime* expr) {
3709 // Load the argument on the stack and call the runtime function. 3469 // Load the argument on the stack and call the runtime function.
3710 ZoneList<Expression*>* args = expr->arguments(); 3470 ZoneList<Expression*>* args = expr->arguments();
3711 ASSERT(args->length() == 1); 3471 ASSERT(args->length() == 1);
3712 VisitForStackValue(args->at(0)); 3472 VisitForStackValue(args->at(0));
3713 __ CallRuntime(Runtime::kMath_log, 1); 3473 __ CallRuntime(Runtime::kMath_log, 1);
3714 context()->Plug(r0); 3474 context()->Plug(x0);
3715 } 3475 }
3716 3476
3717 3477
3718 void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) { 3478 void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) {
3719 // Load the argument on the stack and call the runtime function. 3479 // Load the argument on the stack and call the runtime function.
3720 ZoneList<Expression*>* args = expr->arguments(); 3480 ZoneList<Expression*>* args = expr->arguments();
3721 ASSERT(args->length() == 1); 3481 ASSERT(args->length() == 1);
3722 VisitForStackValue(args->at(0)); 3482 VisitForStackValue(args->at(0));
3723 __ CallRuntime(Runtime::kMath_sqrt, 1); 3483 __ CallRuntime(Runtime::kMath_sqrt, 1);
3724 context()->Plug(r0); 3484 context()->Plug(x0);
3725 } 3485 }
3726 3486
3727 3487
3728 void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { 3488 void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) {
3489 ASM_LOCATION("FullCodeGenerator::EmitCallFunction");
3729 ZoneList<Expression*>* args = expr->arguments(); 3490 ZoneList<Expression*>* args = expr->arguments();
3730 ASSERT(args->length() >= 2); 3491 ASSERT(args->length() >= 2);
3731 3492
3732 int arg_count = args->length() - 2; // 2 ~ receiver and function. 3493 int arg_count = args->length() - 2; // 2 ~ receiver and function.
3733 for (int i = 0; i < arg_count + 1; i++) { 3494 for (int i = 0; i < arg_count + 1; i++) {
3734 VisitForStackValue(args->at(i)); 3495 VisitForStackValue(args->at(i));
3735 } 3496 }
3736 VisitForAccumulatorValue(args->last()); // Function. 3497 VisitForAccumulatorValue(args->last()); // Function.
3737 3498
3738 Label runtime, done; 3499 Label runtime, done;
3739 // Check for non-function argument (including proxy). 3500 // Check for non-function argument (including proxy).
3740 __ JumpIfSmi(r0, &runtime); 3501 __ JumpIfSmi(x0, &runtime);
3741 __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); 3502 __ JumpIfNotObjectType(x0, x1, x1, JS_FUNCTION_TYPE, &runtime);
3742 __ b(ne, &runtime);
3743 3503
3744 // InvokeFunction requires the function in r1. Move it in there. 3504 // InvokeFunction requires the function in x1. Move it in there.
3745 __ mov(r1, result_register()); 3505 __ Mov(x1, x0);
3746 ParameterCount count(arg_count); 3506 ParameterCount count(arg_count);
3747 __ InvokeFunction(r1, count, CALL_FUNCTION, NullCallWrapper()); 3507 __ InvokeFunction(x1, count, CALL_FUNCTION, NullCallWrapper());
3748 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 3508 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3749 __ jmp(&done); 3509 __ B(&done);
3750 3510
3751 __ bind(&runtime); 3511 __ Bind(&runtime);
3752 __ push(r0); 3512 __ Push(x0);
3753 __ CallRuntime(Runtime::kCall, args->length()); 3513 __ CallRuntime(Runtime::kCall, args->length());
3754 __ bind(&done); 3514 __ Bind(&done);
3755 3515
3756 context()->Plug(r0); 3516 context()->Plug(x0);
3757 } 3517 }
3758 3518
3759 3519
3760 void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { 3520 void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) {
3761 RegExpConstructResultStub stub; 3521 RegExpConstructResultStub stub;
3762 ZoneList<Expression*>* args = expr->arguments(); 3522 ZoneList<Expression*>* args = expr->arguments();
3763 ASSERT(args->length() == 3); 3523 ASSERT(args->length() == 3);
3764 VisitForStackValue(args->at(0)); 3524 VisitForStackValue(args->at(0));
3765 VisitForStackValue(args->at(1)); 3525 VisitForStackValue(args->at(1));
3766 VisitForStackValue(args->at(2)); 3526 VisitForAccumulatorValue(args->at(2));
3527 __ Pop(x1, x2);
3767 __ CallStub(&stub); 3528 __ CallStub(&stub);
3768 context()->Plug(r0); 3529 context()->Plug(x0);
3769 } 3530 }
3770 3531
3771 3532
3772 void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { 3533 void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) {
3773 ZoneList<Expression*>* args = expr->arguments(); 3534 ZoneList<Expression*>* args = expr->arguments();
3774 ASSERT_EQ(2, args->length()); 3535 ASSERT_EQ(2, args->length());
3775 ASSERT_NE(NULL, args->at(0)->AsLiteral()); 3536 ASSERT_NE(NULL, args->at(0)->AsLiteral());
3776 int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); 3537 int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value();
3777 3538
3778 Handle<FixedArray> jsfunction_result_caches( 3539 Handle<FixedArray> jsfunction_result_caches(
3779 isolate()->native_context()->jsfunction_result_caches()); 3540 isolate()->native_context()->jsfunction_result_caches());
3780 if (jsfunction_result_caches->length() <= cache_id) { 3541 if (jsfunction_result_caches->length() <= cache_id) {
3781 __ Abort(kAttemptToUseUndefinedCache); 3542 __ Abort(kAttemptToUseUndefinedCache);
3782 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); 3543 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
3783 context()->Plug(r0); 3544 context()->Plug(x0);
3784 return; 3545 return;
3785 } 3546 }
3786 3547
3787 VisitForAccumulatorValue(args->at(1)); 3548 VisitForAccumulatorValue(args->at(1));
3788 3549
3789 Register key = r0; 3550 Register key = x0;
3790 Register cache = r1; 3551 Register cache = x1;
3791 __ ldr(cache, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); 3552 __ Ldr(cache, GlobalObjectMemOperand());
3792 __ ldr(cache, FieldMemOperand(cache, GlobalObject::kNativeContextOffset)); 3553 __ Ldr(cache, FieldMemOperand(cache, GlobalObject::kNativeContextOffset));
3793 __ ldr(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); 3554 __ Ldr(cache, ContextMemOperand(cache,
3794 __ ldr(cache, 3555 Context::JSFUNCTION_RESULT_CACHES_INDEX));
3556 __ Ldr(cache,
3795 FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); 3557 FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id)));
3796 3558
3559 Label done;
3560 __ Ldrsw(x2, UntagSmiFieldMemOperand(cache,
3561 JSFunctionResultCache::kFingerOffset));
3562 __ Add(x3, cache, FixedArray::kHeaderSize - kHeapObjectTag);
3563 __ Add(x3, x3, Operand(x2, LSL, kPointerSizeLog2));
3797 3564
3798 Label done, not_found; 3565 // Load the key and data from the cache.
3799 // tmp now holds finger offset as a smi. 3566 __ Ldp(x2, x3, MemOperand(x3));
3800 __ ldr(r2, FieldMemOperand(cache, JSFunctionResultCache::kFingerOffset));
3801 // r2 now holds finger offset as a smi.
3802 __ add(r3, cache, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3803 // r3 now points to the start of fixed array elements.
3804 __ ldr(r2, MemOperand::PointerAddressFromSmiKey(r3, r2, PreIndex));
3805 // Note side effect of PreIndex: r3 now points to the key of the pair.
3806 __ cmp(key, r2);
3807 __ b(ne, &not_found);
3808 3567
3809 __ ldr(r0, MemOperand(r3, kPointerSize)); 3568 __ Cmp(key, x2);
3810 __ b(&done); 3569 __ CmovX(x0, x3, eq);
3570 __ B(eq, &done);
3811 3571
3812 __ bind(&not_found);
3813 // Call runtime to perform the lookup. 3572 // Call runtime to perform the lookup.
3814 __ Push(cache, key); 3573 __ Push(cache, key);
3815 __ CallRuntime(Runtime::kGetFromCache, 2); 3574 __ CallRuntime(Runtime::kGetFromCache, 2);
3816 3575
3817 __ bind(&done); 3576 __ Bind(&done);
3818 context()->Plug(r0); 3577 context()->Plug(x0);
3819 } 3578 }
3820 3579
3821 3580
3822 void FullCodeGenerator::EmitIsRegExpEquivalent(CallRuntime* expr) {
3823 ZoneList<Expression*>* args = expr->arguments();
3824 ASSERT_EQ(2, args->length());
3825
3826 Register right = r0;
3827 Register left = r1;
3828 Register tmp = r2;
3829 Register tmp2 = r3;
3830
3831 VisitForStackValue(args->at(0));
3832 VisitForAccumulatorValue(args->at(1));
3833 __ pop(left);
3834
3835 Label done, fail, ok;
3836 __ cmp(left, Operand(right));
3837 __ b(eq, &ok);
3838 // Fail if either is a non-HeapObject.
3839 __ and_(tmp, left, Operand(right));
3840 __ JumpIfSmi(tmp, &fail);
3841 __ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset));
3842 __ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset));
3843 __ cmp(tmp2, Operand(JS_REGEXP_TYPE));
3844 __ b(ne, &fail);
3845 __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3846 __ cmp(tmp, Operand(tmp2));
3847 __ b(ne, &fail);
3848 __ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset));
3849 __ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset));
3850 __ cmp(tmp, tmp2);
3851 __ b(eq, &ok);
3852 __ bind(&fail);
3853 __ LoadRoot(r0, Heap::kFalseValueRootIndex);
3854 __ jmp(&done);
3855 __ bind(&ok);
3856 __ LoadRoot(r0, Heap::kTrueValueRootIndex);
3857 __ bind(&done);
3858
3859 context()->Plug(r0);
3860 }
3861
3862
3863 void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { 3581 void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) {
3864 ZoneList<Expression*>* args = expr->arguments(); 3582 ZoneList<Expression*>* args = expr->arguments();
3865 VisitForAccumulatorValue(args->at(0)); 3583 VisitForAccumulatorValue(args->at(0));
3866 3584
3867 Label materialize_true, materialize_false; 3585 Label materialize_true, materialize_false;
3868 Label* if_true = NULL; 3586 Label* if_true = NULL;
3869 Label* if_false = NULL; 3587 Label* if_false = NULL;
3870 Label* fall_through = NULL; 3588 Label* fall_through = NULL;
3871 context()->PrepareTest(&materialize_true, &materialize_false, 3589 context()->PrepareTest(&materialize_true, &materialize_false,
3872 &if_true, &if_false, &fall_through); 3590 &if_true, &if_false, &fall_through);
3873 3591
3874 __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); 3592 __ Ldr(x10, FieldMemOperand(x0, String::kHashFieldOffset));
3875 __ tst(r0, Operand(String::kContainsCachedArrayIndexMask)); 3593 __ Tst(x10, String::kContainsCachedArrayIndexMask);
3876 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 3594 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
3877 Split(eq, if_true, if_false, fall_through); 3595 Split(eq, if_true, if_false, fall_through);
3878 3596
3879 context()->Plug(if_true, if_false); 3597 context()->Plug(if_true, if_false);
3880 } 3598 }
3881 3599
3882 3600
3883 void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { 3601 void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) {
3884 ZoneList<Expression*>* args = expr->arguments(); 3602 ZoneList<Expression*>* args = expr->arguments();
3885 ASSERT(args->length() == 1); 3603 ASSERT(args->length() == 1);
3886 VisitForAccumulatorValue(args->at(0)); 3604 VisitForAccumulatorValue(args->at(0));
3887 3605
3888 __ AssertString(r0); 3606 __ AssertString(x0);
3889 3607
3890 __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); 3608 __ Ldr(x10, FieldMemOperand(x0, String::kHashFieldOffset));
3891 __ IndexFromHash(r0, r0); 3609 __ IndexFromHash(x10, x0);
3892 3610
3893 context()->Plug(r0); 3611 context()->Plug(x0);
3894 } 3612 }
3895 3613
3896 3614
3897 void FullCodeGenerator::EmitFastAsciiArrayJoin(CallRuntime* expr) { 3615 void FullCodeGenerator::EmitFastAsciiArrayJoin(CallRuntime* expr) {
3898 Label bailout, done, one_char_separator, long_separator, non_trivial_array, 3616 ASM_LOCATION("FullCodeGenerator::EmitFastAsciiArrayJoin");
3899 not_size_one_array, loop, empty_separator_loop, one_char_separator_loop, 3617
3900 one_char_separator_loop_entry, long_separator_loop;
3901 ZoneList<Expression*>* args = expr->arguments(); 3618 ZoneList<Expression*>* args = expr->arguments();
3902 ASSERT(args->length() == 2); 3619 ASSERT(args->length() == 2);
3903 VisitForStackValue(args->at(1)); 3620 VisitForStackValue(args->at(1));
3904 VisitForAccumulatorValue(args->at(0)); 3621 VisitForAccumulatorValue(args->at(0));
3905 3622
3906 // All aliases of the same register have disjoint lifetimes. 3623 Register array = x0;
3907 Register array = r0; 3624 Register result = x0;
3908 Register elements = no_reg; // Will be r0. 3625 Register elements = x1;
3909 Register result = no_reg; // Will be r0. 3626 Register element = x2;
3910 Register separator = r1; 3627 Register separator = x3;
3911 Register array_length = r2; 3628 Register array_length = x4;
3912 Register result_pos = no_reg; // Will be r2 3629 Register result_pos = x5;
3913 Register string_length = r3; 3630 Register map = x6;
3914 Register string = r4; 3631 Register string_length = x10;
3915 Register element = r5; 3632 Register elements_end = x11;
3916 Register elements_end = r6; 3633 Register string = x12;
3917 Register scratch = r9; 3634 Register scratch1 = x13;
3635 Register scratch2 = x14;
3636 Register scratch3 = x7;
3637 Register separator_length = x15;
3918 3638
3919 // Separator operand is on the stack. 3639 Label bailout, done, one_char_separator, long_separator,
3920 __ pop(separator); 3640 non_trivial_array, not_size_one_array, loop,
3641 empty_separator_loop, one_char_separator_loop,
3642 one_char_separator_loop_entry, long_separator_loop;
3643
3644 // The separator operand is on the stack.
3645 __ Pop(separator);
3921 3646
3922 // Check that the array is a JSArray. 3647 // Check that the array is a JSArray.
3923 __ JumpIfSmi(array, &bailout); 3648 __ JumpIfSmi(array, &bailout);
3924 __ CompareObjectType(array, scratch, array_length, JS_ARRAY_TYPE); 3649 __ JumpIfNotObjectType(array, map, scratch1, JS_ARRAY_TYPE, &bailout);
3925 __ b(ne, &bailout);
3926 3650
3927 // Check that the array has fast elements. 3651 // Check that the array has fast elements.
3928 __ CheckFastElements(scratch, array_length, &bailout); 3652 __ CheckFastElements(map, scratch1, &bailout);
3929 3653
3930 // If the array has length zero, return the empty string. 3654 // If the array has length zero, return the empty string.
3931 __ ldr(array_length, FieldMemOperand(array, JSArray::kLengthOffset)); 3655 // Load and untag the length of the array.
3932 __ SmiUntag(array_length, SetCC); 3656 // It is an unsigned value, so we can skip sign extension.
3933 __ b(ne, &non_trivial_array); 3657 // We assume little endianness.
3934 __ LoadRoot(r0, Heap::kempty_stringRootIndex); 3658 __ Ldrsw(array_length,
3935 __ b(&done); 3659 UntagSmiFieldMemOperand(array, JSArray::kLengthOffset));
3660 __ Cbnz(array_length, &non_trivial_array);
3661 __ LoadRoot(result, Heap::kempty_stringRootIndex);
3662 __ B(&done);
3936 3663
3937 __ bind(&non_trivial_array); 3664 __ Bind(&non_trivial_array);
3938
3939 // Get the FixedArray containing array's elements. 3665 // Get the FixedArray containing array's elements.
3940 elements = array; 3666 __ Ldr(elements, FieldMemOperand(array, JSArray::kElementsOffset));
3941 __ ldr(elements, FieldMemOperand(array, JSArray::kElementsOffset));
3942 array = no_reg; // End of array's live range.
3943 3667
3944 // Check that all array elements are sequential ASCII strings, and 3668 // Check that all array elements are sequential ASCII strings, and
3945 // accumulate the sum of their lengths, as a smi-encoded value. 3669 // accumulate the sum of their lengths.
3946 __ mov(string_length, Operand::Zero()); 3670 __ Mov(string_length, 0);
3947 __ add(element, 3671 __ Add(element, elements, FixedArray::kHeaderSize - kHeapObjectTag);
3948 elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); 3672 __ Add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2));
3949 __ add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2));
3950 // Loop condition: while (element < elements_end). 3673 // Loop condition: while (element < elements_end).
3951 // Live values in registers: 3674 // Live values in registers:
3952 // elements: Fixed array of strings. 3675 // elements: Fixed array of strings.
3953 // array_length: Length of the fixed array of strings (not smi) 3676 // array_length: Length of the fixed array of strings (not smi)
3954 // separator: Separator string 3677 // separator: Separator string
3955 // string_length: Accumulated sum of string lengths (smi). 3678 // string_length: Accumulated sum of string lengths (not smi).
3956 // element: Current array element. 3679 // element: Current array element.
3957 // elements_end: Array end. 3680 // elements_end: Array end.
3958 if (generate_debug_code_) { 3681 if (FLAG_debug_code) {
3959 __ cmp(array_length, Operand::Zero()); 3682 __ Cmp(array_length, Operand(0));
3960 __ Assert(gt, kNoEmptyArraysHereInEmitFastAsciiArrayJoin); 3683 __ Assert(gt, kNoEmptyArraysHereInEmitFastAsciiArrayJoin);
3961 } 3684 }
3962 __ bind(&loop); 3685 __ Bind(&loop);
3963 __ ldr(string, MemOperand(element, kPointerSize, PostIndex)); 3686 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
3964 __ JumpIfSmi(string, &bailout); 3687 __ JumpIfSmi(string, &bailout);
3965 __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); 3688 __ Ldr(scratch1, FieldMemOperand(string, HeapObject::kMapOffset));
3966 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); 3689 __ Ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3967 __ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, &bailout); 3690 __ JumpIfInstanceTypeIsNotSequentialAscii(scratch1, scratch2, &bailout);
3968 __ ldr(scratch, FieldMemOperand(string, SeqOneByteString::kLengthOffset)); 3691 __ Ldrsw(scratch1,
3969 __ add(string_length, string_length, Operand(scratch), SetCC); 3692 UntagSmiFieldMemOperand(string, SeqOneByteString::kLengthOffset));
3970 __ b(vs, &bailout); 3693 __ Adds(string_length, string_length, scratch1);
3971 __ cmp(element, elements_end); 3694 __ B(vs, &bailout);
3972 __ b(lt, &loop); 3695 __ Cmp(element, elements_end);
3696 __ B(lt, &loop);
3973 3697
3974 // If array_length is 1, return elements[0], a string. 3698 // If array_length is 1, return elements[0], a string.
3975 __ cmp(array_length, Operand(1)); 3699 __ Cmp(array_length, 1);
3976 __ b(ne, &not_size_one_array); 3700 __ B(ne, &not_size_one_array);
3977 __ ldr(r0, FieldMemOperand(elements, FixedArray::kHeaderSize)); 3701 __ Ldr(result, FieldMemOperand(elements, FixedArray::kHeaderSize));
3978 __ b(&done); 3702 __ B(&done);
3979 3703
3980 __ bind(&not_size_one_array); 3704 __ Bind(&not_size_one_array);
3981 3705
3982 // Live values in registers: 3706 // Live values in registers:
3983 // separator: Separator string 3707 // separator: Separator string
3984 // array_length: Length of the array. 3708 // array_length: Length of the array (not smi).
3985 // string_length: Sum of string lengths (smi). 3709 // string_length: Sum of string lengths (not smi).
3986 // elements: FixedArray of strings. 3710 // elements: FixedArray of strings.
3987 3711
3988 // Check that the separator is a flat ASCII string. 3712 // Check that the separator is a flat ASCII string.
3989 __ JumpIfSmi(separator, &bailout); 3713 __ JumpIfSmi(separator, &bailout);
3990 __ ldr(scratch, FieldMemOperand(separator, HeapObject::kMapOffset)); 3714 __ Ldr(scratch1, FieldMemOperand(separator, HeapObject::kMapOffset));
3991 __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); 3715 __ Ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3992 __ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, &bailout); 3716 __ JumpIfInstanceTypeIsNotSequentialAscii(scratch1, scratch2, &bailout);
3993 3717
3994 // Add (separator length times array_length) - separator length to the 3718 // Add (separator length times array_length) - separator length to the
3995 // string_length to get the length of the result string. array_length is not 3719 // string_length to get the length of the result string.
3996 // smi but the other values are, so the result is a smi 3720 // Load the separator length as untagged.
3997 __ ldr(scratch, FieldMemOperand(separator, SeqOneByteString::kLengthOffset)); 3721 // We assume little endianness, and that the length is positive.
3998 __ sub(string_length, string_length, Operand(scratch)); 3722 __ Ldrsw(separator_length,
3999 __ smull(scratch, ip, array_length, scratch); 3723 UntagSmiFieldMemOperand(separator,
4000 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are 3724 SeqOneByteString::kLengthOffset));
4001 // zero. 3725 __ Sub(string_length, string_length, separator_length);
4002 __ cmp(ip, Operand::Zero()); 3726 __ Umaddl(string_length, array_length.W(), separator_length.W(),
4003 __ b(ne, &bailout); 3727 string_length);
4004 __ tst(scratch, Operand(0x80000000));
4005 __ b(ne, &bailout);
4006 __ add(string_length, string_length, Operand(scratch), SetCC);
4007 __ b(vs, &bailout);
4008 __ SmiUntag(string_length);
4009 3728
4010 // Get first element in the array to free up the elements register to be used 3729 // Get first element in the array.
4011 // for the result. 3730 __ Add(element, elements, FixedArray::kHeaderSize - kHeapObjectTag);
4012 __ add(element,
4013 elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4014 result = elements; // End of live range for elements.
4015 elements = no_reg;
4016 // Live values in registers: 3731 // Live values in registers:
4017 // element: First array element 3732 // element: First array element
4018 // separator: Separator string 3733 // separator: Separator string
4019 // string_length: Length of result string (not smi) 3734 // string_length: Length of result string (not smi)
4020 // array_length: Length of the array. 3735 // array_length: Length of the array (not smi).
4021 __ AllocateAsciiString(result, 3736 __ AllocateAsciiString(result, string_length, scratch1, scratch2, scratch3,
4022 string_length,
4023 scratch,
4024 string, // used as scratch
4025 elements_end, // used as scratch
4026 &bailout); 3737 &bailout);
3738
4027 // Prepare for looping. Set up elements_end to end of the array. Set 3739 // Prepare for looping. Set up elements_end to end of the array. Set
4028 // result_pos to the position of the result where to write the first 3740 // result_pos to the position of the result where to write the first
4029 // character. 3741 // character.
4030 __ add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2)); 3742 // TODO(all): useless unless AllocateAsciiString trashes the register.
4031 result_pos = array_length; // End of live range for array_length. 3743 __ Add(elements_end, element, Operand(array_length, LSL, kPointerSizeLog2));
4032 array_length = no_reg; 3744 __ Add(result_pos, result, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4033 __ add(result_pos,
4034 result,
4035 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
4036 3745
4037 // Check the length of the separator. 3746 // Check the length of the separator.
4038 __ ldr(scratch, FieldMemOperand(separator, SeqOneByteString::kLengthOffset)); 3747 __ Cmp(separator_length, 1);
4039 __ cmp(scratch, Operand(Smi::FromInt(1))); 3748 __ B(eq, &one_char_separator);
4040 __ b(eq, &one_char_separator); 3749 __ B(gt, &long_separator);
4041 __ b(gt, &long_separator);
4042 3750
4043 // Empty separator case 3751 // Empty separator case
4044 __ bind(&empty_separator_loop); 3752 __ Bind(&empty_separator_loop);
4045 // Live values in registers: 3753 // Live values in registers:
4046 // result_pos: the position to which we are currently copying characters. 3754 // result_pos: the position to which we are currently copying characters.
4047 // element: Current array element. 3755 // element: Current array element.
4048 // elements_end: Array end. 3756 // elements_end: Array end.
4049 3757
4050 // Copy next array element to the result. 3758 // Copy next array element to the result.
4051 __ ldr(string, MemOperand(element, kPointerSize, PostIndex)); 3759 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
4052 __ ldr(string_length, FieldMemOperand(string, String::kLengthOffset)); 3760 __ Ldrsw(string_length,
4053 __ SmiUntag(string_length); 3761 UntagSmiFieldMemOperand(string, String::kLengthOffset));
4054 __ add(string, 3762 __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4055 string, 3763 __ CopyBytes(result_pos, string, string_length, scratch1);
4056 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); 3764 __ Cmp(element, elements_end);
4057 __ CopyBytes(string, result_pos, string_length, scratch); 3765 __ B(lt, &empty_separator_loop); // End while (element < elements_end).
4058 __ cmp(element, elements_end); 3766 __ B(&done);
4059 __ b(lt, &empty_separator_loop); // End while (element < elements_end).
4060 ASSERT(result.is(r0));
4061 __ b(&done);
4062 3767
4063 // One-character separator case 3768 // One-character separator case
4064 __ bind(&one_char_separator); 3769 __ Bind(&one_char_separator);
4065 // Replace separator with its ASCII character value. 3770 // Replace separator with its ASCII character value.
4066 __ ldrb(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize)); 3771 __ Ldrb(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize));
4067 // Jump into the loop after the code that copies the separator, so the first 3772 // Jump into the loop after the code that copies the separator, so the first
4068 // element is not preceded by a separator 3773 // element is not preceded by a separator
4069 __ jmp(&one_char_separator_loop_entry); 3774 __ B(&one_char_separator_loop_entry);
4070 3775
4071 __ bind(&one_char_separator_loop); 3776 __ Bind(&one_char_separator_loop);
4072 // Live values in registers: 3777 // Live values in registers:
4073 // result_pos: the position to which we are currently copying characters. 3778 // result_pos: the position to which we are currently copying characters.
4074 // element: Current array element. 3779 // element: Current array element.
4075 // elements_end: Array end. 3780 // elements_end: Array end.
4076 // separator: Single separator ASCII char (in lower byte). 3781 // separator: Single separator ASCII char (in lower byte).
4077 3782
4078 // Copy the separator character to the result. 3783 // Copy the separator character to the result.
4079 __ strb(separator, MemOperand(result_pos, 1, PostIndex)); 3784 __ Strb(separator, MemOperand(result_pos, 1, PostIndex));
4080 3785
4081 // Copy next array element to the result. 3786 // Copy next array element to the result.
4082 __ bind(&one_char_separator_loop_entry); 3787 __ Bind(&one_char_separator_loop_entry);
4083 __ ldr(string, MemOperand(element, kPointerSize, PostIndex)); 3788 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
4084 __ ldr(string_length, FieldMemOperand(string, String::kLengthOffset)); 3789 __ Ldrsw(string_length,
4085 __ SmiUntag(string_length); 3790 UntagSmiFieldMemOperand(string, String::kLengthOffset));
4086 __ add(string, 3791 __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4087 string, 3792 __ CopyBytes(result_pos, string, string_length, scratch1);
4088 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); 3793 __ Cmp(element, elements_end);
4089 __ CopyBytes(string, result_pos, string_length, scratch); 3794 __ B(lt, &one_char_separator_loop); // End while (element < elements_end).
4090 __ cmp(element, elements_end); 3795 __ B(&done);
4091 __ b(lt, &one_char_separator_loop); // End while (element < elements_end).
4092 ASSERT(result.is(r0));
4093 __ b(&done);
4094 3796
4095 // Long separator case (separator is more than one character). Entry is at the 3797 // Long separator case (separator is more than one character). Entry is at the
4096 // label long_separator below. 3798 // label long_separator below.
4097 __ bind(&long_separator_loop); 3799 __ Bind(&long_separator_loop);
4098 // Live values in registers: 3800 // Live values in registers:
4099 // result_pos: the position to which we are currently copying characters. 3801 // result_pos: the position to which we are currently copying characters.
4100 // element: Current array element. 3802 // element: Current array element.
4101 // elements_end: Array end. 3803 // elements_end: Array end.
4102 // separator: Separator string. 3804 // separator: Separator string.
4103 3805
4104 // Copy the separator to the result. 3806 // Copy the separator to the result.
4105 __ ldr(string_length, FieldMemOperand(separator, String::kLengthOffset)); 3807 // TODO(all): hoist next two instructions.
4106 __ SmiUntag(string_length); 3808 __ Ldrsw(string_length,
4107 __ add(string, 3809 UntagSmiFieldMemOperand(separator, String::kLengthOffset));
4108 separator, 3810 __ Add(string, separator, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4109 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); 3811 __ CopyBytes(result_pos, string, string_length, scratch1);
4110 __ CopyBytes(string, result_pos, string_length, scratch);
4111 3812
4112 __ bind(&long_separator); 3813 __ Bind(&long_separator);
4113 __ ldr(string, MemOperand(element, kPointerSize, PostIndex)); 3814 __ Ldr(string, MemOperand(element, kPointerSize, PostIndex));
4114 __ ldr(string_length, FieldMemOperand(string, String::kLengthOffset)); 3815 __ Ldrsw(string_length,
4115 __ SmiUntag(string_length); 3816 UntagSmiFieldMemOperand(string, String::kLengthOffset));
4116 __ add(string, 3817 __ Add(string, string, SeqOneByteString::kHeaderSize - kHeapObjectTag);
4117 string, 3818 __ CopyBytes(result_pos, string, string_length, scratch1);
4118 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); 3819 __ Cmp(element, elements_end);
4119 __ CopyBytes(string, result_pos, string_length, scratch); 3820 __ B(lt, &long_separator_loop); // End while (element < elements_end).
4120 __ cmp(element, elements_end); 3821 __ B(&done);
4121 __ b(lt, &long_separator_loop); // End while (element < elements_end).
4122 ASSERT(result.is(r0));
4123 __ b(&done);
4124 3822
4125 __ bind(&bailout); 3823 __ Bind(&bailout);
4126 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); 3824 // Returning undefined will force slower code to handle it.
4127 __ bind(&done); 3825 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
4128 context()->Plug(r0); 3826 __ Bind(&done);
3827 context()->Plug(result);
4129 } 3828 }
4130 3829
4131 3830
4132 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { 3831 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
4133 Handle<String> name = expr->name(); 3832 Handle<String> name = expr->name();
4134 if (name->length() > 0 && name->Get(0) == '_') { 3833 if (name->length() > 0 && name->Get(0) == '_') {
4135 Comment cmnt(masm_, "[ InlineRuntimeCall"); 3834 Comment cmnt(masm_, "[ InlineRuntimeCall");
4136 EmitInlineRuntimeCall(expr); 3835 EmitInlineRuntimeCall(expr);
4137 return; 3836 return;
4138 } 3837 }
4139 3838
4140 Comment cmnt(masm_, "[ CallRuntime"); 3839 Comment cmnt(masm_, "[ CallRunTime");
4141 ZoneList<Expression*>* args = expr->arguments(); 3840 ZoneList<Expression*>* args = expr->arguments();
3841 int arg_count = args->length();
4142 3842
4143 if (expr->is_jsruntime()) { 3843 if (expr->is_jsruntime()) {
4144 // Prepare for calling JS runtime function. 3844 // Push the builtins object as the receiver.
4145 __ ldr(r0, GlobalObjectOperand()); 3845 __ Ldr(x10, GlobalObjectMemOperand());
4146 __ ldr(r0, FieldMemOperand(r0, GlobalObject::kBuiltinsOffset)); 3846 __ Ldr(x0, FieldMemOperand(x10, GlobalObject::kBuiltinsOffset));
4147 __ push(r0); 3847 __ Push(x0);
4148 }
4149 3848
4150 // Push the arguments ("left-to-right"). 3849 // Load the function from the receiver.
4151 int arg_count = args->length(); 3850 __ Mov(x2, Operand(name));
4152 for (int i = 0; i < arg_count; i++) { 3851 CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId());
4153 VisitForStackValue(args->at(i));
4154 }
4155 3852
4156 if (expr->is_jsruntime()) { 3853 // Push the target function under the receiver.
4157 // Call the JS runtime function. 3854 __ Pop(x10);
4158 __ mov(r2, Operand(expr->name())); 3855 __ Push(x0, x10);
4159 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize(arg_count); 3856
4160 CallIC(ic, NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId()); 3857 int arg_count = args->length();
3858 for (int i = 0; i < arg_count; i++) {
3859 VisitForStackValue(args->at(i));
3860 }
3861
3862 // Record source position of the IC call.
3863 SetSourcePosition(expr->position());
3864 CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS);
3865 __ Peek(x1, (arg_count + 1) * kPointerSize);
3866 __ CallStub(&stub);
3867
4161 // Restore context register. 3868 // Restore context register.
4162 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); 3869 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3870
3871 context()->DropAndPlug(1, x0);
4163 } else { 3872 } else {
3873 // Push the arguments ("left-to-right").
3874 for (int i = 0; i < arg_count; i++) {
3875 VisitForStackValue(args->at(i));
3876 }
3877
4164 // Call the C runtime function. 3878 // Call the C runtime function.
4165 __ CallRuntime(expr->function(), arg_count); 3879 __ CallRuntime(expr->function(), arg_count);
3880 context()->Plug(x0);
4166 } 3881 }
4167 context()->Plug(r0);
4168 } 3882 }
4169 3883
4170 3884
4171 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { 3885 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
4172 switch (expr->op()) { 3886 switch (expr->op()) {
4173 case Token::DELETE: { 3887 case Token::DELETE: {
4174 Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); 3888 Comment cmnt(masm_, "[ UnaryOperation (DELETE)");
4175 Property* property = expr->expression()->AsProperty(); 3889 Property* property = expr->expression()->AsProperty();
4176 VariableProxy* proxy = expr->expression()->AsVariableProxy(); 3890 VariableProxy* proxy = expr->expression()->AsVariableProxy();
4177 3891
4178 if (property != NULL) { 3892 if (property != NULL) {
4179 VisitForStackValue(property->obj()); 3893 VisitForStackValue(property->obj());
4180 VisitForStackValue(property->key()); 3894 VisitForStackValue(property->key());
4181 StrictModeFlag strict_mode_flag = (language_mode() == CLASSIC_MODE) 3895 StrictModeFlag strict_mode_flag = (language_mode() == CLASSIC_MODE)
4182 ? kNonStrictMode : kStrictMode; 3896 ? kNonStrictMode : kStrictMode;
4183 __ mov(r1, Operand(Smi::FromInt(strict_mode_flag))); 3897 __ Mov(x10, Operand(Smi::FromInt(strict_mode_flag)));
4184 __ push(r1); 3898 __ Push(x10);
4185 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); 3899 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
4186 context()->Plug(r0); 3900 context()->Plug(x0);
4187 } else if (proxy != NULL) { 3901 } else if (proxy != NULL) {
4188 Variable* var = proxy->var(); 3902 Variable* var = proxy->var();
4189 // Delete of an unqualified identifier is disallowed in strict mode 3903 // Delete of an unqualified identifier is disallowed in strict mode
4190 // but "delete this" is allowed. 3904 // but "delete this" is allowed.
4191 ASSERT(language_mode() == CLASSIC_MODE || var->is_this()); 3905 ASSERT(language_mode() == CLASSIC_MODE || var->is_this());
4192 if (var->IsUnallocated()) { 3906 if (var->IsUnallocated()) {
4193 __ ldr(r2, GlobalObjectOperand()); 3907 __ Ldr(x12, GlobalObjectMemOperand());
4194 __ mov(r1, Operand(var->name())); 3908 __ Mov(x11, Operand(var->name()));
4195 __ mov(r0, Operand(Smi::FromInt(kNonStrictMode))); 3909 __ Mov(x10, Operand(Smi::FromInt(kNonStrictMode)));
4196 __ Push(r2, r1, r0); 3910 __ Push(x12, x11, x10);
4197 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); 3911 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
4198 context()->Plug(r0); 3912 context()->Plug(x0);
4199 } else if (var->IsStackAllocated() || var->IsContextSlot()) { 3913 } else if (var->IsStackAllocated() || var->IsContextSlot()) {
4200 // Result of deleting non-global, non-dynamic variables is false. 3914 // Result of deleting non-global, non-dynamic variables is false.
4201 // The subexpression does not have side effects. 3915 // The subexpression does not have side effects.
4202 context()->Plug(var->is_this()); 3916 context()->Plug(var->is_this());
4203 } else { 3917 } else {
4204 // Non-global variable. Call the runtime to try to delete from the 3918 // Non-global variable. Call the runtime to try to delete from the
4205 // context where the variable was introduced. 3919 // context where the variable was introduced.
4206 ASSERT(!context_register().is(r2)); 3920 __ Mov(x2, Operand(var->name()));
4207 __ mov(r2, Operand(var->name())); 3921 __ Push(context_register(), x2);
4208 __ Push(context_register(), r2);
4209 __ CallRuntime(Runtime::kDeleteContextSlot, 2); 3922 __ CallRuntime(Runtime::kDeleteContextSlot, 2);
4210 context()->Plug(r0); 3923 context()->Plug(x0);
4211 } 3924 }
4212 } else { 3925 } else {
4213 // Result of deleting non-property, non-variable reference is true. 3926 // Result of deleting non-property, non-variable reference is true.
4214 // The subexpression may have side effects. 3927 // The subexpression may have side effects.
4215 VisitForEffect(expr->expression()); 3928 VisitForEffect(expr->expression());
4216 context()->Plug(true); 3929 context()->Plug(true);
4217 } 3930 }
4218 break; 3931 break;
3932 break;
4219 } 3933 }
4220
4221 case Token::VOID: { 3934 case Token::VOID: {
4222 Comment cmnt(masm_, "[ UnaryOperation (VOID)"); 3935 Comment cmnt(masm_, "[ UnaryOperation (VOID)");
4223 VisitForEffect(expr->expression()); 3936 VisitForEffect(expr->expression());
4224 context()->Plug(Heap::kUndefinedValueRootIndex); 3937 context()->Plug(Heap::kUndefinedValueRootIndex);
4225 break; 3938 break;
4226 } 3939 }
4227
4228 case Token::NOT: { 3940 case Token::NOT: {
4229 Comment cmnt(masm_, "[ UnaryOperation (NOT)"); 3941 Comment cmnt(masm_, "[ UnaryOperation (NOT)");
4230 if (context()->IsEffect()) { 3942 if (context()->IsEffect()) {
4231 // Unary NOT has no side effects so it's only necessary to visit the 3943 // Unary NOT has no side effects so it's only necessary to visit the
4232 // subexpression. Match the optimizing compiler by not branching. 3944 // subexpression. Match the optimizing compiler by not branching.
4233 VisitForEffect(expr->expression()); 3945 VisitForEffect(expr->expression());
4234 } else if (context()->IsTest()) { 3946 } else if (context()->IsTest()) {
4235 const TestContext* test = TestContext::cast(context()); 3947 const TestContext* test = TestContext::cast(context());
4236 // The labels are swapped for the recursive call. 3948 // The labels are swapped for the recursive call.
4237 VisitForControl(expr->expression(), 3949 VisitForControl(expr->expression(),
4238 test->false_label(), 3950 test->false_label(),
4239 test->true_label(), 3951 test->true_label(),
4240 test->fall_through()); 3952 test->fall_through());
4241 context()->Plug(test->true_label(), test->false_label()); 3953 context()->Plug(test->true_label(), test->false_label());
4242 } else { 3954 } else {
4243 // We handle value contexts explicitly rather than simply visiting
4244 // for control and plugging the control flow into the context,
4245 // because we need to prepare a pair of extra administrative AST ids
4246 // for the optimizing compiler.
4247 ASSERT(context()->IsAccumulatorValue() || context()->IsStackValue()); 3955 ASSERT(context()->IsAccumulatorValue() || context()->IsStackValue());
3956 // TODO(jbramley): This could be much more efficient using (for
3957 // example) the CSEL instruction.
4248 Label materialize_true, materialize_false, done; 3958 Label materialize_true, materialize_false, done;
4249 VisitForControl(expr->expression(), 3959 VisitForControl(expr->expression(),
4250 &materialize_false, 3960 &materialize_false,
4251 &materialize_true, 3961 &materialize_true,
4252 &materialize_true); 3962 &materialize_true);
4253 __ bind(&materialize_true); 3963
3964 __ Bind(&materialize_true);
4254 PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); 3965 PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS);
4255 __ LoadRoot(r0, Heap::kTrueValueRootIndex); 3966 __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
4256 if (context()->IsStackValue()) __ push(r0); 3967 __ B(&done);
4257 __ jmp(&done); 3968
4258 __ bind(&materialize_false); 3969 __ Bind(&materialize_false);
4259 PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); 3970 PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS);
4260 __ LoadRoot(r0, Heap::kFalseValueRootIndex); 3971 __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
4261 if (context()->IsStackValue()) __ push(r0); 3972 __ B(&done);
4262 __ bind(&done); 3973
3974 __ Bind(&done);
3975 if (context()->IsStackValue()) {
3976 __ Push(result_register());
3977 }
4263 } 3978 }
4264 break; 3979 break;
4265 } 3980 }
4266
4267 case Token::TYPEOF: { 3981 case Token::TYPEOF: {
4268 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); 3982 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
4269 { StackValueContext context(this); 3983 {
3984 StackValueContext context(this);
4270 VisitForTypeofValue(expr->expression()); 3985 VisitForTypeofValue(expr->expression());
4271 } 3986 }
4272 __ CallRuntime(Runtime::kTypeof, 1); 3987 __ CallRuntime(Runtime::kTypeof, 1);
4273 context()->Plug(r0); 3988 context()->Plug(x0);
4274 break; 3989 break;
4275 } 3990 }
4276
4277 default: 3991 default:
4278 UNREACHABLE(); 3992 UNREACHABLE();
4279 } 3993 }
4280 } 3994 }
4281 3995
4282 3996
4283 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { 3997 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
4284 Comment cmnt(masm_, "[ CountOperation"); 3998 Comment cmnt(masm_, "[ CountOperation");
4285 SetSourcePosition(expr->position()); 3999 SetSourcePosition(expr->position());
4286 4000
(...skipping 17 matching lines...) Expand all
4304 } 4018 }
4305 4019
4306 // Evaluate expression and get value. 4020 // Evaluate expression and get value.
4307 if (assign_type == VARIABLE) { 4021 if (assign_type == VARIABLE) {
4308 ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); 4022 ASSERT(expr->expression()->AsVariableProxy()->var() != NULL);
4309 AccumulatorValueContext context(this); 4023 AccumulatorValueContext context(this);
4310 EmitVariableLoad(expr->expression()->AsVariableProxy()); 4024 EmitVariableLoad(expr->expression()->AsVariableProxy());
4311 } else { 4025 } else {
4312 // Reserve space for result of postfix operation. 4026 // Reserve space for result of postfix operation.
4313 if (expr->is_postfix() && !context()->IsEffect()) { 4027 if (expr->is_postfix() && !context()->IsEffect()) {
4314 __ mov(ip, Operand(Smi::FromInt(0))); 4028 __ Push(xzr);
4315 __ push(ip);
4316 } 4029 }
4317 if (assign_type == NAMED_PROPERTY) { 4030 if (assign_type == NAMED_PROPERTY) {
4318 // Put the object both on the stack and in the accumulator. 4031 // Put the object both on the stack and in the accumulator.
4319 VisitForAccumulatorValue(prop->obj()); 4032 VisitForAccumulatorValue(prop->obj());
4320 __ push(r0); 4033 __ Push(x0);
4321 EmitNamedPropertyLoad(prop); 4034 EmitNamedPropertyLoad(prop);
4322 } else { 4035 } else {
4036 // KEYED_PROPERTY
4323 VisitForStackValue(prop->obj()); 4037 VisitForStackValue(prop->obj());
4324 VisitForAccumulatorValue(prop->key()); 4038 VisitForAccumulatorValue(prop->key());
4325 __ ldr(r1, MemOperand(sp, 0)); 4039 __ Peek(x1, 0);
4326 __ push(r0); 4040 __ Push(x0);
4327 EmitKeyedPropertyLoad(prop); 4041 EmitKeyedPropertyLoad(prop);
4328 } 4042 }
4329 } 4043 }
4330 4044
4331 // We need a second deoptimization point after loading the value 4045 // We need a second deoptimization point after loading the value
4332 // in case evaluating the property load my have a side effect. 4046 // in case evaluating the property load my have a side effect.
4333 if (assign_type == VARIABLE) { 4047 if (assign_type == VARIABLE) {
4334 PrepareForBailout(expr->expression(), TOS_REG); 4048 PrepareForBailout(expr->expression(), TOS_REG);
4335 } else { 4049 } else {
4336 PrepareForBailoutForId(prop->LoadId(), TOS_REG); 4050 PrepareForBailoutForId(prop->LoadId(), TOS_REG);
4337 } 4051 }
4338 4052
4339 // Inline smi case if we are in a loop. 4053 // Inline smi case if we are in a loop.
4340 Label stub_call, done; 4054 Label stub_call, done;
4341 JumpPatchSite patch_site(masm_); 4055 JumpPatchSite patch_site(masm_);
4342 4056
4343 int count_value = expr->op() == Token::INC ? 1 : -1; 4057 int count_value = expr->op() == Token::INC ? 1 : -1;
4344 if (ShouldInlineSmiCase(expr->op())) { 4058 if (ShouldInlineSmiCase(expr->op())) {
4345 Label slow; 4059 Label slow;
4346 patch_site.EmitJumpIfNotSmi(r0, &slow); 4060 patch_site.EmitJumpIfNotSmi(x0, &slow);
4347 4061
4348 // Save result for postfix expressions. 4062 // Save result for postfix expressions.
4349 if (expr->is_postfix()) { 4063 if (expr->is_postfix()) {
4350 if (!context()->IsEffect()) { 4064 if (!context()->IsEffect()) {
4351 // Save the result on the stack. If we have a named or keyed property 4065 // Save the result on the stack. If we have a named or keyed property we
4352 // we store the result under the receiver that is currently on top 4066 // store the result under the receiver that is currently on top of the
4353 // of the stack. 4067 // stack.
4354 switch (assign_type) { 4068 switch (assign_type) {
4355 case VARIABLE: 4069 case VARIABLE:
4356 __ push(r0); 4070 __ Push(x0);
4357 break; 4071 break;
4358 case NAMED_PROPERTY: 4072 case NAMED_PROPERTY:
4359 __ str(r0, MemOperand(sp, kPointerSize)); 4073 __ Poke(x0, kPointerSize);
4360 break; 4074 break;
4361 case KEYED_PROPERTY: 4075 case KEYED_PROPERTY:
4362 __ str(r0, MemOperand(sp, 2 * kPointerSize)); 4076 __ Poke(x0, kPointerSize * 2);
4363 break; 4077 break;
4364 } 4078 }
4365 } 4079 }
4366 } 4080 }
4367 4081
4368 __ add(r0, r0, Operand(Smi::FromInt(count_value)), SetCC); 4082 __ Adds(x0, x0, Operand(Smi::FromInt(count_value)));
4369 __ b(vc, &done); 4083 __ B(vc, &done);
4370 // Call stub. Undo operation first. 4084 // Call stub. Undo operation first.
4371 __ sub(r0, r0, Operand(Smi::FromInt(count_value))); 4085 __ Sub(x0, x0, Operand(Smi::FromInt(count_value)));
4372 __ jmp(&stub_call); 4086 __ B(&stub_call);
4373 __ bind(&slow); 4087 __ Bind(&slow);
4374 } 4088 }
4375 ToNumberStub convert_stub; 4089 ToNumberStub convert_stub;
4376 __ CallStub(&convert_stub); 4090 __ CallStub(&convert_stub);
4377 4091
4378 // Save result for postfix expressions. 4092 // Save result for postfix expressions.
4379 if (expr->is_postfix()) { 4093 if (expr->is_postfix()) {
4380 if (!context()->IsEffect()) { 4094 if (!context()->IsEffect()) {
4381 // Save the result on the stack. If we have a named or keyed property 4095 // Save the result on the stack. If we have a named or keyed property
4382 // we store the result under the receiver that is currently on top 4096 // we store the result under the receiver that is currently on top
4383 // of the stack. 4097 // of the stack.
4384 switch (assign_type) { 4098 switch (assign_type) {
4385 case VARIABLE: 4099 case VARIABLE:
4386 __ push(r0); 4100 __ Push(x0);
4387 break; 4101 break;
4388 case NAMED_PROPERTY: 4102 case NAMED_PROPERTY:
4389 __ str(r0, MemOperand(sp, kPointerSize)); 4103 __ Poke(x0, kXRegSizeInBytes);
4390 break; 4104 break;
4391 case KEYED_PROPERTY: 4105 case KEYED_PROPERTY:
4392 __ str(r0, MemOperand(sp, 2 * kPointerSize)); 4106 __ Poke(x0, 2 * kXRegSizeInBytes);
4393 break; 4107 break;
4394 } 4108 }
4395 } 4109 }
4396 } 4110 }
4397 4111
4398 4112 __ Bind(&stub_call);
4399 __ bind(&stub_call); 4113 __ Mov(x1, x0);
4400 __ mov(r1, r0); 4114 __ Mov(x0, Operand(Smi::FromInt(count_value)));
4401 __ mov(r0, Operand(Smi::FromInt(count_value)));
4402 4115
4403 // Record position before stub call. 4116 // Record position before stub call.
4404 SetSourcePosition(expr->position()); 4117 SetSourcePosition(expr->position());
4405 4118
4406 BinaryOpICStub stub(Token::ADD, NO_OVERWRITE); 4119 {
4407 CallIC(stub.GetCode(isolate()), 4120 Assembler::BlockConstPoolScope scope(masm_);
4408 NOT_CONTEXTUAL, 4121 BinaryOpICStub stub(Token::ADD, NO_OVERWRITE);
4409 expr->CountBinOpFeedbackId()); 4122 CallIC(stub.GetCode(isolate()), expr->CountBinOpFeedbackId());
4410 patch_site.EmitPatchInfo(); 4123 patch_site.EmitPatchInfo();
4411 __ bind(&done); 4124 }
4125 __ Bind(&done);
4412 4126
4413 // Store the value returned in r0. 4127 // Store the value returned in x0.
4414 switch (assign_type) { 4128 switch (assign_type) {
4415 case VARIABLE: 4129 case VARIABLE:
4416 if (expr->is_postfix()) { 4130 if (expr->is_postfix()) {
4417 { EffectContext context(this); 4131 { EffectContext context(this);
4418 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), 4132 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4419 Token::ASSIGN); 4133 Token::ASSIGN);
4420 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); 4134 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4421 context.Plug(r0); 4135 context.Plug(x0);
4422 } 4136 }
4423 // For all contexts except EffectConstant We have the result on 4137 // For all contexts except EffectConstant We have the result on
4424 // top of the stack. 4138 // top of the stack.
4425 if (!context()->IsEffect()) { 4139 if (!context()->IsEffect()) {
4426 context()->PlugTOS(); 4140 context()->PlugTOS();
4427 } 4141 }
4428 } else { 4142 } else {
4429 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), 4143 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
4430 Token::ASSIGN); 4144 Token::ASSIGN);
4431 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); 4145 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4432 context()->Plug(r0); 4146 context()->Plug(x0);
4433 } 4147 }
4434 break; 4148 break;
4435 case NAMED_PROPERTY: { 4149 case NAMED_PROPERTY: {
4436 __ mov(r2, Operand(prop->key()->AsLiteral()->value())); 4150 __ Mov(x2, Operand(prop->key()->AsLiteral()->value()));
4437 __ pop(r1); 4151 __ Pop(x1);
4438 CallStoreIC(NOT_CONTEXTUAL, expr->CountStoreFeedbackId()); 4152 CallStoreIC(expr->CountStoreFeedbackId());
4439 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); 4153 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4440 if (expr->is_postfix()) { 4154 if (expr->is_postfix()) {
4441 if (!context()->IsEffect()) { 4155 if (!context()->IsEffect()) {
4442 context()->PlugTOS(); 4156 context()->PlugTOS();
4443 } 4157 }
4444 } else { 4158 } else {
4445 context()->Plug(r0); 4159 context()->Plug(x0);
4446 } 4160 }
4447 break; 4161 break;
4448 } 4162 }
4449 case KEYED_PROPERTY: { 4163 case KEYED_PROPERTY: {
4450 __ Pop(r2, r1); // r1 = key. r2 = receiver. 4164 __ Pop(x1); // Key.
4165 __ Pop(x2); // Receiver.
4451 Handle<Code> ic = is_classic_mode() 4166 Handle<Code> ic = is_classic_mode()
4452 ? isolate()->builtins()->KeyedStoreIC_Initialize() 4167 ? isolate()->builtins()->KeyedStoreIC_Initialize()
4453 : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); 4168 : isolate()->builtins()->KeyedStoreIC_Initialize_Strict();
4454 CallIC(ic, NOT_CONTEXTUAL, expr->CountStoreFeedbackId()); 4169 CallIC(ic, expr->CountStoreFeedbackId());
4455 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); 4170 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
4456 if (expr->is_postfix()) { 4171 if (expr->is_postfix()) {
4457 if (!context()->IsEffect()) { 4172 if (!context()->IsEffect()) {
4458 context()->PlugTOS(); 4173 context()->PlugTOS();
4459 } 4174 }
4460 } else { 4175 } else {
4461 context()->Plug(r0); 4176 context()->Plug(x0);
4462 } 4177 }
4463 break; 4178 break;
4464 } 4179 }
4465 } 4180 }
4466 } 4181 }
4467 4182
4468 4183
4469 void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { 4184 void FullCodeGenerator::VisitForTypeofValue(Expression* expr) {
4470 ASSERT(!context()->IsEffect()); 4185 ASSERT(!context()->IsEffect());
4471 ASSERT(!context()->IsTest()); 4186 ASSERT(!context()->IsTest());
4472 VariableProxy* proxy = expr->AsVariableProxy(); 4187 VariableProxy* proxy = expr->AsVariableProxy();
4473 if (proxy != NULL && proxy->var()->IsUnallocated()) { 4188 if (proxy != NULL && proxy->var()->IsUnallocated()) {
4474 Comment cmnt(masm_, "Global variable"); 4189 Comment cmnt(masm_, "Global variable");
4475 __ ldr(r0, GlobalObjectOperand()); 4190 __ Ldr(x0, GlobalObjectMemOperand());
4476 __ mov(r2, Operand(proxy->name())); 4191 __ Mov(x2, Operand(proxy->name()));
4477 // Use a regular load, not a contextual load, to avoid a reference 4192 // Use a regular load, not a contextual load, to avoid a reference
4478 // error. 4193 // error.
4479 CallLoadIC(NOT_CONTEXTUAL); 4194 CallLoadIC(NOT_CONTEXTUAL);
4480 PrepareForBailout(expr, TOS_REG); 4195 PrepareForBailout(expr, TOS_REG);
4481 context()->Plug(r0); 4196 context()->Plug(x0);
4482 } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { 4197 } else if (proxy != NULL && proxy->var()->IsLookupSlot()) {
4483 Label done, slow; 4198 Label done, slow;
4484 4199
4485 // Generate code for loading from variables potentially shadowed 4200 // Generate code for loading from variables potentially shadowed
4486 // by eval-introduced variables. 4201 // by eval-introduced variables.
4487 EmitDynamicLookupFastCase(proxy->var(), INSIDE_TYPEOF, &slow, &done); 4202 EmitDynamicLookupFastCase(proxy->var(), INSIDE_TYPEOF, &slow, &done);
4488 4203
4489 __ bind(&slow); 4204 __ Bind(&slow);
4490 __ mov(r0, Operand(proxy->name())); 4205 __ Mov(x0, Operand(proxy->name()));
4491 __ Push(cp, r0); 4206 __ Push(cp, x0);
4492 __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); 4207 __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2);
4493 PrepareForBailout(expr, TOS_REG); 4208 PrepareForBailout(expr, TOS_REG);
4494 __ bind(&done); 4209 __ Bind(&done);
4495 4210
4496 context()->Plug(r0); 4211 context()->Plug(x0);
4497 } else { 4212 } else {
4498 // This expression cannot throw a reference error at the top level. 4213 // This expression cannot throw a reference error at the top level.
4499 VisitInDuplicateContext(expr); 4214 VisitInDuplicateContext(expr);
4500 } 4215 }
4501 } 4216 }
4502 4217
4503 4218
4504 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, 4219 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
4505 Expression* sub_expr, 4220 Expression* sub_expr,
4506 Handle<String> check) { 4221 Handle<String> check) {
4222 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof");
4223 Comment cmnt(masm_, "[ EmitLiteralCompareTypeof");
4507 Label materialize_true, materialize_false; 4224 Label materialize_true, materialize_false;
4508 Label* if_true = NULL; 4225 Label* if_true = NULL;
4509 Label* if_false = NULL; 4226 Label* if_false = NULL;
4510 Label* fall_through = NULL; 4227 Label* fall_through = NULL;
4511 context()->PrepareTest(&materialize_true, &materialize_false, 4228 context()->PrepareTest(&materialize_true, &materialize_false,
4512 &if_true, &if_false, &fall_through); 4229 &if_true, &if_false, &fall_through);
4513 4230
4514 { AccumulatorValueContext context(this); 4231 { AccumulatorValueContext context(this);
4515 VisitForTypeofValue(sub_expr); 4232 VisitForTypeofValue(sub_expr);
4516 } 4233 }
4517 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 4234 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4518 4235
4519 if (check->Equals(isolate()->heap()->number_string())) { 4236 if (check->Equals(isolate()->heap()->number_string())) {
4520 __ JumpIfSmi(r0, if_true); 4237 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof number_string");
4521 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); 4238 __ JumpIfSmi(x0, if_true);
4522 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); 4239 __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset));
4523 __ cmp(r0, ip); 4240 __ CompareRoot(x0, Heap::kHeapNumberMapRootIndex);
4524 Split(eq, if_true, if_false, fall_through); 4241 Split(eq, if_true, if_false, fall_through);
4525 } else if (check->Equals(isolate()->heap()->string_string())) { 4242 } else if (check->Equals(isolate()->heap()->string_string())) {
4526 __ JumpIfSmi(r0, if_false); 4243 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof string_string");
4244 __ JumpIfSmi(x0, if_false);
4527 // Check for undetectable objects => false. 4245 // Check for undetectable objects => false.
4528 __ CompareObjectType(r0, r0, r1, FIRST_NONSTRING_TYPE); 4246 __ JumpIfObjectType(x0, x0, x1, FIRST_NONSTRING_TYPE, if_false, ge);
4529 __ b(ge, if_false); 4247 __ Ldrb(x1, FieldMemOperand(x0, Map::kBitFieldOffset));
4530 __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); 4248 __ TestAndSplit(x1, 1 << Map::kIsUndetectable, if_true, if_false,
4531 __ tst(r1, Operand(1 << Map::kIsUndetectable)); 4249 fall_through);
4532 Split(eq, if_true, if_false, fall_through);
4533 } else if (check->Equals(isolate()->heap()->symbol_string())) { 4250 } else if (check->Equals(isolate()->heap()->symbol_string())) {
4534 __ JumpIfSmi(r0, if_false); 4251 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof symbol_string");
4535 __ CompareObjectType(r0, r0, r1, SYMBOL_TYPE); 4252 __ JumpIfSmi(x0, if_false);
4253 __ CompareObjectType(x0, x0, x1, SYMBOL_TYPE);
4536 Split(eq, if_true, if_false, fall_through); 4254 Split(eq, if_true, if_false, fall_through);
4537 } else if (check->Equals(isolate()->heap()->boolean_string())) { 4255 } else if (check->Equals(isolate()->heap()->boolean_string())) {
4538 __ CompareRoot(r0, Heap::kTrueValueRootIndex); 4256 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof boolean_string");
4539 __ b(eq, if_true); 4257 __ JumpIfRoot(x0, Heap::kTrueValueRootIndex, if_true);
4540 __ CompareRoot(r0, Heap::kFalseValueRootIndex); 4258 __ CompareRoot(x0, Heap::kFalseValueRootIndex);
4541 Split(eq, if_true, if_false, fall_through); 4259 Split(eq, if_true, if_false, fall_through);
4542 } else if (FLAG_harmony_typeof && 4260 } else if (FLAG_harmony_typeof &&
4543 check->Equals(isolate()->heap()->null_string())) { 4261 check->Equals(isolate()->heap()->null_string())) {
4544 __ CompareRoot(r0, Heap::kNullValueRootIndex); 4262 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof null_string");
4263 __ CompareRoot(x0, Heap::kNullValueRootIndex);
4545 Split(eq, if_true, if_false, fall_through); 4264 Split(eq, if_true, if_false, fall_through);
4546 } else if (check->Equals(isolate()->heap()->undefined_string())) { 4265 } else if (check->Equals(isolate()->heap()->undefined_string())) {
4547 __ CompareRoot(r0, Heap::kUndefinedValueRootIndex); 4266 ASM_LOCATION(
4548 __ b(eq, if_true); 4267 "FullCodeGenerator::EmitLiteralCompareTypeof undefined_string");
4549 __ JumpIfSmi(r0, if_false); 4268 __ JumpIfRoot(x0, Heap::kUndefinedValueRootIndex, if_true);
4269 __ JumpIfSmi(x0, if_false);
4550 // Check for undetectable objects => true. 4270 // Check for undetectable objects => true.
4551 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); 4271 __ Ldr(x0, FieldMemOperand(x0, HeapObject::kMapOffset));
4552 __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); 4272 __ Ldrb(x1, FieldMemOperand(x0, Map::kBitFieldOffset));
4553 __ tst(r1, Operand(1 << Map::kIsUndetectable)); 4273 __ TestAndSplit(x1, 1 << Map::kIsUndetectable, if_false, if_true,
4554 Split(ne, if_true, if_false, fall_through); 4274 fall_through);
4275 } else if (check->Equals(isolate()->heap()->function_string())) {
4276 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof function_string");
4277 __ JumpIfSmi(x0, if_false);
4278 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
4279 __ JumpIfObjectType(x0, x10, x11, JS_FUNCTION_TYPE, if_true);
4280 __ CompareAndSplit(x11, JS_FUNCTION_PROXY_TYPE, eq, if_true, if_false,
4281 fall_through);
4555 4282
4556 } else if (check->Equals(isolate()->heap()->function_string())) {
4557 __ JumpIfSmi(r0, if_false);
4558 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
4559 __ CompareObjectType(r0, r0, r1, JS_FUNCTION_TYPE);
4560 __ b(eq, if_true);
4561 __ cmp(r1, Operand(JS_FUNCTION_PROXY_TYPE));
4562 Split(eq, if_true, if_false, fall_through);
4563 } else if (check->Equals(isolate()->heap()->object_string())) { 4283 } else if (check->Equals(isolate()->heap()->object_string())) {
4564 __ JumpIfSmi(r0, if_false); 4284 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof object_string");
4285 __ JumpIfSmi(x0, if_false);
4565 if (!FLAG_harmony_typeof) { 4286 if (!FLAG_harmony_typeof) {
4566 __ CompareRoot(r0, Heap::kNullValueRootIndex); 4287 __ JumpIfRoot(x0, Heap::kNullValueRootIndex, if_true);
4567 __ b(eq, if_true);
4568 } 4288 }
4569 // Check for JS objects => true. 4289 // Check for JS objects => true.
4570 __ CompareObjectType(r0, r0, r1, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); 4290 Register map = x10;
4571 __ b(lt, if_false); 4291 __ JumpIfObjectType(x0, map, x11, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE,
4572 __ CompareInstanceType(r0, r1, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); 4292 if_false, lt);
4573 __ b(gt, if_false); 4293 __ CompareInstanceType(map, x11, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
4294 __ B(gt, if_false);
4574 // Check for undetectable objects => false. 4295 // Check for undetectable objects => false.
4575 __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); 4296 __ Ldrb(x10, FieldMemOperand(map, Map::kBitFieldOffset));
4576 __ tst(r1, Operand(1 << Map::kIsUndetectable)); 4297
4577 Split(eq, if_true, if_false, fall_through); 4298 __ TestAndSplit(x10, 1 << Map::kIsUndetectable, if_true, if_false,
4299 fall_through);
4300
4578 } else { 4301 } else {
4579 if (if_false != fall_through) __ jmp(if_false); 4302 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareTypeof other");
4303 if (if_false != fall_through) __ B(if_false);
4580 } 4304 }
4581 context()->Plug(if_true, if_false); 4305 context()->Plug(if_true, if_false);
4582 } 4306 }
4583 4307
4584 4308
4585 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { 4309 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
4586 Comment cmnt(masm_, "[ CompareOperation"); 4310 Comment cmnt(masm_, "[ CompareOperation");
4587 SetSourcePosition(expr->position()); 4311 SetSourcePosition(expr->position());
4588 4312
4589 // First we try a fast inlined version of the compare when one of 4313 // Try to generate an optimized comparison with a literal value.
4590 // the operands is a literal. 4314 // TODO(jbramley): This only checks common values like NaN or undefined.
4591 if (TryLiteralCompare(expr)) return; 4315 // Should it also handle A64 immediate operands?
4316 if (TryLiteralCompare(expr)) {
4317 return;
4318 }
4592 4319
4593 // Always perform the comparison for its control flow. Pack the result 4320 // Assign labels according to context()->PrepareTest.
4594 // into the expression's context after the comparison is performed. 4321 Label materialize_true;
4595 Label materialize_true, materialize_false; 4322 Label materialize_false;
4596 Label* if_true = NULL; 4323 Label* if_true = NULL;
4597 Label* if_false = NULL; 4324 Label* if_false = NULL;
4598 Label* fall_through = NULL; 4325 Label* fall_through = NULL;
4599 context()->PrepareTest(&materialize_true, &materialize_false, 4326 context()->PrepareTest(&materialize_true, &materialize_false,
4600 &if_true, &if_false, &fall_through); 4327 &if_true, &if_false, &fall_through);
4601 4328
4602 Token::Value op = expr->op(); 4329 Token::Value op = expr->op();
4603 VisitForStackValue(expr->left()); 4330 VisitForStackValue(expr->left());
4604 switch (op) { 4331 switch (op) {
4605 case Token::IN: 4332 case Token::IN:
4606 VisitForStackValue(expr->right()); 4333 VisitForStackValue(expr->right());
4607 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); 4334 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION);
4608 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); 4335 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL);
4609 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 4336 __ CompareRoot(x0, Heap::kTrueValueRootIndex);
4610 __ cmp(r0, ip);
4611 Split(eq, if_true, if_false, fall_through); 4337 Split(eq, if_true, if_false, fall_through);
4612 break; 4338 break;
4613 4339
4614 case Token::INSTANCEOF: { 4340 case Token::INSTANCEOF: {
4615 VisitForStackValue(expr->right()); 4341 VisitForStackValue(expr->right());
4616 InstanceofStub stub(InstanceofStub::kNoFlags); 4342 InstanceofStub stub(InstanceofStub::kNoFlags);
4617 __ CallStub(&stub); 4343 __ CallStub(&stub);
4618 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 4344 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4619 // The stub returns 0 for true. 4345 // The stub returns 0 for true.
4620 __ tst(r0, r0); 4346 __ CompareAndSplit(x0, 0, eq, if_true, if_false, fall_through);
4621 Split(eq, if_true, if_false, fall_through);
4622 break; 4347 break;
4623 } 4348 }
4624 4349
4625 default: { 4350 default: {
4626 VisitForAccumulatorValue(expr->right()); 4351 VisitForAccumulatorValue(expr->right());
4627 Condition cond = CompareIC::ComputeCondition(op); 4352 Condition cond = CompareIC::ComputeCondition(op);
4628 __ pop(r1);
4629 4353
4630 bool inline_smi_code = ShouldInlineSmiCase(op); 4354 // Pop the stack value.
4355 __ Pop(x1);
4356
4631 JumpPatchSite patch_site(masm_); 4357 JumpPatchSite patch_site(masm_);
4632 if (inline_smi_code) { 4358 if (ShouldInlineSmiCase(op)) {
4633 Label slow_case; 4359 Label slow_case;
4634 __ orr(r2, r0, Operand(r1)); 4360 patch_site.EmitJumpIfEitherNotSmi(x0, x1, &slow_case);
4635 patch_site.EmitJumpIfNotSmi(r2, &slow_case); 4361 __ Cmp(x1, x0);
4636 __ cmp(r1, r0);
4637 Split(cond, if_true, if_false, NULL); 4362 Split(cond, if_true, if_false, NULL);
4638 __ bind(&slow_case); 4363 __ Bind(&slow_case);
4639 } 4364 }
4640 4365
4641 // Record position and call the compare IC. 4366 // Record position and call the compare IC.
4642 SetSourcePosition(expr->position()); 4367 SetSourcePosition(expr->position());
4643 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); 4368 Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op);
4644 CallIC(ic, NOT_CONTEXTUAL, expr->CompareOperationFeedbackId()); 4369 CallIC(ic, expr->CompareOperationFeedbackId());
4645 patch_site.EmitPatchInfo(); 4370 patch_site.EmitPatchInfo();
4646 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 4371 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4647 __ cmp(r0, Operand::Zero()); 4372 __ CompareAndSplit(x0, 0, cond, if_true, if_false, fall_through);
4648 Split(cond, if_true, if_false, fall_through);
4649 } 4373 }
4650 } 4374 }
4651 4375
4652 // Convert the result of the comparison into one expected for this 4376 // Convert the result of the comparison into one expected for this
4653 // expression's context. 4377 // expression's context.
4654 context()->Plug(if_true, if_false); 4378 context()->Plug(if_true, if_false);
4655 } 4379 }
4656 4380
4657 4381
4658 void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, 4382 void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr,
4659 Expression* sub_expr, 4383 Expression* sub_expr,
4660 NilValue nil) { 4384 NilValue nil) {
4385 ASM_LOCATION("FullCodeGenerator::EmitLiteralCompareNil");
4661 Label materialize_true, materialize_false; 4386 Label materialize_true, materialize_false;
4662 Label* if_true = NULL; 4387 Label* if_true = NULL;
4663 Label* if_false = NULL; 4388 Label* if_false = NULL;
4664 Label* fall_through = NULL; 4389 Label* fall_through = NULL;
4665 context()->PrepareTest(&materialize_true, &materialize_false, 4390 context()->PrepareTest(&materialize_true, &materialize_false,
4666 &if_true, &if_false, &fall_through); 4391 &if_true, &if_false, &fall_through);
4667 4392
4668 VisitForAccumulatorValue(sub_expr); 4393 VisitForAccumulatorValue(sub_expr);
4669 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); 4394 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false);
4395
4670 if (expr->op() == Token::EQ_STRICT) { 4396 if (expr->op() == Token::EQ_STRICT) {
4671 Heap::RootListIndex nil_value = nil == kNullValue ? 4397 Heap::RootListIndex nil_value = nil == kNullValue ?
4672 Heap::kNullValueRootIndex : 4398 Heap::kNullValueRootIndex :
4673 Heap::kUndefinedValueRootIndex; 4399 Heap::kUndefinedValueRootIndex;
4674 __ LoadRoot(r1, nil_value); 4400 __ CompareRoot(x0, nil_value);
4675 __ cmp(r0, r1);
4676 Split(eq, if_true, if_false, fall_through); 4401 Split(eq, if_true, if_false, fall_through);
4677 } else { 4402 } else {
4678 Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); 4403 Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil);
4679 CallIC(ic, NOT_CONTEXTUAL, expr->CompareOperationFeedbackId()); 4404 CallIC(ic, expr->CompareOperationFeedbackId());
4680 __ cmp(r0, Operand(0)); 4405 __ CompareAndSplit(x0, 0, ne, if_true, if_false, fall_through);
4681 Split(ne, if_true, if_false, fall_through);
4682 } 4406 }
4407
4683 context()->Plug(if_true, if_false); 4408 context()->Plug(if_true, if_false);
4684 } 4409 }
4685 4410
4686 4411
4687 void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { 4412 void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
4688 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 4413 __ Ldr(x0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4689 context()->Plug(r0); 4414 context()->Plug(x0);
4690 } 4415 }
4691 4416
4692 4417
4418 void FullCodeGenerator::VisitYield(Yield* expr) {
4419 Comment cmnt(masm_, "[ Yield");
4420 // Evaluate yielded value first; the initial iterator definition depends on
4421 // this. It stays on the stack while we update the iterator.
4422 VisitForStackValue(expr->expression());
4423
4424 // TODO(jbramley): Tidy this up once the merge is done, using named registers
4425 // and suchlike. The implementation changes a little by bleeding_edge so I
4426 // don't want to spend too much time on it now.
4427
4428 switch (expr->yield_kind()) {
4429 case Yield::SUSPEND:
4430 // Pop value from top-of-stack slot; box result into result register.
4431 EmitCreateIteratorResult(false);
4432 __ Push(result_register());
4433 // Fall through.
4434 case Yield::INITIAL: {
4435 Label suspend, continuation, post_runtime, resume;
4436
4437 __ B(&suspend);
4438
4439 // TODO(jbramley): This label is bound here because the following code
4440 // looks at its pos(). Is it possible to do something more efficient here,
4441 // perhaps using Adr?
4442 __ Bind(&continuation);
4443 __ B(&resume);
4444
4445 __ Bind(&suspend);
4446 VisitForAccumulatorValue(expr->generator_object());
4447 ASSERT((continuation.pos() > 0) && Smi::IsValid(continuation.pos()));
4448 __ Mov(x1, Operand(Smi::FromInt(continuation.pos())));
4449 __ Str(x1, FieldMemOperand(x0, JSGeneratorObject::kContinuationOffset));
4450 __ Str(cp, FieldMemOperand(x0, JSGeneratorObject::kContextOffset));
4451 __ Mov(x1, cp);
4452 __ RecordWriteField(x0, JSGeneratorObject::kContextOffset, x1, x2,
4453 kLRHasBeenSaved, kDontSaveFPRegs);
4454 __ Add(x1, fp, StandardFrameConstants::kExpressionsOffset);
4455 __ Cmp(__ StackPointer(), x1);
4456 __ B(eq, &post_runtime);
4457 __ Push(x0); // generator object
4458 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
4459 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4460 __ Bind(&post_runtime);
4461 __ Pop(result_register());
4462 EmitReturnSequence();
4463
4464 __ Bind(&resume);
4465 context()->Plug(result_register());
4466 break;
4467 }
4468
4469 case Yield::FINAL: {
4470 VisitForAccumulatorValue(expr->generator_object());
4471 __ Mov(x1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
4472 __ Str(x1, FieldMemOperand(result_register(),
4473 JSGeneratorObject::kContinuationOffset));
4474 // Pop value from top-of-stack slot, box result into result register.
4475 EmitCreateIteratorResult(true);
4476 EmitUnwindBeforeReturn();
4477 EmitReturnSequence();
4478 break;
4479 }
4480
4481 case Yield::DELEGATING: {
4482 VisitForStackValue(expr->generator_object());
4483
4484 // Initial stack layout is as follows:
4485 // [sp + 1 * kPointerSize] iter
4486 // [sp + 0 * kPointerSize] g
4487
4488 Label l_catch, l_try, l_suspend, l_continuation, l_resume;
4489 Label l_next, l_call, l_loop;
4490 // Initial send value is undefined.
4491 __ LoadRoot(x0, Heap::kUndefinedValueRootIndex);
4492 __ B(&l_next);
4493
4494 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
4495 __ Bind(&l_catch);
4496 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
4497 __ LoadRoot(x2, Heap::kthrow_stringRootIndex); // "throw"
4498 __ Peek(x3, 1 * kPointerSize); // iter
4499 __ Push(x2, x3, x0); // "throw", iter, except
4500 __ B(&l_call);
4501
4502 // try { received = %yield result }
4503 // Shuffle the received result above a try handler and yield it without
4504 // re-boxing.
4505 __ Bind(&l_try);
4506 __ Pop(x0); // result
4507 __ PushTryHandler(StackHandler::CATCH, expr->index());
4508 const int handler_size = StackHandlerConstants::kSize;
4509 __ Push(x0); // result
4510 __ B(&l_suspend);
4511
4512 // TODO(jbramley): This label is bound here because the following code
4513 // looks at its pos(). Is it possible to do something more efficient here,
4514 // perhaps using Adr?
4515 __ Bind(&l_continuation);
4516 __ B(&l_resume);
4517
4518 __ Bind(&l_suspend);
4519 const int generator_object_depth = kPointerSize + handler_size;
4520 __ Peek(x0, generator_object_depth);
4521 __ Push(x0); // g
4522 ASSERT((l_continuation.pos() > 0) && Smi::IsValid(l_continuation.pos()));
4523 __ Mov(x1, Operand(Smi::FromInt(l_continuation.pos())));
4524 __ Str(x1, FieldMemOperand(x0, JSGeneratorObject::kContinuationOffset));
4525 __ Str(cp, FieldMemOperand(x0, JSGeneratorObject::kContextOffset));
4526 __ Mov(x1, cp);
4527 __ RecordWriteField(x0, JSGeneratorObject::kContextOffset, x1, x2,
4528 kLRHasBeenSaved, kDontSaveFPRegs);
4529 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
4530 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4531 __ Pop(x0); // result
4532 EmitReturnSequence();
4533 __ Bind(&l_resume); // received in x0
4534 __ PopTryHandler();
4535
4536 // receiver = iter; f = 'next'; arg = received;
4537 __ Bind(&l_next);
4538 __ LoadRoot(x2, Heap::knext_stringRootIndex); // "next"
4539 __ Peek(x3, 1 * kPointerSize); // iter
4540 __ Push(x2, x3, x0); // "next", iter, received
4541
4542 // result = receiver[f](arg);
4543 __ Bind(&l_call);
4544 __ Peek(x1, 1 * kPointerSize);
4545 __ Peek(x0, 2 * kPointerSize);
4546 Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
4547 CallIC(ic, TypeFeedbackId::None());
4548 __ Mov(x1, x0);
4549 __ Poke(x1, 2 * kPointerSize);
4550 CallFunctionStub stub(1, CALL_AS_METHOD);
4551 __ CallStub(&stub);
4552
4553 __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4554 __ Drop(1); // The function is still on the stack; drop it.
4555
4556 // if (!result.done) goto l_try;
4557 __ Bind(&l_loop);
4558 __ Push(x0); // save result
4559 __ LoadRoot(x2, Heap::kdone_stringRootIndex); // "done"
4560 CallLoadIC(NOT_CONTEXTUAL); // result.done in x0
4561 // The ToBooleanStub argument (result.done) is in x0.
4562 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate());
4563 CallIC(bool_ic);
4564 __ Cbz(x0, &l_try);
4565
4566 // result.value
4567 __ Pop(x0); // result
4568 __ LoadRoot(x2, Heap::kvalue_stringRootIndex); // "value"
4569 CallLoadIC(NOT_CONTEXTUAL); // result.value in x0
4570 context()->DropAndPlug(2, x0); // drop iter and g
4571 break;
4572 }
4573 }
4574 }
4575
4576
4577 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
4578 Expression *value,
4579 JSGeneratorObject::ResumeMode resume_mode) {
4580 ASM_LOCATION("FullCodeGenerator::EmitGeneratorResume");
4581 Register value_reg = x0;
4582 Register generator_object = x1;
4583 Register the_hole = x2;
4584 Register operand_stack_size = w3;
4585 Register function = x4;
4586
4587 // The value stays in x0, and is ultimately read by the resumed generator, as
4588 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
4589 // is read to throw the value when the resumed generator is already closed. r1
4590 // will hold the generator object until the activation has been resumed.
4591 VisitForStackValue(generator);
4592 VisitForAccumulatorValue(value);
4593 __ Pop(generator_object);
4594
4595 // Check generator state.
4596 Label wrong_state, closed_state, done;
4597 __ Ldr(x10, FieldMemOperand(generator_object,
4598 JSGeneratorObject::kContinuationOffset));
4599 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0);
4600 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0);
4601 __ CompareAndBranch(x10, Operand(Smi::FromInt(0)), eq, &closed_state);
4602 __ CompareAndBranch(x10, Operand(Smi::FromInt(0)), lt, &wrong_state);
4603
4604 // Load suspended function and context.
4605 __ Ldr(cp, FieldMemOperand(generator_object,
4606 JSGeneratorObject::kContextOffset));
4607 __ Ldr(function, FieldMemOperand(generator_object,
4608 JSGeneratorObject::kFunctionOffset));
4609
4610 // Load receiver and store as the first argument.
4611 __ Ldr(x10, FieldMemOperand(generator_object,
4612 JSGeneratorObject::kReceiverOffset));
4613 __ Push(x10);
4614
4615 // Push holes for the rest of the arguments to the generator function.
4616 __ Ldr(x10, FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
4617
4618 // The number of arguments is stored as an int32_t, and -1 is a marker
4619 // (SharedFunctionInfo::kDontAdaptArgumentsSentinel), so we need sign
4620 // extension to correctly handle it. However, in this case, we operate on
4621 // 32-bit W registers, so extension isn't required.
4622 __ Ldr(w10, FieldMemOperand(x10,
4623 SharedFunctionInfo::kFormalParameterCountOffset));
4624 __ LoadRoot(the_hole, Heap::kTheHoleValueRootIndex);
4625 __ PushMultipleTimes(the_hole, w10);
4626
4627 // Enter a new JavaScript frame, and initialize its slots as they were when
4628 // the generator was suspended.
4629 Label resume_frame;
4630 __ Bl(&resume_frame);
4631 __ B(&done);
4632
4633 __ Bind(&resume_frame);
4634 __ Push(lr, // Return address.
4635 fp, // Caller's frame pointer.
4636 cp, // Callee's context.
4637 function); // Callee's JS Function.
4638 __ Add(fp, __ StackPointer(), kPointerSize * 2);
4639
4640 // Load and untag the operand stack size.
4641 __ Ldr(x10, FieldMemOperand(generator_object,
4642 JSGeneratorObject::kOperandStackOffset));
4643 __ Ldr(operand_stack_size,
4644 UntagSmiFieldMemOperand(x10, FixedArray::kLengthOffset));
4645
4646 // If we are sending a value and there is no operand stack, we can jump back
4647 // in directly.
4648 if (resume_mode == JSGeneratorObject::NEXT) {
4649 Label slow_resume;
4650 __ Cbnz(operand_stack_size, &slow_resume);
4651 __ Ldr(x10, FieldMemOperand(function, JSFunction::kCodeEntryOffset));
4652 __ Ldrsw(x11,
4653 UntagSmiFieldMemOperand(generator_object,
4654 JSGeneratorObject::kContinuationOffset));
4655 __ Add(x10, x10, x11);
4656 __ Mov(x12, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)));
4657 __ Str(x12, FieldMemOperand(generator_object,
4658 JSGeneratorObject::kContinuationOffset));
4659 __ Br(x10);
4660
4661 __ Bind(&slow_resume);
4662 }
4663
4664 // Otherwise, we push holes for the operand stack and call the runtime to fix
4665 // up the stack and the handlers.
4666 __ PushMultipleTimes(the_hole, operand_stack_size);
4667
4668 __ Mov(x10, Operand(Smi::FromInt(resume_mode)));
4669 __ Push(generator_object, result_register(), x10);
4670 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
4671 // Not reached: the runtime call returns elsewhere.
4672 __ Unreachable();
4673
4674 // Reach here when generator is closed.
4675 __ Bind(&closed_state);
4676 if (resume_mode == JSGeneratorObject::NEXT) {
4677 // Return completed iterator result when generator is closed.
4678 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex);
4679 __ Push(x10);
4680 // Pop value from top-of-stack slot; box result into result register.
4681 EmitCreateIteratorResult(true);
4682 } else {
4683 // Throw the provided value.
4684 __ Push(value_reg);
4685 __ CallRuntime(Runtime::kThrow, 1);
4686 }
4687 __ B(&done);
4688
4689 // Throw error if we attempt to operate on a running generator.
4690 __ Bind(&wrong_state);
4691 __ Push(generator_object);
4692 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1);
4693
4694 __ Bind(&done);
4695 context()->Plug(result_register());
4696 }
4697
4698
4699 void FullCodeGenerator::EmitCreateIteratorResult(bool done) {
4700 Label gc_required;
4701 Label allocated;
4702
4703 Handle<Map> map(isolate()->native_context()->generator_result_map());
4704
4705 // Allocate and populate an object with this form: { value: VAL, done: DONE }
4706
4707 Register result = x0;
4708 __ Allocate(map->instance_size(), result, x10, x11, &gc_required, TAG_OBJECT);
4709 __ B(&allocated);
4710
4711 __ Bind(&gc_required);
4712 __ Push(Smi::FromInt(map->instance_size()));
4713 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
4714 __ Ldr(context_register(),
4715 MemOperand(fp, StandardFrameConstants::kContextOffset));
4716
4717 __ Bind(&allocated);
4718 Register map_reg = x1;
4719 Register result_value = x2;
4720 Register boolean_done = x3;
4721 Register empty_fixed_array = x4;
4722 __ Mov(map_reg, Operand(map));
4723 __ Pop(result_value);
4724 __ Mov(boolean_done, Operand(isolate()->factory()->ToBoolean(done)));
4725 __ Mov(empty_fixed_array, Operand(isolate()->factory()->empty_fixed_array()));
4726 ASSERT_EQ(map->instance_size(), 5 * kPointerSize);
4727 // TODO(jbramley): Use Stp if possible.
4728 __ Str(map_reg, FieldMemOperand(result, HeapObject::kMapOffset));
4729 __ Str(empty_fixed_array,
4730 FieldMemOperand(result, JSObject::kPropertiesOffset));
4731 __ Str(empty_fixed_array, FieldMemOperand(result, JSObject::kElementsOffset));
4732 __ Str(result_value,
4733 FieldMemOperand(result,
4734 JSGeneratorObject::kResultValuePropertyOffset));
4735 __ Str(boolean_done,
4736 FieldMemOperand(result,
4737 JSGeneratorObject::kResultDonePropertyOffset));
4738
4739 // Only the value field needs a write barrier, as the other values are in the
4740 // root set.
4741 __ RecordWriteField(result, JSGeneratorObject::kResultValuePropertyOffset,
4742 x10, x11, kLRHasBeenSaved, kDontSaveFPRegs);
4743 }
4744
4745
4746 // TODO(all): I don't like this method.
4747 // It seems to me that in too many places x0 is used in place of this.
4748 // Also, this function is not suitable for all places where x0 should be
4749 // abstracted (eg. when used as an argument). But some places assume that the
4750 // first argument register is x0, and use this function instead.
4751 // Considering that most of the register allocation is hard-coded in the
4752 // FullCodeGen, that it is unlikely we will need to change it extensively, and
4753 // that abstracting the allocation through functions would not yield any
4754 // performance benefit, I think the existence of this function is debatable.
4693 Register FullCodeGenerator::result_register() { 4755 Register FullCodeGenerator::result_register() {
4694 return r0; 4756 return x0;
4695 } 4757 }
4696 4758
4697 4759
4698 Register FullCodeGenerator::context_register() { 4760 Register FullCodeGenerator::context_register() {
4699 return cp; 4761 return cp;
4700 } 4762 }
4701 4763
4702 4764
4703 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { 4765 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
4704 ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); 4766 ASSERT(POINTER_SIZE_ALIGN(frame_offset) == frame_offset);
4705 __ str(value, MemOperand(fp, frame_offset)); 4767 __ Str(value, MemOperand(fp, frame_offset));
4706 } 4768 }
4707 4769
4708 4770
4709 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { 4771 void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
4710 __ ldr(dst, ContextOperand(cp, context_index)); 4772 __ Ldr(dst, ContextMemOperand(cp, context_index));
4711 } 4773 }
4712 4774
4713 4775
4714 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { 4776 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
4715 Scope* declaration_scope = scope()->DeclarationScope(); 4777 Scope* declaration_scope = scope()->DeclarationScope();
4716 if (declaration_scope->is_global_scope() || 4778 if (declaration_scope->is_global_scope() ||
4717 declaration_scope->is_module_scope()) { 4779 declaration_scope->is_module_scope()) {
4718 // Contexts nested in the native context have a canonical empty function 4780 // Contexts nested in the native context have a canonical empty function
4719 // as their closure, not the anonymous closure containing the global 4781 // as their closure, not the anonymous closure containing the global
4720 // code. Pass a smi sentinel and let the runtime look up the empty 4782 // code. Pass a smi sentinel and let the runtime look up the empty
4721 // function. 4783 // function.
4722 __ mov(ip, Operand(Smi::FromInt(0))); 4784 ASSERT(kSmiTag == 0);
4785 __ Push(xzr);
4723 } else if (declaration_scope->is_eval_scope()) { 4786 } else if (declaration_scope->is_eval_scope()) {
4724 // Contexts created by a call to eval have the same closure as the 4787 // Contexts created by a call to eval have the same closure as the
4725 // context calling eval, not the anonymous closure containing the eval 4788 // context calling eval, not the anonymous closure containing the eval
4726 // code. Fetch it from the context. 4789 // code. Fetch it from the context.
4727 __ ldr(ip, ContextOperand(cp, Context::CLOSURE_INDEX)); 4790 __ Ldr(x10, ContextMemOperand(cp, Context::CLOSURE_INDEX));
4791 __ Push(x10);
4728 } else { 4792 } else {
4729 ASSERT(declaration_scope->is_function_scope()); 4793 ASSERT(declaration_scope->is_function_scope());
4730 __ ldr(ip, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 4794 __ Ldr(x10, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4795 __ Push(x10);
4731 } 4796 }
4732 __ push(ip);
4733 } 4797 }
4734 4798
4735 4799
4736 // ----------------------------------------------------------------------------
4737 // Non-local control flow support.
4738
4739 void FullCodeGenerator::EnterFinallyBlock() { 4800 void FullCodeGenerator::EnterFinallyBlock() {
4740 ASSERT(!result_register().is(r1)); 4801 ASM_LOCATION("FullCodeGenerator::EnterFinallyBlock");
4741 // Store result register while executing finally block. 4802 ASSERT(!result_register().is(x10));
4742 __ push(result_register()); 4803 // Preserve the result register while executing finally block.
4743 // Cook return address in link register to stack (smi encoded Code* delta) 4804 // Also cook the return address in lr to the stack (smi encoded Code* delta).
4744 __ sub(r1, lr, Operand(masm_->CodeObject())); 4805 __ Sub(x10, lr, Operand(masm_->CodeObject()));
4745 __ SmiTag(r1); 4806 __ SmiTag(x10);
4746 4807 __ Push(result_register(), x10);
4747 // Store result register while executing finally block.
4748 __ push(r1);
4749 4808
4750 // Store pending message while executing finally block. 4809 // Store pending message while executing finally block.
4751 ExternalReference pending_message_obj = 4810 ExternalReference pending_message_obj =
4752 ExternalReference::address_of_pending_message_obj(isolate()); 4811 ExternalReference::address_of_pending_message_obj(isolate());
4753 __ mov(ip, Operand(pending_message_obj)); 4812 __ Mov(x10, Operand(pending_message_obj));
4754 __ ldr(r1, MemOperand(ip)); 4813 __ Ldr(x10, MemOperand(x10));
4755 __ push(r1);
4756 4814
4757 ExternalReference has_pending_message = 4815 ExternalReference has_pending_message =
4758 ExternalReference::address_of_has_pending_message(isolate()); 4816 ExternalReference::address_of_has_pending_message(isolate());
4759 __ mov(ip, Operand(has_pending_message)); 4817 __ Mov(x11, Operand(has_pending_message));
4760 __ ldr(r1, MemOperand(ip)); 4818 __ Ldr(x11, MemOperand(x11));
4761 __ SmiTag(r1); 4819 __ SmiTag(x11);
4762 __ push(r1); 4820
4821 __ Push(x10, x11);
4763 4822
4764 ExternalReference pending_message_script = 4823 ExternalReference pending_message_script =
4765 ExternalReference::address_of_pending_message_script(isolate()); 4824 ExternalReference::address_of_pending_message_script(isolate());
4766 __ mov(ip, Operand(pending_message_script)); 4825 __ Mov(x10, Operand(pending_message_script));
4767 __ ldr(r1, MemOperand(ip)); 4826 __ Ldr(x10, MemOperand(x10));
4768 __ push(r1); 4827 __ Push(x10);
4769 } 4828 }
4770 4829
4771 4830
4772 void FullCodeGenerator::ExitFinallyBlock() { 4831 void FullCodeGenerator::ExitFinallyBlock() {
4773 ASSERT(!result_register().is(r1)); 4832 ASM_LOCATION("FullCodeGenerator::ExitFinallyBlock");
4833 ASSERT(!result_register().is(x10));
4834
4774 // Restore pending message from stack. 4835 // Restore pending message from stack.
4775 __ pop(r1); 4836 __ Pop(x10, x11, x12);
4776 ExternalReference pending_message_script = 4837 ExternalReference pending_message_script =
4777 ExternalReference::address_of_pending_message_script(isolate()); 4838 ExternalReference::address_of_pending_message_script(isolate());
4778 __ mov(ip, Operand(pending_message_script)); 4839 __ Mov(x13, Operand(pending_message_script));
4779 __ str(r1, MemOperand(ip)); 4840 __ Str(x10, MemOperand(x13));
4780 4841
4781 __ pop(r1); 4842 __ SmiUntag(x11);
4782 __ SmiUntag(r1);
4783 ExternalReference has_pending_message = 4843 ExternalReference has_pending_message =
4784 ExternalReference::address_of_has_pending_message(isolate()); 4844 ExternalReference::address_of_has_pending_message(isolate());
4785 __ mov(ip, Operand(has_pending_message)); 4845 __ Mov(x13, Operand(has_pending_message));
4786 __ str(r1, MemOperand(ip)); 4846 __ Str(x11, MemOperand(x13));
4787 4847
4788 __ pop(r1);
4789 ExternalReference pending_message_obj = 4848 ExternalReference pending_message_obj =
4790 ExternalReference::address_of_pending_message_obj(isolate()); 4849 ExternalReference::address_of_pending_message_obj(isolate());
4791 __ mov(ip, Operand(pending_message_obj)); 4850 __ Mov(x13, Operand(pending_message_obj));
4792 __ str(r1, MemOperand(ip)); 4851 __ Str(x12, MemOperand(x13));
4793 4852
4794 // Restore result register from stack. 4853 // Restore result register and cooked return address from the stack.
4795 __ pop(r1); 4854 __ Pop(x10, result_register());
4796 4855
4797 // Uncook return address and return. 4856 // Uncook the return address (see EnterFinallyBlock).
4798 __ pop(result_register()); 4857 __ SmiUntag(x10);
4799 __ SmiUntag(r1); 4858 __ Add(x11, x10, Operand(masm_->CodeObject()));
4800 __ add(pc, r1, Operand(masm_->CodeObject())); 4859 __ Br(x11);
4801 }
4802
4803
4804 #undef __
4805
4806 #define __ ACCESS_MASM(masm())
4807
4808 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit(
4809 int* stack_depth,
4810 int* context_length) {
4811 // The macros used here must preserve the result register.
4812
4813 // Because the handler block contains the context of the finally
4814 // code, we can restore it directly from there for the finally code
4815 // rather than iteratively unwinding contexts via their previous
4816 // links.
4817 __ Drop(*stack_depth); // Down to the handler block.
4818 if (*context_length > 0) {
4819 // Restore the context to its dedicated register and the stack.
4820 __ ldr(cp, MemOperand(sp, StackHandlerConstants::kContextOffset));
4821 __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4822 }
4823 __ PopTryHandler();
4824 __ bl(finally_entry_);
4825
4826 *stack_depth = 0;
4827 *context_length = 0;
4828 return previous_;
4829 } 4860 }
4830 4861
4831 4862
4832 #undef __ 4863 #undef __
4833 4864
4834 4865
4835 static const int32_t kBranchBeforeInterrupt = 0x5a000004;
4836
4837
4838 void BackEdgeTable::PatchAt(Code* unoptimized_code, 4866 void BackEdgeTable::PatchAt(Code* unoptimized_code,
4839 Address pc, 4867 Address pc,
4840 BackEdgeState target_state, 4868 BackEdgeState target_state,
4841 Code* replacement_code) { 4869 Code* replacement_code) {
4842 static const int kInstrSize = Assembler::kInstrSize; 4870 // Turn the jump into a nop.
4843 Address branch_address = pc - 3 * kInstrSize; 4871 Address branch_address = pc - 3 * kInstructionSize;
4844 CodePatcher patcher(branch_address, 1); 4872 PatchingAssembler patcher(branch_address, 1);
4845 4873
4846 switch (target_state) { 4874 switch (target_state) {
4847 case INTERRUPT: 4875 case INTERRUPT:
4848 // <decrement profiling counter> 4876 // <decrement profiling counter>
4849 // 2a 00 00 01 bpl ok 4877 // .. .. .. .. b.pl ok
4850 // e5 9f c? ?? ldr ip, [pc, <interrupt stub address>] 4878 // .. .. .. .. ldr x16, pc+<interrupt stub address>
4851 // e1 2f ff 3c blx ip 4879 // .. .. .. .. blr x16
4880 // ... more instructions.
4852 // ok-label 4881 // ok-label
4853 patcher.masm()->b(4 * kInstrSize, pl); // Jump offset is 4 instructions. 4882 // Jump offset is 6 instructions.
4854 ASSERT_EQ(kBranchBeforeInterrupt, Memory::int32_at(branch_address)); 4883 ASSERT(Instruction::Cast(branch_address)
4884 ->IsNop(Assembler::INTERRUPT_CODE_NOP));
4885 patcher.b(6, pl);
4855 break; 4886 break;
4856 case ON_STACK_REPLACEMENT: 4887 case ON_STACK_REPLACEMENT:
4857 case OSR_AFTER_STACK_CHECK: 4888 case OSR_AFTER_STACK_CHECK:
4858 // <decrement profiling counter> 4889 // <decrement profiling counter>
4859 // e1 a0 00 00 mov r0, r0 (NOP) 4890 // .. .. .. .. mov x0, x0 (NOP)
4860 // e5 9f c? ?? ldr ip, [pc, <on-stack replacement address>] 4891 // .. .. .. .. ldr x16, pc+<on-stack replacement address>
4861 // e1 2f ff 3c blx ip 4892 // .. .. .. .. blr x16
4862 // ok-label 4893 ASSERT(Instruction::Cast(branch_address)->IsCondBranchImm());
4863 patcher.masm()->nop(); 4894 ASSERT(Instruction::Cast(branch_address)->ImmPCOffset() ==
4895 6 * kInstructionSize);
4896 patcher.nop(Assembler::INTERRUPT_CODE_NOP);
4864 break; 4897 break;
4865 } 4898 }
4866 4899
4867 Address pc_immediate_load_address = pc - 2 * kInstrSize;
4868 // Replace the call address. 4900 // Replace the call address.
4869 uint32_t interrupt_address_offset = 4901 Instruction* load = Instruction::Cast(pc)->preceding(2);
4870 Memory::uint16_at(pc_immediate_load_address) & 0xfff; 4902 Address interrupt_address_pointer =
4871 Address interrupt_address_pointer = pc + interrupt_address_offset; 4903 reinterpret_cast<Address>(load) + load->ImmPCOffset();
4872 Memory::uint32_at(interrupt_address_pointer) = 4904 ASSERT((Memory::uint64_at(interrupt_address_pointer) ==
4873 reinterpret_cast<uint32_t>(replacement_code->entry()); 4905 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
4906 ->builtins()
4907 ->OnStackReplacement()
4908 ->entry())) ||
4909 (Memory::uint64_at(interrupt_address_pointer) ==
4910 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
4911 ->builtins()
4912 ->InterruptCheck()
4913 ->entry())) ||
4914 (Memory::uint64_at(interrupt_address_pointer) ==
4915 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
4916 ->builtins()
4917 ->OsrAfterStackCheck()
4918 ->entry())) ||
4919 (Memory::uint64_at(interrupt_address_pointer) ==
4920 reinterpret_cast<uint64_t>(unoptimized_code->GetIsolate()
4921 ->builtins()
4922 ->OnStackReplacement()
4923 ->entry())));
4924 Memory::uint64_at(interrupt_address_pointer) =
4925 reinterpret_cast<uint64_t>(replacement_code->entry());
4874 4926
4875 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( 4927 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
4876 unoptimized_code, pc_immediate_load_address, replacement_code); 4928 unoptimized_code, reinterpret_cast<Address>(load), replacement_code);
4877 } 4929 }
4878 4930
4879 4931
4880 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( 4932 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState(
4881 Isolate* isolate, 4933 Isolate* isolate,
4882 Code* unoptimized_code, 4934 Code* unoptimized_code,
4883 Address pc) { 4935 Address pc) {
4884 static const int kInstrSize = Assembler::kInstrSize; 4936 // TODO(jbramley): There should be some extra assertions here (as in the ARM
4885 ASSERT(Memory::int32_at(pc - kInstrSize) == kBlxIp); 4937 // back-end), but this function is gone in bleeding_edge so it might not
4938 // matter anyway.
4939 Instruction* jump_or_nop = Instruction::Cast(pc)->preceding(3);
4886 4940
4887 Address branch_address = pc - 3 * kInstrSize; 4941 if (jump_or_nop->IsNop(Assembler::INTERRUPT_CODE_NOP)) {
4888 Address pc_immediate_load_address = pc - 2 * kInstrSize; 4942 Instruction* load = Instruction::Cast(pc)->preceding(2);
4889 uint32_t interrupt_address_offset = 4943 uint64_t entry = Memory::uint64_at(reinterpret_cast<Address>(load) +
4890 Memory::uint16_at(pc_immediate_load_address) & 0xfff; 4944 load->ImmPCOffset());
4891 Address interrupt_address_pointer = pc + interrupt_address_offset; 4945 if (entry == reinterpret_cast<uint64_t>(
4892 4946 isolate->builtins()->OnStackReplacement()->entry())) {
4893 if (Memory::int32_at(branch_address) == kBranchBeforeInterrupt) { 4947 return ON_STACK_REPLACEMENT;
4894 ASSERT(Memory::uint32_at(interrupt_address_pointer) == 4948 } else if (entry == reinterpret_cast<uint64_t>(
4895 reinterpret_cast<uint32_t>( 4949 isolate->builtins()->OsrAfterStackCheck()->entry())) {
4896 isolate->builtins()->InterruptCheck()->entry())); 4950 return OSR_AFTER_STACK_CHECK;
4897 ASSERT(Assembler::IsLdrPcImmediateOffset( 4951 } else {
4898 Assembler::instr_at(pc_immediate_load_address))); 4952 UNREACHABLE();
4899 return INTERRUPT; 4953 }
4900 } 4954 }
4901 4955
4902 ASSERT(Assembler::IsNop(Assembler::instr_at(branch_address))); 4956 return INTERRUPT;
4903 ASSERT(Assembler::IsLdrPcImmediateOffset( 4957 }
4904 Assembler::instr_at(pc_immediate_load_address)));
4905 4958
4906 if (Memory::uint32_at(interrupt_address_pointer) == 4959
4907 reinterpret_cast<uint32_t>( 4960 #define __ ACCESS_MASM(masm())
4908 isolate->builtins()->OnStackReplacement()->entry())) { 4961
4909 return ON_STACK_REPLACEMENT; 4962
4963 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit(
4964 int* stack_depth,
4965 int* context_length) {
4966 ASM_LOCATION("FullCodeGenerator::TryFinally::Exit");
4967 // The macros used here must preserve the result register.
4968
4969 // Because the handler block contains the context of the finally
4970 // code, we can restore it directly from there for the finally code
4971 // rather than iteratively unwinding contexts via their previous
4972 // links.
4973 __ Drop(*stack_depth); // Down to the handler block.
4974 if (*context_length > 0) {
4975 // Restore the context to its dedicated register and the stack.
4976 __ Peek(cp, StackHandlerConstants::kContextOffset);
4977 __ Str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
4910 } 4978 }
4979 __ PopTryHandler();
4980 __ Bl(finally_entry_);
4911 4981
4912 ASSERT(Memory::uint32_at(interrupt_address_pointer) == 4982 *stack_depth = 0;
4913 reinterpret_cast<uint32_t>( 4983 *context_length = 0;
4914 isolate->builtins()->OsrAfterStackCheck()->entry())); 4984 return previous_;
4915 return OSR_AFTER_STACK_CHECK;
4916 } 4985 }
4917 4986
4918 4987
4988 #undef __
4989
4990
4919 } } // namespace v8::internal 4991 } } // namespace v8::internal
4920 4992
4921 #endif // V8_TARGET_ARCH_ARM 4993 #endif // V8_TARGET_ARCH_A64
OLDNEW
« no previous file with comments | « src/a64/frames-a64.cc ('k') | src/a64/ic-a64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698