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