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