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