kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_X64) |
| 31 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 32 | #include "code-stubs.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 34 | #include "compiler.h" |
| 35 | #include "debug.h" |
| 36 | #include "full-codegen.h" |
| 37 | #include "parser.h" |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 38 | #include "scopes.h" |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 39 | #include "stub-cache.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 40 | |
| 41 | namespace v8 { |
| 42 | namespace internal { |
| 43 | |
| 44 | #define __ ACCESS_MASM(masm_) |
| 45 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 46 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 47 | static unsigned GetPropertyId(Property* property) { |
| 48 | if (property->is_synthetic()) return AstNode::kNoNumber; |
| 49 | return property->id(); |
| 50 | } |
| 51 | |
| 52 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 53 | class JumpPatchSite BASE_EMBEDDED { |
| 54 | public: |
| 55 | explicit JumpPatchSite(MacroAssembler* masm) |
| 56 | : masm_(masm) { |
| 57 | #ifdef DEBUG |
| 58 | info_emitted_ = false; |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | ~JumpPatchSite() { |
| 63 | ASSERT(patch_site_.is_bound() == info_emitted_); |
| 64 | } |
| 65 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 66 | void EmitJumpIfNotSmi(Register reg, |
| 67 | Label* target, |
| 68 | Label::Distance near_jump = Label::kFar) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 69 | __ testb(reg, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 70 | EmitJump(not_carry, target, near_jump); // Always taken before patched. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 71 | } |
| 72 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 73 | void EmitJumpIfSmi(Register reg, |
| 74 | Label* target, |
| 75 | Label::Distance near_jump = Label::kFar) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 76 | __ testb(reg, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 77 | EmitJump(carry, target, near_jump); // Never taken before patched. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void EmitPatchInfo() { |
| 81 | int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); |
| 82 | ASSERT(is_int8(delta_to_patch_site)); |
| 83 | __ testl(rax, Immediate(delta_to_patch_site)); |
| 84 | #ifdef DEBUG |
| 85 | info_emitted_ = true; |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | bool is_bound() const { return patch_site_.is_bound(); } |
| 90 | |
| 91 | private: |
| 92 | // jc will be patched with jz, jnc will become jnz. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 93 | void EmitJump(Condition cc, Label* target, Label::Distance near_jump) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 94 | ASSERT(!patch_site_.is_bound() && !info_emitted_); |
| 95 | ASSERT(cc == carry || cc == not_carry); |
| 96 | __ bind(&patch_site_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 97 | __ j(cc, target, near_jump); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | MacroAssembler* masm_; |
| 101 | Label patch_site_; |
| 102 | #ifdef DEBUG |
| 103 | bool info_emitted_; |
| 104 | #endif |
| 105 | }; |
| 106 | |
| 107 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 108 | // Generate code for a JS function. On entry to the function the receiver |
| 109 | // and arguments have been pushed on the stack left to right, with the |
| 110 | // return address on top of them. The actual argument count matches the |
| 111 | // formal parameter count expected by the function. |
| 112 | // |
| 113 | // The live registers are: |
| 114 | // o rdi: the JS function object being called (ie, ourselves) |
| 115 | // o rsi: our context |
| 116 | // o rbp: our caller's frame pointer |
| 117 | // o rsp: stack pointer (pointing to return address) |
| 118 | // |
| 119 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 120 | // frames-x64.h for its layout. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 121 | void FullCodeGenerator::Generate(CompilationInfo* info) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 122 | ASSERT(info_ == NULL); |
| 123 | info_ = info; |
| 124 | SetFunctionPosition(function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 125 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 126 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 127 | #ifdef DEBUG |
| 128 | if (strlen(FLAG_stop_at) > 0 && |
| 129 | info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 130 | __ int3(); |
| 131 | } |
| 132 | #endif |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 133 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 134 | // Strict mode functions and builtins need to replace the receiver |
| 135 | // with undefined when called as functions (without an explicit |
| 136 | // receiver object). rcx is zero for method calls and non-zero for |
| 137 | // function calls. |
| 138 | if (info->is_strict_mode() || info->is_native()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 139 | Label ok; |
| 140 | __ testq(rcx, rcx); |
| 141 | __ j(zero, &ok, Label::kNear); |
| 142 | // +1 for return address. |
| 143 | int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize; |
| 144 | __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); |
| 145 | __ movq(Operand(rsp, receiver_offset), kScratchRegister); |
| 146 | __ bind(&ok); |
| 147 | } |
| 148 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 149 | __ push(rbp); // Caller's frame pointer. |
| 150 | __ movq(rbp, rsp); |
| 151 | __ push(rsi); // Callee's context. |
| 152 | __ push(rdi); // Callee's JS Function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 153 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 154 | { Comment cmnt(masm_, "[ Allocate locals"); |
| 155 | int locals_count = scope()->num_stack_slots(); |
| 156 | if (locals_count == 1) { |
| 157 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
| 158 | } else if (locals_count > 1) { |
| 159 | __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
| 160 | for (int i = 0; i < locals_count; i++) { |
| 161 | __ push(rdx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 164 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 165 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 166 | bool function_in_register = true; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 167 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 168 | // Possibly allocate a local context. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 169 | int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 170 | if (heap_slots > 0) { |
| 171 | Comment cmnt(masm_, "[ Allocate local context"); |
| 172 | // Argument to NewContext is the function, which is still in rdi. |
| 173 | __ push(rdi); |
| 174 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 175 | FastNewContextStub stub(heap_slots); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 176 | __ CallStub(&stub); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 177 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 178 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 179 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 180 | function_in_register = false; |
| 181 | // Context is returned in both rax and rsi. It replaces the context |
| 182 | // passed to us. It's saved in the stack and kept live in rsi. |
| 183 | __ movq(Operand(rbp, StandardFrameConstants::kContextOffset), rsi); |
| 184 | |
| 185 | // Copy any necessary parameters into the context. |
| 186 | int num_parameters = scope()->num_parameters(); |
| 187 | for (int i = 0; i < num_parameters; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 188 | Slot* slot = scope()->parameter(i)->AsSlot(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 189 | if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 190 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 191 | (num_parameters - 1 - i) * kPointerSize; |
| 192 | // Load parameter from stack. |
| 193 | __ movq(rax, Operand(rbp, parameter_offset)); |
| 194 | // Store it in the context. |
| 195 | int context_offset = Context::SlotOffset(slot->index()); |
| 196 | __ movq(Operand(rsi, context_offset), rax); |
| 197 | // Update the write barrier. This clobbers all involved |
| 198 | // registers, so we have use a third register to avoid |
| 199 | // clobbering rsi. |
| 200 | __ movq(rcx, rsi); |
| 201 | __ RecordWrite(rcx, context_offset, rax, rbx); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // Possibly allocate an arguments object. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 207 | Variable* arguments = scope()->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 208 | if (arguments != NULL) { |
| 209 | // Arguments object must be allocated after the context object, in |
| 210 | // case the "arguments" or ".arguments" variables are in the context. |
| 211 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 212 | if (function_in_register) { |
| 213 | __ push(rdi); |
| 214 | } else { |
| 215 | __ push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 216 | } |
| 217 | // The receiver is just before the parameters on the caller's stack. |
| 218 | int offset = scope()->num_parameters() * kPointerSize; |
| 219 | __ lea(rdx, |
| 220 | Operand(rbp, StandardFrameConstants::kCallerSPOffset + offset)); |
| 221 | __ push(rdx); |
| 222 | __ Push(Smi::FromInt(scope()->num_parameters())); |
| 223 | // Arguments to ArgumentsAccessStub: |
| 224 | // function, receiver address, parameter count. |
| 225 | // The stub will rewrite receiver and parameter count if the previous |
| 226 | // stack frame was an arguments adapter frame. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 227 | ArgumentsAccessStub stub( |
| 228 | is_strict_mode() ? ArgumentsAccessStub::NEW_STRICT |
| 229 | : ArgumentsAccessStub::NEW_NON_STRICT); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 230 | __ CallStub(&stub); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 231 | |
| 232 | Variable* arguments_shadow = scope()->arguments_shadow(); |
| 233 | if (arguments_shadow != NULL) { |
| 234 | // Store new arguments object in both "arguments" and ".arguments" slots. |
| 235 | __ movq(rcx, rax); |
| 236 | Move(arguments_shadow->AsSlot(), rcx, rbx, rdx); |
| 237 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 238 | Move(arguments->AsSlot(), rax, rbx, rdx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 239 | } |
| 240 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 241 | if (FLAG_trace) { |
| 242 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 243 | } |
| 244 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 245 | // Visit the declarations and body unless there is an illegal |
| 246 | // redeclaration. |
| 247 | if (scope()->HasIllegalRedeclaration()) { |
| 248 | Comment cmnt(masm_, "[ Declarations"); |
| 249 | scope()->VisitIllegalRedeclaration(this); |
| 250 | } else { |
| 251 | { Comment cmnt(masm_, "[ Declarations"); |
| 252 | // For named function expressions, declare the function name as a |
| 253 | // constant. |
| 254 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
| 255 | EmitDeclaration(scope()->function(), Variable::CONST, NULL); |
| 256 | } |
| 257 | VisitDeclarations(scope()->declarations()); |
| 258 | } |
| 259 | |
| 260 | { Comment cmnt(masm_, "[ Stack check"); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 261 | PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 262 | Label ok; |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 263 | __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 264 | __ j(above_equal, &ok, Label::kNear); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 265 | StackCheckStub stub; |
| 266 | __ CallStub(&stub); |
| 267 | __ bind(&ok); |
| 268 | } |
| 269 | |
| 270 | { Comment cmnt(masm_, "[ Body"); |
| 271 | ASSERT(loop_depth() == 0); |
| 272 | VisitStatements(function()->body()); |
| 273 | ASSERT(loop_depth() == 0); |
| 274 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 275 | } |
| 276 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 277 | // Always emit a 'return undefined' in case control fell off the end of |
| 278 | // the body. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 279 | { Comment cmnt(masm_, "[ return <undefined>;"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 280 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 281 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 286 | void FullCodeGenerator::ClearAccumulator() { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 287 | __ Set(rax, 0); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) { |
| 292 | Comment cmnt(masm_, "[ Stack check"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 293 | Label ok; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 294 | __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 295 | __ j(above_equal, &ok, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 296 | StackCheckStub stub; |
| 297 | __ CallStub(&stub); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 298 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 299 | // the AST id from the unoptimized code in order to use it as a key into |
| 300 | // the deoptimization input data found in the optimized code. |
| 301 | RecordStackCheck(stmt->OsrEntryId()); |
| 302 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 303 | // Loop stack checks can be patched to perform on-stack replacement. In |
| 304 | // order to decide whether or not to perform OSR we embed the loop depth |
| 305 | // in a test instruction after the call so we can extract it from the OSR |
| 306 | // builtin. |
| 307 | ASSERT(loop_depth() > 0); |
| 308 | __ testl(rax, Immediate(Min(loop_depth(), Code::kMaxLoopNestingMarker))); |
| 309 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 310 | __ bind(&ok); |
| 311 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 312 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 313 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 314 | // we want it to work if it is. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 315 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 319 | void FullCodeGenerator::EmitReturnSequence() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 320 | Comment cmnt(masm_, "[ Return sequence"); |
| 321 | if (return_label_.is_bound()) { |
| 322 | __ jmp(&return_label_); |
| 323 | } else { |
| 324 | __ bind(&return_label_); |
| 325 | if (FLAG_trace) { |
| 326 | __ push(rax); |
| 327 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 328 | } |
| 329 | #ifdef DEBUG |
| 330 | // Add a label for checking the size of the code used for returning. |
| 331 | Label check_exit_codesize; |
| 332 | masm_->bind(&check_exit_codesize); |
| 333 | #endif |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 334 | CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 335 | __ RecordJSReturn(); |
| 336 | // Do not use the leave instruction here because it is too short to |
| 337 | // patch with the code required by the debugger. |
| 338 | __ movq(rsp, rbp); |
| 339 | __ pop(rbp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 340 | |
| 341 | int arguments_bytes = (scope()->num_parameters() + 1) * kPointerSize; |
| 342 | __ Ret(arguments_bytes, rcx); |
| 343 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 344 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 345 | // Add padding that will be overwritten by a debugger breakpoint. We |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 346 | // have just generated at least 7 bytes: "movq rsp, rbp; pop rbp; ret k" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 347 | // (3 + 1 + 3). |
| 348 | const int kPadding = Assembler::kJSReturnSequenceLength - 7; |
| 349 | for (int i = 0; i < kPadding; ++i) { |
| 350 | masm_->int3(); |
| 351 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 352 | // Check that the size of the code used for returning is large enough |
| 353 | // for the debugger's requirements. |
| 354 | ASSERT(Assembler::kJSReturnSequenceLength <= |
| 355 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 356 | #endif |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 361 | void FullCodeGenerator::EffectContext::Plug(Slot* slot) const { |
| 362 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 363 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 364 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 365 | void FullCodeGenerator::AccumulatorValueContext::Plug(Slot* slot) const { |
| 366 | MemOperand slot_operand = codegen()->EmitSlotSearch(slot, result_register()); |
| 367 | __ movq(result_register(), slot_operand); |
| 368 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 369 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 370 | |
| 371 | void FullCodeGenerator::StackValueContext::Plug(Slot* slot) const { |
| 372 | MemOperand slot_operand = codegen()->EmitSlotSearch(slot, result_register()); |
| 373 | __ push(slot_operand); |
| 374 | } |
| 375 | |
| 376 | |
| 377 | void FullCodeGenerator::TestContext::Plug(Slot* slot) const { |
| 378 | codegen()->Move(result_register(), slot); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 379 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 380 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | |
| 384 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 385 | } |
| 386 | |
| 387 | |
| 388 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 389 | Heap::RootListIndex index) const { |
| 390 | __ LoadRoot(result_register(), index); |
| 391 | } |
| 392 | |
| 393 | |
| 394 | void FullCodeGenerator::StackValueContext::Plug( |
| 395 | Heap::RootListIndex index) const { |
| 396 | __ PushRoot(index); |
| 397 | } |
| 398 | |
| 399 | |
| 400 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 401 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, |
| 402 | true, |
| 403 | true_label_, |
| 404 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 405 | if (index == Heap::kUndefinedValueRootIndex || |
| 406 | index == Heap::kNullValueRootIndex || |
| 407 | index == Heap::kFalseValueRootIndex) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 408 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 409 | } else if (index == Heap::kTrueValueRootIndex) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 410 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 411 | } else { |
| 412 | __ LoadRoot(result_register(), index); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 413 | codegen()->DoTest(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
| 417 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 418 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 419 | } |
| 420 | |
| 421 | |
| 422 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 423 | Handle<Object> lit) const { |
| 424 | __ Move(result_register(), lit); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
| 429 | __ Push(lit); |
| 430 | } |
| 431 | |
| 432 | |
| 433 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 434 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, |
| 435 | true, |
| 436 | true_label_, |
| 437 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 438 | ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 439 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 440 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 441 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 442 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 443 | } else if (lit->IsString()) { |
| 444 | if (String::cast(*lit)->length() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 445 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 446 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 447 | if (true_label_ != fall_through_) __ jmp(true_label_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 448 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 449 | } else if (lit->IsSmi()) { |
| 450 | if (Smi::cast(*lit)->value() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 451 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 452 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 453 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 454 | } |
| 455 | } else { |
| 456 | // For simplicity we always test the accumulator register. |
| 457 | __ Move(result_register(), lit); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 458 | codegen()->DoTest(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 463 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 464 | Register reg) const { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 465 | ASSERT(count > 0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 466 | __ Drop(count); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 470 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 471 | int count, |
| 472 | Register reg) const { |
| 473 | ASSERT(count > 0); |
| 474 | __ Drop(count); |
| 475 | __ Move(result_register(), reg); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 479 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 480 | Register reg) const { |
| 481 | ASSERT(count > 0); |
| 482 | if (count > 1) __ Drop(count - 1); |
| 483 | __ movq(Operand(rsp, 0), reg); |
| 484 | } |
| 485 | |
| 486 | |
| 487 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 488 | Register reg) const { |
| 489 | ASSERT(count > 0); |
| 490 | // For simplicity we always test the accumulator register. |
| 491 | __ Drop(count); |
| 492 | __ Move(result_register(), reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 493 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 494 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
| 498 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 499 | Label* materialize_false) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 500 | ASSERT(materialize_true == materialize_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 501 | __ bind(materialize_true); |
| 502 | } |
| 503 | |
| 504 | |
| 505 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 506 | Label* materialize_true, |
| 507 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 508 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 509 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 510 | __ Move(result_register(), isolate()->factory()->true_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 511 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 512 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 513 | __ Move(result_register(), isolate()->factory()->false_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 514 | __ bind(&done); |
| 515 | } |
| 516 | |
| 517 | |
| 518 | void FullCodeGenerator::StackValueContext::Plug( |
| 519 | Label* materialize_true, |
| 520 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 521 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 522 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 523 | __ Push(isolate()->factory()->true_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 524 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 525 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 526 | __ Push(isolate()->factory()->false_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 527 | __ bind(&done); |
| 528 | } |
| 529 | |
| 530 | |
| 531 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 532 | Label* materialize_false) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 533 | ASSERT(materialize_true == true_label_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 534 | ASSERT(materialize_false == false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | |
| 538 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 539 | } |
| 540 | |
| 541 | |
| 542 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
| 543 | Heap::RootListIndex value_root_index = |
| 544 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 545 | __ LoadRoot(result_register(), value_root_index); |
| 546 | } |
| 547 | |
| 548 | |
| 549 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
| 550 | Heap::RootListIndex value_root_index = |
| 551 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 552 | __ PushRoot(value_root_index); |
| 553 | } |
| 554 | |
| 555 | |
| 556 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 557 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, |
| 558 | true, |
| 559 | true_label_, |
| 560 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 561 | if (flag) { |
| 562 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 563 | } else { |
| 564 | if (false_label_ != fall_through_) __ jmp(false_label_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 569 | void FullCodeGenerator::DoTest(Expression* condition, |
| 570 | Label* if_true, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 571 | Label* if_false, |
| 572 | Label* fall_through) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 573 | ToBooleanStub stub; |
| 574 | __ push(result_register()); |
| 575 | __ CallStub(&stub); |
| 576 | __ testq(rax, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 577 | // The stub returns nonzero for true. |
| 578 | Split(not_zero, if_true, if_false, fall_through); |
| 579 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 580 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 581 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 582 | void FullCodeGenerator::Split(Condition cc, |
| 583 | Label* if_true, |
| 584 | Label* if_false, |
| 585 | Label* fall_through) { |
| 586 | if (if_false == fall_through) { |
| 587 | __ j(cc, if_true); |
| 588 | } else if (if_true == fall_through) { |
| 589 | __ j(NegateCondition(cc), if_false); |
| 590 | } else { |
| 591 | __ j(cc, if_true); |
| 592 | __ jmp(if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
| 596 | |
| 597 | MemOperand FullCodeGenerator::EmitSlotSearch(Slot* slot, Register scratch) { |
| 598 | switch (slot->type()) { |
| 599 | case Slot::PARAMETER: |
| 600 | case Slot::LOCAL: |
| 601 | return Operand(rbp, SlotOffset(slot)); |
| 602 | case Slot::CONTEXT: { |
| 603 | int context_chain_length = |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 604 | scope()->ContextChainLength(slot->var()->scope()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 605 | __ LoadContext(scratch, context_chain_length); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 606 | return ContextOperand(scratch, slot->index()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 607 | } |
| 608 | case Slot::LOOKUP: |
| 609 | UNREACHABLE(); |
| 610 | } |
| 611 | UNREACHABLE(); |
| 612 | return Operand(rax, 0); |
| 613 | } |
| 614 | |
| 615 | |
| 616 | void FullCodeGenerator::Move(Register destination, Slot* source) { |
| 617 | MemOperand location = EmitSlotSearch(source, destination); |
| 618 | __ movq(destination, location); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | void FullCodeGenerator::Move(Slot* dst, |
| 623 | Register src, |
| 624 | Register scratch1, |
| 625 | Register scratch2) { |
| 626 | ASSERT(dst->type() != Slot::LOOKUP); // Not yet implemented. |
| 627 | ASSERT(!scratch1.is(src) && !scratch2.is(src)); |
| 628 | MemOperand location = EmitSlotSearch(dst, scratch1); |
| 629 | __ movq(location, src); |
| 630 | // Emit the write barrier code if the location is in the heap. |
| 631 | if (dst->type() == Slot::CONTEXT) { |
| 632 | int offset = FixedArray::kHeaderSize + dst->index() * kPointerSize; |
| 633 | __ RecordWrite(scratch1, offset, src, scratch2); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 638 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(State state, |
| 639 | bool should_normalize, |
| 640 | Label* if_true, |
| 641 | Label* if_false) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 642 | // Only prepare for bailouts before splits if we're in a test |
| 643 | // context. Otherwise, we let the Visit function deal with the |
| 644 | // preparation to avoid preparing with the same AST id twice. |
| 645 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 646 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 647 | Label skip; |
| 648 | if (should_normalize) __ jmp(&skip, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 649 | |
| 650 | ForwardBailoutStack* current = forward_bailout_stack_; |
| 651 | while (current != NULL) { |
| 652 | PrepareForBailout(current->expr(), state); |
| 653 | current = current->parent(); |
| 654 | } |
| 655 | |
| 656 | if (should_normalize) { |
| 657 | __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
| 658 | Split(equal, if_true, if_false, NULL); |
| 659 | __ bind(&skip); |
| 660 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 664 | void FullCodeGenerator::EmitDeclaration(Variable* variable, |
| 665 | Variable::Mode mode, |
| 666 | FunctionLiteral* function) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 667 | Comment cmnt(masm_, "[ Declaration"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 668 | ASSERT(variable != NULL); // Must have been resolved. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 669 | Slot* slot = variable->AsSlot(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 670 | Property* prop = variable->AsProperty(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 671 | |
| 672 | if (slot != NULL) { |
| 673 | switch (slot->type()) { |
| 674 | case Slot::PARAMETER: |
| 675 | case Slot::LOCAL: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 676 | if (mode == Variable::CONST) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 677 | __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
| 678 | __ movq(Operand(rbp, SlotOffset(slot)), kScratchRegister); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 679 | } else if (function != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 680 | VisitForAccumulatorValue(function); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 681 | __ movq(Operand(rbp, SlotOffset(slot)), result_register()); |
| 682 | } |
| 683 | break; |
| 684 | |
| 685 | case Slot::CONTEXT: |
| 686 | // We bypass the general EmitSlotSearch because we know more about |
| 687 | // this specific context. |
| 688 | |
| 689 | // The variable in the decl always resides in the current context. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 690 | ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 691 | if (FLAG_debug_code) { |
| 692 | // Check if we have the correct context pointer. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 693 | __ movq(rbx, ContextOperand(rsi, Context::FCONTEXT_INDEX)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 694 | __ cmpq(rbx, rsi); |
| 695 | __ Check(equal, "Unexpected declaration in current context."); |
| 696 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 697 | if (mode == Variable::CONST) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 698 | __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 699 | __ movq(ContextOperand(rsi, slot->index()), kScratchRegister); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 700 | // No write barrier since the hole value is in old space. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 701 | } else if (function != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 702 | VisitForAccumulatorValue(function); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 703 | __ movq(ContextOperand(rsi, slot->index()), result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 704 | int offset = Context::SlotOffset(slot->index()); |
| 705 | __ movq(rbx, rsi); |
| 706 | __ RecordWrite(rbx, offset, result_register(), rcx); |
| 707 | } |
| 708 | break; |
| 709 | |
| 710 | case Slot::LOOKUP: { |
| 711 | __ push(rsi); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 712 | __ Push(variable->name()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 713 | // Declaration nodes are always introduced in one of two modes. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 714 | ASSERT(mode == Variable::VAR || mode == Variable::CONST); |
| 715 | PropertyAttributes attr = (mode == Variable::VAR) ? NONE : READ_ONLY; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 716 | __ Push(Smi::FromInt(attr)); |
| 717 | // Push initial value, if any. |
| 718 | // Note: For variables we must not push an initial value (such as |
| 719 | // 'undefined') because we may have a (legal) redeclaration and we |
| 720 | // must not destroy the current value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 721 | if (mode == Variable::CONST) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 722 | __ PushRoot(Heap::kTheHoleValueRootIndex); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 723 | } else if (function != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 724 | VisitForStackValue(function); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 725 | } else { |
| 726 | __ Push(Smi::FromInt(0)); // no initial value! |
| 727 | } |
| 728 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 729 | break; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | } else if (prop != NULL) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 734 | // A const declaration aliasing a parameter is an illegal redeclaration. |
| 735 | ASSERT(mode != Variable::CONST); |
| 736 | if (function != NULL) { |
| 737 | // We are declaring a function that rewrites to a property. |
| 738 | // Use (keyed) IC to set the initial value. We cannot visit the |
| 739 | // rewrite because it's shared and we risk recording duplicate AST |
| 740 | // IDs for bailouts from optimized code. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 741 | ASSERT(prop->obj()->AsVariableProxy() != NULL); |
| 742 | { AccumulatorValueContext for_object(this); |
| 743 | EmitVariableLoad(prop->obj()->AsVariableProxy()->var()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 744 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 745 | __ push(rax); |
| 746 | VisitForAccumulatorValue(function); |
| 747 | __ pop(rdx); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 748 | ASSERT(prop->key()->AsLiteral() != NULL && |
| 749 | prop->key()->AsLiteral()->handle()->IsSmi()); |
| 750 | __ Move(rcx, prop->key()->AsLiteral()->handle()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 751 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 752 | Handle<Code> ic = is_strict_mode() |
| 753 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 754 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 755 | EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 761 | void FullCodeGenerator::VisitDeclaration(Declaration* decl) { |
| 762 | EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun()); |
| 763 | } |
| 764 | |
| 765 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 766 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 767 | // Call the runtime to declare the globals. |
| 768 | __ push(rsi); // The context is the first argument. |
| 769 | __ Push(pairs); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 770 | __ Push(Smi::FromInt(is_eval() ? 1 : 0)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 771 | __ Push(Smi::FromInt(strict_mode_flag())); |
| 772 | __ CallRuntime(Runtime::kDeclareGlobals, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 773 | // Return value is ignored. |
| 774 | } |
| 775 | |
| 776 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 777 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 778 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 779 | Breakable nested_statement(this, stmt); |
| 780 | SetStatementPosition(stmt); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 781 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 782 | // Keep the switch value on the stack until a case matches. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 783 | VisitForStackValue(stmt->tag()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 784 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 785 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 786 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 787 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 788 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 789 | Label next_test; // Recycled for each test. |
| 790 | // Compile all the tests with branches to their bodies. |
| 791 | for (int i = 0; i < clauses->length(); i++) { |
| 792 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 793 | clause->body_target()->Unuse(); |
fschneider@chromium.org | d218783 | 2011-01-26 15:44:20 +0000 | [diff] [blame] | 794 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 795 | // The default is not a test, but remember it as final fall through. |
| 796 | if (clause->is_default()) { |
| 797 | default_clause = clause; |
| 798 | continue; |
| 799 | } |
| 800 | |
| 801 | Comment cmnt(masm_, "[ Case comparison"); |
| 802 | __ bind(&next_test); |
| 803 | next_test.Unuse(); |
| 804 | |
| 805 | // Compile the label expression. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 806 | VisitForAccumulatorValue(clause->label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 807 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 808 | // Perform the comparison as if via '==='. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 809 | __ movq(rdx, Operand(rsp, 0)); // Switch value. |
| 810 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 811 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 812 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 813 | Label slow_case; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 814 | __ movq(rcx, rdx); |
| 815 | __ or_(rcx, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 816 | patch_site.EmitJumpIfNotSmi(rcx, &slow_case, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 817 | |
| 818 | __ cmpq(rdx, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 819 | __ j(not_equal, &next_test); |
| 820 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 821 | __ jmp(clause->body_target()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 822 | __ bind(&slow_case); |
| 823 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 824 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 825 | // Record position before stub call for type feedback. |
| 826 | SetSourcePosition(clause->position()); |
| 827 | Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 828 | EmitCallIC(ic, &patch_site, clause->CompareId()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 829 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 830 | __ testq(rax, rax); |
| 831 | __ j(not_equal, &next_test); |
| 832 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 833 | __ jmp(clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | // Discard the test value and jump to the default if present, otherwise to |
| 837 | // the end of the statement. |
| 838 | __ bind(&next_test); |
| 839 | __ Drop(1); // Switch value is no longer needed. |
| 840 | if (default_clause == NULL) { |
| 841 | __ jmp(nested_statement.break_target()); |
| 842 | } else { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 843 | __ jmp(default_clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | // Compile all the case bodies. |
| 847 | for (int i = 0; i < clauses->length(); i++) { |
| 848 | Comment cmnt(masm_, "[ Case body"); |
| 849 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 850 | __ bind(clause->body_target()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 851 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 852 | VisitStatements(clause->statements()); |
| 853 | } |
| 854 | |
| 855 | __ bind(nested_statement.break_target()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 856 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
| 860 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 861 | Comment cmnt(masm_, "[ ForInStatement"); |
| 862 | SetStatementPosition(stmt); |
| 863 | |
| 864 | Label loop, exit; |
| 865 | ForIn loop_statement(this, stmt); |
| 866 | increment_loop_depth(); |
| 867 | |
| 868 | // Get the object to enumerate over. Both SpiderMonkey and JSC |
| 869 | // ignore null and undefined in contrast to the specification; see |
| 870 | // ECMA-262 section 12.6.4. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 871 | VisitForAccumulatorValue(stmt->enumerable()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 872 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 873 | __ j(equal, &exit); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 874 | Register null_value = rdi; |
| 875 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 876 | __ cmpq(rax, null_value); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 877 | __ j(equal, &exit); |
| 878 | |
| 879 | // Convert the object to a JS object. |
| 880 | Label convert, done_convert; |
| 881 | __ JumpIfSmi(rax, &convert); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 882 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 883 | __ j(above_equal, &done_convert); |
| 884 | __ bind(&convert); |
| 885 | __ push(rax); |
| 886 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 887 | __ bind(&done_convert); |
| 888 | __ push(rax); |
| 889 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 890 | // Check cache validity in generated code. This is a fast case for |
| 891 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 892 | // guarantee cache validity, call the runtime system to check cache |
| 893 | // validity or get the property names in a fixed array. |
| 894 | Label next, call_runtime; |
| 895 | Register empty_fixed_array_value = r8; |
| 896 | __ LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex); |
| 897 | Register empty_descriptor_array_value = r9; |
| 898 | __ LoadRoot(empty_descriptor_array_value, |
| 899 | Heap::kEmptyDescriptorArrayRootIndex); |
| 900 | __ movq(rcx, rax); |
| 901 | __ bind(&next); |
| 902 | |
| 903 | // Check that there are no elements. Register rcx contains the |
| 904 | // current JS object we've reached through the prototype chain. |
| 905 | __ cmpq(empty_fixed_array_value, |
| 906 | FieldOperand(rcx, JSObject::kElementsOffset)); |
| 907 | __ j(not_equal, &call_runtime); |
| 908 | |
| 909 | // Check that instance descriptors are not empty so that we can |
| 910 | // check for an enum cache. Leave the map in rbx for the subsequent |
| 911 | // prototype load. |
| 912 | __ movq(rbx, FieldOperand(rcx, HeapObject::kMapOffset)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 913 | __ movq(rdx, FieldOperand(rbx, Map::kInstanceDescriptorsOrBitField3Offset)); |
| 914 | __ JumpIfSmi(rdx, &call_runtime); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 915 | |
| 916 | // Check that there is an enum cache in the non-empty instance |
| 917 | // descriptors (rdx). This is the case if the next enumeration |
| 918 | // index field does not contain a smi. |
| 919 | __ movq(rdx, FieldOperand(rdx, DescriptorArray::kEnumerationIndexOffset)); |
| 920 | __ JumpIfSmi(rdx, &call_runtime); |
| 921 | |
| 922 | // For all objects but the receiver, check that the cache is empty. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 923 | Label check_prototype; |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 924 | __ cmpq(rcx, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 925 | __ j(equal, &check_prototype, Label::kNear); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 926 | __ movq(rdx, FieldOperand(rdx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 927 | __ cmpq(rdx, empty_fixed_array_value); |
| 928 | __ j(not_equal, &call_runtime); |
| 929 | |
| 930 | // Load the prototype from the map and loop if non-null. |
| 931 | __ bind(&check_prototype); |
| 932 | __ movq(rcx, FieldOperand(rbx, Map::kPrototypeOffset)); |
| 933 | __ cmpq(rcx, null_value); |
| 934 | __ j(not_equal, &next); |
| 935 | |
| 936 | // The enum cache is valid. Load the map of the object being |
| 937 | // iterated over and use the cache for the iteration. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 938 | Label use_cache; |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 939 | __ movq(rax, FieldOperand(rax, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 940 | __ jmp(&use_cache, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 941 | |
| 942 | // Get the set of properties to enumerate. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 943 | __ bind(&call_runtime); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 944 | __ push(rax); // Duplicate the enumerable object on the stack. |
| 945 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
| 946 | |
| 947 | // If we got a map from the runtime call, we can do a fast |
| 948 | // modification check. Otherwise, we got a fixed array, and we have |
| 949 | // to do a slow check. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 950 | Label fixed_array; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 951 | __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), |
| 952 | Heap::kMetaMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 953 | __ j(not_equal, &fixed_array, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 954 | |
| 955 | // We got a map in register rax. Get the enumeration cache from it. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 956 | __ bind(&use_cache); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 957 | __ LoadInstanceDescriptors(rax, rcx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 958 | __ movq(rcx, FieldOperand(rcx, DescriptorArray::kEnumerationIndexOffset)); |
| 959 | __ movq(rdx, FieldOperand(rcx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 960 | |
| 961 | // Setup the four remaining stack slots. |
| 962 | __ push(rax); // Map. |
| 963 | __ push(rdx); // Enumeration cache. |
| 964 | __ movq(rax, FieldOperand(rdx, FixedArray::kLengthOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 965 | __ push(rax); // Enumeration cache length (as smi). |
| 966 | __ Push(Smi::FromInt(0)); // Initial index. |
| 967 | __ jmp(&loop); |
| 968 | |
| 969 | // We got a fixed array in register rax. Iterate through that. |
| 970 | __ bind(&fixed_array); |
| 971 | __ Push(Smi::FromInt(0)); // Map (0) - force slow check. |
| 972 | __ push(rax); |
| 973 | __ movq(rax, FieldOperand(rax, FixedArray::kLengthOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 974 | __ push(rax); // Fixed array length (as smi). |
| 975 | __ Push(Smi::FromInt(0)); // Initial index. |
| 976 | |
| 977 | // Generate code for doing the condition check. |
| 978 | __ bind(&loop); |
| 979 | __ movq(rax, Operand(rsp, 0 * kPointerSize)); // Get the current index. |
| 980 | __ cmpq(rax, Operand(rsp, 1 * kPointerSize)); // Compare to the array length. |
| 981 | __ j(above_equal, loop_statement.break_target()); |
| 982 | |
| 983 | // Get the current entry of the array into register rbx. |
| 984 | __ movq(rbx, Operand(rsp, 2 * kPointerSize)); |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 985 | SmiIndex index = masm()->SmiToIndex(rax, rax, kPointerSizeLog2); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 986 | __ movq(rbx, FieldOperand(rbx, |
| 987 | index.reg, |
| 988 | index.scale, |
| 989 | FixedArray::kHeaderSize)); |
| 990 | |
| 991 | // Get the expected map from the stack or a zero map in the |
| 992 | // permanent slow case into register rdx. |
| 993 | __ movq(rdx, Operand(rsp, 3 * kPointerSize)); |
| 994 | |
| 995 | // Check if the expected map still matches that of the enumerable. |
| 996 | // If not, we have to filter the key. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 997 | Label update_each; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 998 | __ movq(rcx, Operand(rsp, 4 * kPointerSize)); |
| 999 | __ cmpq(rdx, FieldOperand(rcx, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1000 | __ j(equal, &update_each, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1001 | |
| 1002 | // Convert the entry to a string or null if it isn't a property |
| 1003 | // anymore. If the property has been removed while iterating, we |
| 1004 | // just skip it. |
| 1005 | __ push(rcx); // Enumerable. |
| 1006 | __ push(rbx); // Current entry. |
| 1007 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1008 | __ Cmp(rax, Smi::FromInt(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1009 | __ j(equal, loop_statement.continue_target()); |
| 1010 | __ movq(rbx, rax); |
| 1011 | |
| 1012 | // Update the 'each' property or variable from the possibly filtered |
| 1013 | // entry in register rbx. |
| 1014 | __ bind(&update_each); |
| 1015 | __ movq(result_register(), rbx); |
| 1016 | // Perform the assignment as if via '='. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1017 | { EffectContext context(this); |
| 1018 | EmitAssignment(stmt->each(), stmt->AssignmentId()); |
| 1019 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1020 | |
| 1021 | // Generate code for the body of the loop. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1022 | Visit(stmt->body()); |
| 1023 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1024 | // Generate code for going to the next element by incrementing the |
| 1025 | // index (smi) stored on top of the stack. |
| 1026 | __ bind(loop_statement.continue_target()); |
| 1027 | __ SmiAddConstant(Operand(rsp, 0 * kPointerSize), Smi::FromInt(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1028 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1029 | EmitStackCheck(stmt); |
| 1030 | __ jmp(&loop); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1031 | |
| 1032 | // Remove the pointers stored on the stack. |
| 1033 | __ bind(loop_statement.break_target()); |
| 1034 | __ addq(rsp, Immediate(5 * kPointerSize)); |
| 1035 | |
| 1036 | // Exit and decrement the loop depth. |
| 1037 | __ bind(&exit); |
| 1038 | decrement_loop_depth(); |
| 1039 | } |
| 1040 | |
| 1041 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1042 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1043 | bool pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1044 | // Use the fast case closure allocation code that allocates in new |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1045 | // space for nested functions that don't need literals cloning. If |
| 1046 | // we're running with the --always-opt or the --prepare-always-opt |
| 1047 | // flag, we need to use the runtime function so that the new function |
| 1048 | // we are creating here gets a chance to have its code optimized and |
| 1049 | // doesn't just get a copy of the existing unoptimized code. |
| 1050 | if (!FLAG_always_opt && |
| 1051 | !FLAG_prepare_always_opt && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1052 | !pretenure && |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1053 | scope()->is_function_scope() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1054 | info->num_literals() == 0) { |
| 1055 | FastNewClosureStub stub(info->strict_mode() ? kStrictMode : kNonStrictMode); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1056 | __ Push(info); |
| 1057 | __ CallStub(&stub); |
| 1058 | } else { |
| 1059 | __ push(rsi); |
| 1060 | __ Push(info); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1061 | __ Push(pretenure |
| 1062 | ? isolate()->factory()->true_value() |
| 1063 | : isolate()->factory()->false_value()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1064 | __ CallRuntime(Runtime::kNewClosure, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1065 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1066 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 1071 | Comment cmnt(masm_, "[ VariableProxy"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1072 | EmitVariableLoad(expr->var()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1076 | void FullCodeGenerator::EmitLoadGlobalSlotCheckExtensions( |
| 1077 | Slot* slot, |
| 1078 | TypeofState typeof_state, |
| 1079 | Label* slow) { |
| 1080 | Register context = rsi; |
| 1081 | Register temp = rdx; |
| 1082 | |
| 1083 | Scope* s = scope(); |
| 1084 | while (s != NULL) { |
| 1085 | if (s->num_heap_slots() > 0) { |
| 1086 | if (s->calls_eval()) { |
| 1087 | // Check that extension is NULL. |
| 1088 | __ cmpq(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1089 | Immediate(0)); |
| 1090 | __ j(not_equal, slow); |
| 1091 | } |
| 1092 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1093 | __ movq(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1094 | // Walk the rest of the chain without clobbering rsi. |
| 1095 | context = temp; |
| 1096 | } |
| 1097 | // If no outer scope calls eval, we do not need to check more |
| 1098 | // context extensions. If we have reached an eval scope, we check |
| 1099 | // all extensions from this point. |
| 1100 | if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 1101 | s = s->outer_scope(); |
| 1102 | } |
| 1103 | |
| 1104 | if (s != NULL && s->is_eval_scope()) { |
| 1105 | // Loop up the context chain. There is no frame effect so it is |
| 1106 | // safe to use raw labels here. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1107 | Label next, fast; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1108 | if (!context.is(temp)) { |
| 1109 | __ movq(temp, context); |
| 1110 | } |
| 1111 | // Load map for comparison into register, outside loop. |
| 1112 | __ LoadRoot(kScratchRegister, Heap::kGlobalContextMapRootIndex); |
| 1113 | __ bind(&next); |
| 1114 | // Terminate at global context. |
| 1115 | __ cmpq(kScratchRegister, FieldOperand(temp, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1116 | __ j(equal, &fast, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1117 | // Check that extension is NULL. |
| 1118 | __ cmpq(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
| 1119 | __ j(not_equal, slow); |
| 1120 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1121 | __ movq(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1122 | __ jmp(&next); |
| 1123 | __ bind(&fast); |
| 1124 | } |
| 1125 | |
| 1126 | // All extension objects were empty and it is safe to use a global |
| 1127 | // load IC call. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1128 | __ movq(rax, GlobalObjectOperand()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1129 | __ Move(rcx, slot->var()->name()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1130 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1131 | RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF) |
| 1132 | ? RelocInfo::CODE_TARGET |
| 1133 | : RelocInfo::CODE_TARGET_CONTEXT; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1134 | EmitCallIC(ic, mode, AstNode::kNoNumber); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions( |
| 1139 | Slot* slot, |
| 1140 | Label* slow) { |
| 1141 | ASSERT(slot->type() == Slot::CONTEXT); |
| 1142 | Register context = rsi; |
| 1143 | Register temp = rbx; |
| 1144 | |
| 1145 | for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) { |
| 1146 | if (s->num_heap_slots() > 0) { |
| 1147 | if (s->calls_eval()) { |
| 1148 | // Check that extension is NULL. |
| 1149 | __ cmpq(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1150 | Immediate(0)); |
| 1151 | __ j(not_equal, slow); |
| 1152 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1153 | __ movq(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1154 | // Walk the rest of the chain without clobbering rsi. |
| 1155 | context = temp; |
| 1156 | } |
| 1157 | } |
| 1158 | // Check that last extension is NULL. |
| 1159 | __ cmpq(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
| 1160 | __ j(not_equal, slow); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1161 | |
| 1162 | // This function is used only for loads, not stores, so it's safe to |
| 1163 | // return an rsi-based operand (the write barrier cannot be allowed to |
| 1164 | // destroy the rsi register). |
| 1165 | return ContextOperand(context, slot->index()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | void FullCodeGenerator::EmitDynamicLoadFromSlotFastCase( |
| 1170 | Slot* slot, |
| 1171 | TypeofState typeof_state, |
| 1172 | Label* slow, |
| 1173 | Label* done) { |
| 1174 | // Generate fast-case code for variables that might be shadowed by |
| 1175 | // eval-introduced variables. Eval is used a lot without |
| 1176 | // introducing variables. In those cases, we do not want to |
| 1177 | // perform a runtime call for all variables in the scope |
| 1178 | // containing the eval. |
| 1179 | if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
| 1180 | EmitLoadGlobalSlotCheckExtensions(slot, typeof_state, slow); |
| 1181 | __ jmp(done); |
| 1182 | } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1183 | Slot* potential_slot = slot->var()->local_if_not_shadowed()->AsSlot(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1184 | Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite(); |
| 1185 | if (potential_slot != NULL) { |
| 1186 | // Generate fast case for locals that rewrite to slots. |
| 1187 | __ movq(rax, |
| 1188 | ContextSlotOperandCheckExtensions(potential_slot, slow)); |
| 1189 | if (potential_slot->var()->mode() == Variable::CONST) { |
| 1190 | __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
| 1191 | __ j(not_equal, done); |
| 1192 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1193 | } |
| 1194 | __ jmp(done); |
| 1195 | } else if (rewrite != NULL) { |
| 1196 | // Generate fast case for calls of an argument function. |
| 1197 | Property* property = rewrite->AsProperty(); |
| 1198 | if (property != NULL) { |
| 1199 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 1200 | Literal* key_literal = property->key()->AsLiteral(); |
| 1201 | if (obj_proxy != NULL && |
| 1202 | key_literal != NULL && |
| 1203 | obj_proxy->IsArguments() && |
| 1204 | key_literal->handle()->IsSmi()) { |
| 1205 | // Load arguments object if there are no eval-introduced |
| 1206 | // variables. Then load the argument from the arguments |
| 1207 | // object using keyed load. |
| 1208 | __ movq(rdx, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1209 | ContextSlotOperandCheckExtensions(obj_proxy->var()->AsSlot(), |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1210 | slow)); |
| 1211 | __ Move(rax, key_literal->handle()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1212 | Handle<Code> ic = |
| 1213 | isolate()->builtins()->KeyedLoadIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1214 | EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(property)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1215 | __ jmp(done); |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1223 | void FullCodeGenerator::EmitVariableLoad(Variable* var) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1224 | // Four cases: non-this global variables, lookup slots, all other |
| 1225 | // types of slots, and parameters that rewrite to explicit property |
| 1226 | // accesses on the arguments object. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1227 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1228 | Property* property = var->AsProperty(); |
| 1229 | |
| 1230 | if (var->is_global() && !var->is_this()) { |
| 1231 | Comment cmnt(masm_, "Global variable"); |
| 1232 | // Use inline caching. Variable name is passed in rcx and the global |
| 1233 | // object on the stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1234 | __ Move(rcx, var->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1235 | __ movq(rax, GlobalObjectOperand()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1236 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1237 | EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT, AstNode::kNoNumber); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1238 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1239 | |
| 1240 | } else if (slot != NULL && slot->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1241 | Label done, slow; |
| 1242 | |
| 1243 | // Generate code for loading from variables potentially shadowed |
| 1244 | // by eval-introduced variables. |
| 1245 | EmitDynamicLoadFromSlotFastCase(slot, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1246 | |
| 1247 | __ bind(&slow); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1248 | Comment cmnt(masm_, "Lookup slot"); |
| 1249 | __ push(rsi); // Context. |
| 1250 | __ Push(var->name()); |
| 1251 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1252 | __ bind(&done); |
| 1253 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1254 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1255 | |
| 1256 | } else if (slot != NULL) { |
| 1257 | Comment cmnt(masm_, (slot->type() == Slot::CONTEXT) |
| 1258 | ? "Context slot" |
| 1259 | : "Stack slot"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1260 | if (var->mode() == Variable::CONST) { |
| 1261 | // Constants may be the hole value if they have not been initialized. |
| 1262 | // Unhole them. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1263 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1264 | MemOperand slot_operand = EmitSlotSearch(slot, rax); |
| 1265 | __ movq(rax, slot_operand); |
| 1266 | __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1267 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1268 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1269 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1270 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1271 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1272 | context()->Plug(slot); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1273 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1274 | |
| 1275 | } else { |
| 1276 | Comment cmnt(masm_, "Rewritten parameter"); |
| 1277 | ASSERT_NOT_NULL(property); |
| 1278 | // Rewritten parameter accesses are of the form "slot[literal]". |
| 1279 | |
| 1280 | // Assert that the object is in a slot. |
| 1281 | Variable* object_var = property->obj()->AsVariableProxy()->AsVariable(); |
| 1282 | ASSERT_NOT_NULL(object_var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1283 | Slot* object_slot = object_var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1284 | ASSERT_NOT_NULL(object_slot); |
| 1285 | |
| 1286 | // Load the object. |
| 1287 | MemOperand object_loc = EmitSlotSearch(object_slot, rax); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1288 | __ movq(rdx, object_loc); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1289 | |
| 1290 | // Assert that the key is a smi. |
| 1291 | Literal* key_literal = property->key()->AsLiteral(); |
| 1292 | ASSERT_NOT_NULL(key_literal); |
| 1293 | ASSERT(key_literal->handle()->IsSmi()); |
| 1294 | |
| 1295 | // Load the key. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1296 | __ Move(rax, key_literal->handle()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1297 | |
| 1298 | // Do a keyed property load. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1299 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1300 | EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(property)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1301 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1307 | Comment cmnt(masm_, "[ RegExpLiteral"); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1308 | Label materialized; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1309 | // Registers will be used as follows: |
| 1310 | // rdi = JS function. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1311 | // rcx = literals array. |
| 1312 | // rbx = regexp literal. |
| 1313 | // rax = regexp literal clone. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1314 | __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1315 | __ movq(rcx, FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1316 | int literal_offset = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1317 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1318 | __ movq(rbx, FieldOperand(rcx, literal_offset)); |
| 1319 | __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
| 1320 | __ j(not_equal, &materialized); |
| 1321 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1322 | // Create regexp literal using runtime function |
| 1323 | // Result will be in rax. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1324 | __ push(rcx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1325 | __ Push(Smi::FromInt(expr->literal_index())); |
| 1326 | __ Push(expr->pattern()); |
| 1327 | __ Push(expr->flags()); |
| 1328 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1329 | __ movq(rbx, rax); |
| 1330 | |
| 1331 | __ bind(&materialized); |
| 1332 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1333 | Label allocated, runtime_allocate; |
| 1334 | __ AllocateInNewSpace(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); |
| 1335 | __ jmp(&allocated); |
| 1336 | |
| 1337 | __ bind(&runtime_allocate); |
| 1338 | __ push(rbx); |
| 1339 | __ Push(Smi::FromInt(size)); |
| 1340 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 1341 | __ pop(rbx); |
| 1342 | |
| 1343 | __ bind(&allocated); |
| 1344 | // Copy the content into the newly allocated memory. |
| 1345 | // (Unroll copy loop once for better throughput). |
| 1346 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 1347 | __ movq(rdx, FieldOperand(rbx, i)); |
| 1348 | __ movq(rcx, FieldOperand(rbx, i + kPointerSize)); |
| 1349 | __ movq(FieldOperand(rax, i), rdx); |
| 1350 | __ movq(FieldOperand(rax, i + kPointerSize), rcx); |
| 1351 | } |
| 1352 | if ((size % (2 * kPointerSize)) != 0) { |
| 1353 | __ movq(rdx, FieldOperand(rbx, size - kPointerSize)); |
| 1354 | __ movq(FieldOperand(rax, size - kPointerSize), rdx); |
| 1355 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1356 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1361 | Comment cmnt(masm_, "[ ObjectLiteral"); |
| 1362 | __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1363 | __ push(FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
| 1364 | __ Push(Smi::FromInt(expr->literal_index())); |
| 1365 | __ Push(expr->constant_properties()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1366 | int flags = expr->fast_elements() |
| 1367 | ? ObjectLiteral::kFastElements |
| 1368 | : ObjectLiteral::kNoFlags; |
| 1369 | flags |= expr->has_function() |
| 1370 | ? ObjectLiteral::kHasFunction |
| 1371 | : ObjectLiteral::kNoFlags; |
| 1372 | __ Push(Smi::FromInt(flags)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1373 | if (expr->depth() > 1) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1374 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1375 | } else { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1376 | __ CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | // If result_saved is true the result is on top of the stack. If |
| 1380 | // result_saved is false the result is in rax. |
| 1381 | bool result_saved = false; |
| 1382 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1383 | // Mark all computed expressions that are bound to a key that |
| 1384 | // is shadowed by a later occurrence of the same key. For the |
| 1385 | // marked expressions, no store code is emitted. |
| 1386 | expr->CalculateEmitStore(); |
| 1387 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1388 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1389 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1390 | if (property->IsCompileTimeValue()) continue; |
| 1391 | |
| 1392 | Literal* key = property->key(); |
| 1393 | Expression* value = property->value(); |
| 1394 | if (!result_saved) { |
| 1395 | __ push(rax); // Save result on the stack |
| 1396 | result_saved = true; |
| 1397 | } |
| 1398 | switch (property->kind()) { |
| 1399 | case ObjectLiteral::Property::CONSTANT: |
| 1400 | UNREACHABLE(); |
| 1401 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1402 | ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
| 1403 | // Fall through. |
| 1404 | case ObjectLiteral::Property::COMPUTED: |
| 1405 | if (key->handle()->IsSymbol()) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1406 | if (property->emit_store()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1407 | VisitForAccumulatorValue(value); |
| 1408 | __ Move(rcx, key->handle()); |
| 1409 | __ movq(rdx, Operand(rsp, 0)); |
| 1410 | Handle<Code> ic = is_strict_mode() |
| 1411 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 1412 | : isolate()->builtins()->StoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1413 | EmitCallIC(ic, RelocInfo::CODE_TARGET, key->id()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1414 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1415 | } else { |
| 1416 | VisitForEffect(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1417 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | } |
| 1420 | // Fall through. |
| 1421 | case ObjectLiteral::Property::PROTOTYPE: |
| 1422 | __ push(Operand(rsp, 0)); // Duplicate receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1423 | VisitForStackValue(key); |
| 1424 | VisitForStackValue(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1425 | if (property->emit_store()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1426 | __ Push(Smi::FromInt(NONE)); // PropertyAttributes |
| 1427 | __ CallRuntime(Runtime::kSetProperty, 4); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1428 | } else { |
| 1429 | __ Drop(3); |
| 1430 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | case ObjectLiteral::Property::SETTER: |
| 1433 | case ObjectLiteral::Property::GETTER: |
| 1434 | __ push(Operand(rsp, 0)); // Duplicate receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1435 | VisitForStackValue(key); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1436 | __ Push(property->kind() == ObjectLiteral::Property::SETTER ? |
| 1437 | Smi::FromInt(1) : |
| 1438 | Smi::FromInt(0)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1439 | VisitForStackValue(value); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1440 | __ CallRuntime(Runtime::kDefineAccessor, 4); |
| 1441 | break; |
| 1442 | } |
| 1443 | } |
| 1444 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1445 | if (expr->has_function()) { |
| 1446 | ASSERT(result_saved); |
| 1447 | __ push(Operand(rsp, 0)); |
| 1448 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1449 | } |
| 1450 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1451 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1452 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1453 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1454 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1460 | Comment cmnt(masm_, "[ ArrayLiteral"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1461 | |
| 1462 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1463 | int length = subexprs->length(); |
| 1464 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1465 | __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1466 | __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
| 1467 | __ Push(Smi::FromInt(expr->literal_index())); |
| 1468 | __ Push(expr->constant_elements()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1469 | if (expr->constant_elements()->map() == |
| 1470 | isolate()->heap()->fixed_cow_array_map()) { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1471 | FastCloneShallowArrayStub stub( |
| 1472 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 1473 | __ CallStub(&stub); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1474 | __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1475 | } else if (expr->depth() > 1) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1476 | __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1477 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1478 | __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1479 | } else { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1480 | FastCloneShallowArrayStub stub( |
| 1481 | FastCloneShallowArrayStub::CLONE_ELEMENTS, length); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1482 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | bool result_saved = false; // Is the result saved to the stack? |
| 1486 | |
| 1487 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1488 | // them into the newly cloned array. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1489 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1490 | Expression* subexpr = subexprs->at(i); |
| 1491 | // If the subexpression is a literal or a simple materialized literal it |
| 1492 | // is already set in the cloned array. |
| 1493 | if (subexpr->AsLiteral() != NULL || |
| 1494 | CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1495 | continue; |
| 1496 | } |
| 1497 | |
| 1498 | if (!result_saved) { |
| 1499 | __ push(rax); |
| 1500 | result_saved = true; |
| 1501 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1502 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1503 | |
| 1504 | // Store the subexpression value in the array's elements. |
| 1505 | __ movq(rbx, Operand(rsp, 0)); // Copy of array literal. |
| 1506 | __ movq(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); |
| 1507 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1508 | __ movq(FieldOperand(rbx, offset), result_register()); |
| 1509 | |
| 1510 | // Update the write barrier for the array store. |
| 1511 | __ RecordWrite(rbx, offset, result_register(), rcx); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1512 | |
| 1513 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1517 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1518 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1519 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1524 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1525 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1526 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 1527 | // on the left-hand side. |
| 1528 | if (!expr->target()->IsValidLeftHandSide()) { |
| 1529 | VisitForEffect(expr->target()); |
| 1530 | return; |
| 1531 | } |
| 1532 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1533 | // Left-hand side can only be a property, a global or a (parameter or local) |
| 1534 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1535 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1536 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1537 | Property* property = expr->target()->AsProperty(); |
| 1538 | if (property != NULL) { |
| 1539 | assign_type = (property->key()->IsPropertyName()) |
| 1540 | ? NAMED_PROPERTY |
| 1541 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | // Evaluate LHS expression. |
| 1545 | switch (assign_type) { |
| 1546 | case VARIABLE: |
| 1547 | // Nothing to do here. |
| 1548 | break; |
| 1549 | case NAMED_PROPERTY: |
| 1550 | if (expr->is_compound()) { |
| 1551 | // We need the receiver both on the stack and in the accumulator. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1552 | VisitForAccumulatorValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1553 | __ push(result_register()); |
| 1554 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1555 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1556 | } |
| 1557 | break; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1558 | case KEYED_PROPERTY: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1559 | if (expr->is_compound()) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1560 | if (property->is_arguments_access()) { |
| 1561 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 1562 | MemOperand slot_operand = |
| 1563 | EmitSlotSearch(obj_proxy->var()->AsSlot(), rcx); |
| 1564 | __ push(slot_operand); |
| 1565 | __ Move(rax, property->key()->AsLiteral()->handle()); |
| 1566 | } else { |
| 1567 | VisitForStackValue(property->obj()); |
| 1568 | VisitForAccumulatorValue(property->key()); |
| 1569 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1570 | __ movq(rdx, Operand(rsp, 0)); |
| 1571 | __ push(rax); |
| 1572 | } else { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1573 | if (property->is_arguments_access()) { |
| 1574 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 1575 | MemOperand slot_operand = |
| 1576 | EmitSlotSearch(obj_proxy->var()->AsSlot(), rcx); |
| 1577 | __ push(slot_operand); |
| 1578 | __ Push(property->key()->AsLiteral()->handle()); |
| 1579 | } else { |
| 1580 | VisitForStackValue(property->obj()); |
| 1581 | VisitForStackValue(property->key()); |
| 1582 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1583 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1584 | break; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1585 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1588 | // For compound assignments we need another deoptimization point after the |
| 1589 | // variable/property load. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1590 | if (expr->is_compound()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1591 | { AccumulatorValueContext context(this); |
| 1592 | switch (assign_type) { |
| 1593 | case VARIABLE: |
| 1594 | EmitVariableLoad(expr->target()->AsVariableProxy()->var()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1595 | PrepareForBailout(expr->target(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1596 | break; |
| 1597 | case NAMED_PROPERTY: |
| 1598 | EmitNamedPropertyLoad(property); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1599 | PrepareForBailoutForId(expr->CompoundLoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1600 | break; |
| 1601 | case KEYED_PROPERTY: |
| 1602 | EmitKeyedPropertyLoad(property); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1603 | PrepareForBailoutForId(expr->CompoundLoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1604 | break; |
| 1605 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1606 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1607 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1608 | Token::Value op = expr->binary_op(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1609 | __ push(rax); // Left operand goes on the stack. |
| 1610 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1611 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1612 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1613 | ? OVERWRITE_RIGHT |
| 1614 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1615 | SetSourcePosition(expr->position() + 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1616 | AccumulatorValueContext context(this); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1617 | if (ShouldInlineSmiCase(op)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1618 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1619 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1620 | mode, |
| 1621 | expr->target(), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1622 | expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1623 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1624 | EmitBinaryOp(expr->binary_operation(), op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1625 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1626 | // Deoptimization point in case the binary operation may have side effects. |
| 1627 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1628 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1629 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | // Record source position before possible IC call. |
| 1633 | SetSourcePosition(expr->position()); |
| 1634 | |
| 1635 | // Store the value. |
| 1636 | switch (assign_type) { |
| 1637 | case VARIABLE: |
| 1638 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1639 | expr->op()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1640 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1641 | context()->Plug(rax); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1642 | break; |
| 1643 | case NAMED_PROPERTY: |
| 1644 | EmitNamedPropertyAssignment(expr); |
| 1645 | break; |
| 1646 | case KEYED_PROPERTY: |
| 1647 | EmitKeyedPropertyAssignment(expr); |
| 1648 | break; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1653 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 1654 | SetSourcePosition(prop->position()); |
| 1655 | Literal* key = prop->key()->AsLiteral(); |
| 1656 | __ Move(rcx, key->handle()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1657 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1658 | EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | |
| 1662 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 1663 | SetSourcePosition(prop->position()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1664 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1665 | EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1669 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1670 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1671 | OverwriteMode mode, |
| 1672 | Expression* left, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1673 | Expression* right) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1674 | // Do combined smi check of the operands. Left operand is on the |
| 1675 | // stack (popped into rdx). Right operand is in rax but moved into |
| 1676 | // rcx to make the shifts easier. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1677 | Label done, stub_call, smi_case; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1678 | __ pop(rdx); |
| 1679 | __ movq(rcx, rax); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1680 | __ or_(rax, rdx); |
| 1681 | JumpPatchSite patch_site(masm_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1682 | patch_site.EmitJumpIfSmi(rax, &smi_case, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1683 | |
| 1684 | __ bind(&stub_call); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1685 | __ movq(rax, rcx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1686 | BinaryOpStub stub(op, mode); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1687 | EmitCallIC(stub.GetCode(), &patch_site, expr->id()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1688 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1689 | |
| 1690 | __ bind(&smi_case); |
| 1691 | switch (op) { |
| 1692 | case Token::SAR: |
| 1693 | __ SmiShiftArithmeticRight(rax, rdx, rcx); |
| 1694 | break; |
| 1695 | case Token::SHL: |
| 1696 | __ SmiShiftLeft(rax, rdx, rcx); |
| 1697 | break; |
| 1698 | case Token::SHR: |
| 1699 | __ SmiShiftLogicalRight(rax, rdx, rcx, &stub_call); |
| 1700 | break; |
| 1701 | case Token::ADD: |
| 1702 | __ SmiAdd(rax, rdx, rcx, &stub_call); |
| 1703 | break; |
| 1704 | case Token::SUB: |
| 1705 | __ SmiSub(rax, rdx, rcx, &stub_call); |
| 1706 | break; |
| 1707 | case Token::MUL: |
| 1708 | __ SmiMul(rax, rdx, rcx, &stub_call); |
| 1709 | break; |
| 1710 | case Token::BIT_OR: |
| 1711 | __ SmiOr(rax, rdx, rcx); |
| 1712 | break; |
| 1713 | case Token::BIT_AND: |
| 1714 | __ SmiAnd(rax, rdx, rcx); |
| 1715 | break; |
| 1716 | case Token::BIT_XOR: |
| 1717 | __ SmiXor(rax, rdx, rcx); |
| 1718 | break; |
| 1719 | default: |
| 1720 | UNREACHABLE(); |
| 1721 | break; |
| 1722 | } |
| 1723 | |
| 1724 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1725 | context()->Plug(rax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1729 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 1730 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1731 | OverwriteMode mode) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1732 | __ pop(rdx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1733 | BinaryOpStub stub(op, mode); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1734 | // NULL signals no inlined smi code. |
| 1735 | EmitCallIC(stub.GetCode(), NULL, expr->id()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1736 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1740 | void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1741 | // Invalid left-hand sides are rewritten to have a 'throw |
| 1742 | // ReferenceError' on the left-hand side. |
| 1743 | if (!expr->IsValidLeftHandSide()) { |
| 1744 | VisitForEffect(expr); |
| 1745 | return; |
| 1746 | } |
| 1747 | |
| 1748 | // Left-hand side can only be a property, a global or a (parameter or local) |
| 1749 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1750 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1751 | LhsKind assign_type = VARIABLE; |
| 1752 | Property* prop = expr->AsProperty(); |
| 1753 | if (prop != NULL) { |
| 1754 | assign_type = (prop->key()->IsPropertyName()) |
| 1755 | ? NAMED_PROPERTY |
| 1756 | : KEYED_PROPERTY; |
| 1757 | } |
| 1758 | |
| 1759 | switch (assign_type) { |
| 1760 | case VARIABLE: { |
| 1761 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1762 | EffectContext context(this); |
| 1763 | EmitVariableAssignment(var, Token::ASSIGN); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1764 | break; |
| 1765 | } |
| 1766 | case NAMED_PROPERTY: { |
| 1767 | __ push(rax); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1768 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1769 | __ movq(rdx, rax); |
| 1770 | __ pop(rax); // Restore value. |
| 1771 | __ Move(rcx, prop->key()->AsLiteral()->handle()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1772 | Handle<Code> ic = is_strict_mode() |
| 1773 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 1774 | : isolate()->builtins()->StoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1775 | EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1776 | break; |
| 1777 | } |
| 1778 | case KEYED_PROPERTY: { |
| 1779 | __ push(rax); // Preserve value. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1780 | if (prop->is_synthetic()) { |
| 1781 | ASSERT(prop->obj()->AsVariableProxy() != NULL); |
| 1782 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 1783 | { AccumulatorValueContext for_object(this); |
| 1784 | EmitVariableLoad(prop->obj()->AsVariableProxy()->var()); |
| 1785 | } |
| 1786 | __ movq(rdx, rax); |
| 1787 | __ Move(rcx, prop->key()->AsLiteral()->handle()); |
| 1788 | } else { |
| 1789 | VisitForStackValue(prop->obj()); |
| 1790 | VisitForAccumulatorValue(prop->key()); |
| 1791 | __ movq(rcx, rax); |
| 1792 | __ pop(rdx); |
| 1793 | } |
| 1794 | __ pop(rax); // Restore value. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1795 | Handle<Code> ic = is_strict_mode() |
| 1796 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 1797 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1798 | EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1799 | break; |
| 1800 | } |
| 1801 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1802 | PrepareForBailoutForId(bailout_ast_id, TOS_REG); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1803 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1807 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1808 | Token::Value op) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1809 | // Left-hand sides that rewrite to explicit property accesses do not reach |
| 1810 | // here. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1811 | ASSERT(var != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1812 | ASSERT(var->is_global() || var->AsSlot() != NULL); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1813 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1814 | if (var->is_global()) { |
| 1815 | ASSERT(!var->is_this()); |
| 1816 | // Assignment to a global variable. Use inline caching for the |
| 1817 | // assignment. Right-hand-side value is passed in rax, variable name in |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1818 | // rcx, and the global object on the stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1819 | __ Move(rcx, var->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1820 | __ movq(rdx, GlobalObjectOperand()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1821 | Handle<Code> ic = is_strict_mode() |
| 1822 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 1823 | : isolate()->builtins()->StoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1824 | EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT, AstNode::kNoNumber); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1825 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1826 | } else if (op == Token::INIT_CONST) { |
| 1827 | // Like var declarations, const declarations are hoisted to function |
| 1828 | // scope. However, unlike var initializers, const initializers are able |
| 1829 | // to drill a hole to that function context, even from inside a 'with' |
| 1830 | // context. We thus bypass the normal static scope lookup. |
| 1831 | Slot* slot = var->AsSlot(); |
| 1832 | Label skip; |
| 1833 | switch (slot->type()) { |
| 1834 | case Slot::PARAMETER: |
| 1835 | // No const parameters. |
| 1836 | UNREACHABLE(); |
| 1837 | break; |
| 1838 | case Slot::LOCAL: |
| 1839 | __ movq(rdx, Operand(rbp, SlotOffset(slot))); |
| 1840 | __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
| 1841 | __ j(not_equal, &skip); |
| 1842 | __ movq(Operand(rbp, SlotOffset(slot)), rax); |
| 1843 | break; |
| 1844 | case Slot::CONTEXT: { |
| 1845 | __ movq(rcx, ContextOperand(rsi, Context::FCONTEXT_INDEX)); |
| 1846 | __ movq(rdx, ContextOperand(rcx, slot->index())); |
| 1847 | __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
| 1848 | __ j(not_equal, &skip); |
| 1849 | __ movq(ContextOperand(rcx, slot->index()), rax); |
| 1850 | int offset = Context::SlotOffset(slot->index()); |
| 1851 | __ movq(rdx, rax); // Preserve the stored value in eax. |
| 1852 | __ RecordWrite(rcx, offset, rdx, rbx); |
| 1853 | break; |
| 1854 | } |
| 1855 | case Slot::LOOKUP: |
| 1856 | __ push(rax); |
| 1857 | __ push(rsi); |
| 1858 | __ Push(var->name()); |
| 1859 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 1860 | break; |
| 1861 | } |
| 1862 | __ bind(&skip); |
| 1863 | |
| 1864 | } else if (var->mode() != Variable::CONST) { |
| 1865 | // Perform the assignment for non-const variables. Const assignments |
| 1866 | // are simply skipped. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1867 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1868 | switch (slot->type()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1869 | case Slot::PARAMETER: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1870 | case Slot::LOCAL: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1871 | // Perform the assignment. |
| 1872 | __ movq(Operand(rbp, SlotOffset(slot)), rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1873 | break; |
| 1874 | |
| 1875 | case Slot::CONTEXT: { |
| 1876 | MemOperand target = EmitSlotSearch(slot, rcx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1877 | // Perform the assignment and issue the write barrier. |
| 1878 | __ movq(target, rax); |
| 1879 | // The value of the assignment is in rax. RecordWrite clobbers its |
| 1880 | // register arguments. |
| 1881 | __ movq(rdx, rax); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1882 | int offset = Context::SlotOffset(slot->index()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1883 | __ RecordWrite(rcx, offset, rdx, rbx); |
| 1884 | break; |
| 1885 | } |
| 1886 | |
| 1887 | case Slot::LOOKUP: |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1888 | // Call the runtime for the assignment. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1889 | __ push(rax); // Value. |
| 1890 | __ push(rsi); // Context. |
| 1891 | __ Push(var->name()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1892 | __ Push(Smi::FromInt(strict_mode_flag())); |
| 1893 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1894 | break; |
| 1895 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | |
| 1900 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 1901 | // Assignment to a property, using a named store IC. |
| 1902 | Property* prop = expr->target()->AsProperty(); |
| 1903 | ASSERT(prop != NULL); |
| 1904 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 1905 | |
| 1906 | // If the assignment starts a block of assignments to the same object, |
| 1907 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1908 | // adding fast properties. |
| 1909 | if (expr->starts_initialization_block()) { |
| 1910 | __ push(result_register()); |
| 1911 | __ push(Operand(rsp, kPointerSize)); // Receiver is now under value. |
| 1912 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1913 | __ pop(result_register()); |
| 1914 | } |
| 1915 | |
| 1916 | // Record source code position before IC call. |
| 1917 | SetSourcePosition(expr->position()); |
| 1918 | __ Move(rcx, prop->key()->AsLiteral()->handle()); |
| 1919 | if (expr->ends_initialization_block()) { |
| 1920 | __ movq(rdx, Operand(rsp, 0)); |
| 1921 | } else { |
| 1922 | __ pop(rdx); |
| 1923 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1924 | Handle<Code> ic = is_strict_mode() |
| 1925 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 1926 | : isolate()->builtins()->StoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1927 | EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1928 | |
| 1929 | // If the assignment ends an initialization block, revert to fast case. |
| 1930 | if (expr->ends_initialization_block()) { |
| 1931 | __ push(rax); // Result of assignment, saved even if not needed. |
| 1932 | __ push(Operand(rsp, kPointerSize)); // Receiver is under value. |
| 1933 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1934 | __ pop(rax); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1935 | __ Drop(1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1936 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1937 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1938 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | |
| 1942 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 1943 | // Assignment to a property, using a keyed store IC. |
| 1944 | |
| 1945 | // If the assignment starts a block of assignments to the same object, |
| 1946 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1947 | // adding fast properties. |
| 1948 | if (expr->starts_initialization_block()) { |
| 1949 | __ push(result_register()); |
| 1950 | // Receiver is now under the key and value. |
| 1951 | __ push(Operand(rsp, 2 * kPointerSize)); |
| 1952 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1953 | __ pop(result_register()); |
| 1954 | } |
| 1955 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1956 | __ pop(rcx); |
| 1957 | if (expr->ends_initialization_block()) { |
| 1958 | __ movq(rdx, Operand(rsp, 0)); // Leave receiver on the stack for later. |
| 1959 | } else { |
| 1960 | __ pop(rdx); |
| 1961 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1962 | // Record source code position before IC call. |
| 1963 | SetSourcePosition(expr->position()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1964 | Handle<Code> ic = is_strict_mode() |
| 1965 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 1966 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1967 | EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1968 | |
| 1969 | // If the assignment ends an initialization block, revert to fast case. |
| 1970 | if (expr->ends_initialization_block()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1971 | __ pop(rdx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1972 | __ push(rax); // Result of assignment, saved even if not needed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1973 | __ push(rdx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1974 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1975 | __ pop(rax); |
| 1976 | } |
| 1977 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1978 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1979 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | |
| 1983 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 1984 | Comment cmnt(masm_, "[ Property"); |
| 1985 | Expression* key = expr->key(); |
| 1986 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1987 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1988 | VisitForAccumulatorValue(expr->obj()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1989 | EmitNamedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1990 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1991 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1992 | VisitForStackValue(expr->obj()); |
| 1993 | VisitForAccumulatorValue(expr->key()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1994 | __ pop(rdx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1995 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1996 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | |
| 2001 | void FullCodeGenerator::EmitCallWithIC(Call* expr, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2002 | Handle<Object> name, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2003 | RelocInfo::Mode mode) { |
| 2004 | // Code common for calls using the IC. |
| 2005 | ZoneList<Expression*>* args = expr->arguments(); |
| 2006 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2007 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2008 | for (int i = 0; i < arg_count; i++) { |
| 2009 | VisitForStackValue(args->at(i)); |
| 2010 | } |
| 2011 | __ Move(rcx, name); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2012 | } |
| 2013 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2014 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2015 | // Call the IC initialization code. |
| 2016 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2017 | Handle<Code> ic = |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2018 | ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2019 | EmitCallIC(ic, mode, expr->id()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2020 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2021 | // Restore context register. |
| 2022 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2023 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2027 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2028 | Expression* key) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2029 | // Load the key. |
| 2030 | VisitForAccumulatorValue(key); |
| 2031 | |
| 2032 | // Swap the name of the function and the receiver on the stack to follow |
| 2033 | // the calling convention for call ICs. |
| 2034 | __ pop(rcx); |
| 2035 | __ push(rax); |
| 2036 | __ push(rcx); |
| 2037 | |
| 2038 | // Load the arguments. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2039 | ZoneList<Expression*>* args = expr->arguments(); |
| 2040 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2041 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2042 | for (int i = 0; i < arg_count; i++) { |
| 2043 | VisitForStackValue(args->at(i)); |
| 2044 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2045 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2046 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2047 | SetSourcePosition(expr->position()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2048 | // Call the IC initialization code. |
| 2049 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2050 | Handle<Code> ic = |
| 2051 | ISOLATE->stub_cache()->ComputeKeyedCallInitialize(arg_count, in_loop); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2052 | __ movq(rcx, Operand(rsp, (arg_count + 1) * kPointerSize)); // Key. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2053 | EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2054 | RecordJSReturnSite(expr); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2055 | // Restore context register. |
| 2056 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2057 | context()->DropAndPlug(1, rax); // Drop the key still on the stack. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2061 | void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2062 | // Code common for calls using the call stub. |
| 2063 | ZoneList<Expression*>* args = expr->arguments(); |
| 2064 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2065 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2066 | for (int i = 0; i < arg_count; i++) { |
| 2067 | VisitForStackValue(args->at(i)); |
| 2068 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2069 | } |
| 2070 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2071 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2072 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2073 | CallFunctionStub stub(arg_count, in_loop, flags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2074 | __ CallStub(&stub); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2075 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2076 | // Restore context register. |
| 2077 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2078 | // Discard the function left on TOS. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2079 | context()->DropAndPlug(1, rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2083 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(ResolveEvalFlag flag, |
| 2084 | int arg_count) { |
| 2085 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2086 | if (arg_count > 0) { |
| 2087 | __ push(Operand(rsp, arg_count * kPointerSize)); |
| 2088 | } else { |
| 2089 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
| 2090 | } |
| 2091 | |
| 2092 | // Push the receiver of the enclosing function and do runtime call. |
| 2093 | __ push(Operand(rbp, (2 + scope()->num_parameters()) * kPointerSize)); |
| 2094 | |
| 2095 | // Push the strict mode flag. |
| 2096 | __ Push(Smi::FromInt(strict_mode_flag())); |
| 2097 | |
| 2098 | __ CallRuntime(flag == SKIP_CONTEXT_LOOKUP |
| 2099 | ? Runtime::kResolvePossiblyDirectEvalNoLookup |
| 2100 | : Runtime::kResolvePossiblyDirectEval, 4); |
| 2101 | } |
| 2102 | |
| 2103 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2104 | void FullCodeGenerator::VisitCall(Call* expr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2105 | #ifdef DEBUG |
| 2106 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2107 | // through this function. Avoid early returns. |
| 2108 | expr->return_is_recorded_ = false; |
| 2109 | #endif |
| 2110 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2111 | Comment cmnt(masm_, "[ Call"); |
| 2112 | Expression* fun = expr->expression(); |
| 2113 | Variable* var = fun->AsVariableProxy()->AsVariable(); |
| 2114 | |
| 2115 | if (var != NULL && var->is_possibly_eval()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2116 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 2117 | // resolve the function we need to call and the receiver of the |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2118 | // call. Then we call the resolved function using the given |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2119 | // arguments. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2120 | ZoneList<Expression*>* args = expr->arguments(); |
| 2121 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2122 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2123 | VisitForStackValue(fun); |
| 2124 | __ PushRoot(Heap::kUndefinedValueRootIndex); // Reserved receiver slot. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2125 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2126 | // Push the arguments. |
| 2127 | for (int i = 0; i < arg_count; i++) { |
| 2128 | VisitForStackValue(args->at(i)); |
| 2129 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2130 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2131 | // If we know that eval can only be shadowed by eval-introduced |
| 2132 | // variables we attempt to load the global eval function directly |
| 2133 | // in generated code. If we succeed, there is no need to perform a |
| 2134 | // context lookup in the runtime system. |
| 2135 | Label done; |
| 2136 | if (var->AsSlot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) { |
| 2137 | Label slow; |
| 2138 | EmitLoadGlobalSlotCheckExtensions(var->AsSlot(), |
| 2139 | NOT_INSIDE_TYPEOF, |
| 2140 | &slow); |
| 2141 | // Push the function and resolve eval. |
| 2142 | __ push(rax); |
| 2143 | EmitResolvePossiblyDirectEval(SKIP_CONTEXT_LOOKUP, arg_count); |
| 2144 | __ jmp(&done); |
| 2145 | __ bind(&slow); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2148 | // Push copy of the function (found below the arguments) and |
| 2149 | // resolve eval. |
| 2150 | __ push(Operand(rsp, (arg_count + 1) * kPointerSize)); |
| 2151 | EmitResolvePossiblyDirectEval(PERFORM_CONTEXT_LOOKUP, arg_count); |
| 2152 | if (done.is_linked()) { |
| 2153 | __ bind(&done); |
| 2154 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2155 | |
| 2156 | // The runtime call returns a pair of values in rax (function) and |
| 2157 | // rdx (receiver). Touch up the stack with the right values. |
| 2158 | __ movq(Operand(rsp, (arg_count + 0) * kPointerSize), rdx); |
| 2159 | __ movq(Operand(rsp, (arg_count + 1) * kPointerSize), rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2160 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2161 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2162 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2163 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2164 | CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_IMPLICIT); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2165 | __ CallStub(&stub); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2166 | RecordJSReturnSite(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2167 | // Restore context register. |
| 2168 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2169 | context()->DropAndPlug(1, rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2170 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
| 2171 | // Call to a global variable. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2172 | // Push global object as receiver for the call IC lookup. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2173 | __ push(GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2174 | EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2175 | } else if (var != NULL && var->AsSlot() != NULL && |
| 2176 | var->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2177 | // Call to a lookup slot (dynamically introduced variable). |
| 2178 | Label slow, done; |
| 2179 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2180 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2181 | // Generate code for loading from variables potentially shadowed |
| 2182 | // by eval-introduced variables. |
| 2183 | EmitDynamicLoadFromSlotFastCase(var->AsSlot(), |
| 2184 | NOT_INSIDE_TYPEOF, |
| 2185 | &slow, |
| 2186 | &done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2187 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2188 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2189 | } |
| 2190 | // Call the runtime to find the function to call (returned in rax) |
| 2191 | // and the object holding it (returned in rdx). |
| 2192 | __ push(context_register()); |
| 2193 | __ Push(var->name()); |
| 2194 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
| 2195 | __ push(rax); // Function. |
| 2196 | __ push(rdx); // Receiver. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2197 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2198 | // If fast case code has been generated, emit code to push the |
| 2199 | // function and receiver and have the slow path jump around this |
| 2200 | // code. |
| 2201 | if (done.is_linked()) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2202 | Label call; |
| 2203 | __ jmp(&call, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2204 | __ bind(&done); |
| 2205 | // Push function. |
| 2206 | __ push(rax); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2207 | // The receiver is implicitly the global receiver. Indicate this |
| 2208 | // by passing the hole to the call function stub. |
| 2209 | __ PushRoot(Heap::kTheHoleValueRootIndex); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2210 | __ bind(&call); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2213 | // The receiver is either the global receiver or an object found |
| 2214 | // by LoadContextSlot. That object could be the hole if the |
| 2215 | // receiver is implicitly the global object. |
| 2216 | EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2217 | } else if (fun->AsProperty() != NULL) { |
| 2218 | // Call to an object property. |
| 2219 | Property* prop = fun->AsProperty(); |
| 2220 | Literal* key = prop->key()->AsLiteral(); |
| 2221 | if (key != NULL && key->handle()->IsSymbol()) { |
| 2222 | // Call to a named property, use call IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2223 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2224 | VisitForStackValue(prop->obj()); |
| 2225 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2226 | EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); |
| 2227 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2228 | // Call to a keyed property. |
| 2229 | // For a synthetic property use keyed load IC followed by function call, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2230 | // for a regular property use keyed EmitCallIC. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2231 | if (prop->is_synthetic()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2232 | // Do not visit the object and key subexpressions (they are shared |
| 2233 | // by all occurrences of the same rewritten parameter). |
| 2234 | ASSERT(prop->obj()->AsVariableProxy() != NULL); |
| 2235 | ASSERT(prop->obj()->AsVariableProxy()->var()->AsSlot() != NULL); |
| 2236 | Slot* slot = prop->obj()->AsVariableProxy()->var()->AsSlot(); |
| 2237 | MemOperand operand = EmitSlotSearch(slot, rdx); |
| 2238 | __ movq(rdx, operand); |
| 2239 | |
| 2240 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 2241 | ASSERT(prop->key()->AsLiteral()->handle()->IsSmi()); |
| 2242 | __ Move(rax, prop->key()->AsLiteral()->handle()); |
| 2243 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2244 | // Record source code position for IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2245 | SetSourcePosition(prop->position()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2246 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2247 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2248 | EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2249 | // Push result (function). |
| 2250 | __ push(rax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2251 | // Push Global receiver. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2252 | __ movq(rcx, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2253 | __ push(FieldOperand(rcx, GlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2254 | EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2255 | } else { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2256 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2257 | VisitForStackValue(prop->obj()); |
| 2258 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2259 | EmitKeyedCallWithIC(expr, prop->key()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2260 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2261 | } |
| 2262 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2263 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2264 | VisitForStackValue(fun); |
| 2265 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2266 | // Load global receiver object. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2267 | __ movq(rbx, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2268 | __ push(FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset)); |
| 2269 | // Emit function call. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2270 | EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2271 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2272 | |
| 2273 | #ifdef DEBUG |
| 2274 | // RecordJSReturnSite should have been called. |
| 2275 | ASSERT(expr->return_is_recorded_); |
| 2276 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | |
| 2280 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2281 | Comment cmnt(masm_, "[ CallNew"); |
| 2282 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2283 | // expression in new calls must be evaluated before the |
| 2284 | // arguments. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2285 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2286 | // Push constructor on the stack. If it's not a function it's used as |
| 2287 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2288 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2289 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2290 | |
| 2291 | // Push the arguments ("left-to-right") on the stack. |
| 2292 | ZoneList<Expression*>* args = expr->arguments(); |
| 2293 | int arg_count = args->length(); |
| 2294 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2295 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | // Call the construct call builtin that handles allocation and |
| 2299 | // constructor invocation. |
| 2300 | SetSourcePosition(expr->position()); |
| 2301 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2302 | // Load function and argument count into rdi and rax. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2303 | __ Set(rax, arg_count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2304 | __ movq(rdi, Operand(rsp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2305 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2306 | Handle<Code> construct_builtin = |
| 2307 | isolate()->builtins()->JSConstructCall(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2308 | __ Call(construct_builtin, RelocInfo::CONSTRUCT_CALL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2309 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2313 | void FullCodeGenerator::EmitIsSmi(ZoneList<Expression*>* args) { |
| 2314 | ASSERT(args->length() == 1); |
| 2315 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2316 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2317 | |
| 2318 | Label materialize_true, materialize_false; |
| 2319 | Label* if_true = NULL; |
| 2320 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2321 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2322 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2323 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2324 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2325 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2326 | __ JumpIfSmi(rax, if_true); |
| 2327 | __ jmp(if_false); |
| 2328 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2329 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | |
| 2333 | void FullCodeGenerator::EmitIsNonNegativeSmi(ZoneList<Expression*>* args) { |
| 2334 | ASSERT(args->length() == 1); |
| 2335 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2336 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2337 | |
| 2338 | Label materialize_true, materialize_false; |
| 2339 | Label* if_true = NULL; |
| 2340 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2341 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2342 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2343 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2344 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2345 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 2346 | Condition non_negative_smi = masm()->CheckNonNegativeSmi(rax); |
| 2347 | Split(non_negative_smi, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2348 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2349 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | |
| 2353 | void FullCodeGenerator::EmitIsObject(ZoneList<Expression*>* args) { |
| 2354 | ASSERT(args->length() == 1); |
| 2355 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2356 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2357 | |
| 2358 | Label materialize_true, materialize_false; |
| 2359 | Label* if_true = NULL; |
| 2360 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2361 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2362 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2363 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2364 | |
| 2365 | __ JumpIfSmi(rax, if_false); |
| 2366 | __ CompareRoot(rax, Heap::kNullValueRootIndex); |
| 2367 | __ j(equal, if_true); |
| 2368 | __ movq(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 2369 | // Undetectable objects behave like undefined when tested with typeof. |
| 2370 | __ testb(FieldOperand(rbx, Map::kBitFieldOffset), |
| 2371 | Immediate(1 << Map::kIsUndetectable)); |
| 2372 | __ j(not_zero, if_false); |
| 2373 | __ movzxbq(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2374 | __ cmpq(rbx, Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2375 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2376 | __ cmpq(rbx, Immediate(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2377 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2378 | Split(below_equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2379 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2380 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2384 | void FullCodeGenerator::EmitIsSpecObject(ZoneList<Expression*>* args) { |
| 2385 | ASSERT(args->length() == 1); |
| 2386 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2387 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2388 | |
| 2389 | Label materialize_true, materialize_false; |
| 2390 | Label* if_true = NULL; |
| 2391 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2392 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2393 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2394 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2395 | |
| 2396 | __ JumpIfSmi(rax, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2397 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rbx); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2398 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2399 | Split(above_equal, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2400 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2401 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2405 | void FullCodeGenerator::EmitIsUndetectableObject(ZoneList<Expression*>* args) { |
| 2406 | ASSERT(args->length() == 1); |
| 2407 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2408 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2409 | |
| 2410 | Label materialize_true, materialize_false; |
| 2411 | Label* if_true = NULL; |
| 2412 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2413 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2414 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2415 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2416 | |
| 2417 | __ JumpIfSmi(rax, if_false); |
| 2418 | __ movq(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 2419 | __ testb(FieldOperand(rbx, Map::kBitFieldOffset), |
| 2420 | Immediate(1 << Map::kIsUndetectable)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2421 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2422 | Split(not_zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2423 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2424 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2428 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
| 2429 | ZoneList<Expression*>* args) { |
| 2430 | ASSERT(args->length() == 1); |
| 2431 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2432 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2433 | |
| 2434 | Label materialize_true, materialize_false; |
| 2435 | Label* if_true = NULL; |
| 2436 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2437 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2438 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2439 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2440 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2441 | if (FLAG_debug_code) __ AbortIfSmi(rax); |
| 2442 | |
| 2443 | // Check whether this map has already been checked to be safe for default |
| 2444 | // valueOf. |
| 2445 | __ movq(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 2446 | __ testb(FieldOperand(rbx, Map::kBitField2Offset), |
| 2447 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 2448 | __ j(not_zero, if_true); |
| 2449 | |
| 2450 | // Check for fast case object. Generate false result for slow case object. |
| 2451 | __ movq(rcx, FieldOperand(rax, JSObject::kPropertiesOffset)); |
| 2452 | __ movq(rcx, FieldOperand(rcx, HeapObject::kMapOffset)); |
| 2453 | __ CompareRoot(rcx, Heap::kHashTableMapRootIndex); |
| 2454 | __ j(equal, if_false); |
| 2455 | |
| 2456 | // Look for valueOf symbol in the descriptor array, and indicate false if |
| 2457 | // found. The type is not checked, so if it is a transition it is a false |
| 2458 | // negative. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2459 | __ LoadInstanceDescriptors(rbx, rbx); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2460 | __ movq(rcx, FieldOperand(rbx, FixedArray::kLengthOffset)); |
| 2461 | // rbx: descriptor array |
| 2462 | // rcx: length of descriptor array |
| 2463 | // Calculate the end of the descriptor array. |
| 2464 | SmiIndex index = masm_->SmiToIndex(rdx, rcx, kPointerSizeLog2); |
| 2465 | __ lea(rcx, |
| 2466 | Operand( |
| 2467 | rbx, index.reg, index.scale, FixedArray::kHeaderSize)); |
| 2468 | // Calculate location of the first key name. |
| 2469 | __ addq(rbx, |
| 2470 | Immediate(FixedArray::kHeaderSize + |
| 2471 | DescriptorArray::kFirstIndex * kPointerSize)); |
| 2472 | // Loop through all the keys in the descriptor array. If one of these is the |
| 2473 | // symbol valueOf the result is false. |
| 2474 | Label entry, loop; |
| 2475 | __ jmp(&entry); |
| 2476 | __ bind(&loop); |
| 2477 | __ movq(rdx, FieldOperand(rbx, 0)); |
| 2478 | __ Cmp(rdx, FACTORY->value_of_symbol()); |
| 2479 | __ j(equal, if_false); |
| 2480 | __ addq(rbx, Immediate(kPointerSize)); |
| 2481 | __ bind(&entry); |
| 2482 | __ cmpq(rbx, rcx); |
| 2483 | __ j(not_equal, &loop); |
| 2484 | |
| 2485 | // Reload map as register rbx was used as temporary above. |
| 2486 | __ movq(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 2487 | |
| 2488 | // If a valueOf property is not found on the object check that it's |
| 2489 | // prototype is the un-modified String prototype. If not result is false. |
| 2490 | __ movq(rcx, FieldOperand(rbx, Map::kPrototypeOffset)); |
| 2491 | __ testq(rcx, Immediate(kSmiTagMask)); |
| 2492 | __ j(zero, if_false); |
| 2493 | __ movq(rcx, FieldOperand(rcx, HeapObject::kMapOffset)); |
| 2494 | __ movq(rdx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2495 | __ movq(rdx, FieldOperand(rdx, GlobalObject::kGlobalContextOffset)); |
| 2496 | __ cmpq(rcx, |
| 2497 | ContextOperand(rdx, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
| 2498 | __ j(not_equal, if_false); |
| 2499 | // Set the bit in the map to indicate that it has been checked safe for |
| 2500 | // default valueOf and set true result. |
| 2501 | __ or_(FieldOperand(rbx, Map::kBitField2Offset), |
| 2502 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 2503 | __ jmp(if_true); |
| 2504 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2505 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2506 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2510 | void FullCodeGenerator::EmitIsFunction(ZoneList<Expression*>* args) { |
| 2511 | ASSERT(args->length() == 1); |
| 2512 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2513 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2514 | |
| 2515 | Label materialize_true, materialize_false; |
| 2516 | Label* if_true = NULL; |
| 2517 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2518 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2519 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2520 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2521 | |
| 2522 | __ JumpIfSmi(rax, if_false); |
| 2523 | __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2524 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2525 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2526 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2527 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | |
| 2531 | void FullCodeGenerator::EmitIsArray(ZoneList<Expression*>* args) { |
| 2532 | ASSERT(args->length() == 1); |
| 2533 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2534 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2535 | |
| 2536 | Label materialize_true, materialize_false; |
| 2537 | Label* if_true = NULL; |
| 2538 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2539 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2540 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2541 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2542 | |
| 2543 | __ JumpIfSmi(rax, if_false); |
| 2544 | __ CmpObjectType(rax, JS_ARRAY_TYPE, rbx); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2545 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2546 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2547 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2548 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | |
| 2552 | void FullCodeGenerator::EmitIsRegExp(ZoneList<Expression*>* args) { |
| 2553 | ASSERT(args->length() == 1); |
| 2554 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2555 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2556 | |
| 2557 | Label materialize_true, materialize_false; |
| 2558 | Label* if_true = NULL; |
| 2559 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2560 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2561 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2562 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2563 | |
| 2564 | __ JumpIfSmi(rax, if_false); |
| 2565 | __ CmpObjectType(rax, JS_REGEXP_TYPE, rbx); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2566 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2567 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2568 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2569 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | |
| 2573 | |
| 2574 | void FullCodeGenerator::EmitIsConstructCall(ZoneList<Expression*>* args) { |
| 2575 | ASSERT(args->length() == 0); |
| 2576 | |
| 2577 | Label materialize_true, materialize_false; |
| 2578 | Label* if_true = NULL; |
| 2579 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2580 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2581 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2582 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2583 | |
| 2584 | // Get the frame pointer for the calling frame. |
| 2585 | __ movq(rax, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
| 2586 | |
| 2587 | // Skip the arguments adaptor frame if it exists. |
| 2588 | Label check_frame_marker; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2589 | __ Cmp(Operand(rax, StandardFrameConstants::kContextOffset), |
| 2590 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2591 | __ j(not_equal, &check_frame_marker); |
| 2592 | __ movq(rax, Operand(rax, StandardFrameConstants::kCallerFPOffset)); |
| 2593 | |
| 2594 | // Check the marker in the calling frame. |
| 2595 | __ bind(&check_frame_marker); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2596 | __ Cmp(Operand(rax, StandardFrameConstants::kMarkerOffset), |
| 2597 | Smi::FromInt(StackFrame::CONSTRUCT)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2598 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2599 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2600 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2601 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | void FullCodeGenerator::EmitObjectEquals(ZoneList<Expression*>* args) { |
| 2606 | ASSERT(args->length() == 2); |
| 2607 | |
| 2608 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2609 | VisitForStackValue(args->at(0)); |
| 2610 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2611 | |
| 2612 | Label materialize_true, materialize_false; |
| 2613 | Label* if_true = NULL; |
| 2614 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2615 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2616 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2617 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2618 | |
| 2619 | __ pop(rbx); |
| 2620 | __ cmpq(rax, rbx); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2621 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2622 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2623 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2624 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | |
| 2628 | void FullCodeGenerator::EmitArguments(ZoneList<Expression*>* args) { |
| 2629 | ASSERT(args->length() == 1); |
| 2630 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2631 | // ArgumentsAccessStub expects the key in rdx and the formal |
| 2632 | // parameter count in rax. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2633 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2634 | __ movq(rdx, rax); |
| 2635 | __ Move(rax, Smi::FromInt(scope()->num_parameters())); |
| 2636 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 2637 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2638 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | |
| 2642 | void FullCodeGenerator::EmitArgumentsLength(ZoneList<Expression*>* args) { |
| 2643 | ASSERT(args->length() == 0); |
| 2644 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2645 | Label exit; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2646 | // Get the number of formal parameters. |
| 2647 | __ Move(rax, Smi::FromInt(scope()->num_parameters())); |
| 2648 | |
| 2649 | // Check if the calling frame is an arguments adaptor frame. |
| 2650 | __ movq(rbx, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2651 | __ Cmp(Operand(rbx, StandardFrameConstants::kContextOffset), |
| 2652 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2653 | __ j(not_equal, &exit, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2654 | |
| 2655 | // Arguments adaptor case: Read the arguments length from the |
| 2656 | // adaptor frame. |
| 2657 | __ movq(rax, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2658 | |
| 2659 | __ bind(&exit); |
| 2660 | if (FLAG_debug_code) __ AbortIfNotSmi(rax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2661 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | |
| 2665 | void FullCodeGenerator::EmitClassOf(ZoneList<Expression*>* args) { |
| 2666 | ASSERT(args->length() == 1); |
| 2667 | Label done, null, function, non_function_constructor; |
| 2668 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2669 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2670 | |
| 2671 | // If the object is a smi, we return null. |
| 2672 | __ JumpIfSmi(rax, &null); |
| 2673 | |
| 2674 | // Check that the object is a JS object but take special care of JS |
| 2675 | // functions to make sure they have 'Function' as their class. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2676 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rax); |
| 2677 | // Map is now in rax. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2678 | __ j(below, &null); |
| 2679 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2680 | // As long as LAST_CALLABLE_SPEC_OBJECT_TYPE is the last instance type, and |
| 2681 | // FIRST_CALLABLE_SPEC_OBJECT_TYPE comes right after |
| 2682 | // LAST_NONCALLABLE_SPEC_OBJECT_TYPE, we can avoid checking for the latter. |
| 2683 | STATIC_ASSERT(LAST_TYPE == LAST_CALLABLE_SPEC_OBJECT_TYPE); |
| 2684 | STATIC_ASSERT(FIRST_CALLABLE_SPEC_OBJECT_TYPE == |
| 2685 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE + 1); |
| 2686 | __ CmpInstanceType(rax, FIRST_CALLABLE_SPEC_OBJECT_TYPE); |
| 2687 | __ j(above_equal, &function); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2688 | |
| 2689 | // Check if the constructor in the map is a function. |
| 2690 | __ movq(rax, FieldOperand(rax, Map::kConstructorOffset)); |
| 2691 | __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx); |
| 2692 | __ j(not_equal, &non_function_constructor); |
| 2693 | |
| 2694 | // rax now contains the constructor function. Grab the |
| 2695 | // instance class name from there. |
| 2696 | __ movq(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); |
| 2697 | __ movq(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2698 | __ jmp(&done); |
| 2699 | |
| 2700 | // Functions have class 'Function'. |
| 2701 | __ bind(&function); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2702 | __ Move(rax, isolate()->factory()->function_class_symbol()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2703 | __ jmp(&done); |
| 2704 | |
| 2705 | // Objects with a non-function constructor have class 'Object'. |
| 2706 | __ bind(&non_function_constructor); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2707 | __ Move(rax, isolate()->factory()->Object_symbol()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2708 | __ jmp(&done); |
| 2709 | |
| 2710 | // Non-JS objects have class null. |
| 2711 | __ bind(&null); |
| 2712 | __ LoadRoot(rax, Heap::kNullValueRootIndex); |
| 2713 | |
| 2714 | // All done. |
| 2715 | __ bind(&done); |
| 2716 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2717 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | |
| 2721 | void FullCodeGenerator::EmitLog(ZoneList<Expression*>* args) { |
| 2722 | // Conditionally generate a log call. |
| 2723 | // Args: |
| 2724 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 2725 | // This is used to determine whether or not to generate the log call. |
| 2726 | // 1 (string): Format string. Access the string at argument index 2 |
| 2727 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 2728 | // 2 (array): Arguments to the format string. |
| 2729 | ASSERT_EQ(args->length(), 3); |
| 2730 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 2731 | if (CodeGenerator::ShouldGenerateLog(args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2732 | VisitForStackValue(args->at(1)); |
| 2733 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2734 | __ CallRuntime(Runtime::kLog, 2); |
| 2735 | } |
| 2736 | #endif |
| 2737 | // Finally, we're expected to leave a value on the top of the stack. |
| 2738 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2739 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | |
| 2743 | void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) { |
| 2744 | ASSERT(args->length() == 0); |
| 2745 | |
| 2746 | Label slow_allocate_heapnumber; |
| 2747 | Label heapnumber_allocated; |
| 2748 | |
| 2749 | __ AllocateHeapNumber(rbx, rcx, &slow_allocate_heapnumber); |
| 2750 | __ jmp(&heapnumber_allocated); |
| 2751 | |
| 2752 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2753 | // Allocate a heap number. |
| 2754 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2755 | __ movq(rbx, rax); |
| 2756 | |
| 2757 | __ bind(&heapnumber_allocated); |
| 2758 | |
| 2759 | // Return a random uint32 number in rax. |
| 2760 | // The fresh HeapNumber is in rbx, which is callee-save on both x64 ABIs. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2761 | __ PrepareCallCFunction(1); |
| 2762 | #ifdef _WIN64 |
| 2763 | __ LoadAddress(rcx, ExternalReference::isolate_address()); |
| 2764 | #else |
| 2765 | __ LoadAddress(rdi, ExternalReference::isolate_address()); |
| 2766 | #endif |
| 2767 | __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2768 | |
| 2769 | // Convert 32 random bits in rax to 0.(32 random bits) in a double |
| 2770 | // by computing: |
| 2771 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 2772 | __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single. |
| 2773 | __ movd(xmm1, rcx); |
| 2774 | __ movd(xmm0, rax); |
| 2775 | __ cvtss2sd(xmm1, xmm1); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2776 | __ xorps(xmm0, xmm1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2777 | __ subsd(xmm0, xmm1); |
| 2778 | __ movsd(FieldOperand(rbx, HeapNumber::kValueOffset), xmm0); |
| 2779 | |
| 2780 | __ movq(rax, rbx); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2781 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | |
| 2785 | void FullCodeGenerator::EmitSubString(ZoneList<Expression*>* args) { |
| 2786 | // Load the arguments on the stack and call the stub. |
| 2787 | SubStringStub stub; |
| 2788 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2789 | VisitForStackValue(args->at(0)); |
| 2790 | VisitForStackValue(args->at(1)); |
| 2791 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2792 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2793 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | |
| 2797 | void FullCodeGenerator::EmitRegExpExec(ZoneList<Expression*>* args) { |
| 2798 | // Load the arguments on the stack and call the stub. |
| 2799 | RegExpExecStub stub; |
| 2800 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2801 | VisitForStackValue(args->at(0)); |
| 2802 | VisitForStackValue(args->at(1)); |
| 2803 | VisitForStackValue(args->at(2)); |
| 2804 | VisitForStackValue(args->at(3)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2805 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2806 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | |
| 2810 | void FullCodeGenerator::EmitValueOf(ZoneList<Expression*>* args) { |
| 2811 | ASSERT(args->length() == 1); |
| 2812 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2813 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2814 | |
| 2815 | Label done; |
| 2816 | // If the object is a smi return the object. |
| 2817 | __ JumpIfSmi(rax, &done); |
| 2818 | // If the object is not a value type, return the object. |
| 2819 | __ CmpObjectType(rax, JS_VALUE_TYPE, rbx); |
| 2820 | __ j(not_equal, &done); |
| 2821 | __ movq(rax, FieldOperand(rax, JSValue::kValueOffset)); |
| 2822 | |
| 2823 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2824 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | |
| 2828 | void FullCodeGenerator::EmitMathPow(ZoneList<Expression*>* args) { |
| 2829 | // Load the arguments on the stack and call the runtime function. |
| 2830 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2831 | VisitForStackValue(args->at(0)); |
| 2832 | VisitForStackValue(args->at(1)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2833 | MathPowStub stub; |
| 2834 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2835 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | |
| 2839 | void FullCodeGenerator::EmitSetValueOf(ZoneList<Expression*>* args) { |
| 2840 | ASSERT(args->length() == 2); |
| 2841 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2842 | VisitForStackValue(args->at(0)); // Load the object. |
| 2843 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2844 | __ pop(rbx); // rax = value. rbx = object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2845 | |
| 2846 | Label done; |
| 2847 | // If the object is a smi, return the value. |
| 2848 | __ JumpIfSmi(rbx, &done); |
| 2849 | |
| 2850 | // If the object is not a value type, return the value. |
| 2851 | __ CmpObjectType(rbx, JS_VALUE_TYPE, rcx); |
| 2852 | __ j(not_equal, &done); |
| 2853 | |
| 2854 | // Store the value. |
| 2855 | __ movq(FieldOperand(rbx, JSValue::kValueOffset), rax); |
| 2856 | // Update the write barrier. Save the value as it will be |
| 2857 | // overwritten by the write barrier code and is needed afterward. |
| 2858 | __ movq(rdx, rax); |
| 2859 | __ RecordWrite(rbx, JSValue::kValueOffset, rdx, rcx); |
| 2860 | |
| 2861 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2862 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | |
| 2866 | void FullCodeGenerator::EmitNumberToString(ZoneList<Expression*>* args) { |
| 2867 | ASSERT_EQ(args->length(), 1); |
| 2868 | |
| 2869 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2870 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2871 | |
| 2872 | NumberToStringStub stub; |
| 2873 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2874 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2878 | void FullCodeGenerator::EmitStringCharFromCode(ZoneList<Expression*>* args) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2879 | ASSERT(args->length() == 1); |
| 2880 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2881 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2882 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2883 | Label done; |
| 2884 | StringCharFromCodeGenerator generator(rax, rbx); |
| 2885 | generator.GenerateFast(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2886 | __ jmp(&done); |
| 2887 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2888 | NopRuntimeCallHelper call_helper; |
| 2889 | generator.GenerateSlow(masm_, call_helper); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2890 | |
| 2891 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2892 | context()->Plug(rbx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2896 | void FullCodeGenerator::EmitStringCharCodeAt(ZoneList<Expression*>* args) { |
| 2897 | ASSERT(args->length() == 2); |
| 2898 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2899 | VisitForStackValue(args->at(0)); |
| 2900 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2901 | |
| 2902 | Register object = rbx; |
| 2903 | Register index = rax; |
| 2904 | Register scratch = rcx; |
| 2905 | Register result = rdx; |
| 2906 | |
| 2907 | __ pop(object); |
| 2908 | |
| 2909 | Label need_conversion; |
| 2910 | Label index_out_of_range; |
| 2911 | Label done; |
| 2912 | StringCharCodeAtGenerator generator(object, |
| 2913 | index, |
| 2914 | scratch, |
| 2915 | result, |
| 2916 | &need_conversion, |
| 2917 | &need_conversion, |
| 2918 | &index_out_of_range, |
| 2919 | STRING_INDEX_IS_NUMBER); |
| 2920 | generator.GenerateFast(masm_); |
| 2921 | __ jmp(&done); |
| 2922 | |
| 2923 | __ bind(&index_out_of_range); |
| 2924 | // When the index is out of range, the spec requires us to return |
| 2925 | // NaN. |
| 2926 | __ LoadRoot(result, Heap::kNanValueRootIndex); |
| 2927 | __ jmp(&done); |
| 2928 | |
| 2929 | __ bind(&need_conversion); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2930 | // Move the undefined value into the result register, which will |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2931 | // trigger conversion. |
| 2932 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 2933 | __ jmp(&done); |
| 2934 | |
| 2935 | NopRuntimeCallHelper call_helper; |
| 2936 | generator.GenerateSlow(masm_, call_helper); |
| 2937 | |
| 2938 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2939 | context()->Plug(result); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2942 | |
| 2943 | void FullCodeGenerator::EmitStringCharAt(ZoneList<Expression*>* args) { |
| 2944 | ASSERT(args->length() == 2); |
| 2945 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2946 | VisitForStackValue(args->at(0)); |
| 2947 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2948 | |
| 2949 | Register object = rbx; |
| 2950 | Register index = rax; |
| 2951 | Register scratch1 = rcx; |
| 2952 | Register scratch2 = rdx; |
| 2953 | Register result = rax; |
| 2954 | |
| 2955 | __ pop(object); |
| 2956 | |
| 2957 | Label need_conversion; |
| 2958 | Label index_out_of_range; |
| 2959 | Label done; |
| 2960 | StringCharAtGenerator generator(object, |
| 2961 | index, |
| 2962 | scratch1, |
| 2963 | scratch2, |
| 2964 | result, |
| 2965 | &need_conversion, |
| 2966 | &need_conversion, |
| 2967 | &index_out_of_range, |
| 2968 | STRING_INDEX_IS_NUMBER); |
| 2969 | generator.GenerateFast(masm_); |
| 2970 | __ jmp(&done); |
| 2971 | |
| 2972 | __ bind(&index_out_of_range); |
| 2973 | // When the index is out of range, the spec requires us to return |
| 2974 | // the empty string. |
| 2975 | __ LoadRoot(result, Heap::kEmptyStringRootIndex); |
| 2976 | __ jmp(&done); |
| 2977 | |
| 2978 | __ bind(&need_conversion); |
| 2979 | // Move smi zero into the result register, which will trigger |
| 2980 | // conversion. |
| 2981 | __ Move(result, Smi::FromInt(0)); |
| 2982 | __ jmp(&done); |
| 2983 | |
| 2984 | NopRuntimeCallHelper call_helper; |
| 2985 | generator.GenerateSlow(masm_, call_helper); |
| 2986 | |
| 2987 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2988 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2992 | void FullCodeGenerator::EmitStringAdd(ZoneList<Expression*>* args) { |
| 2993 | ASSERT_EQ(2, args->length()); |
| 2994 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2995 | VisitForStackValue(args->at(0)); |
| 2996 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2997 | |
| 2998 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 2999 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3000 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | |
| 3004 | void FullCodeGenerator::EmitStringCompare(ZoneList<Expression*>* args) { |
| 3005 | ASSERT_EQ(2, args->length()); |
| 3006 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3007 | VisitForStackValue(args->at(0)); |
| 3008 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3009 | |
| 3010 | StringCompareStub stub; |
| 3011 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3012 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | |
| 3016 | void FullCodeGenerator::EmitMathSin(ZoneList<Expression*>* args) { |
| 3017 | // Load the argument on the stack and call the stub. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3018 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 3019 | TranscendentalCacheStub::TAGGED); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3020 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3021 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3022 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3023 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | |
| 3027 | void FullCodeGenerator::EmitMathCos(ZoneList<Expression*>* args) { |
| 3028 | // Load the argument on the stack and call the stub. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3029 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 3030 | TranscendentalCacheStub::TAGGED); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3031 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3032 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3033 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3034 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3038 | void FullCodeGenerator::EmitMathLog(ZoneList<Expression*>* args) { |
| 3039 | // Load the argument on the stack and call the stub. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3040 | TranscendentalCacheStub stub(TranscendentalCache::LOG, |
| 3041 | TranscendentalCacheStub::TAGGED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3042 | ASSERT(args->length() == 1); |
| 3043 | VisitForStackValue(args->at(0)); |
| 3044 | __ CallStub(&stub); |
| 3045 | context()->Plug(rax); |
| 3046 | } |
| 3047 | |
| 3048 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3049 | void FullCodeGenerator::EmitMathSqrt(ZoneList<Expression*>* args) { |
| 3050 | // Load the argument on the stack and call the runtime function. |
| 3051 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3052 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3053 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3054 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | |
| 3058 | void FullCodeGenerator::EmitCallFunction(ZoneList<Expression*>* args) { |
| 3059 | ASSERT(args->length() >= 2); |
| 3060 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3061 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3062 | for (int i = 0; i < arg_count + 1; i++) { |
| 3063 | VisitForStackValue(args->at(i)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3064 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3065 | VisitForAccumulatorValue(args->last()); // Function. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3066 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3067 | // InvokeFunction requires the function in rdi. Move it in there. |
| 3068 | __ movq(rdi, result_register()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3069 | ParameterCount count(arg_count); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3070 | __ InvokeFunction(rdi, count, CALL_FUNCTION, |
| 3071 | NullCallWrapper(), CALL_AS_METHOD); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3072 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3073 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | |
| 3077 | void FullCodeGenerator::EmitRegExpConstructResult(ZoneList<Expression*>* args) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3078 | RegExpConstructResultStub stub; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3079 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3080 | VisitForStackValue(args->at(0)); |
| 3081 | VisitForStackValue(args->at(1)); |
| 3082 | VisitForStackValue(args->at(2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3083 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3084 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | |
| 3088 | void FullCodeGenerator::EmitSwapElements(ZoneList<Expression*>* args) { |
| 3089 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3090 | VisitForStackValue(args->at(0)); |
| 3091 | VisitForStackValue(args->at(1)); |
| 3092 | VisitForStackValue(args->at(2)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3093 | Label done; |
| 3094 | Label slow_case; |
| 3095 | Register object = rax; |
| 3096 | Register index_1 = rbx; |
| 3097 | Register index_2 = rcx; |
| 3098 | Register elements = rdi; |
| 3099 | Register temp = rdx; |
| 3100 | __ movq(object, Operand(rsp, 2 * kPointerSize)); |
| 3101 | // Fetch the map and check if array is in fast case. |
| 3102 | // Check that object doesn't require security checks and |
| 3103 | // has no indexed interceptor. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3104 | __ CmpObjectType(object, JS_ARRAY_TYPE, temp); |
| 3105 | __ j(not_equal, &slow_case); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3106 | __ testb(FieldOperand(temp, Map::kBitFieldOffset), |
| 3107 | Immediate(KeyedLoadIC::kSlowCaseBitFieldMask)); |
| 3108 | __ j(not_zero, &slow_case); |
| 3109 | |
| 3110 | // Check the object's elements are in fast case and writable. |
| 3111 | __ movq(elements, FieldOperand(object, JSObject::kElementsOffset)); |
| 3112 | __ CompareRoot(FieldOperand(elements, HeapObject::kMapOffset), |
| 3113 | Heap::kFixedArrayMapRootIndex); |
| 3114 | __ j(not_equal, &slow_case); |
| 3115 | |
| 3116 | // Check that both indices are smis. |
| 3117 | __ movq(index_1, Operand(rsp, 1 * kPointerSize)); |
| 3118 | __ movq(index_2, Operand(rsp, 0 * kPointerSize)); |
| 3119 | __ JumpIfNotBothSmi(index_1, index_2, &slow_case); |
| 3120 | |
| 3121 | // Check that both indices are valid. |
| 3122 | // The JSArray length field is a smi since the array is in fast case mode. |
| 3123 | __ movq(temp, FieldOperand(object, JSArray::kLengthOffset)); |
| 3124 | __ SmiCompare(temp, index_1); |
| 3125 | __ j(below_equal, &slow_case); |
| 3126 | __ SmiCompare(temp, index_2); |
| 3127 | __ j(below_equal, &slow_case); |
| 3128 | |
| 3129 | __ SmiToInteger32(index_1, index_1); |
| 3130 | __ SmiToInteger32(index_2, index_2); |
| 3131 | // Bring addresses into index1 and index2. |
| 3132 | __ lea(index_1, FieldOperand(elements, index_1, times_pointer_size, |
| 3133 | FixedArray::kHeaderSize)); |
| 3134 | __ lea(index_2, FieldOperand(elements, index_2, times_pointer_size, |
| 3135 | FixedArray::kHeaderSize)); |
| 3136 | |
| 3137 | // Swap elements. Use object and temp as scratch registers. |
| 3138 | __ movq(object, Operand(index_1, 0)); |
| 3139 | __ movq(temp, Operand(index_2, 0)); |
| 3140 | __ movq(Operand(index_2, 0), object); |
| 3141 | __ movq(Operand(index_1, 0), temp); |
| 3142 | |
| 3143 | Label new_space; |
| 3144 | __ InNewSpace(elements, temp, equal, &new_space); |
| 3145 | |
| 3146 | __ movq(object, elements); |
| 3147 | __ RecordWriteHelper(object, index_1, temp); |
| 3148 | __ RecordWriteHelper(elements, index_2, temp); |
| 3149 | |
| 3150 | __ bind(&new_space); |
| 3151 | // We are done. Drop elements from the stack, and return undefined. |
| 3152 | __ addq(rsp, Immediate(3 * kPointerSize)); |
| 3153 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 3154 | __ jmp(&done); |
| 3155 | |
| 3156 | __ bind(&slow_case); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3157 | __ CallRuntime(Runtime::kSwapElements, 3); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3158 | |
| 3159 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3160 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | |
| 3164 | void FullCodeGenerator::EmitGetFromCache(ZoneList<Expression*>* args) { |
| 3165 | ASSERT_EQ(2, args->length()); |
| 3166 | |
| 3167 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 3168 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 3169 | |
| 3170 | Handle<FixedArray> jsfunction_result_caches( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3171 | isolate()->global_context()->jsfunction_result_caches()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3172 | if (jsfunction_result_caches->length() <= cache_id) { |
| 3173 | __ Abort("Attempt to use undefined cache."); |
| 3174 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3175 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3176 | return; |
| 3177 | } |
| 3178 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3179 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3180 | |
| 3181 | Register key = rax; |
| 3182 | Register cache = rbx; |
| 3183 | Register tmp = rcx; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3184 | __ movq(cache, ContextOperand(rsi, Context::GLOBAL_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3185 | __ movq(cache, |
| 3186 | FieldOperand(cache, GlobalObject::kGlobalContextOffset)); |
| 3187 | __ movq(cache, |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3188 | ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3189 | __ movq(cache, |
| 3190 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3191 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3192 | Label done, not_found; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3193 | // tmp now holds finger offset as a smi. |
| 3194 | ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 3195 | __ movq(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 3196 | SmiIndex index = |
| 3197 | __ SmiToIndex(kScratchRegister, tmp, kPointerSizeLog2); |
| 3198 | __ cmpq(key, FieldOperand(cache, |
| 3199 | index.reg, |
| 3200 | index.scale, |
| 3201 | FixedArray::kHeaderSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3202 | __ j(not_equal, ¬_found, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3203 | __ movq(rax, FieldOperand(cache, |
| 3204 | index.reg, |
| 3205 | index.scale, |
| 3206 | FixedArray::kHeaderSize + kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3207 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3208 | |
| 3209 | __ bind(¬_found); |
| 3210 | // Call runtime to perform the lookup. |
| 3211 | __ push(cache); |
| 3212 | __ push(key); |
| 3213 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 3214 | |
| 3215 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3216 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3220 | void FullCodeGenerator::EmitIsRegExpEquivalent(ZoneList<Expression*>* args) { |
| 3221 | ASSERT_EQ(2, args->length()); |
| 3222 | |
| 3223 | Register right = rax; |
| 3224 | Register left = rbx; |
| 3225 | Register tmp = rcx; |
| 3226 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3227 | VisitForStackValue(args->at(0)); |
| 3228 | VisitForAccumulatorValue(args->at(1)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3229 | __ pop(left); |
| 3230 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3231 | Label done, fail, ok; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3232 | __ cmpq(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3233 | __ j(equal, &ok, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3234 | // Fail if either is a non-HeapObject. |
| 3235 | Condition either_smi = masm()->CheckEitherSmi(left, right, tmp); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3236 | __ j(either_smi, &fail, Label::kNear); |
| 3237 | __ j(zero, &fail, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3238 | __ movq(tmp, FieldOperand(left, HeapObject::kMapOffset)); |
| 3239 | __ cmpb(FieldOperand(tmp, Map::kInstanceTypeOffset), |
| 3240 | Immediate(JS_REGEXP_TYPE)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3241 | __ j(not_equal, &fail, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3242 | __ cmpq(tmp, FieldOperand(right, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3243 | __ j(not_equal, &fail, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3244 | __ movq(tmp, FieldOperand(left, JSRegExp::kDataOffset)); |
| 3245 | __ cmpq(tmp, FieldOperand(right, JSRegExp::kDataOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3246 | __ j(equal, &ok, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3247 | __ bind(&fail); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3248 | __ Move(rax, isolate()->factory()->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3249 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3250 | __ bind(&ok); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3251 | __ Move(rax, isolate()->factory()->true_value()); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3252 | __ bind(&done); |
| 3253 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3254 | context()->Plug(rax); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3258 | void FullCodeGenerator::EmitHasCachedArrayIndex(ZoneList<Expression*>* args) { |
| 3259 | ASSERT(args->length() == 1); |
| 3260 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3261 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3262 | |
| 3263 | Label materialize_true, materialize_false; |
| 3264 | Label* if_true = NULL; |
| 3265 | Label* if_false = NULL; |
| 3266 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3267 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3268 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3269 | |
| 3270 | __ testl(FieldOperand(rax, String::kHashFieldOffset), |
| 3271 | Immediate(String::kContainsCachedArrayIndexMask)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3272 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3273 | __ j(zero, if_true); |
| 3274 | __ jmp(if_false); |
| 3275 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3276 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | |
| 3280 | void FullCodeGenerator::EmitGetCachedArrayIndex(ZoneList<Expression*>* args) { |
| 3281 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3282 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3283 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3284 | if (FLAG_debug_code) { |
| 3285 | __ AbortIfNotString(rax); |
| 3286 | } |
| 3287 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3288 | __ movl(rax, FieldOperand(rax, String::kHashFieldOffset)); |
| 3289 | ASSERT(String::kHashShift >= kSmiTagSize); |
| 3290 | __ IndexFromHash(rax, rax); |
| 3291 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3292 | context()->Plug(rax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3296 | void FullCodeGenerator::EmitFastAsciiArrayJoin(ZoneList<Expression*>* args) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3297 | Label bailout, return_result, done, one_char_separator, long_separator, |
| 3298 | non_trivial_array, not_size_one_array, loop, |
| 3299 | loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry; |
| 3300 | ASSERT(args->length() == 2); |
| 3301 | // We will leave the separator on the stack until the end of the function. |
| 3302 | VisitForStackValue(args->at(1)); |
| 3303 | // Load this to rax (= array) |
| 3304 | VisitForAccumulatorValue(args->at(0)); |
| 3305 | // All aliases of the same register have disjoint lifetimes. |
| 3306 | Register array = rax; |
| 3307 | Register elements = no_reg; // Will be rax. |
| 3308 | |
| 3309 | Register index = rdx; |
| 3310 | |
| 3311 | Register string_length = rcx; |
| 3312 | |
| 3313 | Register string = rsi; |
| 3314 | |
| 3315 | Register scratch = rbx; |
| 3316 | |
| 3317 | Register array_length = rdi; |
| 3318 | Register result_pos = no_reg; // Will be rdi. |
| 3319 | |
| 3320 | Operand separator_operand = Operand(rsp, 2 * kPointerSize); |
| 3321 | Operand result_operand = Operand(rsp, 1 * kPointerSize); |
| 3322 | Operand array_length_operand = Operand(rsp, 0 * kPointerSize); |
| 3323 | // Separator operand is already pushed. Make room for the two |
| 3324 | // other stack fields, and clear the direction flag in anticipation |
| 3325 | // of calling CopyBytes. |
| 3326 | __ subq(rsp, Immediate(2 * kPointerSize)); |
| 3327 | __ cld(); |
| 3328 | // Check that the array is a JSArray |
| 3329 | __ JumpIfSmi(array, &bailout); |
| 3330 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 3331 | __ j(not_equal, &bailout); |
| 3332 | |
| 3333 | // Check that the array has fast elements. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3334 | __ CheckFastElements(scratch, &bailout); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3335 | |
| 3336 | // Array has fast elements, so its length must be a smi. |
| 3337 | // If the array has length zero, return the empty string. |
| 3338 | __ movq(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
| 3339 | __ SmiCompare(array_length, Smi::FromInt(0)); |
| 3340 | __ j(not_zero, &non_trivial_array); |
| 3341 | __ LoadRoot(rax, Heap::kEmptyStringRootIndex); |
| 3342 | __ jmp(&return_result); |
| 3343 | |
| 3344 | // Save the array length on the stack. |
| 3345 | __ bind(&non_trivial_array); |
| 3346 | __ SmiToInteger32(array_length, array_length); |
| 3347 | __ movl(array_length_operand, array_length); |
| 3348 | |
| 3349 | // Save the FixedArray containing array's elements. |
| 3350 | // End of array's live range. |
| 3351 | elements = array; |
| 3352 | __ movq(elements, FieldOperand(array, JSArray::kElementsOffset)); |
| 3353 | array = no_reg; |
| 3354 | |
| 3355 | |
| 3356 | // Check that all array elements are sequential ASCII strings, and |
| 3357 | // accumulate the sum of their lengths, as a smi-encoded value. |
| 3358 | __ Set(index, 0); |
| 3359 | __ Set(string_length, 0); |
| 3360 | // Loop condition: while (index < array_length). |
| 3361 | // Live loop registers: index(int32), array_length(int32), string(String*), |
| 3362 | // scratch, string_length(int32), elements(FixedArray*). |
| 3363 | if (FLAG_debug_code) { |
| 3364 | __ cmpq(index, array_length); |
| 3365 | __ Assert(below, "No empty arrays here in EmitFastAsciiArrayJoin"); |
| 3366 | } |
| 3367 | __ bind(&loop); |
| 3368 | __ movq(string, FieldOperand(elements, |
| 3369 | index, |
| 3370 | times_pointer_size, |
| 3371 | FixedArray::kHeaderSize)); |
| 3372 | __ JumpIfSmi(string, &bailout); |
| 3373 | __ movq(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3374 | __ movzxbl(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3375 | __ andb(scratch, Immediate( |
| 3376 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 3377 | __ cmpb(scratch, Immediate(kStringTag | kAsciiStringTag | kSeqStringTag)); |
| 3378 | __ j(not_equal, &bailout); |
| 3379 | __ AddSmiField(string_length, |
| 3380 | FieldOperand(string, SeqAsciiString::kLengthOffset)); |
| 3381 | __ j(overflow, &bailout); |
| 3382 | __ incl(index); |
| 3383 | __ cmpl(index, array_length); |
| 3384 | __ j(less, &loop); |
| 3385 | |
| 3386 | // Live registers: |
| 3387 | // string_length: Sum of string lengths. |
| 3388 | // elements: FixedArray of strings. |
| 3389 | // index: Array length. |
| 3390 | // array_length: Array length. |
| 3391 | |
| 3392 | // If array_length is 1, return elements[0], a string. |
| 3393 | __ cmpl(array_length, Immediate(1)); |
| 3394 | __ j(not_equal, ¬_size_one_array); |
| 3395 | __ movq(rax, FieldOperand(elements, FixedArray::kHeaderSize)); |
| 3396 | __ jmp(&return_result); |
| 3397 | |
| 3398 | __ bind(¬_size_one_array); |
| 3399 | |
| 3400 | // End of array_length live range. |
| 3401 | result_pos = array_length; |
| 3402 | array_length = no_reg; |
| 3403 | |
| 3404 | // Live registers: |
| 3405 | // string_length: Sum of string lengths. |
| 3406 | // elements: FixedArray of strings. |
| 3407 | // index: Array length. |
| 3408 | |
| 3409 | // Check that the separator is a sequential ASCII string. |
| 3410 | __ movq(string, separator_operand); |
| 3411 | __ JumpIfSmi(string, &bailout); |
| 3412 | __ movq(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3413 | __ movzxbl(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3414 | __ andb(scratch, Immediate( |
| 3415 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 3416 | __ cmpb(scratch, Immediate(kStringTag | kAsciiStringTag | kSeqStringTag)); |
| 3417 | __ j(not_equal, &bailout); |
| 3418 | |
| 3419 | // Live registers: |
| 3420 | // string_length: Sum of string lengths. |
| 3421 | // elements: FixedArray of strings. |
| 3422 | // index: Array length. |
| 3423 | // string: Separator string. |
| 3424 | |
| 3425 | // Add (separator length times (array_length - 1)) to string_length. |
| 3426 | __ SmiToInteger32(scratch, |
| 3427 | FieldOperand(string, SeqAsciiString::kLengthOffset)); |
| 3428 | __ decl(index); |
| 3429 | __ imull(scratch, index); |
| 3430 | __ j(overflow, &bailout); |
| 3431 | __ addl(string_length, scratch); |
| 3432 | __ j(overflow, &bailout); |
| 3433 | |
| 3434 | // Live registers and stack values: |
| 3435 | // string_length: Total length of result string. |
| 3436 | // elements: FixedArray of strings. |
| 3437 | __ AllocateAsciiString(result_pos, string_length, scratch, |
| 3438 | index, string, &bailout); |
| 3439 | __ movq(result_operand, result_pos); |
| 3440 | __ lea(result_pos, FieldOperand(result_pos, SeqAsciiString::kHeaderSize)); |
| 3441 | |
| 3442 | __ movq(string, separator_operand); |
| 3443 | __ SmiCompare(FieldOperand(string, SeqAsciiString::kLengthOffset), |
| 3444 | Smi::FromInt(1)); |
| 3445 | __ j(equal, &one_char_separator); |
| 3446 | __ j(greater, &long_separator); |
| 3447 | |
| 3448 | |
| 3449 | // Empty separator case: |
| 3450 | __ Set(index, 0); |
| 3451 | __ movl(scratch, array_length_operand); |
| 3452 | __ jmp(&loop_1_condition); |
| 3453 | // Loop condition: while (index < array_length). |
| 3454 | __ bind(&loop_1); |
| 3455 | // Each iteration of the loop concatenates one string to the result. |
| 3456 | // Live values in registers: |
| 3457 | // index: which element of the elements array we are adding to the result. |
| 3458 | // result_pos: the position to which we are currently copying characters. |
| 3459 | // elements: the FixedArray of strings we are joining. |
| 3460 | // scratch: array length. |
| 3461 | |
| 3462 | // Get string = array[index]. |
| 3463 | __ movq(string, FieldOperand(elements, index, |
| 3464 | times_pointer_size, |
| 3465 | FixedArray::kHeaderSize)); |
| 3466 | __ SmiToInteger32(string_length, |
| 3467 | FieldOperand(string, String::kLengthOffset)); |
| 3468 | __ lea(string, |
| 3469 | FieldOperand(string, SeqAsciiString::kHeaderSize)); |
| 3470 | __ CopyBytes(result_pos, string, string_length); |
| 3471 | __ incl(index); |
| 3472 | __ bind(&loop_1_condition); |
| 3473 | __ cmpl(index, scratch); |
| 3474 | __ j(less, &loop_1); // Loop while (index < array_length). |
| 3475 | __ jmp(&done); |
| 3476 | |
| 3477 | // Generic bailout code used from several places. |
| 3478 | __ bind(&bailout); |
| 3479 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 3480 | __ jmp(&return_result); |
| 3481 | |
| 3482 | |
| 3483 | // One-character separator case |
| 3484 | __ bind(&one_char_separator); |
| 3485 | // Get the separator ascii character value. |
| 3486 | // Register "string" holds the separator. |
| 3487 | __ movzxbl(scratch, FieldOperand(string, SeqAsciiString::kHeaderSize)); |
| 3488 | __ Set(index, 0); |
| 3489 | // Jump into the loop after the code that copies the separator, so the first |
| 3490 | // element is not preceded by a separator |
| 3491 | __ jmp(&loop_2_entry); |
| 3492 | // Loop condition: while (index < length). |
| 3493 | __ bind(&loop_2); |
| 3494 | // Each iteration of the loop concatenates one string to the result. |
| 3495 | // Live values in registers: |
| 3496 | // elements: The FixedArray of strings we are joining. |
| 3497 | // index: which element of the elements array we are adding to the result. |
| 3498 | // result_pos: the position to which we are currently copying characters. |
| 3499 | // scratch: Separator character. |
| 3500 | |
| 3501 | // Copy the separator character to the result. |
| 3502 | __ movb(Operand(result_pos, 0), scratch); |
| 3503 | __ incq(result_pos); |
| 3504 | |
| 3505 | __ bind(&loop_2_entry); |
| 3506 | // Get string = array[index]. |
| 3507 | __ movq(string, FieldOperand(elements, index, |
| 3508 | times_pointer_size, |
| 3509 | FixedArray::kHeaderSize)); |
| 3510 | __ SmiToInteger32(string_length, |
| 3511 | FieldOperand(string, String::kLengthOffset)); |
| 3512 | __ lea(string, |
| 3513 | FieldOperand(string, SeqAsciiString::kHeaderSize)); |
| 3514 | __ CopyBytes(result_pos, string, string_length); |
| 3515 | __ incl(index); |
| 3516 | __ cmpl(index, array_length_operand); |
| 3517 | __ j(less, &loop_2); // End while (index < length). |
| 3518 | __ jmp(&done); |
| 3519 | |
| 3520 | |
| 3521 | // Long separator case (separator is more than one character). |
| 3522 | __ bind(&long_separator); |
| 3523 | |
| 3524 | // Make elements point to end of elements array, and index |
| 3525 | // count from -array_length to zero, so we don't need to maintain |
| 3526 | // a loop limit. |
| 3527 | __ movl(index, array_length_operand); |
| 3528 | __ lea(elements, FieldOperand(elements, index, times_pointer_size, |
| 3529 | FixedArray::kHeaderSize)); |
| 3530 | __ neg(index); |
| 3531 | |
| 3532 | // Replace separator string with pointer to its first character, and |
| 3533 | // make scratch be its length. |
| 3534 | __ movq(string, separator_operand); |
| 3535 | __ SmiToInteger32(scratch, |
| 3536 | FieldOperand(string, String::kLengthOffset)); |
| 3537 | __ lea(string, |
| 3538 | FieldOperand(string, SeqAsciiString::kHeaderSize)); |
| 3539 | __ movq(separator_operand, string); |
| 3540 | |
| 3541 | // Jump into the loop after the code that copies the separator, so the first |
| 3542 | // element is not preceded by a separator |
| 3543 | __ jmp(&loop_3_entry); |
| 3544 | // Loop condition: while (index < length). |
| 3545 | __ bind(&loop_3); |
| 3546 | // Each iteration of the loop concatenates one string to the result. |
| 3547 | // Live values in registers: |
| 3548 | // index: which element of the elements array we are adding to the result. |
| 3549 | // result_pos: the position to which we are currently copying characters. |
| 3550 | // scratch: Separator length. |
| 3551 | // separator_operand (rsp[0x10]): Address of first char of separator. |
| 3552 | |
| 3553 | // Copy the separator to the result. |
| 3554 | __ movq(string, separator_operand); |
| 3555 | __ movl(string_length, scratch); |
| 3556 | __ CopyBytes(result_pos, string, string_length, 2); |
| 3557 | |
| 3558 | __ bind(&loop_3_entry); |
| 3559 | // Get string = array[index]. |
| 3560 | __ movq(string, Operand(elements, index, times_pointer_size, 0)); |
| 3561 | __ SmiToInteger32(string_length, |
| 3562 | FieldOperand(string, String::kLengthOffset)); |
| 3563 | __ lea(string, |
| 3564 | FieldOperand(string, SeqAsciiString::kHeaderSize)); |
| 3565 | __ CopyBytes(result_pos, string, string_length); |
| 3566 | __ incq(index); |
| 3567 | __ j(not_equal, &loop_3); // Loop while (index < 0). |
| 3568 | |
| 3569 | __ bind(&done); |
| 3570 | __ movq(rax, result_operand); |
| 3571 | |
| 3572 | __ bind(&return_result); |
| 3573 | // Drop temp values from the stack, and restore context register. |
| 3574 | __ addq(rsp, Immediate(3 * kPointerSize)); |
| 3575 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 3576 | context()->Plug(rax); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3580 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3581 | Handle<String> name = expr->name(); |
| 3582 | if (name->length() > 0 && name->Get(0) == '_') { |
| 3583 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 3584 | EmitInlineRuntimeCall(expr); |
| 3585 | return; |
| 3586 | } |
| 3587 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3588 | Comment cmnt(masm_, "[ CallRuntime"); |
| 3589 | ZoneList<Expression*>* args = expr->arguments(); |
| 3590 | |
| 3591 | if (expr->is_jsruntime()) { |
| 3592 | // Prepare for calling JS runtime function. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3593 | __ movq(rax, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3594 | __ push(FieldOperand(rax, GlobalObject::kBuiltinsOffset)); |
| 3595 | } |
| 3596 | |
| 3597 | // Push the arguments ("left-to-right"). |
| 3598 | int arg_count = args->length(); |
| 3599 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3600 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | if (expr->is_jsruntime()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3604 | // Call the JS runtime function using a call IC. |
| 3605 | __ Move(rcx, expr->name()); |
| 3606 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3607 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3608 | Handle<Code> ic = |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3609 | ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode); |
| 3610 | EmitCallIC(ic, mode, expr->id()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3611 | // Restore context register. |
| 3612 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3613 | } else { |
| 3614 | __ CallRuntime(expr->function(), arg_count); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3615 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3616 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | |
| 3620 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 3621 | switch (expr->op()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3622 | case Token::DELETE: { |
| 3623 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
| 3624 | Property* prop = expr->expression()->AsProperty(); |
| 3625 | Variable* var = expr->expression()->AsVariableProxy()->AsVariable(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3626 | |
| 3627 | if (prop != NULL) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3628 | if (prop->is_synthetic()) { |
| 3629 | // Result of deleting parameters is false, even when they rewrite |
| 3630 | // to accesses on the arguments object. |
| 3631 | context()->Plug(false); |
| 3632 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3633 | VisitForStackValue(prop->obj()); |
| 3634 | VisitForStackValue(prop->key()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3635 | __ Push(Smi::FromInt(strict_mode_flag())); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3636 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3637 | context()->Plug(rax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3638 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3639 | } else if (var != NULL) { |
| 3640 | // Delete of an unqualified identifier is disallowed in strict mode |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3641 | // but "delete this" is. |
| 3642 | ASSERT(strict_mode_flag() == kNonStrictMode || var->is_this()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3643 | if (var->is_global()) { |
| 3644 | __ push(GlobalObjectOperand()); |
| 3645 | __ Push(var->name()); |
| 3646 | __ Push(Smi::FromInt(kNonStrictMode)); |
| 3647 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 3648 | context()->Plug(rax); |
| 3649 | } else if (var->AsSlot() != NULL && |
| 3650 | var->AsSlot()->type() != Slot::LOOKUP) { |
| 3651 | // Result of deleting non-global, non-dynamic variables is false. |
| 3652 | // The subexpression does not have side effects. |
| 3653 | context()->Plug(false); |
| 3654 | } else { |
| 3655 | // Non-global variable. Call the runtime to try to delete from the |
| 3656 | // context where the variable was introduced. |
| 3657 | __ push(context_register()); |
| 3658 | __ Push(var->name()); |
| 3659 | __ CallRuntime(Runtime::kDeleteContextSlot, 2); |
| 3660 | context()->Plug(rax); |
| 3661 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3662 | } else { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3663 | // Result of deleting non-property, non-variable reference is true. |
| 3664 | // The subexpression may have side effects. |
| 3665 | VisitForEffect(expr->expression()); |
| 3666 | context()->Plug(true); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3667 | } |
| 3668 | break; |
| 3669 | } |
| 3670 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3671 | case Token::VOID: { |
| 3672 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 3673 | VisitForEffect(expr->expression()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3674 | context()->Plug(Heap::kUndefinedValueRootIndex); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3675 | break; |
| 3676 | } |
| 3677 | |
| 3678 | case Token::NOT: { |
| 3679 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3680 | if (context()->IsEffect()) { |
| 3681 | // Unary NOT has no side effects so it's only necessary to visit the |
| 3682 | // subexpression. Match the optimizing compiler by not branching. |
| 3683 | VisitForEffect(expr->expression()); |
| 3684 | } else { |
| 3685 | Label materialize_true, materialize_false; |
| 3686 | Label* if_true = NULL; |
| 3687 | Label* if_false = NULL; |
| 3688 | Label* fall_through = NULL; |
| 3689 | // Notice that the labels are swapped. |
| 3690 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3691 | &if_false, &if_true, &fall_through); |
| 3692 | if (context()->IsTest()) ForwardBailoutToChild(expr); |
| 3693 | VisitForControl(expr->expression(), if_true, if_false, fall_through); |
| 3694 | context()->Plug(if_false, if_true); // Labels swapped. |
| 3695 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3696 | break; |
| 3697 | } |
| 3698 | |
| 3699 | case Token::TYPEOF: { |
| 3700 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3701 | { StackValueContext context(this); |
| 3702 | VisitForTypeofValue(expr->expression()); |
| 3703 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3704 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3705 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3706 | break; |
| 3707 | } |
| 3708 | |
| 3709 | case Token::ADD: { |
| 3710 | Comment cmt(masm_, "[ UnaryOperation (ADD)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3711 | VisitForAccumulatorValue(expr->expression()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3712 | Label no_conversion; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3713 | Condition is_smi = masm_->CheckSmi(result_register()); |
| 3714 | __ j(is_smi, &no_conversion); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3715 | ToNumberStub convert_stub; |
| 3716 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3717 | __ bind(&no_conversion); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3718 | context()->Plug(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3719 | break; |
| 3720 | } |
| 3721 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3722 | case Token::SUB: |
| 3723 | EmitUnaryOperation(expr, "[ UnaryOperation (SUB)"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3724 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3725 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3726 | case Token::BIT_NOT: |
| 3727 | EmitUnaryOperation(expr, "[ UnaryOperation (BIT_NOT)"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3728 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3729 | |
| 3730 | default: |
| 3731 | UNREACHABLE(); |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3736 | void FullCodeGenerator::EmitUnaryOperation(UnaryOperation* expr, |
| 3737 | const char* comment) { |
| 3738 | // TODO(svenpanne): Allowing format strings in Comment would be nice here... |
| 3739 | Comment cmt(masm_, comment); |
| 3740 | bool can_overwrite = expr->expression()->ResultOverwriteAllowed(); |
| 3741 | UnaryOverwriteMode overwrite = |
| 3742 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3743 | UnaryOpStub stub(expr->op(), overwrite); |
| 3744 | // UnaryOpStub expects the argument to be in the |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3745 | // accumulator register rax. |
| 3746 | VisitForAccumulatorValue(expr->expression()); |
| 3747 | SetSourcePosition(expr->position()); |
| 3748 | EmitCallIC(stub.GetCode(), NULL, expr->id()); |
| 3749 | context()->Plug(rax); |
| 3750 | } |
| 3751 | |
| 3752 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3753 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 3754 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3755 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3756 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3757 | // Invalid left-hand-sides are rewritten to have a 'throw |
| 3758 | // ReferenceError' as the left-hand side. |
| 3759 | if (!expr->expression()->IsValidLeftHandSide()) { |
| 3760 | VisitForEffect(expr->expression()); |
| 3761 | return; |
| 3762 | } |
| 3763 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3764 | // Expression can only be a property, a global or a (parameter or local) |
| 3765 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 3766 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 3767 | LhsKind assign_type = VARIABLE; |
| 3768 | Property* prop = expr->expression()->AsProperty(); |
| 3769 | // In case of a property we use the uninitialized expression context |
| 3770 | // of the key to detect a named property. |
| 3771 | if (prop != NULL) { |
| 3772 | assign_type = |
| 3773 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 3774 | } |
| 3775 | |
| 3776 | // Evaluate expression and get value. |
| 3777 | if (assign_type == VARIABLE) { |
| 3778 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3779 | AccumulatorValueContext context(this); |
| 3780 | EmitVariableLoad(expr->expression()->AsVariableProxy()->var()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3781 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3782 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3783 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3784 | __ Push(Smi::FromInt(0)); |
| 3785 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3786 | if (assign_type == NAMED_PROPERTY) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3787 | VisitForAccumulatorValue(prop->obj()); |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 3788 | __ push(rax); // Copy of receiver, needed for later store. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3789 | EmitNamedPropertyLoad(prop); |
| 3790 | } else { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3791 | if (prop->is_arguments_access()) { |
| 3792 | VariableProxy* obj_proxy = prop->obj()->AsVariableProxy(); |
| 3793 | MemOperand slot_operand = |
| 3794 | EmitSlotSearch(obj_proxy->var()->AsSlot(), rcx); |
| 3795 | __ push(slot_operand); |
| 3796 | __ Move(rax, prop->key()->AsLiteral()->handle()); |
| 3797 | } else { |
| 3798 | VisitForStackValue(prop->obj()); |
| 3799 | VisitForAccumulatorValue(prop->key()); |
| 3800 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3801 | __ movq(rdx, Operand(rsp, 0)); // Leave receiver on stack |
| 3802 | __ push(rax); // Copy of key, needed for later store. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3803 | EmitKeyedPropertyLoad(prop); |
| 3804 | } |
| 3805 | } |
| 3806 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3807 | // We need a second deoptimization point after loading the value |
| 3808 | // in case evaluating the property load my have a side effect. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3809 | if (assign_type == VARIABLE) { |
| 3810 | PrepareForBailout(expr->expression(), TOS_REG); |
| 3811 | } else { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3812 | PrepareForBailoutForId(expr->CountId(), TOS_REG); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3813 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3814 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3815 | // Call ToNumber only if operand is not a smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3816 | Label no_conversion; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3817 | Condition is_smi; |
| 3818 | is_smi = masm_->CheckSmi(rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3819 | __ j(is_smi, &no_conversion, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3820 | ToNumberStub convert_stub; |
| 3821 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3822 | __ bind(&no_conversion); |
| 3823 | |
| 3824 | // Save result for postfix expressions. |
| 3825 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3826 | if (!context()->IsEffect()) { |
| 3827 | // Save the result on the stack. If we have a named or keyed property |
| 3828 | // we store the result under the receiver that is currently on top |
| 3829 | // of the stack. |
| 3830 | switch (assign_type) { |
| 3831 | case VARIABLE: |
| 3832 | __ push(rax); |
| 3833 | break; |
| 3834 | case NAMED_PROPERTY: |
| 3835 | __ movq(Operand(rsp, kPointerSize), rax); |
| 3836 | break; |
| 3837 | case KEYED_PROPERTY: |
| 3838 | __ movq(Operand(rsp, 2 * kPointerSize), rax); |
| 3839 | break; |
| 3840 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | // Inline smi case if we are in a loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3845 | Label done, stub_call; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 3846 | JumpPatchSite patch_site(masm_); |
| 3847 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3848 | if (ShouldInlineSmiCase(expr->op())) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3849 | if (expr->op() == Token::INC) { |
| 3850 | __ SmiAddConstant(rax, rax, Smi::FromInt(1)); |
| 3851 | } else { |
| 3852 | __ SmiSubConstant(rax, rax, Smi::FromInt(1)); |
| 3853 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3854 | __ j(overflow, &stub_call, Label::kNear); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3855 | // We could eliminate this smi check if we split the code at |
| 3856 | // the first smi check before calling ToNumber. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3857 | patch_site.EmitJumpIfSmi(rax, &done, Label::kNear); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3858 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3859 | __ bind(&stub_call); |
| 3860 | // Call stub. Undo operation first. |
| 3861 | if (expr->op() == Token::INC) { |
| 3862 | __ SmiSubConstant(rax, rax, Smi::FromInt(1)); |
| 3863 | } else { |
| 3864 | __ SmiAddConstant(rax, rax, Smi::FromInt(1)); |
| 3865 | } |
| 3866 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3867 | |
| 3868 | // Record position before stub call. |
| 3869 | SetSourcePosition(expr->position()); |
| 3870 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3871 | // Call stub for +1/-1. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3872 | BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3873 | if (expr->op() == Token::INC) { |
| 3874 | __ Move(rdx, Smi::FromInt(1)); |
| 3875 | } else { |
| 3876 | __ movq(rdx, rax); |
| 3877 | __ Move(rax, Smi::FromInt(1)); |
| 3878 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3879 | EmitCallIC(stub.GetCode(), &patch_site, expr->CountId()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3880 | __ bind(&done); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 3881 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3882 | // Store the value returned in rax. |
| 3883 | switch (assign_type) { |
| 3884 | case VARIABLE: |
| 3885 | if (expr->is_postfix()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3886 | // Perform the assignment as if via '='. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3887 | { EffectContext context(this); |
| 3888 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 3889 | Token::ASSIGN); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3890 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3891 | context.Plug(rax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3892 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3893 | // For all contexts except kEffect: We have the result on |
| 3894 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3895 | if (!context()->IsEffect()) { |
| 3896 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3897 | } |
| 3898 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3899 | // Perform the assignment as if via '='. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3900 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3901 | Token::ASSIGN); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3902 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3903 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3904 | } |
| 3905 | break; |
| 3906 | case NAMED_PROPERTY: { |
| 3907 | __ Move(rcx, prop->key()->AsLiteral()->handle()); |
| 3908 | __ pop(rdx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3909 | Handle<Code> ic = is_strict_mode() |
| 3910 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 3911 | : isolate()->builtins()->StoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3912 | EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3913 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3914 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3915 | if (!context()->IsEffect()) { |
| 3916 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3917 | } |
| 3918 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3919 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3920 | } |
| 3921 | break; |
| 3922 | } |
| 3923 | case KEYED_PROPERTY: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3924 | __ pop(rcx); |
| 3925 | __ pop(rdx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3926 | Handle<Code> ic = is_strict_mode() |
| 3927 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 3928 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3929 | EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3930 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3931 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3932 | if (!context()->IsEffect()) { |
| 3933 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3934 | } |
| 3935 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3936 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3937 | } |
| 3938 | break; |
| 3939 | } |
| 3940 | } |
| 3941 | } |
| 3942 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3943 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3944 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3945 | VariableProxy* proxy = expr->AsVariableProxy(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3946 | ASSERT(!context()->IsEffect()); |
| 3947 | ASSERT(!context()->IsTest()); |
| 3948 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3949 | if (proxy != NULL && !proxy->var()->is_this() && proxy->var()->is_global()) { |
| 3950 | Comment cmnt(masm_, "Global variable"); |
| 3951 | __ Move(rcx, proxy->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3952 | __ movq(rax, GlobalObjectOperand()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3953 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3954 | // Use a regular load, not a contextual load, to avoid a reference |
| 3955 | // error. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3956 | EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3957 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3958 | context()->Plug(rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3959 | } else if (proxy != NULL && |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3960 | proxy->var()->AsSlot() != NULL && |
| 3961 | proxy->var()->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3962 | Label done, slow; |
| 3963 | |
| 3964 | // Generate code for loading from variables potentially shadowed |
| 3965 | // by eval-introduced variables. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3966 | Slot* slot = proxy->var()->AsSlot(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3967 | EmitDynamicLoadFromSlotFastCase(slot, INSIDE_TYPEOF, &slow, &done); |
| 3968 | |
| 3969 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3970 | __ push(rsi); |
| 3971 | __ Push(proxy->name()); |
| 3972 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3973 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3974 | __ bind(&done); |
| 3975 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3976 | context()->Plug(rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3977 | } else { |
| 3978 | // This expression cannot throw a reference error at the top level. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3979 | VisitInCurrentContext(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3980 | } |
| 3981 | } |
| 3982 | |
| 3983 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3984 | bool FullCodeGenerator::TryLiteralCompare(Token::Value op, |
| 3985 | Expression* left, |
| 3986 | Expression* right, |
| 3987 | Label* if_true, |
| 3988 | Label* if_false, |
| 3989 | Label* fall_through) { |
| 3990 | if (op != Token::EQ && op != Token::EQ_STRICT) return false; |
| 3991 | |
| 3992 | // Check for the pattern: typeof <expression> == <string literal>. |
| 3993 | Literal* right_literal = right->AsLiteral(); |
| 3994 | if (right_literal == NULL) return false; |
| 3995 | Handle<Object> right_literal_value = right_literal->handle(); |
| 3996 | if (!right_literal_value->IsString()) return false; |
| 3997 | UnaryOperation* left_unary = left->AsUnaryOperation(); |
| 3998 | if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false; |
| 3999 | Handle<String> check = Handle<String>::cast(right_literal_value); |
| 4000 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4001 | { AccumulatorValueContext context(this); |
| 4002 | VisitForTypeofValue(left_unary->expression()); |
| 4003 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4004 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4005 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4006 | if (check->Equals(isolate()->heap()->number_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4007 | __ JumpIfSmi(rax, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4008 | __ movq(rax, FieldOperand(rax, HeapObject::kMapOffset)); |
| 4009 | __ CompareRoot(rax, Heap::kHeapNumberMapRootIndex); |
| 4010 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4011 | } else if (check->Equals(isolate()->heap()->string_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4012 | __ JumpIfSmi(rax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4013 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4014 | __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdx); |
| 4015 | __ j(above_equal, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4016 | __ testb(FieldOperand(rdx, Map::kBitFieldOffset), |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4017 | Immediate(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4018 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4019 | } else if (check->Equals(isolate()->heap()->boolean_symbol())) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4020 | __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
| 4021 | __ j(equal, if_true); |
| 4022 | __ CompareRoot(rax, Heap::kFalseValueRootIndex); |
| 4023 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4024 | } else if (check->Equals(isolate()->heap()->undefined_symbol())) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4025 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 4026 | __ j(equal, if_true); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4027 | __ JumpIfSmi(rax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4028 | // Check for undetectable objects => true. |
| 4029 | __ movq(rdx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 4030 | __ testb(FieldOperand(rdx, Map::kBitFieldOffset), |
| 4031 | Immediate(1 << Map::kIsUndetectable)); |
| 4032 | Split(not_zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4033 | } else if (check->Equals(isolate()->heap()->function_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4034 | __ JumpIfSmi(rax, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4035 | STATIC_ASSERT(LAST_CALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 4036 | __ CmpObjectType(rax, FIRST_CALLABLE_SPEC_OBJECT_TYPE, rdx); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4037 | Split(above_equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4038 | } else if (check->Equals(isolate()->heap()->object_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4039 | __ JumpIfSmi(rax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4040 | __ CompareRoot(rax, Heap::kNullValueRootIndex); |
| 4041 | __ j(equal, if_true); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4042 | __ CmpObjectType(rax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, rdx); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4043 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4044 | __ CmpInstanceType(rdx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4045 | __ j(above, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4046 | // Check for undetectable objects => false. |
| 4047 | __ testb(FieldOperand(rdx, Map::kBitFieldOffset), |
| 4048 | Immediate(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4049 | Split(zero, if_true, if_false, fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4050 | } else { |
| 4051 | if (if_false != fall_through) __ jmp(if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4052 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4053 | |
| 4054 | return true; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4058 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 4059 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4060 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4061 | |
| 4062 | // Always perform the comparison for its control flow. Pack the result |
| 4063 | // into the expression's context after the comparison is performed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4064 | Label materialize_true, materialize_false; |
| 4065 | Label* if_true = NULL; |
| 4066 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4067 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4068 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4069 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4070 | |
| 4071 | // First we try a fast inlined version of the compare when one of |
| 4072 | // the operands is a literal. |
| 4073 | Token::Value op = expr->op(); |
| 4074 | Expression* left = expr->left(); |
| 4075 | Expression* right = expr->right(); |
| 4076 | if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4077 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4078 | return; |
| 4079 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4080 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4081 | VisitForStackValue(expr->left()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4082 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4083 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4084 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4085 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4086 | PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4087 | __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4088 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4089 | break; |
| 4090 | |
| 4091 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4092 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4093 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4094 | __ CallStub(&stub); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4095 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4096 | __ testq(rax, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4097 | // The stub returns 0 for true. |
| 4098 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4099 | break; |
| 4100 | } |
| 4101 | |
| 4102 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4103 | VisitForAccumulatorValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4104 | Condition cc = no_condition; |
| 4105 | bool strict = false; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4106 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4107 | case Token::EQ_STRICT: |
| 4108 | strict = true; |
| 4109 | // Fall through. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4110 | case Token::EQ: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4111 | cc = equal; |
| 4112 | __ pop(rdx); |
| 4113 | break; |
| 4114 | case Token::LT: |
| 4115 | cc = less; |
| 4116 | __ pop(rdx); |
| 4117 | break; |
| 4118 | case Token::GT: |
| 4119 | // Reverse left and right sizes to obtain ECMA-262 conversion order. |
| 4120 | cc = less; |
| 4121 | __ movq(rdx, result_register()); |
| 4122 | __ pop(rax); |
| 4123 | break; |
| 4124 | case Token::LTE: |
| 4125 | // Reverse left and right sizes to obtain ECMA-262 conversion order. |
| 4126 | cc = greater_equal; |
| 4127 | __ movq(rdx, result_register()); |
| 4128 | __ pop(rax); |
| 4129 | break; |
| 4130 | case Token::GTE: |
| 4131 | cc = greater_equal; |
| 4132 | __ pop(rdx); |
| 4133 | break; |
| 4134 | case Token::IN: |
| 4135 | case Token::INSTANCEOF: |
| 4136 | default: |
| 4137 | UNREACHABLE(); |
| 4138 | } |
| 4139 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4140 | bool inline_smi_code = ShouldInlineSmiCase(op); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4141 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4142 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4143 | Label slow_case; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4144 | __ movq(rcx, rdx); |
| 4145 | __ or_(rcx, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4146 | patch_site.EmitJumpIfNotSmi(rcx, &slow_case, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4147 | __ cmpq(rdx, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4148 | Split(cc, if_true, if_false, NULL); |
| 4149 | __ bind(&slow_case); |
| 4150 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4151 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4152 | // Record position and call the compare IC. |
| 4153 | SetSourcePosition(expr->position()); |
| 4154 | Handle<Code> ic = CompareIC::GetUninitialized(op); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4155 | EmitCallIC(ic, &patch_site, expr->id()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4156 | |
| 4157 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4158 | __ testq(rax, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4159 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4160 | } |
| 4161 | } |
| 4162 | |
| 4163 | // Convert the result of the comparison into one expected for this |
| 4164 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4165 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4169 | void FullCodeGenerator::VisitCompareToNull(CompareToNull* expr) { |
| 4170 | Comment cmnt(masm_, "[ CompareToNull"); |
| 4171 | Label materialize_true, materialize_false; |
| 4172 | Label* if_true = NULL; |
| 4173 | Label* if_false = NULL; |
| 4174 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4175 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4176 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4177 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4178 | VisitForAccumulatorValue(expr->expression()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4179 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4180 | __ CompareRoot(rax, Heap::kNullValueRootIndex); |
| 4181 | if (expr->is_strict()) { |
| 4182 | Split(equal, if_true, if_false, fall_through); |
| 4183 | } else { |
| 4184 | __ j(equal, if_true); |
| 4185 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 4186 | __ j(equal, if_true); |
| 4187 | Condition is_smi = masm_->CheckSmi(rax); |
| 4188 | __ j(is_smi, if_false); |
| 4189 | // It can be an undetectable object. |
| 4190 | __ movq(rdx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 4191 | __ testb(FieldOperand(rdx, Map::kBitFieldOffset), |
| 4192 | Immediate(1 << Map::kIsUndetectable)); |
| 4193 | Split(not_zero, if_true, if_false, fall_through); |
| 4194 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4195 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4199 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 4200 | __ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4201 | context()->Plug(rax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4205 | Register FullCodeGenerator::result_register() { |
| 4206 | return rax; |
| 4207 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4208 | |
| 4209 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4210 | Register FullCodeGenerator::context_register() { |
| 4211 | return rsi; |
| 4212 | } |
| 4213 | |
| 4214 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4215 | void FullCodeGenerator::EmitCallIC(Handle<Code> ic, |
| 4216 | RelocInfo::Mode mode, |
| 4217 | unsigned ast_id) { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4218 | ASSERT(mode == RelocInfo::CODE_TARGET || |
| 4219 | mode == RelocInfo::CODE_TARGET_CONTEXT); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4220 | Counters* counters = isolate()->counters(); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4221 | switch (ic->kind()) { |
| 4222 | case Code::LOAD_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4223 | __ IncrementCounter(counters->named_load_full(), 1); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4224 | break; |
| 4225 | case Code::KEYED_LOAD_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4226 | __ IncrementCounter(counters->keyed_load_full(), 1); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4227 | break; |
| 4228 | case Code::STORE_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4229 | __ IncrementCounter(counters->named_store_full(), 1); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4230 | break; |
| 4231 | case Code::KEYED_STORE_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4232 | __ IncrementCounter(counters->keyed_store_full(), 1); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4233 | default: |
| 4234 | break; |
| 4235 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4236 | __ call(ic, mode, ast_id); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4237 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4238 | |
| 4239 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4240 | void FullCodeGenerator::EmitCallIC(Handle<Code> ic, |
| 4241 | JumpPatchSite* patch_site, |
| 4242 | unsigned ast_id) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4243 | Counters* counters = isolate()->counters(); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 4244 | switch (ic->kind()) { |
| 4245 | case Code::LOAD_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4246 | __ IncrementCounter(counters->named_load_full(), 1); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 4247 | break; |
| 4248 | case Code::KEYED_LOAD_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4249 | __ IncrementCounter(counters->keyed_load_full(), 1); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 4250 | break; |
| 4251 | case Code::STORE_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4252 | __ IncrementCounter(counters->named_store_full(), 1); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 4253 | break; |
| 4254 | case Code::KEYED_STORE_IC: |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4255 | __ IncrementCounter(counters->keyed_store_full(), 1); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 4256 | default: |
| 4257 | break; |
| 4258 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4259 | __ call(ic, RelocInfo::CODE_TARGET, ast_id); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4260 | if (patch_site != NULL && patch_site->is_bound()) { |
| 4261 | patch_site->EmitPatchInfo(); |
| 4262 | } else { |
| 4263 | __ nop(); // Signals no inlined code. |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4268 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 4269 | ASSERT(IsAligned(frame_offset, kPointerSize)); |
| 4270 | __ movq(Operand(rbp, frame_offset), value); |
| 4271 | } |
| 4272 | |
| 4273 | |
| 4274 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4275 | __ movq(dst, ContextOperand(rsi, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | |
| 4279 | // ---------------------------------------------------------------------------- |
| 4280 | // Non-local control flow support. |
| 4281 | |
| 4282 | |
| 4283 | void FullCodeGenerator::EnterFinallyBlock() { |
| 4284 | ASSERT(!result_register().is(rdx)); |
| 4285 | ASSERT(!result_register().is(rcx)); |
| 4286 | // Cook return address on top of stack (smi encoded Code* delta) |
| 4287 | __ movq(rdx, Operand(rsp, 0)); |
| 4288 | __ Move(rcx, masm_->CodeObject()); |
| 4289 | __ subq(rdx, rcx); |
| 4290 | __ Integer32ToSmi(rdx, rdx); |
| 4291 | __ movq(Operand(rsp, 0), rdx); |
| 4292 | // Store result register while executing finally block. |
| 4293 | __ push(result_register()); |
| 4294 | } |
| 4295 | |
| 4296 | |
| 4297 | void FullCodeGenerator::ExitFinallyBlock() { |
| 4298 | ASSERT(!result_register().is(rdx)); |
| 4299 | ASSERT(!result_register().is(rcx)); |
| 4300 | // Restore result register from stack. |
| 4301 | __ pop(result_register()); |
| 4302 | // Uncook return address. |
| 4303 | __ movq(rdx, Operand(rsp, 0)); |
| 4304 | __ SmiToInteger32(rdx, rdx); |
| 4305 | __ Move(rcx, masm_->CodeObject()); |
| 4306 | __ addq(rdx, rcx); |
| 4307 | __ movq(Operand(rsp, 0), rdx); |
| 4308 | // And return. |
| 4309 | __ ret(0); |
| 4310 | } |
| 4311 | |
| 4312 | |
| 4313 | #undef __ |
| 4314 | |
| 4315 | |
| 4316 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4317 | |
| 4318 | #endif // V8_TARGET_ARCH_X64 |