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