sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_ARM) |
| 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "codegen-inl.h" |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 35 | #include "compiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "debug.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 37 | #include "ic-inl.h" |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 38 | #include "jsregexp.h" |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 39 | #include "jump-target-light-inl.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 40 | #include "parser.h" |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 41 | #include "regexp-macro-assembler.h" |
| 42 | #include "regexp-stack.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 43 | #include "register-allocator-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "runtime.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 45 | #include "scopes.h" |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 46 | #include "stub-cache.h" |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 47 | #include "virtual-frame-inl.h" |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 48 | #include "virtual-frame-arm-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 50 | namespace v8 { |
| 51 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 53 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 54 | #define __ ACCESS_MASM(masm_) |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 55 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 56 | // ------------------------------------------------------------------------- |
| 57 | // Platform-specific DeferredCode functions. |
| 58 | |
| 59 | void DeferredCode::SaveRegisters() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 60 | // On ARM you either have a completely spilled frame or you |
| 61 | // handle it yourself, but at the moment there's no automation |
| 62 | // of registers and deferred code. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
| 66 | void DeferredCode::RestoreRegisters() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
| 70 | // ------------------------------------------------------------------------- |
| 71 | // Platform-specific RuntimeCallHelper functions. |
| 72 | |
| 73 | void VirtualFrameRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
| 74 | frame_state_->frame()->AssertIsSpilled(); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | void VirtualFrameRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 79 | } |
| 80 | |
| 81 | |
| 82 | void ICRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
| 83 | masm->EnterInternalFrame(); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | void ICRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 88 | masm->LeaveInternalFrame(); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 89 | } |
| 90 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 91 | |
| 92 | // ------------------------------------------------------------------------- |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 93 | // CodeGenState implementation. |
| 94 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 95 | CodeGenState::CodeGenState(CodeGenerator* owner) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 96 | : owner_(owner), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 97 | previous_(owner->state()) { |
| 98 | owner->set_state(this); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 102 | ConditionCodeGenState::ConditionCodeGenState(CodeGenerator* owner, |
| 103 | JumpTarget* true_target, |
| 104 | JumpTarget* false_target) |
| 105 | : CodeGenState(owner), |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 106 | true_target_(true_target), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 107 | false_target_(false_target) { |
| 108 | owner->set_state(this); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | TypeInfoCodeGenState::TypeInfoCodeGenState(CodeGenerator* owner, |
| 113 | Slot* slot, |
| 114 | TypeInfo type_info) |
| 115 | : CodeGenState(owner), |
| 116 | slot_(slot) { |
| 117 | owner->set_state(this); |
| 118 | old_type_info_ = owner->set_type_info(slot, type_info); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 122 | CodeGenState::~CodeGenState() { |
| 123 | ASSERT(owner_->state() == this); |
| 124 | owner_->set_state(previous_); |
| 125 | } |
| 126 | |
| 127 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 128 | TypeInfoCodeGenState::~TypeInfoCodeGenState() { |
| 129 | owner()->set_type_info(slot_, old_type_info_); |
| 130 | } |
| 131 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 132 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 133 | // CodeGenerator implementation |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 135 | int CodeGenerator::inlined_write_barrier_size_ = -1; |
| 136 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 137 | CodeGenerator::CodeGenerator(MacroAssembler* masm) |
| 138 | : deferred_(8), |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 139 | masm_(masm), |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 140 | info_(NULL), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 141 | frame_(NULL), |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 142 | allocator_(NULL), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | cc_reg_(al), |
| 144 | state_(NULL), |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 145 | loop_nesting_(0), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 146 | type_info_(NULL), |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 147 | function_return_(JumpTarget::BIDIRECTIONAL), |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 148 | function_return_is_shadowed_(false) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | |
| 152 | // Calling conventions: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 153 | // fp: caller's frame pointer |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 154 | // sp: stack pointer |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 155 | // r1: called JS function |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | // cp: callee's context |
| 157 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 158 | void CodeGenerator::Generate(CompilationInfo* info) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 159 | // Record the position for debugging purposes. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 160 | CodeForFunctionPosition(info->function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 161 | Comment cmnt(masm_, "[ function compiled by virtual frame code generator"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | |
| 163 | // Initialize state. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 164 | info_ = info; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 165 | |
| 166 | int slots = scope()->num_parameters() + scope()->num_stack_slots(); |
| 167 | ScopedVector<TypeInfo> type_info_array(slots); |
| 168 | type_info_ = &type_info_array; |
| 169 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 170 | ASSERT(allocator_ == NULL); |
| 171 | RegisterAllocator register_allocator(this); |
| 172 | allocator_ = ®ister_allocator; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 173 | ASSERT(frame_ == NULL); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 174 | frame_ = new VirtualFrame(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 175 | cc_reg_ = al; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 176 | |
| 177 | // Adjust for function-level loop nesting. |
| 178 | ASSERT_EQ(0, loop_nesting_); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 179 | loop_nesting_ = info->is_in_loop() ? 1 : 0; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 180 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 181 | { |
| 182 | CodeGenState state(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 184 | // Entry: |
| 185 | // Stack: receiver, arguments |
| 186 | // lr: return address |
| 187 | // fp: caller's frame pointer |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | // sp: stack pointer |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 189 | // r1: called JS function |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 190 | // cp: callee's context |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 191 | allocator_->Initialize(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 192 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | #ifdef DEBUG |
| 194 | if (strlen(FLAG_stop_at) > 0 && |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 195 | info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 196 | frame_->SpillAll(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 197 | __ stop("stop-at"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | } |
| 199 | #endif |
| 200 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 201 | frame_->Enter(); |
| 202 | // tos: code slot |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 203 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 204 | // Allocate space for locals and initialize them. This also checks |
| 205 | // for stack overflow. |
| 206 | frame_->AllocateStackSlots(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 207 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 208 | frame_->AssertIsSpilled(); |
| 209 | int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 210 | if (heap_slots > 0) { |
| 211 | // Allocate local context. |
| 212 | // Get outer context and create a new context based on it. |
| 213 | __ ldr(r0, frame_->Function()); |
| 214 | frame_->EmitPush(r0); |
| 215 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 216 | FastNewContextStub stub(heap_slots); |
| 217 | frame_->CallStub(&stub, 1); |
| 218 | } else { |
| 219 | frame_->CallRuntime(Runtime::kNewContext, 1); |
| 220 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 221 | |
| 222 | #ifdef DEBUG |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 223 | JumpTarget verified_true; |
| 224 | __ cmp(r0, cp); |
| 225 | verified_true.Branch(eq); |
| 226 | __ stop("NewContext: r0 is expected to be the same as cp"); |
| 227 | verified_true.Bind(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 228 | #endif |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 229 | // Update context local. |
| 230 | __ str(cp, frame_->Context()); |
| 231 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 232 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 233 | // TODO(1241774): Improve this code: |
| 234 | // 1) only needed if we have a context |
| 235 | // 2) no need to recompute context ptr every single time |
| 236 | // 3) don't copy parameter operand code from SlotOperand! |
| 237 | { |
| 238 | Comment cmnt2(masm_, "[ copy context parameters into .context"); |
| 239 | // Note that iteration order is relevant here! If we have the same |
| 240 | // parameter twice (e.g., function (x, y, x)), and that parameter |
| 241 | // needs to be copied into the context, it must be the last argument |
| 242 | // passed to the parameter that needs to be copied. This is a rare |
| 243 | // case so we don't check for it, instead we rely on the copying |
| 244 | // order: such a parameter is copied repeatedly into the same |
| 245 | // context location and thus the last value is what is seen inside |
| 246 | // the function. |
| 247 | frame_->AssertIsSpilled(); |
| 248 | for (int i = 0; i < scope()->num_parameters(); i++) { |
| 249 | Variable* par = scope()->parameter(i); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 250 | Slot* slot = par->AsSlot(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 251 | if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 252 | ASSERT(!scope()->is_global_scope()); // No params in global scope. |
| 253 | __ ldr(r1, frame_->ParameterAt(i)); |
| 254 | // Loads r2 with context; used below in RecordWrite. |
| 255 | __ str(r1, SlotOperand(slot, r2)); |
| 256 | // Load the offset into r3. |
| 257 | int slot_offset = |
| 258 | FixedArray::kHeaderSize + slot->index() * kPointerSize; |
| 259 | __ RecordWrite(r2, Operand(slot_offset), r3, r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 260 | } |
| 261 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 262 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 263 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 264 | // Store the arguments object. This must happen after context |
| 265 | // initialization because the arguments object may be stored in |
| 266 | // the context. |
| 267 | if (ArgumentsMode() != NO_ARGUMENTS_ALLOCATION) { |
| 268 | StoreArgumentsObject(true); |
| 269 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 270 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 271 | // Initialize ThisFunction reference if present. |
| 272 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
| 273 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 274 | StoreToSlot(scope()->function()->AsSlot(), NOT_CONST_INIT); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 275 | } |
| 276 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 277 | // Initialize the function return target after the locals are set |
| 278 | // up, because it needs the expected frame height from the frame. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 279 | function_return_.SetExpectedHeight(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 280 | function_return_is_shadowed_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 282 | // Generate code to 'execute' declarations and initialize functions |
| 283 | // (source elements). In case of an illegal redeclaration we need to |
| 284 | // handle that instead of processing the declarations. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 285 | if (scope()->HasIllegalRedeclaration()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | Comment cmnt(masm_, "[ illegal redeclarations"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 287 | scope()->VisitIllegalRedeclaration(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 288 | } else { |
| 289 | Comment cmnt(masm_, "[ declarations"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 290 | ProcessDeclarations(scope()->declarations()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 291 | // Bail out if a stack-overflow exception occurred when processing |
| 292 | // declarations. |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 293 | if (HasStackOverflow()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | } |
| 295 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 296 | if (FLAG_trace) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 297 | frame_->CallRuntime(Runtime::kTraceEnter, 0); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 298 | // Ignore the return value. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 299 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 300 | |
| 301 | // Compile the body of the function in a vanilla state. Don't |
| 302 | // bother compiling all the code if the scope has an illegal |
| 303 | // redeclaration. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 304 | if (!scope()->HasIllegalRedeclaration()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | Comment cmnt(masm_, "[ function body"); |
| 306 | #ifdef DEBUG |
| 307 | bool is_builtin = Bootstrapper::IsActive(); |
| 308 | bool should_trace = |
| 309 | is_builtin ? FLAG_trace_builtin_calls : FLAG_trace_calls; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 310 | if (should_trace) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 311 | frame_->CallRuntime(Runtime::kDebugTrace, 0); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 312 | // Ignore the return value. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 313 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | #endif |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 315 | VisitStatements(info->function()->body()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 317 | } |
| 318 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 319 | // Handle the return from the function. |
| 320 | if (has_valid_frame()) { |
| 321 | // If there is a valid frame, control flow can fall off the end of |
| 322 | // the body. In that case there is an implicit return statement. |
| 323 | ASSERT(!function_return_is_shadowed_); |
| 324 | frame_->PrepareForReturn(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 325 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 326 | if (function_return_.is_bound()) { |
| 327 | function_return_.Jump(); |
| 328 | } else { |
| 329 | function_return_.Bind(); |
| 330 | GenerateReturnSequence(); |
| 331 | } |
| 332 | } else if (function_return_.is_linked()) { |
| 333 | // If the return target has dangling jumps to it, then we have not |
| 334 | // yet generated the return sequence. This can happen when (a) |
| 335 | // control does not flow off the end of the body so we did not |
| 336 | // compile an artificial return statement just above, and (b) there |
| 337 | // are return statements in the body but (c) they are all shadowed. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 338 | function_return_.Bind(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 339 | GenerateReturnSequence(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 340 | } |
| 341 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 342 | // Adjust for function-level loop nesting. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 343 | ASSERT(loop_nesting_ == info->is_in_loop()? 1 : 0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 344 | loop_nesting_ = 0; |
| 345 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 346 | // Code generation state must be reset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 347 | ASSERT(!has_cc()); |
| 348 | ASSERT(state_ == NULL); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 349 | ASSERT(loop_nesting() == 0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 350 | ASSERT(!function_return_is_shadowed_); |
| 351 | function_return_.Unuse(); |
| 352 | DeleteFrame(); |
| 353 | |
| 354 | // Process any deferred code using the register allocator. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 355 | if (!HasStackOverflow()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 356 | ProcessDeferred(); |
| 357 | } |
| 358 | |
| 359 | allocator_ = NULL; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 360 | type_info_ = NULL; |
| 361 | } |
| 362 | |
| 363 | |
| 364 | int CodeGenerator::NumberOfSlot(Slot* slot) { |
| 365 | if (slot == NULL) return kInvalidSlotNumber; |
| 366 | switch (slot->type()) { |
| 367 | case Slot::PARAMETER: |
| 368 | return slot->index(); |
| 369 | case Slot::LOCAL: |
| 370 | return slot->index() + scope()->num_parameters(); |
| 371 | default: |
| 372 | break; |
| 373 | } |
| 374 | return kInvalidSlotNumber; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 378 | MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) { |
| 379 | // Currently, this assertion will fail if we try to assign to |
| 380 | // a constant variable that is constant because it is read-only |
| 381 | // (such as the variable referring to a named function expression). |
| 382 | // We need to implement assignments to read-only variables. |
| 383 | // Ideally, we should do this during AST generation (by converting |
| 384 | // such assignments into expression statements); however, in general |
| 385 | // we may not be able to make the decision until past AST generation, |
| 386 | // that is when the entire program is known. |
| 387 | ASSERT(slot != NULL); |
| 388 | int index = slot->index(); |
| 389 | switch (slot->type()) { |
| 390 | case Slot::PARAMETER: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 391 | return frame_->ParameterAt(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 392 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 393 | case Slot::LOCAL: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 394 | return frame_->LocalAt(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 395 | |
| 396 | case Slot::CONTEXT: { |
| 397 | // Follow the context chain if necessary. |
| 398 | ASSERT(!tmp.is(cp)); // do not overwrite context register |
| 399 | Register context = cp; |
| 400 | int chain_length = scope()->ContextChainLength(slot->var()->scope()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 401 | for (int i = 0; i < chain_length; i++) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 402 | // Load the closure. |
| 403 | // (All contexts, even 'with' contexts, have a closure, |
| 404 | // and it is the same for all contexts inside a function. |
| 405 | // There is no need to go to the function context first.) |
| 406 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 407 | // Load the function context (which is the incoming, outer context). |
| 408 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 409 | context = tmp; |
| 410 | } |
| 411 | // We may have a 'with' context now. Get the function context. |
| 412 | // (In fact this mov may never be the needed, since the scope analysis |
| 413 | // may not permit a direct context access in this case and thus we are |
| 414 | // always at a function context. However it is safe to dereference be- |
| 415 | // cause the function context of a function context is itself. Before |
| 416 | // deleting this mov we should try to create a counter-example first, |
| 417 | // though...) |
| 418 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
| 419 | return ContextOperand(tmp, index); |
| 420 | } |
| 421 | |
| 422 | default: |
| 423 | UNREACHABLE(); |
| 424 | return MemOperand(r0, 0); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 429 | MemOperand CodeGenerator::ContextSlotOperandCheckExtensions( |
| 430 | Slot* slot, |
| 431 | Register tmp, |
| 432 | Register tmp2, |
| 433 | JumpTarget* slow) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 434 | ASSERT(slot->type() == Slot::CONTEXT); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 435 | Register context = cp; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 436 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 437 | for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) { |
| 438 | if (s->num_heap_slots() > 0) { |
| 439 | if (s->calls_eval()) { |
| 440 | // Check that extension is NULL. |
| 441 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 442 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 443 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 444 | } |
| 445 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 446 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 447 | context = tmp; |
| 448 | } |
| 449 | } |
| 450 | // Check that last extension is NULL. |
| 451 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 452 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 453 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 454 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 455 | return ContextOperand(tmp, slot->index()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 459 | // Loads a value on TOS. If it is a boolean value, the result may have been |
| 460 | // (partially) translated into branches, or it may have set the condition |
| 461 | // code register. If force_cc is set, the value is forced to set the |
| 462 | // condition code register and no value is pushed. If the condition code |
| 463 | // register was set, has_cc() is true and cc_reg_ contains the condition to |
| 464 | // test for 'true'. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 465 | void CodeGenerator::LoadCondition(Expression* x, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 466 | JumpTarget* true_target, |
| 467 | JumpTarget* false_target, |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 468 | bool force_cc) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 469 | ASSERT(!has_cc()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 470 | int original_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 472 | { ConditionCodeGenState new_state(this, true_target, false_target); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 473 | Visit(x); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 474 | |
| 475 | // If we hit a stack overflow, we may not have actually visited |
| 476 | // the expression. In that case, we ensure that we have a |
| 477 | // valid-looking frame state because we will continue to generate |
| 478 | // code as we unwind the C++ stack. |
| 479 | // |
| 480 | // It's possible to have both a stack overflow and a valid frame |
| 481 | // state (eg, a subexpression overflowed, visiting it returned |
| 482 | // with a dummied frame state, and visiting this expression |
| 483 | // returned with a normal-looking state). |
| 484 | if (HasStackOverflow() && |
| 485 | has_valid_frame() && |
| 486 | !has_cc() && |
| 487 | frame_->height() == original_height) { |
| 488 | true_target->Jump(); |
| 489 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 490 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 491 | if (force_cc && frame_ != NULL && !has_cc()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 492 | // Convert the TOS value to a boolean in the condition code register. |
| 493 | ToBoolean(true_target, false_target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 494 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 495 | ASSERT(!force_cc || !has_valid_frame() || has_cc()); |
| 496 | ASSERT(!has_valid_frame() || |
| 497 | (has_cc() && frame_->height() == original_height) || |
| 498 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 502 | void CodeGenerator::Load(Expression* expr) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 503 | // We generally assume that we are not in a spilled scope for most |
| 504 | // of the code generator. A failure to ensure this caused issue 815 |
| 505 | // and this assert is designed to catch similar issues. |
| 506 | frame_->AssertIsNotSpilled(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 507 | #ifdef DEBUG |
| 508 | int original_height = frame_->height(); |
| 509 | #endif |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 510 | JumpTarget true_target; |
| 511 | JumpTarget false_target; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 512 | LoadCondition(expr, &true_target, &false_target, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 513 | |
| 514 | if (has_cc()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 515 | // Convert cc_reg_ into a boolean value. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 516 | JumpTarget loaded; |
| 517 | JumpTarget materialize_true; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 518 | materialize_true.Branch(cc_reg_); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 519 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 520 | loaded.Jump(); |
| 521 | materialize_true.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 522 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 523 | loaded.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | cc_reg_ = al; |
| 525 | } |
| 526 | |
| 527 | if (true_target.is_linked() || false_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 528 | // We have at least one condition value that has been "translated" |
| 529 | // into a branch, thus it needs to be loaded explicitly. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 530 | JumpTarget loaded; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 531 | if (frame_ != NULL) { |
| 532 | loaded.Jump(); // Don't lose the current TOS. |
| 533 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | bool both = true_target.is_linked() && false_target.is_linked(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 535 | // Load "true" if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | if (true_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 537 | true_target.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 538 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 540 | // If both "true" and "false" need to be loaded jump across the code for |
| 541 | // "false". |
| 542 | if (both) { |
| 543 | loaded.Jump(); |
| 544 | } |
| 545 | // Load "false" if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 546 | if (false_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 547 | false_target.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 548 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 549 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 550 | // A value is loaded on all paths reaching this point. |
| 551 | loaded.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 552 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 553 | ASSERT(has_valid_frame()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 554 | ASSERT(!has_cc()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 555 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 559 | void CodeGenerator::LoadGlobal() { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 560 | Register reg = frame_->GetTOSRegister(); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 561 | __ ldr(reg, GlobalObjectOperand()); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 562 | frame_->EmitPush(reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 566 | void CodeGenerator::LoadGlobalReceiver(Register scratch) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 567 | Register reg = frame_->GetTOSRegister(); |
| 568 | __ ldr(reg, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 569 | __ ldr(reg, |
| 570 | FieldMemOperand(reg, GlobalObject::kGlobalReceiverOffset)); |
| 571 | frame_->EmitPush(reg); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 575 | ArgumentsAllocationMode CodeGenerator::ArgumentsMode() { |
| 576 | if (scope()->arguments() == NULL) return NO_ARGUMENTS_ALLOCATION; |
| 577 | ASSERT(scope()->arguments_shadow() != NULL); |
| 578 | // We don't want to do lazy arguments allocation for functions that |
| 579 | // have heap-allocated contexts, because it interfers with the |
| 580 | // uninitialized const tracking in the context objects. |
| 581 | return (scope()->num_heap_slots() > 0) |
| 582 | ? EAGER_ARGUMENTS_ALLOCATION |
| 583 | : LAZY_ARGUMENTS_ALLOCATION; |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void CodeGenerator::StoreArgumentsObject(bool initial) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 588 | ArgumentsAllocationMode mode = ArgumentsMode(); |
| 589 | ASSERT(mode != NO_ARGUMENTS_ALLOCATION); |
| 590 | |
| 591 | Comment cmnt(masm_, "[ store arguments object"); |
| 592 | if (mode == LAZY_ARGUMENTS_ALLOCATION && initial) { |
| 593 | // When using lazy arguments allocation, we store the hole value |
| 594 | // as a sentinel indicating that the arguments object hasn't been |
| 595 | // allocated yet. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 596 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 597 | } else { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 598 | frame_->SpillAll(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 599 | ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 600 | __ ldr(r2, frame_->Function()); |
| 601 | // The receiver is below the arguments, the return address, and the |
| 602 | // frame pointer on the stack. |
| 603 | const int kReceiverDisplacement = 2 + scope()->num_parameters(); |
| 604 | __ add(r1, fp, Operand(kReceiverDisplacement * kPointerSize)); |
| 605 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 606 | frame_->Adjust(3); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 607 | __ Push(r2, r1, r0); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 608 | frame_->CallStub(&stub, 3); |
| 609 | frame_->EmitPush(r0); |
| 610 | } |
| 611 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 612 | Variable* arguments = scope()->arguments(); |
| 613 | Variable* shadow = scope()->arguments_shadow(); |
| 614 | ASSERT(arguments != NULL && arguments->AsSlot() != NULL); |
| 615 | ASSERT(shadow != NULL && shadow->AsSlot() != NULL); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 616 | JumpTarget done; |
| 617 | if (mode == LAZY_ARGUMENTS_ALLOCATION && !initial) { |
| 618 | // We have to skip storing into the arguments slot if it has |
| 619 | // already been written to. This can happen if the a function |
| 620 | // has a local variable named 'arguments'. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 621 | LoadFromSlot(scope()->arguments()->AsSlot(), NOT_INSIDE_TYPEOF); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 622 | Register arguments = frame_->PopToRegister(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 623 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 624 | __ cmp(arguments, ip); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 625 | done.Branch(ne); |
| 626 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 627 | StoreToSlot(arguments->AsSlot(), NOT_CONST_INIT); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 628 | if (mode == LAZY_ARGUMENTS_ALLOCATION) done.Bind(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 629 | StoreToSlot(shadow->AsSlot(), NOT_CONST_INIT); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 633 | void CodeGenerator::LoadTypeofExpression(Expression* expr) { |
| 634 | // Special handling of identifiers as subexpressions of typeof. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 635 | Variable* variable = expr->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | if (variable != NULL && !variable->is_this() && variable->is_global()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 637 | // For a global variable we build the property reference |
| 638 | // <global>.<variable> and perform a (regular non-contextual) property |
| 639 | // load to make sure we do not get reference errors. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 640 | Slot global(variable, Slot::CONTEXT, Context::GLOBAL_INDEX); |
| 641 | Literal key(variable->name()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 642 | Property property(&global, &key, RelocInfo::kNoPosition); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 643 | Reference ref(this, &property); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 644 | ref.GetValue(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 645 | } else if (variable != NULL && variable->AsSlot() != NULL) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 646 | // For a variable that rewrites to a slot, we signal it is the immediate |
| 647 | // subexpression of a typeof. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 648 | LoadFromSlotCheckForArguments(variable->AsSlot(), INSIDE_TYPEOF); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 649 | } else { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 650 | // Anything else can be handled normally. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 651 | Load(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
| 655 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 656 | Reference::Reference(CodeGenerator* cgen, |
| 657 | Expression* expression, |
| 658 | bool persist_after_get) |
| 659 | : cgen_(cgen), |
| 660 | expression_(expression), |
| 661 | type_(ILLEGAL), |
| 662 | persist_after_get_(persist_after_get) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 663 | // We generally assume that we are not in a spilled scope for most |
| 664 | // of the code generator. A failure to ensure this caused issue 815 |
| 665 | // and this assert is designed to catch similar issues. |
| 666 | cgen->frame()->AssertIsNotSpilled(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 667 | cgen->LoadReference(this); |
| 668 | } |
| 669 | |
| 670 | |
| 671 | Reference::~Reference() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 672 | ASSERT(is_unloaded() || is_illegal()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 676 | void CodeGenerator::LoadReference(Reference* ref) { |
| 677 | Comment cmnt(masm_, "[ LoadReference"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 678 | Expression* e = ref->expression(); |
| 679 | Property* property = e->AsProperty(); |
| 680 | Variable* var = e->AsVariableProxy()->AsVariable(); |
| 681 | |
| 682 | if (property != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 683 | // The expression is either a property or a variable proxy that rewrites |
| 684 | // to a property. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 685 | Load(property->obj()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 686 | if (property->key()->IsPropertyName()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 687 | ref->set_type(Reference::NAMED); |
| 688 | } else { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 689 | Load(property->key()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 690 | ref->set_type(Reference::KEYED); |
| 691 | } |
| 692 | } else if (var != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 693 | // The expression is a variable proxy that does not rewrite to a |
| 694 | // property. Global variables are treated as named property references. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 695 | if (var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 696 | LoadGlobal(); |
| 697 | ref->set_type(Reference::NAMED); |
| 698 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 699 | ASSERT(var->AsSlot() != NULL); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 700 | ref->set_type(Reference::SLOT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | } |
| 702 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 703 | // Anything else is a runtime error. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 704 | Load(e); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 705 | frame_->CallRuntime(Runtime::kThrowReferenceError, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
| 709 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 710 | void CodeGenerator::UnloadReference(Reference* ref) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 711 | int size = ref->size(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 712 | ref->set_unloaded(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 713 | if (size == 0) return; |
| 714 | |
| 715 | // Pop a reference from the stack while preserving TOS. |
| 716 | VirtualFrame::RegisterAllocationScope scope(this); |
| 717 | Comment cmnt(masm_, "[ UnloadReference"); |
| 718 | if (size > 0) { |
| 719 | Register tos = frame_->PopToRegister(); |
| 720 | frame_->Drop(size); |
| 721 | frame_->EmitPush(tos); |
| 722 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 726 | // ECMA-262, section 9.2, page 30: ToBoolean(). Convert the given |
| 727 | // register to a boolean in the condition code register. The code |
| 728 | // may jump to 'false_target' in case the register converts to 'false'. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 729 | void CodeGenerator::ToBoolean(JumpTarget* true_target, |
| 730 | JumpTarget* false_target) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 731 | // Note: The generated code snippet does not change stack variables. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 732 | // Only the condition code should be set. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 733 | bool known_smi = frame_->KnownSmiAt(0); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 734 | Register tos = frame_->PopToRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 735 | |
| 736 | // Fast case checks |
| 737 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 738 | // Check if the value is 'false'. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 739 | if (!known_smi) { |
| 740 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 741 | __ cmp(tos, ip); |
| 742 | false_target->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 743 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 744 | // Check if the value is 'true'. |
| 745 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 746 | __ cmp(tos, ip); |
| 747 | true_target->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 748 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 749 | // Check if the value is 'undefined'. |
| 750 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 751 | __ cmp(tos, ip); |
| 752 | false_target->Branch(eq); |
| 753 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 754 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 755 | // Check if the value is a smi. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 756 | __ cmp(tos, Operand(Smi::FromInt(0))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 757 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 758 | if (!known_smi) { |
| 759 | false_target->Branch(eq); |
| 760 | __ tst(tos, Operand(kSmiTagMask)); |
| 761 | true_target->Branch(eq); |
| 762 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 763 | // Slow case. |
| 764 | if (CpuFeatures::IsSupported(VFP3)) { |
| 765 | CpuFeatures::Scope scope(VFP3); |
| 766 | // Implements the slow case by using ToBooleanStub. |
| 767 | // The ToBooleanStub takes a single argument, and |
| 768 | // returns a non-zero value for true, or zero for false. |
| 769 | // Both the argument value and the return value use the |
| 770 | // register assigned to tos_ |
| 771 | ToBooleanStub stub(tos); |
| 772 | frame_->CallStub(&stub, 0); |
| 773 | // Convert the result in "tos" to a condition code. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 774 | __ cmp(tos, Operand(0, RelocInfo::NONE)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 775 | } else { |
| 776 | // Implements slow case by calling the runtime. |
| 777 | frame_->EmitPush(tos); |
| 778 | frame_->CallRuntime(Runtime::kToBool, 1); |
| 779 | // Convert the result (r0) to a condition code. |
| 780 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 781 | __ cmp(r0, ip); |
| 782 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 783 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 784 | |
| 785 | cc_reg_ = ne; |
| 786 | } |
| 787 | |
| 788 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 789 | void CodeGenerator::GenericBinaryOperation(Token::Value op, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 790 | OverwriteMode overwrite_mode, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 791 | GenerateInlineSmi inline_smi, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 792 | int constant_rhs) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 793 | // top of virtual frame: y |
| 794 | // 2nd elt. on virtual frame : x |
| 795 | // result : top of virtual frame |
| 796 | |
| 797 | // Stub is entered with a call: 'return address' is in lr. |
| 798 | switch (op) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 799 | case Token::ADD: |
| 800 | case Token::SUB: |
| 801 | if (inline_smi) { |
| 802 | JumpTarget done; |
| 803 | Register rhs = frame_->PopToRegister(); |
| 804 | Register lhs = frame_->PopToRegister(rhs); |
| 805 | Register scratch = VirtualFrame::scratch0(); |
| 806 | __ orr(scratch, rhs, Operand(lhs)); |
| 807 | // Check they are both small and positive. |
| 808 | __ tst(scratch, Operand(kSmiTagMask | 0xc0000000)); |
| 809 | ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 810 | STATIC_ASSERT(kSmiTag == 0); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 811 | if (op == Token::ADD) { |
| 812 | __ add(r0, lhs, Operand(rhs), LeaveCC, eq); |
| 813 | } else { |
| 814 | __ sub(r0, lhs, Operand(rhs), LeaveCC, eq); |
| 815 | } |
| 816 | done.Branch(eq); |
| 817 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 818 | frame_->SpillAll(); |
| 819 | frame_->CallStub(&stub, 0); |
| 820 | done.Bind(); |
| 821 | frame_->EmitPush(r0); |
| 822 | break; |
| 823 | } else { |
| 824 | // Fall through! |
| 825 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 826 | case Token::BIT_OR: |
| 827 | case Token::BIT_AND: |
| 828 | case Token::BIT_XOR: |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 829 | if (inline_smi) { |
| 830 | bool rhs_is_smi = frame_->KnownSmiAt(0); |
| 831 | bool lhs_is_smi = frame_->KnownSmiAt(1); |
| 832 | Register rhs = frame_->PopToRegister(); |
| 833 | Register lhs = frame_->PopToRegister(rhs); |
| 834 | Register smi_test_reg; |
| 835 | Condition cond; |
| 836 | if (!rhs_is_smi || !lhs_is_smi) { |
| 837 | if (rhs_is_smi) { |
| 838 | smi_test_reg = lhs; |
| 839 | } else if (lhs_is_smi) { |
| 840 | smi_test_reg = rhs; |
| 841 | } else { |
| 842 | smi_test_reg = VirtualFrame::scratch0(); |
| 843 | __ orr(smi_test_reg, rhs, Operand(lhs)); |
| 844 | } |
| 845 | // Check they are both Smis. |
| 846 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 847 | cond = eq; |
| 848 | } else { |
| 849 | cond = al; |
| 850 | } |
| 851 | ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now. |
| 852 | if (op == Token::BIT_OR) { |
| 853 | __ orr(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 854 | } else if (op == Token::BIT_AND) { |
| 855 | __ and_(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 856 | } else { |
| 857 | ASSERT(op == Token::BIT_XOR); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 858 | STATIC_ASSERT(kSmiTag == 0); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 859 | __ eor(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 860 | } |
| 861 | if (cond != al) { |
| 862 | JumpTarget done; |
| 863 | done.Branch(cond); |
| 864 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 865 | frame_->SpillAll(); |
| 866 | frame_->CallStub(&stub, 0); |
| 867 | done.Bind(); |
| 868 | } |
| 869 | frame_->EmitPush(r0); |
| 870 | break; |
| 871 | } else { |
| 872 | // Fall through! |
| 873 | } |
| 874 | case Token::MUL: |
| 875 | case Token::DIV: |
| 876 | case Token::MOD: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 877 | case Token::SHL: |
| 878 | case Token::SHR: |
| 879 | case Token::SAR: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 880 | Register rhs = frame_->PopToRegister(); |
| 881 | Register lhs = frame_->PopToRegister(rhs); // Don't pop to rhs register. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 882 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 883 | frame_->SpillAll(); |
| 884 | frame_->CallStub(&stub, 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 885 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | break; |
| 887 | } |
| 888 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 889 | case Token::COMMA: { |
| 890 | Register scratch = frame_->PopToRegister(); |
| 891 | // Simply discard left value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 892 | frame_->Drop(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 893 | frame_->EmitPush(scratch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 894 | break; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 895 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | |
| 897 | default: |
| 898 | // Other cases should have been handled before this point. |
| 899 | UNREACHABLE(); |
| 900 | break; |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 905 | class DeferredInlineSmiOperation: public DeferredCode { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 906 | public: |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 907 | DeferredInlineSmiOperation(Token::Value op, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 908 | int value, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 909 | bool reversed, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 910 | OverwriteMode overwrite_mode, |
| 911 | Register tos) |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 912 | : op_(op), |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 913 | value_(value), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 914 | reversed_(reversed), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 915 | overwrite_mode_(overwrite_mode), |
| 916 | tos_register_(tos) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 917 | set_comment("[ DeferredInlinedSmiOperation"); |
| 918 | } |
| 919 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 920 | virtual void Generate(); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 921 | // This stub makes explicit calls to SaveRegisters(), RestoreRegisters() and |
| 922 | // Exit(). Currently on ARM SaveRegisters() and RestoreRegisters() are empty |
| 923 | // methods, it is the responsibility of the deferred code to save and restore |
| 924 | // registers. |
| 925 | virtual bool AutoSaveAndRestore() { return false; } |
| 926 | |
| 927 | void JumpToNonSmiInput(Condition cond); |
| 928 | void JumpToAnswerOutOfRange(Condition cond); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 929 | |
| 930 | private: |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 931 | void GenerateNonSmiInput(); |
| 932 | void GenerateAnswerOutOfRange(); |
| 933 | void WriteNonSmiAnswer(Register answer, |
| 934 | Register heap_number, |
| 935 | Register scratch); |
| 936 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 937 | Token::Value op_; |
| 938 | int value_; |
| 939 | bool reversed_; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 940 | OverwriteMode overwrite_mode_; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 941 | Register tos_register_; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 942 | Label non_smi_input_; |
| 943 | Label answer_out_of_range_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 944 | }; |
| 945 | |
| 946 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 947 | // For bit operations we try harder and handle the case where the input is not |
| 948 | // a Smi but a 32bits integer without calling the generic stub. |
| 949 | void DeferredInlineSmiOperation::JumpToNonSmiInput(Condition cond) { |
| 950 | ASSERT(Token::IsBitOp(op_)); |
| 951 | |
| 952 | __ b(cond, &non_smi_input_); |
| 953 | } |
| 954 | |
| 955 | |
| 956 | // For bit operations the result is always 32bits so we handle the case where |
| 957 | // the result does not fit in a Smi without calling the generic stub. |
| 958 | void DeferredInlineSmiOperation::JumpToAnswerOutOfRange(Condition cond) { |
| 959 | ASSERT(Token::IsBitOp(op_)); |
| 960 | |
| 961 | if ((op_ == Token::SHR) && !CpuFeatures::IsSupported(VFP3)) { |
| 962 | // >>> requires an unsigned to double conversion and the non VFP code |
| 963 | // does not support this conversion. |
| 964 | __ b(cond, entry_label()); |
| 965 | } else { |
| 966 | __ b(cond, &answer_out_of_range_); |
| 967 | } |
| 968 | } |
| 969 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 970 | |
| 971 | // On entry the non-constant side of the binary operation is in tos_register_ |
| 972 | // and the constant smi side is nowhere. The tos_register_ is not used by the |
| 973 | // virtual frame. On exit the answer is in the tos_register_ and the virtual |
| 974 | // frame is unchanged. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 975 | void DeferredInlineSmiOperation::Generate() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 976 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 977 | copied_frame.SpillAll(); |
| 978 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 979 | Register lhs = r1; |
| 980 | Register rhs = r0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 981 | switch (op_) { |
| 982 | case Token::ADD: { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 983 | // Revert optimistic add. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 984 | if (reversed_) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 985 | __ sub(r0, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 986 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 987 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 988 | __ sub(r1, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 989 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 990 | } |
| 991 | break; |
| 992 | } |
| 993 | |
| 994 | case Token::SUB: { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 995 | // Revert optimistic sub. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 996 | if (reversed_) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 997 | __ rsb(r0, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 998 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 999 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1000 | __ add(r1, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1001 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 1002 | } |
| 1003 | break; |
| 1004 | } |
| 1005 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1006 | // For these operations there is no optimistic operation that needs to be |
| 1007 | // reverted. |
| 1008 | case Token::MUL: |
| 1009 | case Token::MOD: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1010 | case Token::BIT_OR: |
| 1011 | case Token::BIT_XOR: |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1012 | case Token::BIT_AND: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1013 | case Token::SHL: |
| 1014 | case Token::SHR: |
| 1015 | case Token::SAR: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1016 | if (tos_register_.is(r1)) { |
| 1017 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 1018 | } else { |
| 1019 | ASSERT(tos_register_.is(r0)); |
| 1020 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 1021 | } |
| 1022 | if (reversed_ == tos_register_.is(r1)) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1023 | lhs = r0; |
| 1024 | rhs = r1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1025 | } |
| 1026 | break; |
| 1027 | } |
| 1028 | |
| 1029 | default: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1030 | // Other cases should have been handled before this point. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1031 | UNREACHABLE(); |
| 1032 | break; |
| 1033 | } |
| 1034 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1035 | GenericBinaryOpStub stub(op_, overwrite_mode_, lhs, rhs, value_); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1036 | __ CallStub(&stub); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1037 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1038 | // The generic stub returns its value in r0, but that's not |
| 1039 | // necessarily what we want. We want whatever the inlined code |
| 1040 | // expected, which is that the answer is in the same register as |
| 1041 | // the operand was. |
| 1042 | __ Move(tos_register_, r0); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1043 | |
| 1044 | // The tos register was not in use for the virtual frame that we |
| 1045 | // came into this function with, so we can merge back to that frame |
| 1046 | // without trashing it. |
| 1047 | copied_frame.MergeTo(frame_state()->frame()); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1048 | |
| 1049 | Exit(); |
| 1050 | |
| 1051 | if (non_smi_input_.is_linked()) { |
| 1052 | GenerateNonSmiInput(); |
| 1053 | } |
| 1054 | |
| 1055 | if (answer_out_of_range_.is_linked()) { |
| 1056 | GenerateAnswerOutOfRange(); |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | // Convert and write the integer answer into heap_number. |
| 1062 | void DeferredInlineSmiOperation::WriteNonSmiAnswer(Register answer, |
| 1063 | Register heap_number, |
| 1064 | Register scratch) { |
| 1065 | if (CpuFeatures::IsSupported(VFP3)) { |
| 1066 | CpuFeatures::Scope scope(VFP3); |
| 1067 | __ vmov(s0, answer); |
| 1068 | if (op_ == Token::SHR) { |
| 1069 | __ vcvt_f64_u32(d0, s0); |
| 1070 | } else { |
| 1071 | __ vcvt_f64_s32(d0, s0); |
| 1072 | } |
| 1073 | __ sub(scratch, heap_number, Operand(kHeapObjectTag)); |
| 1074 | __ vstr(d0, scratch, HeapNumber::kValueOffset); |
| 1075 | } else { |
| 1076 | WriteInt32ToHeapNumberStub stub(answer, heap_number, scratch); |
| 1077 | __ CallStub(&stub); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | void DeferredInlineSmiOperation::GenerateNonSmiInput() { |
| 1083 | // We know the left hand side is not a Smi and the right hand side is an |
| 1084 | // immediate value (value_) which can be represented as a Smi. We only |
| 1085 | // handle bit operations. |
| 1086 | ASSERT(Token::IsBitOp(op_)); |
| 1087 | |
| 1088 | if (FLAG_debug_code) { |
| 1089 | __ Abort("Should not fall through!"); |
| 1090 | } |
| 1091 | |
| 1092 | __ bind(&non_smi_input_); |
| 1093 | if (FLAG_debug_code) { |
| 1094 | __ AbortIfSmi(tos_register_); |
| 1095 | } |
| 1096 | |
| 1097 | // This routine uses the registers from r2 to r6. At the moment they are |
| 1098 | // not used by the register allocator, but when they are it should use |
| 1099 | // SpillAll and MergeTo like DeferredInlineSmiOperation::Generate() above. |
| 1100 | |
| 1101 | Register heap_number_map = r7; |
| 1102 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 1103 | __ ldr(r3, FieldMemOperand(tos_register_, HeapNumber::kMapOffset)); |
| 1104 | __ cmp(r3, heap_number_map); |
| 1105 | // Not a number, fall back to the GenericBinaryOpStub. |
| 1106 | __ b(ne, entry_label()); |
| 1107 | |
| 1108 | Register int32 = r2; |
| 1109 | // Not a 32bits signed int, fall back to the GenericBinaryOpStub. |
| 1110 | __ ConvertToInt32(tos_register_, int32, r4, r5, entry_label()); |
| 1111 | |
| 1112 | // tos_register_ (r0 or r1): Original heap number. |
| 1113 | // int32: signed 32bits int. |
| 1114 | |
| 1115 | Label result_not_a_smi; |
| 1116 | int shift_value = value_ & 0x1f; |
| 1117 | switch (op_) { |
| 1118 | case Token::BIT_OR: __ orr(int32, int32, Operand(value_)); break; |
| 1119 | case Token::BIT_XOR: __ eor(int32, int32, Operand(value_)); break; |
| 1120 | case Token::BIT_AND: __ and_(int32, int32, Operand(value_)); break; |
| 1121 | case Token::SAR: |
| 1122 | ASSERT(!reversed_); |
| 1123 | if (shift_value != 0) { |
| 1124 | __ mov(int32, Operand(int32, ASR, shift_value)); |
| 1125 | } |
| 1126 | break; |
| 1127 | case Token::SHR: |
| 1128 | ASSERT(!reversed_); |
| 1129 | if (shift_value != 0) { |
| 1130 | __ mov(int32, Operand(int32, LSR, shift_value), SetCC); |
| 1131 | } else { |
| 1132 | // SHR is special because it is required to produce a positive answer. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1133 | __ cmp(int32, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1134 | } |
| 1135 | if (CpuFeatures::IsSupported(VFP3)) { |
| 1136 | __ b(mi, &result_not_a_smi); |
| 1137 | } else { |
| 1138 | // Non VFP code cannot convert from unsigned to double, so fall back |
| 1139 | // to GenericBinaryOpStub. |
| 1140 | __ b(mi, entry_label()); |
| 1141 | } |
| 1142 | break; |
| 1143 | case Token::SHL: |
| 1144 | ASSERT(!reversed_); |
| 1145 | if (shift_value != 0) { |
| 1146 | __ mov(int32, Operand(int32, LSL, shift_value)); |
| 1147 | } |
| 1148 | break; |
| 1149 | default: UNREACHABLE(); |
| 1150 | } |
| 1151 | // Check that the *signed* result fits in a smi. Not necessary for AND, SAR |
| 1152 | // if the shift if more than 0 or SHR if the shit is more than 1. |
| 1153 | if (!( (op_ == Token::AND) || |
| 1154 | ((op_ == Token::SAR) && (shift_value > 0)) || |
| 1155 | ((op_ == Token::SHR) && (shift_value > 1)))) { |
| 1156 | __ add(r3, int32, Operand(0x40000000), SetCC); |
| 1157 | __ b(mi, &result_not_a_smi); |
| 1158 | } |
| 1159 | __ mov(tos_register_, Operand(int32, LSL, kSmiTagSize)); |
| 1160 | Exit(); |
| 1161 | |
| 1162 | if (result_not_a_smi.is_linked()) { |
| 1163 | __ bind(&result_not_a_smi); |
| 1164 | if (overwrite_mode_ != OVERWRITE_LEFT) { |
| 1165 | ASSERT((overwrite_mode_ == NO_OVERWRITE) || |
| 1166 | (overwrite_mode_ == OVERWRITE_RIGHT)); |
| 1167 | // If the allocation fails, fall back to the GenericBinaryOpStub. |
| 1168 | __ AllocateHeapNumber(r4, r5, r6, heap_number_map, entry_label()); |
| 1169 | // Nothing can go wrong now, so overwrite tos. |
| 1170 | __ mov(tos_register_, Operand(r4)); |
| 1171 | } |
| 1172 | |
| 1173 | // int32: answer as signed 32bits integer. |
| 1174 | // tos_register_: Heap number to write the answer into. |
| 1175 | WriteNonSmiAnswer(int32, tos_register_, r3); |
| 1176 | |
| 1177 | Exit(); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | void DeferredInlineSmiOperation::GenerateAnswerOutOfRange() { |
| 1183 | // The input from a bitwise operation were Smis but the result cannot fit |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1184 | // into a Smi, so we store it into a heap number. VirtualFrame::scratch0() |
| 1185 | // holds the untagged result to be converted. tos_register_ contains the |
| 1186 | // input. See the calls to JumpToAnswerOutOfRange to see how we got here. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1187 | ASSERT(Token::IsBitOp(op_)); |
| 1188 | ASSERT(!reversed_); |
| 1189 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1190 | Register untagged_result = VirtualFrame::scratch0(); |
| 1191 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1192 | if (FLAG_debug_code) { |
| 1193 | __ Abort("Should not fall through!"); |
| 1194 | } |
| 1195 | |
| 1196 | __ bind(&answer_out_of_range_); |
| 1197 | if (((value_ & 0x1f) == 0) && (op_ == Token::SHR)) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1198 | // >>> 0 is a special case where the untagged_result register is not set up |
| 1199 | // yet. We untag the input to get it. |
| 1200 | __ mov(untagged_result, Operand(tos_register_, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | // This routine uses the registers from r2 to r6. At the moment they are |
| 1204 | // not used by the register allocator, but when they are it should use |
| 1205 | // SpillAll and MergeTo like DeferredInlineSmiOperation::Generate() above. |
| 1206 | |
| 1207 | // Allocate the result heap number. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1208 | Register heap_number_map = VirtualFrame::scratch1(); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1209 | Register heap_number = r4; |
| 1210 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 1211 | // If the allocation fails, fall back to the GenericBinaryOpStub. |
| 1212 | __ AllocateHeapNumber(heap_number, r5, r6, heap_number_map, entry_label()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1213 | WriteNonSmiAnswer(untagged_result, heap_number, r3); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1214 | __ mov(tos_register_, Operand(heap_number)); |
| 1215 | |
| 1216 | Exit(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1220 | static bool PopCountLessThanEqual2(unsigned int x) { |
| 1221 | x &= x - 1; |
| 1222 | return (x & (x - 1)) == 0; |
| 1223 | } |
| 1224 | |
| 1225 | |
| 1226 | // Returns the index of the lowest bit set. |
| 1227 | static int BitPosition(unsigned x) { |
| 1228 | int bit_posn = 0; |
| 1229 | while ((x & 0xf) == 0) { |
| 1230 | bit_posn += 4; |
| 1231 | x >>= 4; |
| 1232 | } |
| 1233 | while ((x & 1) == 0) { |
| 1234 | bit_posn++; |
| 1235 | x >>= 1; |
| 1236 | } |
| 1237 | return bit_posn; |
| 1238 | } |
| 1239 | |
| 1240 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1241 | // Can we multiply by x with max two shifts and an add. |
| 1242 | // This answers yes to all integers from 2 to 10. |
| 1243 | static bool IsEasyToMultiplyBy(int x) { |
| 1244 | if (x < 2) return false; // Avoid special cases. |
| 1245 | if (x > (Smi::kMaxValue + 1) >> 2) return false; // Almost always overflows. |
| 1246 | if (IsPowerOf2(x)) return true; // Simple shift. |
| 1247 | if (PopCountLessThanEqual2(x)) return true; // Shift and add and shift. |
| 1248 | if (IsPowerOf2(x + 1)) return true; // Patterns like 11111. |
| 1249 | return false; |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | // Can multiply by anything that IsEasyToMultiplyBy returns true for. |
| 1254 | // Source and destination may be the same register. This routine does |
| 1255 | // not set carry and overflow the way a mul instruction would. |
| 1256 | static void InlineMultiplyByKnownInt(MacroAssembler* masm, |
| 1257 | Register source, |
| 1258 | Register destination, |
| 1259 | int known_int) { |
| 1260 | if (IsPowerOf2(known_int)) { |
| 1261 | masm->mov(destination, Operand(source, LSL, BitPosition(known_int))); |
| 1262 | } else if (PopCountLessThanEqual2(known_int)) { |
| 1263 | int first_bit = BitPosition(known_int); |
| 1264 | int second_bit = BitPosition(known_int ^ (1 << first_bit)); |
| 1265 | masm->add(destination, source, |
| 1266 | Operand(source, LSL, second_bit - first_bit)); |
| 1267 | if (first_bit != 0) { |
| 1268 | masm->mov(destination, Operand(destination, LSL, first_bit)); |
| 1269 | } |
| 1270 | } else { |
| 1271 | ASSERT(IsPowerOf2(known_int + 1)); // Patterns like 1111. |
| 1272 | int the_bit = BitPosition(known_int + 1); |
| 1273 | masm->rsb(destination, source, Operand(source, LSL, the_bit)); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1278 | void CodeGenerator::SmiOperation(Token::Value op, |
| 1279 | Handle<Object> value, |
| 1280 | bool reversed, |
| 1281 | OverwriteMode mode) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1282 | int int_value = Smi::cast(*value)->value(); |
| 1283 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1284 | bool both_sides_are_smi = frame_->KnownSmiAt(0); |
| 1285 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1286 | bool something_to_inline; |
| 1287 | switch (op) { |
| 1288 | case Token::ADD: |
| 1289 | case Token::SUB: |
| 1290 | case Token::BIT_AND: |
| 1291 | case Token::BIT_OR: |
| 1292 | case Token::BIT_XOR: { |
| 1293 | something_to_inline = true; |
| 1294 | break; |
| 1295 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1296 | case Token::SHL: { |
| 1297 | something_to_inline = (both_sides_are_smi || !reversed); |
| 1298 | break; |
| 1299 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1300 | case Token::SHR: |
| 1301 | case Token::SAR: { |
| 1302 | if (reversed) { |
| 1303 | something_to_inline = false; |
| 1304 | } else { |
| 1305 | something_to_inline = true; |
| 1306 | } |
| 1307 | break; |
| 1308 | } |
| 1309 | case Token::MOD: { |
| 1310 | if (reversed || int_value < 2 || !IsPowerOf2(int_value)) { |
| 1311 | something_to_inline = false; |
| 1312 | } else { |
| 1313 | something_to_inline = true; |
| 1314 | } |
| 1315 | break; |
| 1316 | } |
| 1317 | case Token::MUL: { |
| 1318 | if (!IsEasyToMultiplyBy(int_value)) { |
| 1319 | something_to_inline = false; |
| 1320 | } else { |
| 1321 | something_to_inline = true; |
| 1322 | } |
| 1323 | break; |
| 1324 | } |
| 1325 | default: { |
| 1326 | something_to_inline = false; |
| 1327 | break; |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | if (!something_to_inline) { |
| 1332 | if (!reversed) { |
| 1333 | // Push the rhs onto the virtual frame by putting it in a TOS register. |
| 1334 | Register rhs = frame_->GetTOSRegister(); |
| 1335 | __ mov(rhs, Operand(value)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1336 | frame_->EmitPush(rhs, TypeInfo::Smi()); |
| 1337 | GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, int_value); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1338 | } else { |
| 1339 | // Pop the rhs, then push lhs and rhs in the right order. Only performs |
| 1340 | // at most one pop, the rest takes place in TOS registers. |
| 1341 | Register lhs = frame_->GetTOSRegister(); // Get reg for pushing. |
| 1342 | Register rhs = frame_->PopToRegister(lhs); // Don't use lhs for this. |
| 1343 | __ mov(lhs, Operand(value)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1344 | frame_->EmitPush(lhs, TypeInfo::Smi()); |
| 1345 | TypeInfo t = both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Unknown(); |
| 1346 | frame_->EmitPush(rhs, t); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1347 | GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, |
| 1348 | GenericBinaryOpStub::kUnknownIntValue); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1349 | } |
| 1350 | return; |
| 1351 | } |
| 1352 | |
| 1353 | // We move the top of stack to a register (normally no move is invoved). |
| 1354 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1355 | switch (op) { |
| 1356 | case Token::ADD: { |
| 1357 | DeferredCode* deferred = |
| 1358 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1359 | |
| 1360 | __ add(tos, tos, Operand(value), SetCC); |
| 1361 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1362 | if (!both_sides_are_smi) { |
| 1363 | __ tst(tos, Operand(kSmiTagMask)); |
| 1364 | deferred->Branch(ne); |
| 1365 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1366 | deferred->BindExit(); |
| 1367 | frame_->EmitPush(tos); |
| 1368 | break; |
| 1369 | } |
| 1370 | |
| 1371 | case Token::SUB: { |
| 1372 | DeferredCode* deferred = |
| 1373 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1374 | |
| 1375 | if (reversed) { |
| 1376 | __ rsb(tos, tos, Operand(value), SetCC); |
| 1377 | } else { |
| 1378 | __ sub(tos, tos, Operand(value), SetCC); |
| 1379 | } |
| 1380 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1381 | if (!both_sides_are_smi) { |
| 1382 | __ tst(tos, Operand(kSmiTagMask)); |
| 1383 | deferred->Branch(ne); |
| 1384 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1385 | deferred->BindExit(); |
| 1386 | frame_->EmitPush(tos); |
| 1387 | break; |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | case Token::BIT_OR: |
| 1392 | case Token::BIT_XOR: |
| 1393 | case Token::BIT_AND: { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1394 | if (both_sides_are_smi) { |
| 1395 | switch (op) { |
| 1396 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1397 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1398 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1399 | default: UNREACHABLE(); |
| 1400 | } |
| 1401 | frame_->EmitPush(tos, TypeInfo::Smi()); |
| 1402 | } else { |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1403 | DeferredInlineSmiOperation* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1404 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1405 | __ tst(tos, Operand(kSmiTagMask)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1406 | deferred->JumpToNonSmiInput(ne); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1407 | switch (op) { |
| 1408 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1409 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1410 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1411 | default: UNREACHABLE(); |
| 1412 | } |
| 1413 | deferred->BindExit(); |
| 1414 | TypeInfo result_type = |
| 1415 | (op == Token::BIT_AND) ? TypeInfo::Smi() : TypeInfo::Integer32(); |
| 1416 | frame_->EmitPush(tos, result_type); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1417 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | } |
| 1420 | |
| 1421 | case Token::SHL: |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1422 | if (reversed) { |
| 1423 | ASSERT(both_sides_are_smi); |
| 1424 | int max_shift = 0; |
| 1425 | int max_result = int_value == 0 ? 1 : int_value; |
| 1426 | while (Smi::IsValid(max_result << 1)) { |
| 1427 | max_shift++; |
| 1428 | max_result <<= 1; |
| 1429 | } |
| 1430 | DeferredCode* deferred = |
| 1431 | new DeferredInlineSmiOperation(op, int_value, true, mode, tos); |
| 1432 | // Mask off the last 5 bits of the shift operand (rhs). This is part |
| 1433 | // of the definition of shift in JS and we know we have a Smi so we |
| 1434 | // can safely do this. The masked version gets passed to the |
| 1435 | // deferred code, but that makes no difference. |
| 1436 | __ and_(tos, tos, Operand(Smi::FromInt(0x1f))); |
| 1437 | __ cmp(tos, Operand(Smi::FromInt(max_shift))); |
| 1438 | deferred->Branch(ge); |
| 1439 | Register scratch = VirtualFrame::scratch0(); |
| 1440 | __ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Untag. |
| 1441 | __ mov(tos, Operand(Smi::FromInt(int_value))); // Load constant. |
| 1442 | __ mov(tos, Operand(tos, LSL, scratch)); // Shift constant. |
| 1443 | deferred->BindExit(); |
| 1444 | TypeInfo result = TypeInfo::Integer32(); |
| 1445 | frame_->EmitPush(tos, result); |
| 1446 | break; |
| 1447 | } |
| 1448 | // Fall through! |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1449 | case Token::SHR: |
| 1450 | case Token::SAR: { |
| 1451 | ASSERT(!reversed); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1452 | int shift_value = int_value & 0x1f; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1453 | TypeInfo result = TypeInfo::Number(); |
| 1454 | |
| 1455 | if (op == Token::SHR) { |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1456 | if (shift_value > 1) { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1457 | result = TypeInfo::Smi(); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1458 | } else if (shift_value > 0) { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1459 | result = TypeInfo::Integer32(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1460 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1461 | } else if (op == Token::SAR) { |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1462 | if (shift_value > 0) { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1463 | result = TypeInfo::Smi(); |
| 1464 | } else { |
| 1465 | result = TypeInfo::Integer32(); |
| 1466 | } |
| 1467 | } else { |
| 1468 | ASSERT(op == Token::SHL); |
| 1469 | result = TypeInfo::Integer32(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1470 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1471 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1472 | DeferredInlineSmiOperation* deferred = |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1473 | new DeferredInlineSmiOperation(op, shift_value, false, mode, tos); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1474 | if (!both_sides_are_smi) { |
| 1475 | __ tst(tos, Operand(kSmiTagMask)); |
| 1476 | deferred->JumpToNonSmiInput(ne); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1477 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1478 | switch (op) { |
| 1479 | case Token::SHL: { |
| 1480 | if (shift_value != 0) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1481 | Register untagged_result = VirtualFrame::scratch0(); |
| 1482 | Register scratch = VirtualFrame::scratch1(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1483 | int adjusted_shift = shift_value - kSmiTagSize; |
| 1484 | ASSERT(adjusted_shift >= 0); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1485 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1486 | if (adjusted_shift != 0) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1487 | __ mov(untagged_result, Operand(tos, LSL, adjusted_shift)); |
| 1488 | } else { |
| 1489 | __ mov(untagged_result, Operand(tos)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1490 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1491 | // Check that the *signed* result fits in a smi. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1492 | __ add(scratch, untagged_result, Operand(0x40000000), SetCC); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1493 | deferred->JumpToAnswerOutOfRange(mi); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1494 | __ mov(tos, Operand(untagged_result, LSL, kSmiTagSize)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1495 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1496 | break; |
| 1497 | } |
| 1498 | case Token::SHR: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1499 | if (shift_value != 0) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1500 | Register untagged_result = VirtualFrame::scratch0(); |
| 1501 | // Remove tag. |
| 1502 | __ mov(untagged_result, Operand(tos, ASR, kSmiTagSize)); |
| 1503 | __ mov(untagged_result, Operand(untagged_result, LSR, shift_value)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1504 | if (shift_value == 1) { |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1505 | // Check that the *unsigned* result fits in a smi. |
| 1506 | // Neither of the two high-order bits can be set: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1507 | // - 0x80000000: high bit would be lost when smi tagging |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1508 | // - 0x40000000: this number would convert to negative when Smi |
| 1509 | // tagging. |
| 1510 | // These two cases can only happen with shifts by 0 or 1 when |
| 1511 | // handed a valid smi. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1512 | __ tst(untagged_result, Operand(0xc0000000)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1513 | deferred->JumpToAnswerOutOfRange(ne); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1514 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1515 | __ mov(tos, Operand(untagged_result, LSL, kSmiTagSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1516 | } else { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1517 | __ cmp(tos, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1518 | deferred->JumpToAnswerOutOfRange(mi); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1519 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1520 | break; |
| 1521 | } |
| 1522 | case Token::SAR: { |
| 1523 | if (shift_value != 0) { |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1524 | // Do the shift and the tag removal in one operation. If the shift |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1525 | // is 31 bits (the highest possible value) then we emit the |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1526 | // instruction as a shift by 0 which in the ARM ISA means shift |
| 1527 | // arithmetically by 32. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1528 | __ mov(tos, Operand(tos, ASR, (kSmiTagSize + shift_value) & 0x1f)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1529 | __ mov(tos, Operand(tos, LSL, kSmiTagSize)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1530 | } |
| 1531 | break; |
| 1532 | } |
| 1533 | default: UNREACHABLE(); |
| 1534 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1535 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1536 | frame_->EmitPush(tos, result); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1537 | break; |
| 1538 | } |
| 1539 | |
| 1540 | case Token::MOD: { |
| 1541 | ASSERT(!reversed); |
| 1542 | ASSERT(int_value >= 2); |
| 1543 | ASSERT(IsPowerOf2(int_value)); |
| 1544 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1545 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1546 | unsigned mask = (0x80000000u | kSmiTagMask); |
| 1547 | __ tst(tos, Operand(mask)); |
| 1548 | deferred->Branch(ne); // Go to deferred code on non-Smis and negative. |
| 1549 | mask = (int_value << kSmiTagSize) - 1; |
| 1550 | __ and_(tos, tos, Operand(mask)); |
| 1551 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1552 | // Mod of positive power of 2 Smi gives a Smi if the lhs is an integer. |
| 1553 | frame_->EmitPush( |
| 1554 | tos, |
| 1555 | both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Number()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1556 | break; |
| 1557 | } |
| 1558 | |
| 1559 | case Token::MUL: { |
| 1560 | ASSERT(IsEasyToMultiplyBy(int_value)); |
| 1561 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1562 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1563 | unsigned max_smi_that_wont_overflow = Smi::kMaxValue / int_value; |
| 1564 | max_smi_that_wont_overflow <<= kSmiTagSize; |
| 1565 | unsigned mask = 0x80000000u; |
| 1566 | while ((mask & max_smi_that_wont_overflow) == 0) { |
| 1567 | mask |= mask >> 1; |
| 1568 | } |
| 1569 | mask |= kSmiTagMask; |
| 1570 | // This does a single mask that checks for a too high value in a |
| 1571 | // conservative way and for a non-Smi. It also filters out negative |
| 1572 | // numbers, unfortunately, but since this code is inline we prefer |
| 1573 | // brevity to comprehensiveness. |
| 1574 | __ tst(tos, Operand(mask)); |
| 1575 | deferred->Branch(ne); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1576 | InlineMultiplyByKnownInt(masm_, tos, tos, int_value); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1577 | deferred->BindExit(); |
| 1578 | frame_->EmitPush(tos); |
| 1579 | break; |
| 1580 | } |
| 1581 | |
| 1582 | default: |
| 1583 | UNREACHABLE(); |
| 1584 | break; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1589 | void CodeGenerator::Comparison(Condition cc, |
| 1590 | Expression* left, |
| 1591 | Expression* right, |
| 1592 | bool strict) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1593 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1594 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1595 | if (left != NULL) Load(left); |
| 1596 | if (right != NULL) Load(right); |
| 1597 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1598 | // sp[0] : y |
| 1599 | // sp[1] : x |
| 1600 | // result : cc register |
| 1601 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1602 | // Strict only makes sense for equality comparisons. |
| 1603 | ASSERT(!strict || cc == eq); |
| 1604 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1605 | Register lhs; |
| 1606 | Register rhs; |
| 1607 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1608 | bool lhs_is_smi; |
| 1609 | bool rhs_is_smi; |
| 1610 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1611 | // We load the top two stack positions into registers chosen by the virtual |
| 1612 | // frame. This should keep the register shuffling to a minimum. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1613 | // Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order. |
| 1614 | if (cc == gt || cc == le) { |
| 1615 | cc = ReverseCondition(cc); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1616 | lhs_is_smi = frame_->KnownSmiAt(0); |
| 1617 | rhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1618 | lhs = frame_->PopToRegister(); |
| 1619 | rhs = frame_->PopToRegister(lhs); // Don't pop to the same register again! |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1620 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1621 | rhs_is_smi = frame_->KnownSmiAt(0); |
| 1622 | lhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1623 | rhs = frame_->PopToRegister(); |
| 1624 | lhs = frame_->PopToRegister(rhs); // Don't pop to the same register again! |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1625 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1626 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1627 | bool both_sides_are_smi = (lhs_is_smi && rhs_is_smi); |
| 1628 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1629 | ASSERT(rhs.is(r0) || rhs.is(r1)); |
| 1630 | ASSERT(lhs.is(r0) || lhs.is(r1)); |
| 1631 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1632 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1633 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1634 | if (!both_sides_are_smi) { |
| 1635 | // Now we have the two sides in r0 and r1. We flush any other registers |
| 1636 | // because the stub doesn't know about register allocation. |
| 1637 | frame_->SpillAll(); |
| 1638 | Register scratch = VirtualFrame::scratch0(); |
| 1639 | Register smi_test_reg; |
| 1640 | if (lhs_is_smi) { |
| 1641 | smi_test_reg = rhs; |
| 1642 | } else if (rhs_is_smi) { |
| 1643 | smi_test_reg = lhs; |
| 1644 | } else { |
| 1645 | __ orr(scratch, lhs, Operand(rhs)); |
| 1646 | smi_test_reg = scratch; |
| 1647 | } |
| 1648 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 1649 | JumpTarget smi; |
| 1650 | smi.Branch(eq); |
| 1651 | |
| 1652 | // Perform non-smi comparison by stub. |
| 1653 | // CompareStub takes arguments in r0 and r1, returns <0, >0 or 0 in r0. |
| 1654 | // We call with 0 args because there are 0 on the stack. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1655 | CompareStub stub(cc, strict, NO_SMI_COMPARE_IN_STUB, lhs, rhs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1656 | frame_->CallStub(&stub, 0); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1657 | __ cmp(r0, Operand(0, RelocInfo::NONE)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1658 | exit.Jump(); |
| 1659 | |
| 1660 | smi.Bind(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1663 | // Do smi comparisons by pointer comparison. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1664 | __ cmp(lhs, Operand(rhs)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1665 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1666 | exit.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1667 | cc_reg_ = cc; |
| 1668 | } |
| 1669 | |
| 1670 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1671 | // Call the function on the stack with the given arguments. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1672 | void CodeGenerator::CallWithArguments(ZoneList<Expression*>* args, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1673 | CallFunctionFlags flags, |
| 1674 | int position) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1675 | // Push the arguments ("left-to-right") on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1676 | int arg_count = args->length(); |
| 1677 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1678 | Load(args->at(i)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1679 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1680 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1681 | // Record the position for debugging purposes. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1682 | CodeForSourcePosition(position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1683 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1684 | // Use the shared code stub to call the function. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1685 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1686 | CallFunctionStub call_function(arg_count, in_loop, flags); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1687 | frame_->CallStub(&call_function, arg_count + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1688 | |
| 1689 | // Restore context and pop function from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1690 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1691 | frame_->Drop(); // discard the TOS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1695 | void CodeGenerator::CallApplyLazy(Expression* applicand, |
| 1696 | Expression* receiver, |
| 1697 | VariableProxy* arguments, |
| 1698 | int position) { |
| 1699 | // An optimized implementation of expressions of the form |
| 1700 | // x.apply(y, arguments). |
| 1701 | // If the arguments object of the scope has not been allocated, |
| 1702 | // and x.apply is Function.prototype.apply, this optimization |
| 1703 | // just copies y and the arguments of the current function on the |
| 1704 | // stack, as receiver and arguments, and calls x. |
| 1705 | // In the implementation comments, we call x the applicand |
| 1706 | // and y the receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1707 | |
| 1708 | ASSERT(ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION); |
| 1709 | ASSERT(arguments->IsArguments()); |
| 1710 | |
| 1711 | // Load applicand.apply onto the stack. This will usually |
| 1712 | // give us a megamorphic load site. Not super, but it works. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1713 | Load(applicand); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1714 | Handle<String> name = Factory::LookupAsciiSymbol("apply"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1715 | frame_->Dup(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1716 | frame_->CallLoadIC(name, RelocInfo::CODE_TARGET); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1717 | frame_->EmitPush(r0); |
| 1718 | |
| 1719 | // Load the receiver and the existing arguments object onto the |
| 1720 | // expression stack. Avoid allocating the arguments object here. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1721 | Load(receiver); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1722 | LoadFromSlot(scope()->arguments()->AsSlot(), NOT_INSIDE_TYPEOF); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1723 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1724 | // At this point the top two stack elements are probably in registers |
| 1725 | // since they were just loaded. Ensure they are in regs and get the |
| 1726 | // regs. |
| 1727 | Register receiver_reg = frame_->Peek2(); |
| 1728 | Register arguments_reg = frame_->Peek(); |
| 1729 | |
| 1730 | // From now on the frame is spilled. |
| 1731 | frame_->SpillAll(); |
| 1732 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1733 | // Emit the source position information after having loaded the |
| 1734 | // receiver and the arguments. |
| 1735 | CodeForSourcePosition(position); |
| 1736 | // Contents of the stack at this point: |
| 1737 | // sp[0]: arguments object of the current function or the hole. |
| 1738 | // sp[1]: receiver |
| 1739 | // sp[2]: applicand.apply |
| 1740 | // sp[3]: applicand. |
| 1741 | |
| 1742 | // Check if the arguments object has been lazily allocated |
| 1743 | // already. If so, just use that instead of copying the arguments |
| 1744 | // from the stack. This also deals with cases where a local variable |
| 1745 | // named 'arguments' has been introduced. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1746 | JumpTarget slow; |
| 1747 | Label done; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1748 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1749 | __ cmp(ip, arguments_reg); |
| 1750 | slow.Branch(ne); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1751 | |
| 1752 | Label build_args; |
| 1753 | // Get rid of the arguments object probe. |
| 1754 | frame_->Drop(); |
| 1755 | // Stack now has 3 elements on it. |
| 1756 | // Contents of stack at this point: |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1757 | // sp[0]: receiver - in the receiver_reg register. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1758 | // sp[1]: applicand.apply |
| 1759 | // sp[2]: applicand. |
| 1760 | |
| 1761 | // Check that the receiver really is a JavaScript object. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1762 | __ BranchOnSmi(receiver_reg, &build_args); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1763 | // We allow all JSObjects including JSFunctions. As long as |
| 1764 | // JS_FUNCTION_TYPE is the last instance type and it is right |
| 1765 | // after LAST_JS_OBJECT_TYPE, we do not have to check the upper |
| 1766 | // bound. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1767 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 1768 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1769 | __ CompareObjectType(receiver_reg, r2, r3, FIRST_JS_OBJECT_TYPE); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1770 | __ b(lt, &build_args); |
| 1771 | |
| 1772 | // Check that applicand.apply is Function.prototype.apply. |
| 1773 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1774 | __ BranchOnSmi(r0, &build_args); |
| 1775 | __ CompareObjectType(r0, r1, r2, JS_FUNCTION_TYPE); |
| 1776 | __ b(ne, &build_args); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1777 | Handle<Code> apply_code(Builtins::builtin(Builtins::FunctionApply)); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1778 | __ ldr(r1, FieldMemOperand(r0, JSFunction::kCodeEntryOffset)); |
| 1779 | __ sub(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1780 | __ cmp(r1, Operand(apply_code)); |
| 1781 | __ b(ne, &build_args); |
| 1782 | |
| 1783 | // Check that applicand is a function. |
| 1784 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
| 1785 | __ BranchOnSmi(r1, &build_args); |
| 1786 | __ CompareObjectType(r1, r2, r3, JS_FUNCTION_TYPE); |
| 1787 | __ b(ne, &build_args); |
| 1788 | |
| 1789 | // Copy the arguments to this function possibly from the |
| 1790 | // adaptor frame below it. |
| 1791 | Label invoke, adapted; |
| 1792 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 1793 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 1794 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 1795 | __ b(eq, &adapted); |
| 1796 | |
| 1797 | // No arguments adaptor frame. Copy fixed number of arguments. |
| 1798 | __ mov(r0, Operand(scope()->num_parameters())); |
| 1799 | for (int i = 0; i < scope()->num_parameters(); i++) { |
| 1800 | __ ldr(r2, frame_->ParameterAt(i)); |
| 1801 | __ push(r2); |
| 1802 | } |
| 1803 | __ jmp(&invoke); |
| 1804 | |
| 1805 | // Arguments adaptor frame present. Copy arguments from there, but |
| 1806 | // avoid copying too many arguments to avoid stack overflows. |
| 1807 | __ bind(&adapted); |
| 1808 | static const uint32_t kArgumentsLimit = 1 * KB; |
| 1809 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1810 | __ mov(r0, Operand(r0, LSR, kSmiTagSize)); |
| 1811 | __ mov(r3, r0); |
| 1812 | __ cmp(r0, Operand(kArgumentsLimit)); |
| 1813 | __ b(gt, &build_args); |
| 1814 | |
| 1815 | // Loop through the arguments pushing them onto the execution |
| 1816 | // stack. We don't inform the virtual frame of the push, so we don't |
| 1817 | // have to worry about getting rid of the elements from the virtual |
| 1818 | // frame. |
| 1819 | Label loop; |
| 1820 | // r3 is a small non-negative integer, due to the test above. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1821 | __ cmp(r3, Operand(0, RelocInfo::NONE)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1822 | __ b(eq, &invoke); |
| 1823 | // Compute the address of the first argument. |
| 1824 | __ add(r2, r2, Operand(r3, LSL, kPointerSizeLog2)); |
| 1825 | __ add(r2, r2, Operand(kPointerSize)); |
| 1826 | __ bind(&loop); |
| 1827 | // Post-decrement argument address by kPointerSize on each iteration. |
| 1828 | __ ldr(r4, MemOperand(r2, kPointerSize, NegPostIndex)); |
| 1829 | __ push(r4); |
| 1830 | __ sub(r3, r3, Operand(1), SetCC); |
| 1831 | __ b(gt, &loop); |
| 1832 | |
| 1833 | // Invoke the function. |
| 1834 | __ bind(&invoke); |
| 1835 | ParameterCount actual(r0); |
| 1836 | __ InvokeFunction(r1, actual, CALL_FUNCTION); |
| 1837 | // Drop applicand.apply and applicand from the stack, and push |
| 1838 | // the result of the function call, but leave the spilled frame |
| 1839 | // unchanged, with 3 elements, so it is correct when we compile the |
| 1840 | // slow-case code. |
| 1841 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 1842 | __ push(r0); |
| 1843 | // Stack now has 1 element: |
| 1844 | // sp[0]: result |
| 1845 | __ jmp(&done); |
| 1846 | |
| 1847 | // Slow-case: Allocate the arguments object since we know it isn't |
| 1848 | // there, and fall-through to the slow-case where we call |
| 1849 | // applicand.apply. |
| 1850 | __ bind(&build_args); |
| 1851 | // Stack now has 3 elements, because we have jumped from where: |
| 1852 | // sp[0]: receiver |
| 1853 | // sp[1]: applicand.apply |
| 1854 | // sp[2]: applicand. |
| 1855 | StoreArgumentsObject(false); |
| 1856 | |
| 1857 | // Stack and frame now have 4 elements. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1858 | slow.Bind(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1859 | |
| 1860 | // Generic computation of x.apply(y, args) with no special optimization. |
| 1861 | // Flip applicand.apply and applicand on the stack, so |
| 1862 | // applicand looks like the receiver of the applicand.apply call. |
| 1863 | // Then process it as a normal function call. |
| 1864 | __ ldr(r0, MemOperand(sp, 3 * kPointerSize)); |
| 1865 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1866 | __ Strd(r0, r1, MemOperand(sp, 2 * kPointerSize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1867 | |
| 1868 | CallFunctionStub call_function(2, NOT_IN_LOOP, NO_CALL_FUNCTION_FLAGS); |
| 1869 | frame_->CallStub(&call_function, 3); |
| 1870 | // The function and its two arguments have been dropped. |
| 1871 | frame_->Drop(); // Drop the receiver as well. |
| 1872 | frame_->EmitPush(r0); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1873 | frame_->SpillAll(); // A spilled frame is also jumping to label done. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1874 | // Stack now has 1 element: |
| 1875 | // sp[0]: result |
| 1876 | __ bind(&done); |
| 1877 | |
| 1878 | // Restore the context register after a call. |
| 1879 | __ ldr(cp, frame_->Context()); |
| 1880 | } |
| 1881 | |
| 1882 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1883 | void CodeGenerator::Branch(bool if_true, JumpTarget* target) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | ASSERT(has_cc()); |
| 1885 | Condition cc = if_true ? cc_reg_ : NegateCondition(cc_reg_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1886 | target->Branch(cc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1887 | cc_reg_ = al; |
| 1888 | } |
| 1889 | |
| 1890 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1891 | void CodeGenerator::CheckStack() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1892 | frame_->SpillAll(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1893 | Comment cmnt(masm_, "[ check stack"); |
| 1894 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1895 | masm_->cmp(sp, Operand(ip)); |
| 1896 | StackCheckStub stub; |
| 1897 | // Call the stub if lower. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1898 | masm_->mov(ip, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1899 | Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), |
| 1900 | RelocInfo::CODE_TARGET), |
| 1901 | LeaveCC, |
| 1902 | lo); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1903 | masm_->Call(ip, lo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1907 | void CodeGenerator::VisitStatements(ZoneList<Statement*>* statements) { |
| 1908 | #ifdef DEBUG |
| 1909 | int original_height = frame_->height(); |
| 1910 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1911 | for (int i = 0; frame_ != NULL && i < statements->length(); i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1912 | Visit(statements->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1913 | } |
| 1914 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 1915 | } |
| 1916 | |
| 1917 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1918 | void CodeGenerator::VisitBlock(Block* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1919 | #ifdef DEBUG |
| 1920 | int original_height = frame_->height(); |
| 1921 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1922 | Comment cmnt(masm_, "[ Block"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1923 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1924 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1925 | VisitStatements(node->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1926 | if (node->break_target()->is_linked()) { |
| 1927 | node->break_target()->Bind(); |
| 1928 | } |
| 1929 | node->break_target()->Unuse(); |
| 1930 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1934 | void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1935 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1936 | frame_->EmitPush(Operand(pairs)); |
| 1937 | frame_->EmitPush(Operand(Smi::FromInt(is_eval() ? 1 : 0))); |
| 1938 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1939 | frame_->CallRuntime(Runtime::kDeclareGlobals, 3); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1940 | // The result is discarded. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1944 | void CodeGenerator::VisitDeclaration(Declaration* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1945 | #ifdef DEBUG |
| 1946 | int original_height = frame_->height(); |
| 1947 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | Comment cmnt(masm_, "[ Declaration"); |
| 1949 | Variable* var = node->proxy()->var(); |
| 1950 | ASSERT(var != NULL); // must have been resolved |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1951 | Slot* slot = var->AsSlot(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1952 | |
| 1953 | // If it was not possible to allocate the variable at compile time, |
| 1954 | // we need to "declare" it at runtime to make sure it actually |
| 1955 | // exists in the local context. |
| 1956 | if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 1957 | // Variables with a "LOOKUP" slot were introduced as non-locals |
| 1958 | // during variable resolution and must have mode DYNAMIC. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1959 | ASSERT(var->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1960 | // For now, just do a runtime call. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1961 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1962 | frame_->EmitPush(Operand(var->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1963 | // Declaration nodes are always declared in only two modes. |
| 1964 | ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); |
| 1965 | PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1966 | frame_->EmitPush(Operand(Smi::FromInt(attr))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1967 | // Push initial value, if any. |
| 1968 | // Note: For variables we must not push an initial value (such as |
| 1969 | // 'undefined') because we may have a (legal) redeclaration and we |
| 1970 | // must not destroy the current value. |
| 1971 | if (node->mode() == Variable::CONST) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1972 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1973 | } else if (node->fun() != NULL) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1974 | Load(node->fun()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1975 | } else { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1976 | frame_->EmitPush(Operand(0, RelocInfo::NONE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1977 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1978 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1979 | frame_->CallRuntime(Runtime::kDeclareContextSlot, 4); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1980 | // Ignore the return value (declarations are statements). |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1981 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1982 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1983 | return; |
| 1984 | } |
| 1985 | |
| 1986 | ASSERT(!var->is_global()); |
| 1987 | |
| 1988 | // If we have a function or a constant, we need to initialize the variable. |
| 1989 | Expression* val = NULL; |
| 1990 | if (node->mode() == Variable::CONST) { |
| 1991 | val = new Literal(Factory::the_hole_value()); |
| 1992 | } else { |
| 1993 | val = node->fun(); // NULL if we don't have a function |
| 1994 | } |
| 1995 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1996 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1997 | if (val != NULL) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1998 | WriteBarrierCharacter wb_info = |
| 1999 | val->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
| 2000 | if (val->AsLiteral() != NULL) wb_info = NEVER_NEWSPACE; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2001 | // Set initial value. |
| 2002 | Reference target(this, node->proxy()); |
| 2003 | Load(val); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2004 | target.SetValue(NOT_CONST_INIT, wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2005 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2006 | // Get rid of the assigned value (declarations are statements). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2007 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2008 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2009 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2013 | void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2014 | #ifdef DEBUG |
| 2015 | int original_height = frame_->height(); |
| 2016 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2017 | Comment cmnt(masm_, "[ ExpressionStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2018 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2019 | Expression* expression = node->expression(); |
| 2020 | expression->MarkAsStatement(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2021 | Load(expression); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2022 | frame_->Drop(); |
| 2023 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2027 | void CodeGenerator::VisitEmptyStatement(EmptyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2028 | #ifdef DEBUG |
| 2029 | int original_height = frame_->height(); |
| 2030 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2031 | Comment cmnt(masm_, "// EmptyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2032 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2033 | // nothing to do |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2034 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2038 | void CodeGenerator::VisitIfStatement(IfStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2039 | #ifdef DEBUG |
| 2040 | int original_height = frame_->height(); |
| 2041 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2042 | Comment cmnt(masm_, "[ IfStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2043 | // Generate different code depending on which parts of the if statement |
| 2044 | // are present or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2045 | bool has_then_stm = node->HasThenStatement(); |
| 2046 | bool has_else_stm = node->HasElseStatement(); |
| 2047 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2048 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2049 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2050 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2051 | if (has_then_stm && has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2052 | Comment cmnt(masm_, "[ IfThenElse"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2053 | JumpTarget then; |
| 2054 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2055 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2056 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2057 | if (frame_ != NULL) { |
| 2058 | Branch(false, &else_); |
| 2059 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2060 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2061 | if (frame_ != NULL || then.is_linked()) { |
| 2062 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2063 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2064 | } |
| 2065 | if (frame_ != NULL) { |
| 2066 | exit.Jump(); |
| 2067 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2068 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2069 | if (else_.is_linked()) { |
| 2070 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2071 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2072 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2073 | |
| 2074 | } else if (has_then_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2075 | Comment cmnt(masm_, "[ IfThen"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2076 | ASSERT(!has_else_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2077 | JumpTarget then; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2078 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2079 | LoadCondition(node->condition(), &then, &exit, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2080 | if (frame_ != NULL) { |
| 2081 | Branch(false, &exit); |
| 2082 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2083 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2084 | if (frame_ != NULL || then.is_linked()) { |
| 2085 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2086 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2087 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2088 | |
| 2089 | } else if (has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2090 | Comment cmnt(masm_, "[ IfElse"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2091 | ASSERT(!has_then_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2092 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2093 | // if (!cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2094 | LoadCondition(node->condition(), &exit, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2095 | if (frame_ != NULL) { |
| 2096 | Branch(true, &exit); |
| 2097 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2098 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2099 | if (frame_ != NULL || else_.is_linked()) { |
| 2100 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2101 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2102 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2103 | |
| 2104 | } else { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2105 | Comment cmnt(masm_, "[ If"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2106 | ASSERT(!has_then_stm && !has_else_stm); |
| 2107 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2108 | LoadCondition(node->condition(), &exit, &exit, false); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2109 | if (frame_ != NULL) { |
| 2110 | if (has_cc()) { |
| 2111 | cc_reg_ = al; |
| 2112 | } else { |
| 2113 | frame_->Drop(); |
| 2114 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | // end |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2119 | if (exit.is_linked()) { |
| 2120 | exit.Bind(); |
| 2121 | } |
| 2122 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2126 | void CodeGenerator::VisitContinueStatement(ContinueStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2127 | Comment cmnt(masm_, "[ ContinueStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2128 | CodeForStatementPosition(node); |
| 2129 | node->target()->continue_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2133 | void CodeGenerator::VisitBreakStatement(BreakStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2134 | Comment cmnt(masm_, "[ BreakStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2135 | CodeForStatementPosition(node); |
| 2136 | node->target()->break_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2140 | void CodeGenerator::VisitReturnStatement(ReturnStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2141 | Comment cmnt(masm_, "[ ReturnStatement"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2142 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2143 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2144 | Load(node->expression()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2145 | frame_->PopToR0(); |
| 2146 | frame_->PrepareForReturn(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2147 | if (function_return_is_shadowed_) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2148 | function_return_.Jump(); |
| 2149 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2150 | // Pop the result from the frame and prepare the frame for |
| 2151 | // returning thus making it easier to merge. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2152 | if (function_return_.is_bound()) { |
| 2153 | // If the function return label is already bound we reuse the |
| 2154 | // code by jumping to the return site. |
| 2155 | function_return_.Jump(); |
| 2156 | } else { |
| 2157 | function_return_.Bind(); |
| 2158 | GenerateReturnSequence(); |
| 2159 | } |
| 2160 | } |
| 2161 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2162 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2163 | |
| 2164 | void CodeGenerator::GenerateReturnSequence() { |
| 2165 | if (FLAG_trace) { |
| 2166 | // Push the return value on the stack as the parameter. |
| 2167 | // Runtime::TraceExit returns the parameter as it is. |
| 2168 | frame_->EmitPush(r0); |
| 2169 | frame_->CallRuntime(Runtime::kTraceExit, 1); |
| 2170 | } |
| 2171 | |
| 2172 | #ifdef DEBUG |
| 2173 | // Add a label for checking the size of the code used for returning. |
| 2174 | Label check_exit_codesize; |
| 2175 | masm_->bind(&check_exit_codesize); |
| 2176 | #endif |
| 2177 | // Make sure that the constant pool is not emitted inside of the return |
| 2178 | // sequence. |
| 2179 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 2180 | // Tear down the frame which will restore the caller's frame pointer and |
| 2181 | // the link register. |
| 2182 | frame_->Exit(); |
| 2183 | |
| 2184 | // Here we use masm_-> instead of the __ macro to avoid the code coverage |
| 2185 | // tool from instrumenting as we rely on the code size here. |
| 2186 | int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize; |
| 2187 | masm_->add(sp, sp, Operand(sp_delta)); |
| 2188 | masm_->Jump(lr); |
| 2189 | DeleteFrame(); |
| 2190 | |
| 2191 | #ifdef DEBUG |
| 2192 | // Check that the size of the code used for returning matches what is |
| 2193 | // expected by the debugger. If the sp_delts above cannot be encoded in |
| 2194 | // the add instruction the add will generate two instructions. |
| 2195 | int return_sequence_length = |
| 2196 | masm_->InstructionsGeneratedSince(&check_exit_codesize); |
| 2197 | CHECK(return_sequence_length == |
| 2198 | Assembler::kJSReturnSequenceInstructions || |
| 2199 | return_sequence_length == |
| 2200 | Assembler::kJSReturnSequenceInstructions + 1); |
| 2201 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2202 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2206 | void CodeGenerator::VisitWithEnterStatement(WithEnterStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2207 | #ifdef DEBUG |
| 2208 | int original_height = frame_->height(); |
| 2209 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2210 | Comment cmnt(masm_, "[ WithEnterStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2211 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2212 | Load(node->expression()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2213 | if (node->is_catch_block()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2214 | frame_->CallRuntime(Runtime::kPushCatchContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2215 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2216 | frame_->CallRuntime(Runtime::kPushContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2217 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2218 | #ifdef DEBUG |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2219 | JumpTarget verified_true; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2220 | __ cmp(r0, cp); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2221 | verified_true.Branch(eq); |
| 2222 | __ stop("PushContext: r0 is expected to be the same as cp"); |
| 2223 | verified_true.Bind(); |
| 2224 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2225 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2226 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2227 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2231 | void CodeGenerator::VisitWithExitStatement(WithExitStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2232 | #ifdef DEBUG |
| 2233 | int original_height = frame_->height(); |
| 2234 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2235 | Comment cmnt(masm_, "[ WithExitStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2236 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2237 | // Pop context. |
| 2238 | __ ldr(cp, ContextOperand(cp, Context::PREVIOUS_INDEX)); |
| 2239 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2240 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2241 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2245 | void CodeGenerator::VisitSwitchStatement(SwitchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2246 | #ifdef DEBUG |
| 2247 | int original_height = frame_->height(); |
| 2248 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2249 | Comment cmnt(masm_, "[ SwitchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2250 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2251 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2252 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2253 | Load(node->tag()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2254 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2255 | JumpTarget next_test; |
| 2256 | JumpTarget fall_through; |
| 2257 | JumpTarget default_entry; |
| 2258 | JumpTarget default_exit(JumpTarget::BIDIRECTIONAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2259 | ZoneList<CaseClause*>* cases = node->cases(); |
| 2260 | int length = cases->length(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2261 | CaseClause* default_clause = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2262 | |
| 2263 | for (int i = 0; i < length; i++) { |
| 2264 | CaseClause* clause = cases->at(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2265 | if (clause->is_default()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2266 | // Remember the default clause and compile it at the end. |
| 2267 | default_clause = clause; |
| 2268 | continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | } |
| 2270 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2271 | Comment cmnt(masm_, "[ Case clause"); |
| 2272 | // Compile the test. |
| 2273 | next_test.Bind(); |
| 2274 | next_test.Unuse(); |
| 2275 | // Duplicate TOS. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2276 | frame_->Dup(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2277 | Comparison(eq, NULL, clause->label(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2278 | Branch(false, &next_test); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2279 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2280 | // Before entering the body from the test, remove the switch value from |
| 2281 | // the stack. |
| 2282 | frame_->Drop(); |
| 2283 | |
| 2284 | // Label the body so that fall through is enabled. |
| 2285 | if (i > 0 && cases->at(i - 1)->is_default()) { |
| 2286 | default_exit.Bind(); |
| 2287 | } else { |
| 2288 | fall_through.Bind(); |
| 2289 | fall_through.Unuse(); |
| 2290 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2291 | VisitStatements(clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2292 | |
| 2293 | // If control flow can fall through from the body, jump to the next body |
| 2294 | // or the end of the statement. |
| 2295 | if (frame_ != NULL) { |
| 2296 | if (i < length - 1 && cases->at(i + 1)->is_default()) { |
| 2297 | default_entry.Jump(); |
| 2298 | } else { |
| 2299 | fall_through.Jump(); |
| 2300 | } |
| 2301 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2304 | // The final "test" removes the switch value. |
| 2305 | next_test.Bind(); |
| 2306 | frame_->Drop(); |
| 2307 | |
| 2308 | // If there is a default clause, compile it. |
| 2309 | if (default_clause != NULL) { |
| 2310 | Comment cmnt(masm_, "[ Default clause"); |
| 2311 | default_entry.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2312 | VisitStatements(default_clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2313 | // If control flow can fall out of the default and there is a case after |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2314 | // it, jump to that case's body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2315 | if (frame_ != NULL && default_exit.is_bound()) { |
| 2316 | default_exit.Jump(); |
| 2317 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2318 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2319 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2320 | if (fall_through.is_linked()) { |
| 2321 | fall_through.Bind(); |
| 2322 | } |
| 2323 | |
| 2324 | if (node->break_target()->is_linked()) { |
| 2325 | node->break_target()->Bind(); |
| 2326 | } |
| 2327 | node->break_target()->Unuse(); |
| 2328 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2332 | void CodeGenerator::VisitDoWhileStatement(DoWhileStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2333 | #ifdef DEBUG |
| 2334 | int original_height = frame_->height(); |
| 2335 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2336 | Comment cmnt(masm_, "[ DoWhileStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2337 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2338 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2339 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2340 | IncrementLoopNesting(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2341 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2342 | // Label the top of the loop for the backward CFG edge. If the test |
| 2343 | // is always true we can use the continue target, and if the test is |
| 2344 | // always false there is no need. |
| 2345 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2346 | switch (info) { |
| 2347 | case ALWAYS_TRUE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2348 | node->continue_target()->SetExpectedHeight(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2349 | node->continue_target()->Bind(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2350 | break; |
| 2351 | case ALWAYS_FALSE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2352 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | case DONT_KNOW: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2355 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2356 | body.Bind(); |
| 2357 | break; |
| 2358 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2359 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2360 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2361 | Visit(node->body()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2362 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2363 | // Compile the test. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2364 | switch (info) { |
| 2365 | case ALWAYS_TRUE: |
| 2366 | // If control can fall off the end of the body, jump back to the |
| 2367 | // top. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2368 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2369 | node->continue_target()->Jump(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2370 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2371 | break; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2372 | case ALWAYS_FALSE: |
| 2373 | // If we have a continue in the body, we only have to bind its |
| 2374 | // jump target. |
| 2375 | if (node->continue_target()->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2376 | node->continue_target()->Bind(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2377 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | case DONT_KNOW: |
| 2380 | // We have to compile the test expression if it can be reached by |
| 2381 | // control flow falling out of the body or via continue. |
| 2382 | if (node->continue_target()->is_linked()) { |
| 2383 | node->continue_target()->Bind(); |
| 2384 | } |
| 2385 | if (has_valid_frame()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2386 | Comment cmnt(masm_, "[ DoWhileCondition"); |
| 2387 | CodeForDoWhileConditionPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2388 | LoadCondition(node->cond(), &body, node->break_target(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2389 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2390 | // A invalid frame here indicates that control did not |
| 2391 | // fall out of the test expression. |
| 2392 | Branch(true, &body); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2393 | } |
| 2394 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | } |
| 2397 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2398 | if (node->break_target()->is_linked()) { |
| 2399 | node->break_target()->Bind(); |
| 2400 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2401 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2402 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2403 | } |
| 2404 | |
| 2405 | |
| 2406 | void CodeGenerator::VisitWhileStatement(WhileStatement* node) { |
| 2407 | #ifdef DEBUG |
| 2408 | int original_height = frame_->height(); |
| 2409 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2410 | Comment cmnt(masm_, "[ WhileStatement"); |
| 2411 | CodeForStatementPosition(node); |
| 2412 | |
| 2413 | // If the test is never true and has no side effects there is no need |
| 2414 | // to compile the test or body. |
| 2415 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2416 | if (info == ALWAYS_FALSE) return; |
| 2417 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2418 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2419 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2420 | |
| 2421 | // Label the top of the loop with the continue target for the backward |
| 2422 | // CFG edge. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2423 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2424 | node->continue_target()->Bind(); |
| 2425 | |
| 2426 | if (info == DONT_KNOW) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2427 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2428 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2429 | if (has_valid_frame()) { |
| 2430 | // A NULL frame indicates that control did not fall out of the |
| 2431 | // test expression. |
| 2432 | Branch(false, node->break_target()); |
| 2433 | } |
| 2434 | if (has_valid_frame() || body.is_linked()) { |
| 2435 | body.Bind(); |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | if (has_valid_frame()) { |
| 2440 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2441 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2442 | |
| 2443 | // If control flow can fall out of the body, jump back to the top. |
| 2444 | if (has_valid_frame()) { |
| 2445 | node->continue_target()->Jump(); |
| 2446 | } |
| 2447 | } |
| 2448 | if (node->break_target()->is_linked()) { |
| 2449 | node->break_target()->Bind(); |
| 2450 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2451 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2452 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2453 | } |
| 2454 | |
| 2455 | |
| 2456 | void CodeGenerator::VisitForStatement(ForStatement* node) { |
| 2457 | #ifdef DEBUG |
| 2458 | int original_height = frame_->height(); |
| 2459 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2460 | Comment cmnt(masm_, "[ ForStatement"); |
| 2461 | CodeForStatementPosition(node); |
| 2462 | if (node->init() != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2463 | Visit(node->init()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | // If the test is never true there is no need to compile the test or |
| 2467 | // body. |
| 2468 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2469 | if (info == ALWAYS_FALSE) return; |
| 2470 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2471 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2472 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2473 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2474 | // We know that the loop index is a smi if it is not modified in the |
| 2475 | // loop body and it is checked against a constant limit in the loop |
| 2476 | // condition. In this case, we reset the static type information of the |
| 2477 | // loop index to smi before compiling the body, the update expression, and |
| 2478 | // the bottom check of the loop condition. |
| 2479 | TypeInfoCodeGenState type_info_scope(this, |
| 2480 | node->is_fast_smi_loop() ? |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2481 | node->loop_variable()->AsSlot() : |
| 2482 | NULL, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2483 | TypeInfo::Smi()); |
| 2484 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2485 | // If there is no update statement, label the top of the loop with the |
| 2486 | // continue target, otherwise with the loop target. |
| 2487 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2488 | if (node->next() == NULL) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2489 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2490 | node->continue_target()->Bind(); |
| 2491 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2492 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2493 | loop.Bind(); |
| 2494 | } |
| 2495 | |
| 2496 | // If the test is always true, there is no need to compile it. |
| 2497 | if (info == DONT_KNOW) { |
| 2498 | JumpTarget body; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2499 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2500 | if (has_valid_frame()) { |
| 2501 | Branch(false, node->break_target()); |
| 2502 | } |
| 2503 | if (has_valid_frame() || body.is_linked()) { |
| 2504 | body.Bind(); |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | if (has_valid_frame()) { |
| 2509 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2510 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2511 | |
| 2512 | if (node->next() == NULL) { |
| 2513 | // If there is no update statement and control flow can fall out |
| 2514 | // of the loop, jump directly to the continue label. |
| 2515 | if (has_valid_frame()) { |
| 2516 | node->continue_target()->Jump(); |
| 2517 | } |
| 2518 | } else { |
| 2519 | // If there is an update statement and control flow can reach it |
| 2520 | // via falling out of the body of the loop or continuing, we |
| 2521 | // compile the update statement. |
| 2522 | if (node->continue_target()->is_linked()) { |
| 2523 | node->continue_target()->Bind(); |
| 2524 | } |
| 2525 | if (has_valid_frame()) { |
| 2526 | // Record source position of the statement as this code which is |
| 2527 | // after the code for the body actually belongs to the loop |
| 2528 | // statement and not the body. |
| 2529 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2530 | Visit(node->next()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2531 | loop.Jump(); |
| 2532 | } |
| 2533 | } |
| 2534 | } |
| 2535 | if (node->break_target()->is_linked()) { |
| 2536 | node->break_target()->Bind(); |
| 2537 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2538 | DecrementLoopNesting(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2539 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2543 | void CodeGenerator::VisitForInStatement(ForInStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2544 | #ifdef DEBUG |
| 2545 | int original_height = frame_->height(); |
| 2546 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2547 | Comment cmnt(masm_, "[ ForInStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2548 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2549 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2550 | JumpTarget primitive; |
| 2551 | JumpTarget jsobject; |
| 2552 | JumpTarget fixed_array; |
| 2553 | JumpTarget entry(JumpTarget::BIDIRECTIONAL); |
| 2554 | JumpTarget end_del_check; |
| 2555 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2556 | |
| 2557 | // Get the object to enumerate over (converted to JSObject). |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2558 | Load(node->enumerable()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2559 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2560 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2561 | // Both SpiderMonkey and kjs ignore null and undefined in contrast |
| 2562 | // to the specification. 12.6.4 mandates a call to ToObject. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2563 | frame_->EmitPop(r0); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2564 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 2565 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2566 | exit.Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2567 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2568 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2569 | exit.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2570 | |
| 2571 | // Stack layout in body: |
| 2572 | // [iteration counter (Smi)] |
| 2573 | // [length of array] |
| 2574 | // [FixedArray] |
| 2575 | // [Map or 0] |
| 2576 | // [Object] |
| 2577 | |
| 2578 | // Check if enumerable is already a JSObject |
| 2579 | __ tst(r0, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2580 | primitive.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2581 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2582 | jsobject.Branch(hs); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2583 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2584 | primitive.Bind(); |
| 2585 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2586 | frame_->InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2587 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2588 | jsobject.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2589 | // Get the set of properties (as a FixedArray or Map). |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2590 | // r0: value to be iterated over |
| 2591 | frame_->EmitPush(r0); // Push the object being iterated over. |
| 2592 | |
| 2593 | // Check cache validity in generated code. This is a fast case for |
| 2594 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 2595 | // guarantee cache validity, call the runtime system to check cache |
| 2596 | // validity or get the property names in a fixed array. |
| 2597 | JumpTarget call_runtime; |
| 2598 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2599 | JumpTarget check_prototype; |
| 2600 | JumpTarget use_cache; |
| 2601 | __ mov(r1, Operand(r0)); |
| 2602 | loop.Bind(); |
| 2603 | // Check that there are no elements. |
| 2604 | __ ldr(r2, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 2605 | __ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex); |
| 2606 | __ cmp(r2, r4); |
| 2607 | call_runtime.Branch(ne); |
| 2608 | // Check that instance descriptors are not empty so that we can |
| 2609 | // check for an enum cache. Leave the map in r3 for the subsequent |
| 2610 | // prototype load. |
| 2611 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2612 | __ ldr(r2, FieldMemOperand(r3, Map::kInstanceDescriptorsOffset)); |
| 2613 | __ LoadRoot(ip, Heap::kEmptyDescriptorArrayRootIndex); |
| 2614 | __ cmp(r2, ip); |
| 2615 | call_runtime.Branch(eq); |
| 2616 | // Check that there in an enum cache in the non-empty instance |
| 2617 | // descriptors. This is the case if the next enumeration index |
| 2618 | // field does not contain a smi. |
| 2619 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumerationIndexOffset)); |
| 2620 | __ tst(r2, Operand(kSmiTagMask)); |
| 2621 | call_runtime.Branch(eq); |
| 2622 | // For all objects but the receiver, check that the cache is empty. |
| 2623 | // r4: empty fixed array root. |
| 2624 | __ cmp(r1, r0); |
| 2625 | check_prototype.Branch(eq); |
| 2626 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2627 | __ cmp(r2, r4); |
| 2628 | call_runtime.Branch(ne); |
| 2629 | check_prototype.Bind(); |
| 2630 | // Load the prototype from the map and loop if non-null. |
| 2631 | __ ldr(r1, FieldMemOperand(r3, Map::kPrototypeOffset)); |
| 2632 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2633 | __ cmp(r1, ip); |
| 2634 | loop.Branch(ne); |
| 2635 | // The enum cache is valid. Load the map of the object being |
| 2636 | // iterated over and use the cache for the iteration. |
| 2637 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2638 | use_cache.Jump(); |
| 2639 | |
| 2640 | call_runtime.Bind(); |
| 2641 | // Call the runtime to get the property names for the object. |
| 2642 | frame_->EmitPush(r0); // push the object (slot 4) for the runtime call |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2643 | frame_->CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2644 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2645 | // If we got a map from the runtime call, we can do a fast |
| 2646 | // modification check. Otherwise, we got a fixed array, and we have |
| 2647 | // to do a slow check. |
| 2648 | // r0: map or fixed array (result from call to |
| 2649 | // Runtime::kGetPropertyNamesFast) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2650 | __ mov(r2, Operand(r0)); |
| 2651 | __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2652 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 2653 | __ cmp(r1, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2654 | fixed_array.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2655 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2656 | use_cache.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2657 | // Get enum cache |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2658 | // r0: map (either the result from a call to |
| 2659 | // Runtime::kGetPropertyNamesFast or has been fetched directly from |
| 2660 | // the object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2661 | __ mov(r1, Operand(r0)); |
| 2662 | __ ldr(r1, FieldMemOperand(r1, Map::kInstanceDescriptorsOffset)); |
| 2663 | __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); |
| 2664 | __ ldr(r2, |
| 2665 | FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2666 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2667 | frame_->EmitPush(r0); // map |
| 2668 | frame_->EmitPush(r2); // enum cache bridge cache |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2669 | __ ldr(r0, FieldMemOperand(r2, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2670 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2671 | __ mov(r0, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2672 | frame_->EmitPush(r0); |
| 2673 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2674 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2675 | fixed_array.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2676 | __ mov(r1, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2677 | frame_->EmitPush(r1); // insert 0 in place of Map |
| 2678 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2679 | |
| 2680 | // Push the length of the array and the initial index onto the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2681 | __ ldr(r0, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2682 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2683 | __ mov(r0, Operand(Smi::FromInt(0))); // init index |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2684 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2685 | |
| 2686 | // Condition. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2687 | entry.Bind(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2688 | // sp[0] : index |
| 2689 | // sp[1] : array/enum cache length |
| 2690 | // sp[2] : array or enum cache |
| 2691 | // sp[3] : 0 or map |
| 2692 | // sp[4] : enumerable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2693 | // Grab the current frame's height for the break and continue |
| 2694 | // targets only after all the state is pushed on the frame. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2695 | node->break_target()->SetExpectedHeight(); |
| 2696 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2697 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2698 | // Load the current count to r0, load the length to r1. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2699 | __ Ldrd(r0, r1, frame_->ElementAt(0)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2700 | __ cmp(r0, r1); // compare to the array length |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2701 | node->break_target()->Branch(hs); |
| 2702 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2703 | // Get the i'th entry of the array. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2704 | __ ldr(r2, frame_->ElementAt(2)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2705 | __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2706 | __ ldr(r3, MemOperand(r2, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 2707 | |
| 2708 | // Get Map or 0. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2709 | __ ldr(r2, frame_->ElementAt(3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2710 | // Check if this (still) matches the map of the enumerable. |
| 2711 | // If not, we have to filter the key. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2712 | __ ldr(r1, frame_->ElementAt(4)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2713 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2714 | __ cmp(r1, Operand(r2)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2715 | end_del_check.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2716 | |
| 2717 | // Convert the entry to a string (or null if it isn't a property anymore). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2718 | __ ldr(r0, frame_->ElementAt(4)); // push enumerable |
| 2719 | frame_->EmitPush(r0); |
| 2720 | frame_->EmitPush(r3); // push entry |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2721 | frame_->InvokeBuiltin(Builtins::FILTER_KEY, CALL_JS, 2); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2722 | __ mov(r3, Operand(r0), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2723 | // If the property has been removed while iterating, we just skip it. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2724 | node->continue_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2725 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2726 | end_del_check.Bind(); |
| 2727 | // Store the entry in the 'each' expression and take another spin in the |
| 2728 | // loop. r3: i'th entry of the enum cache (or string there of) |
| 2729 | frame_->EmitPush(r3); // push entry |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2730 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2731 | Reference each(this, node->each()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2732 | if (!each.is_illegal()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2733 | if (each.size() > 0) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2734 | // Loading a reference may leave the frame in an unspilled state. |
| 2735 | frame_->SpillAll(); // Sync stack to memory. |
| 2736 | // Get the value (under the reference on the stack) from memory. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2737 | __ ldr(r0, frame_->ElementAt(each.size())); |
| 2738 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2739 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2740 | frame_->Drop(2); // The result of the set and the extra pushed value. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2741 | } else { |
| 2742 | // If the reference was to a slot we rely on the convenient property |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2743 | // that it doesn't matter whether a value (eg, ebx pushed above) is |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2744 | // right on top of or right underneath a zero-sized reference. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2745 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2746 | frame_->Drop(1); // Drop the result of the set operation. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2747 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2748 | } |
| 2749 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2750 | // Body. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2751 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2752 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2753 | Visit(node->body()); |
| 2754 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2755 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2756 | // Next. Reestablish a spilled frame in case we are coming here via |
| 2757 | // a continue in the body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2758 | node->continue_target()->Bind(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2759 | frame_->SpillAll(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2760 | frame_->EmitPop(r0); |
| 2761 | __ add(r0, r0, Operand(Smi::FromInt(1))); |
| 2762 | frame_->EmitPush(r0); |
| 2763 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2764 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2765 | // Cleanup. No need to spill because VirtualFrame::Drop is safe for |
| 2766 | // any frame. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2767 | node->break_target()->Bind(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2768 | frame_->Drop(5); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2769 | |
| 2770 | // Exit. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2771 | exit.Bind(); |
| 2772 | node->continue_target()->Unuse(); |
| 2773 | node->break_target()->Unuse(); |
| 2774 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2778 | void CodeGenerator::VisitTryCatchStatement(TryCatchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2779 | #ifdef DEBUG |
| 2780 | int original_height = frame_->height(); |
| 2781 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2782 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2783 | Comment cmnt(masm_, "[ TryCatchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2784 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2785 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2786 | JumpTarget try_block; |
| 2787 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2788 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2789 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2790 | // --- Catch block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2791 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2792 | |
| 2793 | // Store the caught exception in the catch variable. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2794 | Variable* catch_var = node->catch_var()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2795 | ASSERT(catch_var != NULL && catch_var->AsSlot() != NULL); |
| 2796 | StoreToSlot(catch_var->AsSlot(), NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2797 | |
| 2798 | // Remove the exception from the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2799 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2800 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2801 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2802 | VisitStatements(node->catch_block()->statements()); |
| 2803 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2804 | if (frame_ != NULL) { |
| 2805 | exit.Jump(); |
| 2806 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2807 | |
| 2808 | |
| 2809 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2810 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2811 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2812 | frame_->PushTryHandler(TRY_CATCH_HANDLER); |
| 2813 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2814 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2815 | // Shadow the labels for all escapes from the try block, including |
| 2816 | // returns. During shadowing, the original label is hidden as the |
| 2817 | // LabelShadow and operations on the original actually affect the |
| 2818 | // shadowing label. |
| 2819 | // |
| 2820 | // We should probably try to unify the escaping labels and the return |
| 2821 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2822 | int nof_escapes = node->escaping_targets()->length(); |
| 2823 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2824 | |
| 2825 | // Add the shadow target for the function return. |
| 2826 | static const int kReturnShadowIndex = 0; |
| 2827 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2828 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2829 | function_return_is_shadowed_ = true; |
| 2830 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2831 | |
| 2832 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2833 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2834 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | // Generate code for the statements in the try block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2838 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2839 | VisitStatements(node->try_block()->statements()); |
| 2840 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2841 | |
| 2842 | // Stop the introduced shadowing and count the number of required unlinks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2843 | // After shadowing stops, the original labels are unshadowed and the |
| 2844 | // LabelShadows represent the formerly shadowing labels. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2845 | bool has_unlinks = false; |
| 2846 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2847 | shadows[i]->StopShadowing(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2848 | has_unlinks = has_unlinks || shadows[i]->is_linked(); |
| 2849 | } |
| 2850 | function_return_is_shadowed_ = function_return_was_shadowed; |
| 2851 | |
| 2852 | // Get an external reference to the handler address. |
| 2853 | ExternalReference handler_address(Top::k_handler_address); |
| 2854 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2855 | // If we can fall off the end of the try block, unlink from try chain. |
| 2856 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2857 | // The next handler address is on top of the frame. Unlink from |
| 2858 | // the handler list and drop the rest of this handler from the |
| 2859 | // frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2860 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2861 | frame_->EmitPop(r1); // r0 can contain the return value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2862 | __ mov(r3, Operand(handler_address)); |
| 2863 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2864 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2865 | if (has_unlinks) { |
| 2866 | exit.Jump(); |
| 2867 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2870 | // Generate unlink code for the (formerly) shadowing labels that have been |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2871 | // jumped to. Deallocate each shadow target. |
| 2872 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2873 | if (shadows[i]->is_linked()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2874 | // Unlink from try chain; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2875 | shadows[i]->Bind(); |
| 2876 | // Because we can be jumping here (to spilled code) from unspilled |
| 2877 | // code, we need to reestablish a spilled frame at this block. |
| 2878 | frame_->SpillAll(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2879 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2880 | // Reload sp from the top handler, because some statements that we |
| 2881 | // break from (eg, for...in) may have left stuff on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2882 | __ mov(r3, Operand(handler_address)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2883 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2884 | frame_->Forget(frame_->height() - handler_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2885 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2886 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2887 | frame_->EmitPop(r1); // r0 can contain the return value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2888 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2889 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2890 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2891 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
| 2892 | frame_->PrepareForReturn(); |
| 2893 | } |
| 2894 | shadows[i]->other_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2895 | } |
| 2896 | } |
| 2897 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2898 | exit.Bind(); |
| 2899 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2903 | void CodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2904 | #ifdef DEBUG |
| 2905 | int original_height = frame_->height(); |
| 2906 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2907 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2908 | Comment cmnt(masm_, "[ TryFinallyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2909 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2910 | |
| 2911 | // State: Used to keep track of reason for entering the finally |
| 2912 | // block. Should probably be extended to hold information for |
| 2913 | // break/continue from within the try block. |
| 2914 | enum { FALLING, THROWING, JUMPING }; |
| 2915 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2916 | JumpTarget try_block; |
| 2917 | JumpTarget finally_block; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2918 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2919 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2920 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2921 | frame_->EmitPush(r0); // save exception object on the stack |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2922 | // In case of thrown exceptions, this is where we continue. |
| 2923 | __ mov(r2, Operand(Smi::FromInt(THROWING))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2924 | finally_block.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2925 | |
| 2926 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2927 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2928 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2929 | frame_->PushTryHandler(TRY_FINALLY_HANDLER); |
| 2930 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2931 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2932 | // Shadow the labels for all escapes from the try block, including |
| 2933 | // returns. Shadowing hides the original label as the LabelShadow and |
| 2934 | // operations on the original actually affect the shadowing label. |
| 2935 | // |
| 2936 | // We should probably try to unify the escaping labels and the return |
| 2937 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2938 | int nof_escapes = node->escaping_targets()->length(); |
| 2939 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2940 | |
| 2941 | // Add the shadow target for the function return. |
| 2942 | static const int kReturnShadowIndex = 0; |
| 2943 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2944 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2945 | function_return_is_shadowed_ = true; |
| 2946 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2947 | |
| 2948 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2949 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2950 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | // Generate code for the statements in the try block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2954 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2955 | VisitStatements(node->try_block()->statements()); |
| 2956 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2957 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2958 | // Stop the introduced shadowing and count the number of required unlinks. |
| 2959 | // After shadowing stops, the original labels are unshadowed and the |
| 2960 | // LabelShadows represent the formerly shadowing labels. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2961 | int nof_unlinks = 0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2962 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2963 | shadows[i]->StopShadowing(); |
| 2964 | if (shadows[i]->is_linked()) nof_unlinks++; |
| 2965 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2966 | function_return_is_shadowed_ = function_return_was_shadowed; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2967 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2968 | // Get an external reference to the handler address. |
| 2969 | ExternalReference handler_address(Top::k_handler_address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2971 | // If we can fall off the end of the try block, unlink from the try |
| 2972 | // chain and set the state on the frame to FALLING. |
| 2973 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2974 | // The next handler address is on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2975 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2976 | frame_->EmitPop(r1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2977 | __ mov(r3, Operand(handler_address)); |
| 2978 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2979 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2980 | |
| 2981 | // Fake a top of stack value (unneeded when FALLING) and set the |
| 2982 | // state in r2, then jump around the unlink blocks if any. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2983 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2984 | frame_->EmitPush(r0); |
| 2985 | __ mov(r2, Operand(Smi::FromInt(FALLING))); |
| 2986 | if (nof_unlinks > 0) { |
| 2987 | finally_block.Jump(); |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | // Generate code to unlink and set the state for the (formerly) |
| 2992 | // shadowing targets that have been jumped to. |
| 2993 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2994 | if (shadows[i]->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2995 | // If we have come from the shadowed return, the return value is |
| 2996 | // in (a non-refcounted reference to) r0. We must preserve it |
| 2997 | // until it is pushed. |
| 2998 | // |
| 2999 | // Because we can be jumping here (to spilled code) from |
| 3000 | // unspilled code, we need to reestablish a spilled frame at |
| 3001 | // this block. |
| 3002 | shadows[i]->Bind(); |
| 3003 | frame_->SpillAll(); |
| 3004 | |
| 3005 | // Reload sp from the top handler, because some statements that |
| 3006 | // we break from (eg, for...in) may have left stuff on the |
| 3007 | // stack. |
| 3008 | __ mov(r3, Operand(handler_address)); |
| 3009 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3010 | frame_->Forget(frame_->height() - handler_height); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3011 | |
| 3012 | // Unlink this handler and drop it from the frame. The next |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3013 | // handler address is currently on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 3014 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3015 | frame_->EmitPop(r1); |
| 3016 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3017 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3018 | |
| 3019 | if (i == kReturnShadowIndex) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3020 | // If this label shadowed the function return, materialize the |
| 3021 | // return value on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3022 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3023 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3024 | // Fake TOS for targets that shadowed breaks and continues. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3025 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3026 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3027 | } |
| 3028 | __ mov(r2, Operand(Smi::FromInt(JUMPING + i))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3029 | if (--nof_unlinks > 0) { |
| 3030 | // If this is not the last unlink block, jump around the next. |
| 3031 | finally_block.Jump(); |
| 3032 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3033 | } |
| 3034 | } |
| 3035 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3036 | // --- Finally block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3037 | finally_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3038 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3039 | // Push the state on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3040 | frame_->EmitPush(r2); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3041 | |
| 3042 | // We keep two elements on the stack - the (possibly faked) result |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3043 | // and the state - while evaluating the finally block. |
| 3044 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3045 | // Generate code for the statements in the finally block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3046 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 3047 | VisitStatements(node->finally_block()->statements()); |
| 3048 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3049 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3050 | if (has_valid_frame()) { |
| 3051 | // Restore state and return value or faked TOS. |
| 3052 | frame_->EmitPop(r2); |
| 3053 | frame_->EmitPop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3054 | } |
| 3055 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3056 | // Generate code to jump to the right destination for all used |
| 3057 | // formerly shadowing targets. Deallocate each shadow target. |
| 3058 | for (int i = 0; i < shadows.length(); i++) { |
| 3059 | if (has_valid_frame() && shadows[i]->is_bound()) { |
| 3060 | JumpTarget* original = shadows[i]->other_target(); |
| 3061 | __ cmp(r2, Operand(Smi::FromInt(JUMPING + i))); |
| 3062 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3063 | JumpTarget skip; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3064 | skip.Branch(ne); |
| 3065 | frame_->PrepareForReturn(); |
| 3066 | original->Jump(); |
| 3067 | skip.Bind(); |
| 3068 | } else { |
| 3069 | original->Branch(eq); |
| 3070 | } |
| 3071 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3072 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3073 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3074 | if (has_valid_frame()) { |
| 3075 | // Check if we need to rethrow the exception. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3076 | JumpTarget exit; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3077 | __ cmp(r2, Operand(Smi::FromInt(THROWING))); |
| 3078 | exit.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3079 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3080 | // Rethrow exception. |
| 3081 | frame_->EmitPush(r0); |
| 3082 | frame_->CallRuntime(Runtime::kReThrow, 1); |
| 3083 | |
| 3084 | // Done. |
| 3085 | exit.Bind(); |
| 3086 | } |
| 3087 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3091 | void CodeGenerator::VisitDebuggerStatement(DebuggerStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3092 | #ifdef DEBUG |
| 3093 | int original_height = frame_->height(); |
| 3094 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3095 | Comment cmnt(masm_, "[ DebuggerStatament"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3096 | CodeForStatementPosition(node); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3097 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3098 | frame_->DebugBreak(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3099 | #endif |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3100 | // Ignore the return value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3101 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3105 | void CodeGenerator::InstantiateFunction( |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame^] | 3106 | Handle<SharedFunctionInfo> function_info, |
| 3107 | bool pretenure) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3108 | // Use the fast case closure allocation code that allocates in new |
| 3109 | // space for nested functions that don't need literals cloning. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame^] | 3110 | if (scope()->is_function_scope() && |
| 3111 | function_info->num_literals() == 0 && |
| 3112 | !pretenure) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3113 | FastNewClosureStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3114 | frame_->EmitPush(Operand(function_info)); |
| 3115 | frame_->SpillAll(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3116 | frame_->CallStub(&stub, 1); |
| 3117 | frame_->EmitPush(r0); |
| 3118 | } else { |
| 3119 | // Create a new closure. |
| 3120 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3121 | frame_->EmitPush(Operand(function_info)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame^] | 3122 | frame_->EmitPush(Operand(pretenure |
| 3123 | ? Factory::true_value() |
| 3124 | : Factory::false_value())); |
| 3125 | frame_->CallRuntime(Runtime::kNewClosure, 3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3126 | frame_->EmitPush(r0); |
| 3127 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3131 | void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3132 | #ifdef DEBUG |
| 3133 | int original_height = frame_->height(); |
| 3134 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3135 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 3136 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3137 | // Build the function info and instantiate it. |
| 3138 | Handle<SharedFunctionInfo> function_info = |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 3139 | Compiler::BuildFunctionInfo(node, script()); |
| 3140 | if (function_info.is_null()) { |
| 3141 | SetStackOverflow(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3142 | ASSERT(frame_->height() == original_height); |
| 3143 | return; |
| 3144 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame^] | 3145 | InstantiateFunction(function_info, node->pretenure()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3146 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3150 | void CodeGenerator::VisitSharedFunctionInfoLiteral( |
| 3151 | SharedFunctionInfoLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3152 | #ifdef DEBUG |
| 3153 | int original_height = frame_->height(); |
| 3154 | #endif |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3155 | Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame^] | 3156 | InstantiateFunction(node->shared_function_info(), false); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3157 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3161 | void CodeGenerator::VisitConditional(Conditional* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3162 | #ifdef DEBUG |
| 3163 | int original_height = frame_->height(); |
| 3164 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3165 | Comment cmnt(masm_, "[ Conditional"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3166 | JumpTarget then; |
| 3167 | JumpTarget else_; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3168 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3169 | if (has_valid_frame()) { |
| 3170 | Branch(false, &else_); |
| 3171 | } |
| 3172 | if (has_valid_frame() || then.is_linked()) { |
| 3173 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3174 | Load(node->then_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3175 | } |
| 3176 | if (else_.is_linked()) { |
| 3177 | JumpTarget exit; |
| 3178 | if (has_valid_frame()) exit.Jump(); |
| 3179 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3180 | Load(node->else_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3181 | if (exit.is_linked()) exit.Bind(); |
| 3182 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3183 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3187 | void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) { |
| 3188 | if (slot->type() == Slot::LOOKUP) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3189 | ASSERT(slot->var()->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3190 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3191 | // JumpTargets do not yet support merging frames so the frame must be |
| 3192 | // spilled when jumping to these targets. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3193 | JumpTarget slow; |
| 3194 | JumpTarget done; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3195 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3196 | // Generate fast case for loading from slots that correspond to |
| 3197 | // local/global variables or arguments unless they are shadowed by |
| 3198 | // eval-introduced bindings. |
| 3199 | EmitDynamicLoadFromSlotFastCase(slot, |
| 3200 | typeof_state, |
| 3201 | &slow, |
| 3202 | &done); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3203 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3204 | slow.Bind(); |
| 3205 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3206 | frame_->EmitPush(Operand(slot->var()->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3207 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3208 | if (typeof_state == INSIDE_TYPEOF) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3209 | frame_->CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3210 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3211 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3212 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3213 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3214 | done.Bind(); |
| 3215 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3216 | |
| 3217 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3218 | Register scratch = VirtualFrame::scratch0(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3219 | TypeInfo info = type_info(slot); |
| 3220 | frame_->EmitPush(SlotOperand(slot, scratch), info); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3221 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3222 | if (slot->var()->mode() == Variable::CONST) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3223 | // Const slots may contain 'the hole' value (the constant hasn't been |
| 3224 | // initialized yet) which needs to be converted into the 'undefined' |
| 3225 | // value. |
| 3226 | Comment cmnt(masm_, "[ Unhole const"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3227 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3228 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3229 | __ cmp(tos, ip); |
| 3230 | __ LoadRoot(tos, Heap::kUndefinedValueRootIndex, eq); |
| 3231 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3232 | } |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3237 | void CodeGenerator::LoadFromSlotCheckForArguments(Slot* slot, |
| 3238 | TypeofState state) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3239 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3240 | LoadFromSlot(slot, state); |
| 3241 | |
| 3242 | // Bail out quickly if we're not using lazy arguments allocation. |
| 3243 | if (ArgumentsMode() != LAZY_ARGUMENTS_ALLOCATION) return; |
| 3244 | |
| 3245 | // ... or if the slot isn't a non-parameter arguments slot. |
| 3246 | if (slot->type() == Slot::PARAMETER || !slot->is_arguments()) return; |
| 3247 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3248 | // Load the loaded value from the stack into a register but leave it on the |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3249 | // stack. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3250 | Register tos = frame_->Peek(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3251 | |
| 3252 | // If the loaded value is the sentinel that indicates that we |
| 3253 | // haven't loaded the arguments object yet, we need to do it now. |
| 3254 | JumpTarget exit; |
| 3255 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3256 | __ cmp(tos, ip); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3257 | exit.Branch(ne); |
| 3258 | frame_->Drop(); |
| 3259 | StoreArgumentsObject(false); |
| 3260 | exit.Bind(); |
| 3261 | } |
| 3262 | |
| 3263 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3264 | void CodeGenerator::StoreToSlot(Slot* slot, InitState init_state) { |
| 3265 | ASSERT(slot != NULL); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3266 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3267 | if (slot->type() == Slot::LOOKUP) { |
| 3268 | ASSERT(slot->var()->is_dynamic()); |
| 3269 | |
| 3270 | // For now, just do a runtime call. |
| 3271 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3272 | frame_->EmitPush(Operand(slot->var()->name())); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3273 | |
| 3274 | if (init_state == CONST_INIT) { |
| 3275 | // Same as the case for a normal store, but ignores attribute |
| 3276 | // (e.g. READ_ONLY) of context slot so that we can initialize |
| 3277 | // const properties (introduced via eval("const foo = (some |
| 3278 | // expr);")). Also, uses the current function context instead of |
| 3279 | // the top context. |
| 3280 | // |
| 3281 | // Note that we must declare the foo upon entry of eval(), via a |
| 3282 | // context slot declaration, but we cannot initialize it at the |
| 3283 | // same time, because the const declaration may be at the end of |
| 3284 | // the eval code (sigh...) and the const variable may have been |
| 3285 | // used before (where its value is 'undefined'). Thus, we can only |
| 3286 | // do the initialization when we actually encounter the expression |
| 3287 | // and when the expression operands are defined and valid, and |
| 3288 | // thus we need the split into 2 operations: declaration of the |
| 3289 | // context slot followed by initialization. |
| 3290 | frame_->CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 3291 | } else { |
| 3292 | frame_->CallRuntime(Runtime::kStoreContextSlot, 3); |
| 3293 | } |
| 3294 | // Storing a variable must keep the (new) value on the expression |
| 3295 | // stack. This is necessary for compiling assignment expressions. |
| 3296 | frame_->EmitPush(r0); |
| 3297 | |
| 3298 | } else { |
| 3299 | ASSERT(!slot->var()->is_dynamic()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3300 | Register scratch = VirtualFrame::scratch0(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3301 | Register scratch2 = VirtualFrame::scratch1(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3302 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3303 | // The frame must be spilled when branching to this target. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3304 | JumpTarget exit; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3305 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3306 | if (init_state == CONST_INIT) { |
| 3307 | ASSERT(slot->var()->mode() == Variable::CONST); |
| 3308 | // Only the first const initialization must be executed (the slot |
| 3309 | // still contains 'the hole' value). When the assignment is |
| 3310 | // executed, the code is identical to a normal store (see below). |
| 3311 | Comment cmnt(masm_, "[ Init const"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3312 | __ ldr(scratch, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3313 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3314 | __ cmp(scratch, ip); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3315 | exit.Branch(ne); |
| 3316 | } |
| 3317 | |
| 3318 | // We must execute the store. Storing a variable must keep the |
| 3319 | // (new) value on the stack. This is necessary for compiling |
| 3320 | // assignment expressions. |
| 3321 | // |
| 3322 | // Note: We will reach here even with slot->var()->mode() == |
| 3323 | // Variable::CONST because of const declarations which will |
| 3324 | // initialize consts to 'the hole' value and by doing so, end up |
| 3325 | // calling this code. r2 may be loaded with context; used below in |
| 3326 | // RecordWrite. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3327 | Register tos = frame_->Peek(); |
| 3328 | __ str(tos, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3329 | if (slot->type() == Slot::CONTEXT) { |
| 3330 | // Skip write barrier if the written value is a smi. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3331 | __ tst(tos, Operand(kSmiTagMask)); |
| 3332 | // We don't use tos any more after here. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3333 | exit.Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3334 | // scratch is loaded with context when calling SlotOperand above. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3335 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3336 | // We need an extra register. Until we have a way to do that in the |
| 3337 | // virtual frame we will cheat and ask for a free TOS register. |
| 3338 | Register scratch3 = frame_->GetTOSRegister(); |
| 3339 | __ RecordWrite(scratch, Operand(offset), scratch2, scratch3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3340 | } |
| 3341 | // If we definitely did not jump over the assignment, we do not need |
| 3342 | // to bind the exit label. Doing so can defeat peephole |
| 3343 | // optimization. |
| 3344 | if (init_state == CONST_INIT || slot->type() == Slot::CONTEXT) { |
| 3345 | exit.Bind(); |
| 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3351 | void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 3352 | TypeofState typeof_state, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3353 | JumpTarget* slow) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3354 | // Check that no extension objects have been created by calls to |
| 3355 | // eval from the current scope to the global scope. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3356 | Register tmp = frame_->scratch0(); |
| 3357 | Register tmp2 = frame_->scratch1(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3358 | Register context = cp; |
| 3359 | Scope* s = scope(); |
| 3360 | while (s != NULL) { |
| 3361 | if (s->num_heap_slots() > 0) { |
| 3362 | if (s->calls_eval()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3363 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3364 | // Check that extension is NULL. |
| 3365 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 3366 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3367 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3368 | } |
| 3369 | // Load next context in chain. |
| 3370 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 3371 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3372 | context = tmp; |
| 3373 | } |
| 3374 | // If no outer scope calls eval, we do not need to check more |
| 3375 | // context extensions. |
| 3376 | if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 3377 | s = s->outer_scope(); |
| 3378 | } |
| 3379 | |
| 3380 | if (s->is_eval_scope()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3381 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3382 | Label next, fast; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3383 | __ Move(tmp, context); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3384 | __ bind(&next); |
| 3385 | // Terminate at global context. |
| 3386 | __ ldr(tmp2, FieldMemOperand(tmp, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3387 | __ LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 3388 | __ cmp(tmp2, ip); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3389 | __ b(eq, &fast); |
| 3390 | // Check that extension is NULL. |
| 3391 | __ ldr(tmp2, ContextOperand(tmp, Context::EXTENSION_INDEX)); |
| 3392 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3393 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3394 | // Load next context in chain. |
| 3395 | __ ldr(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); |
| 3396 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3397 | __ b(&next); |
| 3398 | __ bind(&fast); |
| 3399 | } |
| 3400 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3401 | // Load the global object. |
| 3402 | LoadGlobal(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3403 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3404 | frame_->CallLoadIC(slot->var()->name(), |
| 3405 | typeof_state == INSIDE_TYPEOF |
| 3406 | ? RelocInfo::CODE_TARGET |
| 3407 | : RelocInfo::CODE_TARGET_CONTEXT); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3411 | void CodeGenerator::EmitDynamicLoadFromSlotFastCase(Slot* slot, |
| 3412 | TypeofState typeof_state, |
| 3413 | JumpTarget* slow, |
| 3414 | JumpTarget* done) { |
| 3415 | // Generate fast-case code for variables that might be shadowed by |
| 3416 | // eval-introduced variables. Eval is used a lot without |
| 3417 | // introducing variables. In those cases, we do not want to |
| 3418 | // perform a runtime call for all variables in the scope |
| 3419 | // containing the eval. |
| 3420 | if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
| 3421 | LoadFromGlobalSlotCheckExtensions(slot, typeof_state, slow); |
| 3422 | frame_->SpillAll(); |
| 3423 | done->Jump(); |
| 3424 | |
| 3425 | } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
| 3426 | frame_->SpillAll(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3427 | Slot* potential_slot = slot->var()->local_if_not_shadowed()->AsSlot(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3428 | Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite(); |
| 3429 | if (potential_slot != NULL) { |
| 3430 | // Generate fast case for locals that rewrite to slots. |
| 3431 | __ ldr(r0, |
| 3432 | ContextSlotOperandCheckExtensions(potential_slot, |
| 3433 | r1, |
| 3434 | r2, |
| 3435 | slow)); |
| 3436 | if (potential_slot->var()->mode() == Variable::CONST) { |
| 3437 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3438 | __ cmp(r0, ip); |
| 3439 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 3440 | } |
| 3441 | done->Jump(); |
| 3442 | } else if (rewrite != NULL) { |
| 3443 | // Generate fast case for argument loads. |
| 3444 | Property* property = rewrite->AsProperty(); |
| 3445 | if (property != NULL) { |
| 3446 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 3447 | Literal* key_literal = property->key()->AsLiteral(); |
| 3448 | if (obj_proxy != NULL && |
| 3449 | key_literal != NULL && |
| 3450 | obj_proxy->IsArguments() && |
| 3451 | key_literal->handle()->IsSmi()) { |
| 3452 | // Load arguments object if there are no eval-introduced |
| 3453 | // variables. Then load the argument from the arguments |
| 3454 | // object using keyed load. |
| 3455 | __ ldr(r0, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3456 | ContextSlotOperandCheckExtensions(obj_proxy->var()->AsSlot(), |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3457 | r1, |
| 3458 | r2, |
| 3459 | slow)); |
| 3460 | frame_->EmitPush(r0); |
| 3461 | __ mov(r1, Operand(key_literal->handle())); |
| 3462 | frame_->EmitPush(r1); |
| 3463 | EmitKeyedLoad(); |
| 3464 | done->Jump(); |
| 3465 | } |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3472 | void CodeGenerator::VisitSlot(Slot* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3473 | #ifdef DEBUG |
| 3474 | int original_height = frame_->height(); |
| 3475 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3476 | Comment cmnt(masm_, "[ Slot"); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3477 | LoadFromSlotCheckForArguments(node, NOT_INSIDE_TYPEOF); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3478 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3479 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3480 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3481 | |
| 3482 | void CodeGenerator::VisitVariableProxy(VariableProxy* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3483 | #ifdef DEBUG |
| 3484 | int original_height = frame_->height(); |
| 3485 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3486 | Comment cmnt(masm_, "[ VariableProxy"); |
| 3487 | |
| 3488 | Variable* var = node->var(); |
| 3489 | Expression* expr = var->rewrite(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3490 | if (expr != NULL) { |
| 3491 | Visit(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3492 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3493 | ASSERT(var->is_global()); |
| 3494 | Reference ref(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3495 | ref.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3496 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3497 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3501 | void CodeGenerator::VisitLiteral(Literal* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3502 | #ifdef DEBUG |
| 3503 | int original_height = frame_->height(); |
| 3504 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3505 | Comment cmnt(masm_, "[ Literal"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3506 | Register reg = frame_->GetTOSRegister(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3507 | bool is_smi = node->handle()->IsSmi(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3508 | __ mov(reg, Operand(node->handle())); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3509 | frame_->EmitPush(reg, is_smi ? TypeInfo::Smi() : TypeInfo::Unknown()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3510 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3514 | void CodeGenerator::VisitRegExpLiteral(RegExpLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3515 | #ifdef DEBUG |
| 3516 | int original_height = frame_->height(); |
| 3517 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3518 | Comment cmnt(masm_, "[ RexExp Literal"); |
| 3519 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3520 | Register tmp = VirtualFrame::scratch0(); |
| 3521 | // Free up a TOS register that can be used to push the literal. |
| 3522 | Register literal = frame_->GetTOSRegister(); |
| 3523 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3524 | // Retrieve the literal array and check the allocated entry. |
| 3525 | |
| 3526 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3527 | __ ldr(tmp, frame_->Function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3528 | |
| 3529 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3530 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kLiteralsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3531 | |
| 3532 | // Load the literal at the ast saved index. |
| 3533 | int literal_offset = |
| 3534 | FixedArray::kHeaderSize + node->literal_index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3535 | __ ldr(literal, FieldMemOperand(tmp, literal_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3536 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3537 | JumpTarget materialized; |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3538 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3539 | __ cmp(literal, ip); |
| 3540 | // This branch locks the virtual frame at the done label to match the |
| 3541 | // one we have here, where the literal register is not on the stack and |
| 3542 | // nothing is spilled. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3543 | materialized.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3544 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3545 | // If the entry is undefined we call the runtime system to compute |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3546 | // the literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3547 | // literal array (0) |
| 3548 | frame_->EmitPush(tmp); |
| 3549 | // literal index (1) |
| 3550 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3551 | // RegExp pattern (2) |
| 3552 | frame_->EmitPush(Operand(node->pattern())); |
| 3553 | // RegExp flags (3) |
| 3554 | frame_->EmitPush(Operand(node->flags())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3555 | frame_->CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3556 | __ Move(literal, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3557 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3558 | materialized.Bind(); |
| 3559 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3560 | frame_->EmitPush(literal); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3561 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 3562 | frame_->EmitPush(Operand(Smi::FromInt(size))); |
| 3563 | frame_->CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 3564 | // TODO(lrn): Use AllocateInNewSpace macro with fallback to runtime. |
| 3565 | // r0 is newly allocated space. |
| 3566 | |
| 3567 | // Reuse literal variable with (possibly) a new register, still holding |
| 3568 | // the materialized boilerplate. |
| 3569 | literal = frame_->PopToRegister(r0); |
| 3570 | |
| 3571 | __ CopyFields(r0, literal, tmp.bit(), size / kPointerSize); |
| 3572 | |
| 3573 | // Push the clone. |
| 3574 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3575 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3579 | void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3580 | #ifdef DEBUG |
| 3581 | int original_height = frame_->height(); |
| 3582 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3583 | Comment cmnt(masm_, "[ ObjectLiteral"); |
| 3584 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3585 | Register literal = frame_->GetTOSRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3586 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3587 | __ ldr(literal, frame_->Function()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3588 | // Literal array. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3589 | __ ldr(literal, FieldMemOperand(literal, JSFunction::kLiteralsOffset)); |
| 3590 | frame_->EmitPush(literal); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3591 | // Literal index. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3592 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3593 | // Constant properties. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3594 | frame_->EmitPush(Operand(node->constant_properties())); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3595 | // Should the object literal have fast elements? |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3596 | frame_->EmitPush(Operand(Smi::FromInt(node->fast_elements() ? 1 : 0))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3597 | if (node->depth() > 1) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3598 | frame_->CallRuntime(Runtime::kCreateObjectLiteral, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3599 | } else { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3600 | frame_->CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3601 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3602 | frame_->EmitPush(r0); // save the result |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3603 | |
| 3604 | // Mark all computed expressions that are bound to a key that |
| 3605 | // is shadowed by a later occurrence of the same key. For the |
| 3606 | // marked expressions, no store code is emitted. |
| 3607 | node->CalculateEmitStore(); |
| 3608 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3609 | for (int i = 0; i < node->properties()->length(); i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3610 | // At the start of each iteration, the top of stack contains |
| 3611 | // the newly created object literal. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3612 | ObjectLiteral::Property* property = node->properties()->at(i); |
| 3613 | Literal* key = property->key(); |
| 3614 | Expression* value = property->value(); |
| 3615 | switch (property->kind()) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3616 | case ObjectLiteral::Property::CONSTANT: |
| 3617 | break; |
| 3618 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 3619 | if (CompileTimeValue::IsCompileTimeValue(property->value())) break; |
| 3620 | // else fall through |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3621 | case ObjectLiteral::Property::COMPUTED: |
| 3622 | if (key->handle()->IsSymbol()) { |
| 3623 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3624 | Load(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3625 | if (property->emit_store()) { |
| 3626 | frame_->PopToR0(); |
| 3627 | // Fetch the object literal. |
| 3628 | frame_->SpillAllButCopyTOSToR1(); |
| 3629 | __ mov(r2, Operand(key->handle())); |
| 3630 | frame_->CallCodeObject(ic, RelocInfo::CODE_TARGET, 0); |
| 3631 | } else { |
| 3632 | frame_->Drop(); |
| 3633 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3634 | break; |
| 3635 | } |
| 3636 | // else fall through |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3637 | case ObjectLiteral::Property::PROTOTYPE: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3638 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3639 | Load(key); |
| 3640 | Load(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3641 | if (property->emit_store()) { |
| 3642 | frame_->CallRuntime(Runtime::kSetProperty, 3); |
| 3643 | } else { |
| 3644 | frame_->Drop(3); |
| 3645 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3646 | break; |
| 3647 | } |
| 3648 | case ObjectLiteral::Property::SETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3649 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3650 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3651 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3652 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3653 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3654 | break; |
| 3655 | } |
| 3656 | case ObjectLiteral::Property::GETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3657 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3658 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3659 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3660 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3661 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3662 | break; |
| 3663 | } |
| 3664 | } |
| 3665 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3666 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3670 | void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3671 | #ifdef DEBUG |
| 3672 | int original_height = frame_->height(); |
| 3673 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3674 | Comment cmnt(masm_, "[ ArrayLiteral"); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3675 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3676 | Register tos = frame_->GetTOSRegister(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3677 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3678 | __ ldr(tos, frame_->Function()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3679 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3680 | __ ldr(tos, FieldMemOperand(tos, JSFunction::kLiteralsOffset)); |
| 3681 | frame_->EmitPush(tos); |
| 3682 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3683 | frame_->EmitPush(Operand(node->constant_elements())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3684 | int length = node->values()->length(); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3685 | if (node->constant_elements()->map() == Heap::fixed_cow_array_map()) { |
| 3686 | FastCloneShallowArrayStub stub( |
| 3687 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 3688 | frame_->CallStub(&stub, 3); |
| 3689 | __ IncrementCounter(&Counters::cow_arrays_created_stub, 1, r1, r2); |
| 3690 | } else if (node->depth() > 1) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3691 | frame_->CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3692 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3693 | frame_->CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3694 | } else { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3695 | FastCloneShallowArrayStub stub( |
| 3696 | FastCloneShallowArrayStub::CLONE_ELEMENTS, length); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3697 | frame_->CallStub(&stub, 3); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3698 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3699 | frame_->EmitPush(r0); // save the result |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3700 | // r0: created object literal |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3701 | |
| 3702 | // Generate code to set the elements in the array that are not |
| 3703 | // literals. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3704 | for (int i = 0; i < node->values()->length(); i++) { |
| 3705 | Expression* value = node->values()->at(i); |
| 3706 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3707 | // If value is a literal the property value is already set in the |
| 3708 | // boilerplate object. |
| 3709 | if (value->AsLiteral() != NULL) continue; |
| 3710 | // If value is a materialized literal the property value is already set |
| 3711 | // in the boilerplate object if it is simple. |
| 3712 | if (CompileTimeValue::IsCompileTimeValue(value)) continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3713 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3714 | // The property must be set by generated code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3715 | Load(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3716 | frame_->PopToR0(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3717 | // Fetch the object literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3718 | frame_->SpillAllButCopyTOSToR1(); |
| 3719 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3720 | // Get the elements array. |
| 3721 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3722 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3723 | // Write to the indexed properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3724 | int offset = i * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3725 | __ str(r0, FieldMemOperand(r1, offset)); |
| 3726 | |
| 3727 | // Update the write barrier for the array address. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3728 | __ RecordWrite(r1, Operand(offset), r3, r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3729 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3730 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3734 | void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3735 | #ifdef DEBUG |
| 3736 | int original_height = frame_->height(); |
| 3737 | #endif |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3738 | // Call runtime routine to allocate the catch extension object and |
| 3739 | // assign the exception value to the catch variable. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3740 | Comment cmnt(masm_, "[ CatchExtensionObject"); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3741 | Load(node->key()); |
| 3742 | Load(node->value()); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 3743 | frame_->CallRuntime(Runtime::kCreateCatchExtensionObject, 2); |
| 3744 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3745 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3746 | } |
| 3747 | |
| 3748 | |
| 3749 | void CodeGenerator::EmitSlotAssignment(Assignment* node) { |
| 3750 | #ifdef DEBUG |
| 3751 | int original_height = frame_->height(); |
| 3752 | #endif |
| 3753 | Comment cmnt(masm(), "[ Variable Assignment"); |
| 3754 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3755 | ASSERT(var != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3756 | Slot* slot = var->AsSlot(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3757 | ASSERT(slot != NULL); |
| 3758 | |
| 3759 | // Evaluate the right-hand side. |
| 3760 | if (node->is_compound()) { |
| 3761 | // For a compound assignment the right-hand side is a binary operation |
| 3762 | // between the current property value and the actual right-hand side. |
| 3763 | LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
| 3764 | |
| 3765 | // Perform the binary operation. |
| 3766 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3767 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3768 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3769 | SmiOperation(node->binary_op(), |
| 3770 | literal->handle(), |
| 3771 | false, |
| 3772 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3773 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3774 | GenerateInlineSmi inline_smi = |
| 3775 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3776 | if (literal != NULL) { |
| 3777 | ASSERT(!literal->handle()->IsSmi()); |
| 3778 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3779 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3780 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3781 | GenericBinaryOperation(node->binary_op(), |
| 3782 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3783 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3784 | } |
| 3785 | } else { |
| 3786 | Load(node->value()); |
| 3787 | } |
| 3788 | |
| 3789 | // Perform the assignment. |
| 3790 | if (var->mode() != Variable::CONST || node->op() == Token::INIT_CONST) { |
| 3791 | CodeForSourcePosition(node->position()); |
| 3792 | StoreToSlot(slot, |
| 3793 | node->op() == Token::INIT_CONST ? CONST_INIT : NOT_CONST_INIT); |
| 3794 | } |
| 3795 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3796 | } |
| 3797 | |
| 3798 | |
| 3799 | void CodeGenerator::EmitNamedPropertyAssignment(Assignment* node) { |
| 3800 | #ifdef DEBUG |
| 3801 | int original_height = frame_->height(); |
| 3802 | #endif |
| 3803 | Comment cmnt(masm(), "[ Named Property Assignment"); |
| 3804 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3805 | Property* prop = node->target()->AsProperty(); |
| 3806 | ASSERT(var == NULL || (prop == NULL && var->is_global())); |
| 3807 | |
| 3808 | // Initialize name and evaluate the receiver sub-expression if necessary. If |
| 3809 | // the receiver is trivial it is not placed on the stack at this point, but |
| 3810 | // loaded whenever actually needed. |
| 3811 | Handle<String> name; |
| 3812 | bool is_trivial_receiver = false; |
| 3813 | if (var != NULL) { |
| 3814 | name = var->name(); |
| 3815 | } else { |
| 3816 | Literal* lit = prop->key()->AsLiteral(); |
| 3817 | ASSERT_NOT_NULL(lit); |
| 3818 | name = Handle<String>::cast(lit->handle()); |
| 3819 | // Do not materialize the receiver on the frame if it is trivial. |
| 3820 | is_trivial_receiver = prop->obj()->IsTrivial(); |
| 3821 | if (!is_trivial_receiver) Load(prop->obj()); |
| 3822 | } |
| 3823 | |
| 3824 | // Change to slow case in the beginning of an initialization block to |
| 3825 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3826 | if (node->starts_initialization_block()) { |
| 3827 | // Initialization block consists of assignments of the form expr.x = ..., so |
| 3828 | // this will never be an assignment to a variable, so there must be a |
| 3829 | // receiver object. |
| 3830 | ASSERT_EQ(NULL, var); |
| 3831 | if (is_trivial_receiver) { |
| 3832 | Load(prop->obj()); |
| 3833 | } else { |
| 3834 | frame_->Dup(); |
| 3835 | } |
| 3836 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3837 | } |
| 3838 | |
| 3839 | // Change to fast case at the end of an initialization block. To prepare for |
| 3840 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3841 | // converted back to fast case after the assignment. |
| 3842 | if (node->ends_initialization_block() && !is_trivial_receiver) { |
| 3843 | frame_->Dup(); |
| 3844 | } |
| 3845 | |
| 3846 | // Stack layout: |
| 3847 | // [tos] : receiver (only materialized if non-trivial) |
| 3848 | // [tos+1] : receiver if at the end of an initialization block |
| 3849 | |
| 3850 | // Evaluate the right-hand side. |
| 3851 | if (node->is_compound()) { |
| 3852 | // For a compound assignment the right-hand side is a binary operation |
| 3853 | // between the current property value and the actual right-hand side. |
| 3854 | if (is_trivial_receiver) { |
| 3855 | Load(prop->obj()); |
| 3856 | } else if (var != NULL) { |
| 3857 | LoadGlobal(); |
| 3858 | } else { |
| 3859 | frame_->Dup(); |
| 3860 | } |
| 3861 | EmitNamedLoad(name, var != NULL); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3862 | |
| 3863 | // Perform the binary operation. |
| 3864 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3865 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3866 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3867 | SmiOperation(node->binary_op(), |
| 3868 | literal->handle(), |
| 3869 | false, |
| 3870 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3871 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3872 | GenerateInlineSmi inline_smi = |
| 3873 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3874 | if (literal != NULL) { |
| 3875 | ASSERT(!literal->handle()->IsSmi()); |
| 3876 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3877 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3878 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3879 | GenericBinaryOperation(node->binary_op(), |
| 3880 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3881 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3882 | } |
| 3883 | } else { |
| 3884 | // For non-compound assignment just load the right-hand side. |
| 3885 | Load(node->value()); |
| 3886 | } |
| 3887 | |
| 3888 | // Stack layout: |
| 3889 | // [tos] : value |
| 3890 | // [tos+1] : receiver (only materialized if non-trivial) |
| 3891 | // [tos+2] : receiver if at the end of an initialization block |
| 3892 | |
| 3893 | // Perform the assignment. It is safe to ignore constants here. |
| 3894 | ASSERT(var == NULL || var->mode() != Variable::CONST); |
| 3895 | ASSERT_NE(Token::INIT_CONST, node->op()); |
| 3896 | if (is_trivial_receiver) { |
| 3897 | // Load the receiver and swap with the value. |
| 3898 | Load(prop->obj()); |
| 3899 | Register t0 = frame_->PopToRegister(); |
| 3900 | Register t1 = frame_->PopToRegister(t0); |
| 3901 | frame_->EmitPush(t0); |
| 3902 | frame_->EmitPush(t1); |
| 3903 | } |
| 3904 | CodeForSourcePosition(node->position()); |
| 3905 | bool is_contextual = (var != NULL); |
| 3906 | EmitNamedStore(name, is_contextual); |
| 3907 | frame_->EmitPush(r0); |
| 3908 | |
| 3909 | // Change to fast case at the end of an initialization block. |
| 3910 | if (node->ends_initialization_block()) { |
| 3911 | ASSERT_EQ(NULL, var); |
| 3912 | // The argument to the runtime call is the receiver. |
| 3913 | if (is_trivial_receiver) { |
| 3914 | Load(prop->obj()); |
| 3915 | } else { |
| 3916 | // A copy of the receiver is below the value of the assignment. Swap |
| 3917 | // the receiver and the value of the assignment expression. |
| 3918 | Register t0 = frame_->PopToRegister(); |
| 3919 | Register t1 = frame_->PopToRegister(t0); |
| 3920 | frame_->EmitPush(t0); |
| 3921 | frame_->EmitPush(t1); |
| 3922 | } |
| 3923 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 3924 | } |
| 3925 | |
| 3926 | // Stack layout: |
| 3927 | // [tos] : result |
| 3928 | |
| 3929 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3930 | } |
| 3931 | |
| 3932 | |
| 3933 | void CodeGenerator::EmitKeyedPropertyAssignment(Assignment* node) { |
| 3934 | #ifdef DEBUG |
| 3935 | int original_height = frame_->height(); |
| 3936 | #endif |
| 3937 | Comment cmnt(masm_, "[ Keyed Property Assignment"); |
| 3938 | Property* prop = node->target()->AsProperty(); |
| 3939 | ASSERT_NOT_NULL(prop); |
| 3940 | |
| 3941 | // Evaluate the receiver subexpression. |
| 3942 | Load(prop->obj()); |
| 3943 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3944 | WriteBarrierCharacter wb_info; |
| 3945 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3946 | // Change to slow case in the beginning of an initialization block to |
| 3947 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3948 | if (node->starts_initialization_block()) { |
| 3949 | frame_->Dup(); |
| 3950 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3951 | } |
| 3952 | |
| 3953 | // Change to fast case at the end of an initialization block. To prepare for |
| 3954 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3955 | // converted back to fast case after the assignment. |
| 3956 | if (node->ends_initialization_block()) { |
| 3957 | frame_->Dup(); |
| 3958 | } |
| 3959 | |
| 3960 | // Evaluate the key subexpression. |
| 3961 | Load(prop->key()); |
| 3962 | |
| 3963 | // Stack layout: |
| 3964 | // [tos] : key |
| 3965 | // [tos+1] : receiver |
| 3966 | // [tos+2] : receiver if at the end of an initialization block |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3967 | // |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3968 | // Evaluate the right-hand side. |
| 3969 | if (node->is_compound()) { |
| 3970 | // For a compound assignment the right-hand side is a binary operation |
| 3971 | // between the current property value and the actual right-hand side. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3972 | // Duplicate receiver and key for loading the current property value. |
| 3973 | frame_->Dup2(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3974 | EmitKeyedLoad(); |
| 3975 | frame_->EmitPush(r0); |
| 3976 | |
| 3977 | // Perform the binary operation. |
| 3978 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3979 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3980 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3981 | SmiOperation(node->binary_op(), |
| 3982 | literal->handle(), |
| 3983 | false, |
| 3984 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3985 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3986 | GenerateInlineSmi inline_smi = |
| 3987 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3988 | if (literal != NULL) { |
| 3989 | ASSERT(!literal->handle()->IsSmi()); |
| 3990 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3991 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3992 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3993 | GenericBinaryOperation(node->binary_op(), |
| 3994 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3995 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3996 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3997 | wb_info = node->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3998 | } else { |
| 3999 | // For non-compound assignment just load the right-hand side. |
| 4000 | Load(node->value()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4001 | wb_info = node->value()->AsLiteral() != NULL ? |
| 4002 | NEVER_NEWSPACE : |
| 4003 | (node->value()->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | // Stack layout: |
| 4007 | // [tos] : value |
| 4008 | // [tos+1] : key |
| 4009 | // [tos+2] : receiver |
| 4010 | // [tos+3] : receiver if at the end of an initialization block |
| 4011 | |
| 4012 | // Perform the assignment. It is safe to ignore constants here. |
| 4013 | ASSERT(node->op() != Token::INIT_CONST); |
| 4014 | CodeForSourcePosition(node->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4015 | EmitKeyedStore(prop->key()->type(), wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4016 | frame_->EmitPush(r0); |
| 4017 | |
| 4018 | // Stack layout: |
| 4019 | // [tos] : result |
| 4020 | // [tos+1] : receiver if at the end of an initialization block |
| 4021 | |
| 4022 | // Change to fast case at the end of an initialization block. |
| 4023 | if (node->ends_initialization_block()) { |
| 4024 | // The argument to the runtime call is the extra copy of the receiver, |
| 4025 | // which is below the value of the assignment. Swap the receiver and |
| 4026 | // the value of the assignment expression. |
| 4027 | Register t0 = frame_->PopToRegister(); |
| 4028 | Register t1 = frame_->PopToRegister(t0); |
| 4029 | frame_->EmitPush(t1); |
| 4030 | frame_->EmitPush(t0); |
| 4031 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 4032 | } |
| 4033 | |
| 4034 | // Stack layout: |
| 4035 | // [tos] : result |
| 4036 | |
| 4037 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4038 | } |
| 4039 | |
| 4040 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4041 | void CodeGenerator::VisitAssignment(Assignment* node) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4042 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4043 | #ifdef DEBUG |
| 4044 | int original_height = frame_->height(); |
| 4045 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4046 | Comment cmnt(masm_, "[ Assignment"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4047 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4048 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 4049 | Property* prop = node->target()->AsProperty(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4050 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4051 | if (var != NULL && !var->is_global()) { |
| 4052 | EmitSlotAssignment(node); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4053 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4054 | } else if ((prop != NULL && prop->key()->IsPropertyName()) || |
| 4055 | (var != NULL && var->is_global())) { |
| 4056 | // Properties whose keys are property names and global variables are |
| 4057 | // treated as named property references. We do not need to consider |
| 4058 | // global 'this' because it is not a valid left-hand side. |
| 4059 | EmitNamedPropertyAssignment(node); |
| 4060 | |
| 4061 | } else if (prop != NULL) { |
| 4062 | // Other properties (including rewritten parameters for a function that |
| 4063 | // uses arguments) are keyed property assignments. |
| 4064 | EmitKeyedPropertyAssignment(node); |
| 4065 | |
| 4066 | } else { |
| 4067 | // Invalid left-hand side. |
| 4068 | Load(node->target()); |
| 4069 | frame_->CallRuntime(Runtime::kThrowReferenceError, 1); |
| 4070 | // The runtime call doesn't actually return but the code generator will |
| 4071 | // still generate code and expects a certain frame height. |
| 4072 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4073 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4074 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4078 | void CodeGenerator::VisitThrow(Throw* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4079 | #ifdef DEBUG |
| 4080 | int original_height = frame_->height(); |
| 4081 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4082 | Comment cmnt(masm_, "[ Throw"); |
| 4083 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4084 | Load(node->exception()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4085 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4086 | frame_->CallRuntime(Runtime::kThrow, 1); |
| 4087 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4088 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4092 | void CodeGenerator::VisitProperty(Property* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4093 | #ifdef DEBUG |
| 4094 | int original_height = frame_->height(); |
| 4095 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4096 | Comment cmnt(masm_, "[ Property"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4097 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4098 | { Reference property(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 4099 | property.GetValue(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4100 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4101 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4105 | void CodeGenerator::VisitCall(Call* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4106 | #ifdef DEBUG |
| 4107 | int original_height = frame_->height(); |
| 4108 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4109 | Comment cmnt(masm_, "[ Call"); |
| 4110 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4111 | Expression* function = node->expression(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4112 | ZoneList<Expression*>* args = node->arguments(); |
| 4113 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4114 | // Standard function call. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4115 | // Check if the function is a variable or a property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4116 | Variable* var = function->AsVariableProxy()->AsVariable(); |
| 4117 | Property* property = function->AsProperty(); |
| 4118 | |
| 4119 | // ------------------------------------------------------------------------ |
| 4120 | // Fast-case: Use inline caching. |
| 4121 | // --- |
| 4122 | // According to ECMA-262, section 11.2.3, page 44, the function to call |
| 4123 | // must be resolved after the arguments have been evaluated. The IC code |
| 4124 | // automatically handles this by loading the arguments before the function |
| 4125 | // is resolved in cache misses (this also holds for megamorphic calls). |
| 4126 | // ------------------------------------------------------------------------ |
| 4127 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4128 | if (var != NULL && var->is_possibly_eval()) { |
| 4129 | // ---------------------------------- |
| 4130 | // JavaScript example: 'eval(arg)' // eval is not known to be shadowed |
| 4131 | // ---------------------------------- |
| 4132 | |
| 4133 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 4134 | // resolve the function we need to call and the receiver of the |
| 4135 | // call. Then we call the resolved function using the given |
| 4136 | // arguments. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4137 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4138 | // Prepare stack for call to resolved function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4139 | Load(function); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4140 | |
| 4141 | // Allocate a frame slot for the receiver. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4142 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4143 | |
| 4144 | // Load the arguments. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4145 | int arg_count = args->length(); |
| 4146 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4147 | Load(args->at(i)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4150 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4151 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4152 | // If we know that eval can only be shadowed by eval-introduced |
| 4153 | // variables we attempt to load the global eval function directly |
| 4154 | // in generated code. If we succeed, there is no need to perform a |
| 4155 | // context lookup in the runtime system. |
| 4156 | JumpTarget done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4157 | if (var->AsSlot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) { |
| 4158 | ASSERT(var->AsSlot()->type() == Slot::LOOKUP); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4159 | JumpTarget slow; |
| 4160 | // Prepare the stack for the call to |
| 4161 | // ResolvePossiblyDirectEvalNoLookup by pushing the loaded |
| 4162 | // function, the first argument to the eval call and the |
| 4163 | // receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4164 | LoadFromGlobalSlotCheckExtensions(var->AsSlot(), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4165 | NOT_INSIDE_TYPEOF, |
| 4166 | &slow); |
| 4167 | frame_->EmitPush(r0); |
| 4168 | if (arg_count > 0) { |
| 4169 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 4170 | frame_->EmitPush(r1); |
| 4171 | } else { |
| 4172 | frame_->EmitPush(r2); |
| 4173 | } |
| 4174 | __ ldr(r1, frame_->Receiver()); |
| 4175 | frame_->EmitPush(r1); |
| 4176 | |
| 4177 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEvalNoLookup, 3); |
| 4178 | |
| 4179 | done.Jump(); |
| 4180 | slow.Bind(); |
| 4181 | } |
| 4182 | |
| 4183 | // Prepare the stack for the call to ResolvePossiblyDirectEval by |
| 4184 | // pushing the loaded function, the first argument to the eval |
| 4185 | // call and the receiver. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4186 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize + kPointerSize)); |
| 4187 | frame_->EmitPush(r1); |
| 4188 | if (arg_count > 0) { |
| 4189 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 4190 | frame_->EmitPush(r1); |
| 4191 | } else { |
| 4192 | frame_->EmitPush(r2); |
| 4193 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4194 | __ ldr(r1, frame_->Receiver()); |
| 4195 | frame_->EmitPush(r1); |
| 4196 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4197 | // Resolve the call. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4198 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEval, 3); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4199 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4200 | // If we generated fast-case code bind the jump-target where fast |
| 4201 | // and slow case merge. |
| 4202 | if (done.is_linked()) done.Bind(); |
| 4203 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4204 | // Touch up stack with the right values for the function and the receiver. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4205 | __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4206 | __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 4207 | |
| 4208 | // Call the function. |
| 4209 | CodeForSourcePosition(node->position()); |
| 4210 | |
| 4211 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4212 | CallFunctionStub call_function(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4213 | frame_->CallStub(&call_function, arg_count + 1); |
| 4214 | |
| 4215 | __ ldr(cp, frame_->Context()); |
| 4216 | // Remove the function from the stack. |
| 4217 | frame_->Drop(); |
| 4218 | frame_->EmitPush(r0); |
| 4219 | |
| 4220 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4221 | // ---------------------------------- |
| 4222 | // JavaScript example: 'foo(1, 2, 3)' // foo is global |
| 4223 | // ---------------------------------- |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4224 | // Pass the global object as the receiver and let the IC stub |
| 4225 | // patch the stack to use the global proxy as 'this' in the |
| 4226 | // invoked function. |
| 4227 | LoadGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4228 | |
| 4229 | // Load the arguments. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4230 | int arg_count = args->length(); |
| 4231 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4232 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4233 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4234 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4235 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4236 | // Setup the name register and call the IC initialization code. |
| 4237 | __ mov(r2, Operand(var->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4238 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4239 | Handle<Code> stub = StubCache::ComputeCallInitialize(arg_count, in_loop); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4240 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4241 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET_CONTEXT, |
| 4242 | arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 4243 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4244 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4245 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4246 | } else if (var != NULL && var->AsSlot() != NULL && |
| 4247 | var->AsSlot()->type() == Slot::LOOKUP) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4248 | // ---------------------------------- |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4249 | // JavaScript examples: |
| 4250 | // |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4251 | // with (obj) foo(1, 2, 3) // foo may be in obj. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4252 | // |
| 4253 | // function f() {}; |
| 4254 | // function g() { |
| 4255 | // eval(...); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4256 | // f(); // f could be in extension object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4257 | // } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4258 | // ---------------------------------- |
| 4259 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4260 | JumpTarget slow, done; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4261 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4262 | // Generate fast case for loading functions from slots that |
| 4263 | // correspond to local/global variables or arguments unless they |
| 4264 | // are shadowed by eval-introduced bindings. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4265 | EmitDynamicLoadFromSlotFastCase(var->AsSlot(), |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4266 | NOT_INSIDE_TYPEOF, |
| 4267 | &slow, |
| 4268 | &done); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4269 | |
| 4270 | slow.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4271 | // Load the function |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4272 | frame_->EmitPush(cp); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4273 | frame_->EmitPush(Operand(var->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4274 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4275 | // r0: slot value; r1: receiver |
| 4276 | |
| 4277 | // Load the receiver. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4278 | frame_->EmitPush(r0); // function |
| 4279 | frame_->EmitPush(r1); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4280 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4281 | // If fast case code has been generated, emit code to push the |
| 4282 | // function and receiver and have the slow path jump around this |
| 4283 | // code. |
| 4284 | if (done.is_linked()) { |
| 4285 | JumpTarget call; |
| 4286 | call.Jump(); |
| 4287 | done.Bind(); |
| 4288 | frame_->EmitPush(r0); // function |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4289 | LoadGlobalReceiver(VirtualFrame::scratch0()); // receiver |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4290 | call.Bind(); |
| 4291 | } |
| 4292 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4293 | // Call the function. At this point, everything is spilled but the |
| 4294 | // function and receiver are in r0 and r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4295 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4296 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4297 | |
| 4298 | } else if (property != NULL) { |
| 4299 | // Check if the key is a literal string. |
| 4300 | Literal* literal = property->key()->AsLiteral(); |
| 4301 | |
| 4302 | if (literal != NULL && literal->handle()->IsSymbol()) { |
| 4303 | // ------------------------------------------------------------------ |
| 4304 | // JavaScript example: 'object.foo(1, 2, 3)' or 'map["key"](1, 2, 3)' |
| 4305 | // ------------------------------------------------------------------ |
| 4306 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4307 | Handle<String> name = Handle<String>::cast(literal->handle()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4308 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4309 | if (ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION && |
| 4310 | name->IsEqualTo(CStrVector("apply")) && |
| 4311 | args->length() == 2 && |
| 4312 | args->at(1)->AsVariableProxy() != NULL && |
| 4313 | args->at(1)->AsVariableProxy()->IsArguments()) { |
| 4314 | // Use the optimized Function.prototype.apply that avoids |
| 4315 | // allocating lazily allocated arguments objects. |
| 4316 | CallApplyLazy(property->obj(), |
| 4317 | args->at(0), |
| 4318 | args->at(1)->AsVariableProxy(), |
| 4319 | node->position()); |
| 4320 | |
| 4321 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4322 | Load(property->obj()); // Receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4323 | // Load the arguments. |
| 4324 | int arg_count = args->length(); |
| 4325 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4326 | Load(args->at(i)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4329 | VirtualFrame::SpilledScope spilled_scope(frame_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4330 | // Set the name register and call the IC initialization code. |
| 4331 | __ mov(r2, Operand(name)); |
| 4332 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4333 | Handle<Code> stub = |
| 4334 | StubCache::ComputeCallInitialize(arg_count, in_loop); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4335 | CodeForSourcePosition(node->position()); |
| 4336 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
| 4337 | __ ldr(cp, frame_->Context()); |
| 4338 | frame_->EmitPush(r0); |
| 4339 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4340 | |
| 4341 | } else { |
| 4342 | // ------------------------------------------- |
| 4343 | // JavaScript example: 'array[index](1, 2, 3)' |
| 4344 | // ------------------------------------------- |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4345 | |
| 4346 | // Load the receiver and name of the function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4347 | Load(property->obj()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4348 | Load(property->key()); |
| 4349 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4350 | if (property->is_synthetic()) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4351 | EmitKeyedLoad(); |
| 4352 | // Put the function below the receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4353 | // Use the global receiver. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4354 | frame_->EmitPush(r0); // Function. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4355 | LoadGlobalReceiver(VirtualFrame::scratch0()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4356 | // Call the function. |
| 4357 | CallWithArguments(args, RECEIVER_MIGHT_BE_VALUE, node->position()); |
| 4358 | frame_->EmitPush(r0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4359 | } else { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4360 | // Swap the name of the function and the receiver on the stack to follow |
| 4361 | // the calling convention for call ICs. |
| 4362 | Register key = frame_->PopToRegister(); |
| 4363 | Register receiver = frame_->PopToRegister(key); |
| 4364 | frame_->EmitPush(key); |
| 4365 | frame_->EmitPush(receiver); |
| 4366 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4367 | // Load the arguments. |
| 4368 | int arg_count = args->length(); |
| 4369 | for (int i = 0; i < arg_count; i++) { |
| 4370 | Load(args->at(i)); |
| 4371 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4372 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4373 | // Load the key into r2 and call the IC initialization code. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4374 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4375 | Handle<Code> stub = |
| 4376 | StubCache::ComputeKeyedCallInitialize(arg_count, in_loop); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4377 | CodeForSourcePosition(node->position()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4378 | frame_->SpillAll(); |
| 4379 | __ ldr(r2, frame_->ElementAt(arg_count + 1)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4380 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4381 | frame_->Drop(); // Drop the key still on the stack. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4382 | __ ldr(cp, frame_->Context()); |
| 4383 | frame_->EmitPush(r0); |
| 4384 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | } else { |
| 4388 | // ---------------------------------- |
| 4389 | // JavaScript example: 'foo(1, 2, 3)' // foo is not global |
| 4390 | // ---------------------------------- |
| 4391 | |
| 4392 | // Load the function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4393 | Load(function); |
| 4394 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4395 | // Pass the global proxy as the receiver. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4396 | LoadGlobalReceiver(VirtualFrame::scratch0()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4397 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4398 | // Call the function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4399 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4400 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4401 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4402 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4406 | void CodeGenerator::VisitCallNew(CallNew* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4407 | #ifdef DEBUG |
| 4408 | int original_height = frame_->height(); |
| 4409 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4410 | Comment cmnt(masm_, "[ CallNew"); |
| 4411 | |
| 4412 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 4413 | // expression in new calls must be evaluated before the |
| 4414 | // arguments. This is different from ordinary calls, where the |
| 4415 | // actual function to call is resolved after the arguments have been |
| 4416 | // evaluated. |
| 4417 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4418 | // Push constructor on the stack. If it's not a function it's used as |
| 4419 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 4420 | // ignored. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4421 | Load(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4422 | |
| 4423 | // Push the arguments ("left-to-right") on the stack. |
| 4424 | ZoneList<Expression*>* args = node->arguments(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4425 | int arg_count = args->length(); |
| 4426 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4427 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4428 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4429 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4430 | // Spill everything from here to simplify the implementation. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4431 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4432 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4433 | // Load the argument count into r0 and the function into r1 as per |
| 4434 | // calling convention. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4435 | __ mov(r0, Operand(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4436 | __ ldr(r1, frame_->ElementAt(arg_count)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4437 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4438 | // Call the construct call builtin that handles allocation and |
| 4439 | // constructor invocation. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4440 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4441 | Handle<Code> ic(Builtins::builtin(Builtins::JSConstructCall)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4442 | frame_->CallCodeObject(ic, RelocInfo::CONSTRUCT_CALL, arg_count + 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4443 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4444 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4445 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4449 | void CodeGenerator::GenerateClassOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4450 | Register scratch = VirtualFrame::scratch0(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4451 | JumpTarget null, function, leave, non_function_constructor; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4452 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4453 | // Load the object into register. |
| 4454 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4455 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4456 | Register tos = frame_->PopToRegister(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4457 | |
| 4458 | // If the object is a smi, we return null. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4459 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4460 | null.Branch(eq); |
| 4461 | |
| 4462 | // Check that the object is a JS object but take special care of JS |
| 4463 | // functions to make sure they have 'Function' as their class. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4464 | __ CompareObjectType(tos, tos, scratch, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4465 | null.Branch(lt); |
| 4466 | |
| 4467 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 4468 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 4469 | // LAST_JS_OBJECT_TYPE. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 4470 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 4471 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4472 | __ cmp(scratch, Operand(JS_FUNCTION_TYPE)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4473 | function.Branch(eq); |
| 4474 | |
| 4475 | // Check if the constructor in the map is a function. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4476 | __ ldr(tos, FieldMemOperand(tos, Map::kConstructorOffset)); |
| 4477 | __ CompareObjectType(tos, scratch, scratch, JS_FUNCTION_TYPE); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4478 | non_function_constructor.Branch(ne); |
| 4479 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4480 | // The tos register now contains the constructor function. Grab the |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4481 | // instance class name from there. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4482 | __ ldr(tos, FieldMemOperand(tos, JSFunction::kSharedFunctionInfoOffset)); |
| 4483 | __ ldr(tos, |
| 4484 | FieldMemOperand(tos, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 4485 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4486 | leave.Jump(); |
| 4487 | |
| 4488 | // Functions have class 'Function'. |
| 4489 | function.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4490 | __ mov(tos, Operand(Factory::function_class_symbol())); |
| 4491 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4492 | leave.Jump(); |
| 4493 | |
| 4494 | // Objects with a non-function constructor have class 'Object'. |
| 4495 | non_function_constructor.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4496 | __ mov(tos, Operand(Factory::Object_symbol())); |
| 4497 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4498 | leave.Jump(); |
| 4499 | |
| 4500 | // Non-JS objects have class null. |
| 4501 | null.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4502 | __ LoadRoot(tos, Heap::kNullValueRootIndex); |
| 4503 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4504 | |
| 4505 | // All done. |
| 4506 | leave.Bind(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4510 | void CodeGenerator::GenerateValueOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4511 | Register scratch = VirtualFrame::scratch0(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4512 | JumpTarget leave; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4513 | |
| 4514 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4515 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4516 | Register tos = frame_->PopToRegister(); // tos contains object. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4517 | // if (object->IsSmi()) return the object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4518 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4519 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4520 | // It is a heap object - get map. If (!object->IsJSValue()) return the object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4521 | __ CompareObjectType(tos, scratch, scratch, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4522 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4523 | // Load the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4524 | __ ldr(tos, FieldMemOperand(tos, JSValue::kValueOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4525 | leave.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4526 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4530 | void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4531 | Register scratch1 = VirtualFrame::scratch0(); |
| 4532 | Register scratch2 = VirtualFrame::scratch1(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4533 | JumpTarget leave; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4534 | |
| 4535 | ASSERT(args->length() == 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4536 | Load(args->at(0)); // Load the object. |
| 4537 | Load(args->at(1)); // Load the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4538 | Register value = frame_->PopToRegister(); |
| 4539 | Register object = frame_->PopToRegister(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4540 | // if (object->IsSmi()) return object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4541 | __ tst(object, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4542 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4543 | // It is a heap object - get map. If (!object->IsJSValue()) return the object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4544 | __ CompareObjectType(object, scratch1, scratch1, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4545 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4546 | // Store the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4547 | __ str(value, FieldMemOperand(object, JSValue::kValueOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4548 | // Update the write barrier. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4549 | __ RecordWrite(object, |
| 4550 | Operand(JSValue::kValueOffset - kHeapObjectTag), |
| 4551 | scratch1, |
| 4552 | scratch2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4553 | // Leave. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4554 | leave.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4555 | frame_->EmitPush(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4559 | void CodeGenerator::GenerateIsSmi(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4560 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4561 | Load(args->at(0)); |
| 4562 | Register reg = frame_->PopToRegister(); |
| 4563 | __ tst(reg, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4564 | cc_reg_ = eq; |
| 4565 | } |
| 4566 | |
| 4567 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4568 | void CodeGenerator::GenerateLog(ZoneList<Expression*>* args) { |
| 4569 | // See comment in CodeGenerator::GenerateLog in codegen-ia32.cc. |
| 4570 | ASSERT_EQ(args->length(), 3); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4571 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4572 | if (ShouldGenerateLog(args->at(0))) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4573 | Load(args->at(1)); |
| 4574 | Load(args->at(2)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4575 | frame_->CallRuntime(Runtime::kLog, 2); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4576 | } |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4577 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4578 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4582 | void CodeGenerator::GenerateIsNonNegativeSmi(ZoneList<Expression*>* args) { |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4583 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4584 | Load(args->at(0)); |
| 4585 | Register reg = frame_->PopToRegister(); |
| 4586 | __ tst(reg, Operand(kSmiTagMask | 0x80000000u)); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4587 | cc_reg_ = eq; |
| 4588 | } |
| 4589 | |
| 4590 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4591 | // Generates the Math.pow method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4592 | void CodeGenerator::GenerateMathPow(ZoneList<Expression*>* args) { |
| 4593 | ASSERT(args->length() == 2); |
| 4594 | Load(args->at(0)); |
| 4595 | Load(args->at(1)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4596 | |
| 4597 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4598 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4599 | frame_->EmitPush(r0); |
| 4600 | } else { |
| 4601 | CpuFeatures::Scope scope(VFP3); |
| 4602 | JumpTarget runtime, done; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4603 | Label exponent_nonsmi, base_nonsmi, powi, not_minus_half, allocate_return; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4604 | |
| 4605 | Register scratch1 = VirtualFrame::scratch0(); |
| 4606 | Register scratch2 = VirtualFrame::scratch1(); |
| 4607 | |
| 4608 | // Get base and exponent to registers. |
| 4609 | Register exponent = frame_->PopToRegister(); |
| 4610 | Register base = frame_->PopToRegister(exponent); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4611 | Register heap_number_map = no_reg; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4612 | |
| 4613 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4614 | // jump target label so the frame needs to be established before that. |
| 4615 | ASSERT(runtime.entry_frame() == NULL); |
| 4616 | runtime.set_entry_frame(frame_); |
| 4617 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4618 | __ BranchOnNotSmi(exponent, &exponent_nonsmi); |
| 4619 | __ BranchOnNotSmi(base, &base_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4620 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4621 | heap_number_map = r6; |
| 4622 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4623 | |
| 4624 | // Exponent is a smi and base is a smi. Get the smi value into vfp register |
| 4625 | // d1. |
| 4626 | __ SmiToDoubleVFPRegister(base, d1, scratch1, s0); |
| 4627 | __ b(&powi); |
| 4628 | |
| 4629 | __ bind(&base_nonsmi); |
| 4630 | // Exponent is smi and base is non smi. Get the double value from the base |
| 4631 | // into vfp register d1. |
| 4632 | __ ObjectToDoubleVFPRegister(base, d1, |
| 4633 | scratch1, scratch2, heap_number_map, s0, |
| 4634 | runtime.entry_label()); |
| 4635 | |
| 4636 | __ bind(&powi); |
| 4637 | |
| 4638 | // Load 1.0 into d0. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4639 | __ vmov(d0, 1.0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4640 | |
| 4641 | // Get the absolute untagged value of the exponent and use that for the |
| 4642 | // calculation. |
| 4643 | __ mov(scratch1, Operand(exponent, ASR, kSmiTagSize), SetCC); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4644 | // Negate if negative. |
| 4645 | __ rsb(scratch1, scratch1, Operand(0, RelocInfo::NONE), LeaveCC, mi); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4646 | __ vmov(d2, d0, mi); // 1.0 needed in d2 later if exponent is negative. |
| 4647 | |
| 4648 | // Run through all the bits in the exponent. The result is calculated in d0 |
| 4649 | // and d1 holds base^(bit^2). |
| 4650 | Label more_bits; |
| 4651 | __ bind(&more_bits); |
| 4652 | __ mov(scratch1, Operand(scratch1, LSR, 1), SetCC); |
| 4653 | __ vmul(d0, d0, d1, cs); // Multiply with base^(bit^2) if bit is set. |
| 4654 | __ vmul(d1, d1, d1, ne); // Don't bother calculating next d1 if done. |
| 4655 | __ b(ne, &more_bits); |
| 4656 | |
| 4657 | // If exponent is positive we are done. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4658 | __ cmp(exponent, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4659 | __ b(ge, &allocate_return); |
| 4660 | |
| 4661 | // If exponent is negative result is 1/result (d2 already holds 1.0 in that |
| 4662 | // case). However if d0 has reached infinity this will not provide the |
| 4663 | // correct result, so call runtime if that is the case. |
| 4664 | __ mov(scratch2, Operand(0x7FF00000)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4665 | __ mov(scratch1, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4666 | __ vmov(d1, scratch1, scratch2); // Load infinity into d1. |
| 4667 | __ vcmp(d0, d1); |
| 4668 | __ vmrs(pc); |
| 4669 | runtime.Branch(eq); // d0 reached infinity. |
| 4670 | __ vdiv(d0, d2, d0); |
| 4671 | __ b(&allocate_return); |
| 4672 | |
| 4673 | __ bind(&exponent_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4674 | // Special handling of raising to the power of -0.5 and 0.5. First check |
| 4675 | // that the value is a heap number and that the lower bits (which for both |
| 4676 | // values are zero). |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4677 | heap_number_map = r6; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4678 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4679 | __ ldr(scratch1, FieldMemOperand(exponent, HeapObject::kMapOffset)); |
| 4680 | __ ldr(scratch2, FieldMemOperand(exponent, HeapNumber::kMantissaOffset)); |
| 4681 | __ cmp(scratch1, heap_number_map); |
| 4682 | runtime.Branch(ne); |
| 4683 | __ tst(scratch2, scratch2); |
| 4684 | runtime.Branch(ne); |
| 4685 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4686 | // Load the higher bits (which contains the floating point exponent). |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4687 | __ ldr(scratch1, FieldMemOperand(exponent, HeapNumber::kExponentOffset)); |
| 4688 | |
| 4689 | // Compare exponent with -0.5. |
| 4690 | __ cmp(scratch1, Operand(0xbfe00000)); |
| 4691 | __ b(ne, ¬_minus_half); |
| 4692 | |
| 4693 | // Get the double value from the base into vfp register d0. |
| 4694 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4695 | scratch1, scratch2, heap_number_map, s0, |
| 4696 | runtime.entry_label(), |
| 4697 | AVOID_NANS_AND_INFINITIES); |
| 4698 | |
| 4699 | // Load 1.0 into d2. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4700 | __ vmov(d2, 1.0); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4701 | |
| 4702 | // Calculate the reciprocal of the square root. 1/sqrt(x) = sqrt(1/x). |
| 4703 | __ vdiv(d0, d2, d0); |
| 4704 | __ vsqrt(d0, d0); |
| 4705 | |
| 4706 | __ b(&allocate_return); |
| 4707 | |
| 4708 | __ bind(¬_minus_half); |
| 4709 | // Compare exponent with 0.5. |
| 4710 | __ cmp(scratch1, Operand(0x3fe00000)); |
| 4711 | runtime.Branch(ne); |
| 4712 | |
| 4713 | // Get the double value from the base into vfp register d0. |
| 4714 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4715 | scratch1, scratch2, heap_number_map, s0, |
| 4716 | runtime.entry_label(), |
| 4717 | AVOID_NANS_AND_INFINITIES); |
| 4718 | __ vsqrt(d0, d0); |
| 4719 | |
| 4720 | __ bind(&allocate_return); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4721 | Register scratch3 = r5; |
| 4722 | __ AllocateHeapNumberWithValue(scratch3, d0, scratch1, scratch2, |
| 4723 | heap_number_map, runtime.entry_label()); |
| 4724 | __ mov(base, scratch3); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4725 | done.Jump(); |
| 4726 | |
| 4727 | runtime.Bind(); |
| 4728 | |
| 4729 | // Push back the arguments again for the runtime call. |
| 4730 | frame_->EmitPush(base); |
| 4731 | frame_->EmitPush(exponent); |
| 4732 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4733 | __ Move(base, r0); |
| 4734 | |
| 4735 | done.Bind(); |
| 4736 | frame_->EmitPush(base); |
| 4737 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4741 | // Generates the Math.sqrt method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4742 | void CodeGenerator::GenerateMathSqrt(ZoneList<Expression*>* args) { |
| 4743 | ASSERT(args->length() == 1); |
| 4744 | Load(args->at(0)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4745 | |
| 4746 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4747 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4748 | frame_->EmitPush(r0); |
| 4749 | } else { |
| 4750 | CpuFeatures::Scope scope(VFP3); |
| 4751 | JumpTarget runtime, done; |
| 4752 | |
| 4753 | Register scratch1 = VirtualFrame::scratch0(); |
| 4754 | Register scratch2 = VirtualFrame::scratch1(); |
| 4755 | |
| 4756 | // Get the value from the frame. |
| 4757 | Register tos = frame_->PopToRegister(); |
| 4758 | |
| 4759 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4760 | // jump target label so the frame needs to be established before that. |
| 4761 | ASSERT(runtime.entry_frame() == NULL); |
| 4762 | runtime.set_entry_frame(frame_); |
| 4763 | |
| 4764 | Register heap_number_map = r6; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4765 | Register new_heap_number = r5; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4766 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4767 | |
| 4768 | // Get the double value from the heap number into vfp register d0. |
| 4769 | __ ObjectToDoubleVFPRegister(tos, d0, |
| 4770 | scratch1, scratch2, heap_number_map, s0, |
| 4771 | runtime.entry_label()); |
| 4772 | |
| 4773 | // Calculate the square root of d0 and place result in a heap number object. |
| 4774 | __ vsqrt(d0, d0); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4775 | __ AllocateHeapNumberWithValue(new_heap_number, |
| 4776 | d0, |
| 4777 | scratch1, scratch2, |
| 4778 | heap_number_map, |
| 4779 | runtime.entry_label()); |
| 4780 | __ mov(tos, Operand(new_heap_number)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4781 | done.Jump(); |
| 4782 | |
| 4783 | runtime.Bind(); |
| 4784 | // Push back the argument again for the runtime call. |
| 4785 | frame_->EmitPush(tos); |
| 4786 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4787 | __ Move(tos, r0); |
| 4788 | |
| 4789 | done.Bind(); |
| 4790 | frame_->EmitPush(tos); |
| 4791 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4795 | class DeferredStringCharCodeAt : public DeferredCode { |
| 4796 | public: |
| 4797 | DeferredStringCharCodeAt(Register object, |
| 4798 | Register index, |
| 4799 | Register scratch, |
| 4800 | Register result) |
| 4801 | : result_(result), |
| 4802 | char_code_at_generator_(object, |
| 4803 | index, |
| 4804 | scratch, |
| 4805 | result, |
| 4806 | &need_conversion_, |
| 4807 | &need_conversion_, |
| 4808 | &index_out_of_range_, |
| 4809 | STRING_INDEX_IS_NUMBER) {} |
| 4810 | |
| 4811 | StringCharCodeAtGenerator* fast_case_generator() { |
| 4812 | return &char_code_at_generator_; |
| 4813 | } |
| 4814 | |
| 4815 | virtual void Generate() { |
| 4816 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4817 | char_code_at_generator_.GenerateSlow(masm(), call_helper); |
| 4818 | |
| 4819 | __ bind(&need_conversion_); |
| 4820 | // Move the undefined value into the result register, which will |
| 4821 | // trigger conversion. |
| 4822 | __ LoadRoot(result_, Heap::kUndefinedValueRootIndex); |
| 4823 | __ jmp(exit_label()); |
| 4824 | |
| 4825 | __ bind(&index_out_of_range_); |
| 4826 | // When the index is out of range, the spec requires us to return |
| 4827 | // NaN. |
| 4828 | __ LoadRoot(result_, Heap::kNanValueRootIndex); |
| 4829 | __ jmp(exit_label()); |
| 4830 | } |
| 4831 | |
| 4832 | private: |
| 4833 | Register result_; |
| 4834 | |
| 4835 | Label need_conversion_; |
| 4836 | Label index_out_of_range_; |
| 4837 | |
| 4838 | StringCharCodeAtGenerator char_code_at_generator_; |
| 4839 | }; |
| 4840 | |
| 4841 | |
| 4842 | // This generates code that performs a String.prototype.charCodeAt() call |
| 4843 | // or returns a smi in order to trigger conversion. |
| 4844 | void CodeGenerator::GenerateStringCharCodeAt(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4845 | Comment(masm_, "[ GenerateStringCharCodeAt"); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4846 | ASSERT(args->length() == 2); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4847 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4848 | Load(args->at(0)); |
| 4849 | Load(args->at(1)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4850 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4851 | Register index = frame_->PopToRegister(); |
| 4852 | Register object = frame_->PopToRegister(index); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4853 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4854 | // We need two extra registers. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4855 | Register scratch = VirtualFrame::scratch0(); |
| 4856 | Register result = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4857 | |
| 4858 | DeferredStringCharCodeAt* deferred = |
| 4859 | new DeferredStringCharCodeAt(object, |
| 4860 | index, |
| 4861 | scratch, |
| 4862 | result); |
| 4863 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4864 | deferred->BindExit(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4865 | frame_->EmitPush(result); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4869 | class DeferredStringCharFromCode : public DeferredCode { |
| 4870 | public: |
| 4871 | DeferredStringCharFromCode(Register code, |
| 4872 | Register result) |
| 4873 | : char_from_code_generator_(code, result) {} |
| 4874 | |
| 4875 | StringCharFromCodeGenerator* fast_case_generator() { |
| 4876 | return &char_from_code_generator_; |
| 4877 | } |
| 4878 | |
| 4879 | virtual void Generate() { |
| 4880 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4881 | char_from_code_generator_.GenerateSlow(masm(), call_helper); |
| 4882 | } |
| 4883 | |
| 4884 | private: |
| 4885 | StringCharFromCodeGenerator char_from_code_generator_; |
| 4886 | }; |
| 4887 | |
| 4888 | |
| 4889 | // Generates code for creating a one-char string from a char code. |
| 4890 | void CodeGenerator::GenerateStringCharFromCode(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4891 | Comment(masm_, "[ GenerateStringCharFromCode"); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4892 | ASSERT(args->length() == 1); |
| 4893 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4894 | Load(args->at(0)); |
| 4895 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4896 | Register result = frame_->GetTOSRegister(); |
| 4897 | Register code = frame_->PopToRegister(result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4898 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4899 | DeferredStringCharFromCode* deferred = new DeferredStringCharFromCode( |
| 4900 | code, result); |
| 4901 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4902 | deferred->BindExit(); |
| 4903 | frame_->EmitPush(result); |
| 4904 | } |
| 4905 | |
| 4906 | |
| 4907 | class DeferredStringCharAt : public DeferredCode { |
| 4908 | public: |
| 4909 | DeferredStringCharAt(Register object, |
| 4910 | Register index, |
| 4911 | Register scratch1, |
| 4912 | Register scratch2, |
| 4913 | Register result) |
| 4914 | : result_(result), |
| 4915 | char_at_generator_(object, |
| 4916 | index, |
| 4917 | scratch1, |
| 4918 | scratch2, |
| 4919 | result, |
| 4920 | &need_conversion_, |
| 4921 | &need_conversion_, |
| 4922 | &index_out_of_range_, |
| 4923 | STRING_INDEX_IS_NUMBER) {} |
| 4924 | |
| 4925 | StringCharAtGenerator* fast_case_generator() { |
| 4926 | return &char_at_generator_; |
| 4927 | } |
| 4928 | |
| 4929 | virtual void Generate() { |
| 4930 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4931 | char_at_generator_.GenerateSlow(masm(), call_helper); |
| 4932 | |
| 4933 | __ bind(&need_conversion_); |
| 4934 | // Move smi zero into the result register, which will trigger |
| 4935 | // conversion. |
| 4936 | __ mov(result_, Operand(Smi::FromInt(0))); |
| 4937 | __ jmp(exit_label()); |
| 4938 | |
| 4939 | __ bind(&index_out_of_range_); |
| 4940 | // When the index is out of range, the spec requires us to return |
| 4941 | // the empty string. |
| 4942 | __ LoadRoot(result_, Heap::kEmptyStringRootIndex); |
| 4943 | __ jmp(exit_label()); |
| 4944 | } |
| 4945 | |
| 4946 | private: |
| 4947 | Register result_; |
| 4948 | |
| 4949 | Label need_conversion_; |
| 4950 | Label index_out_of_range_; |
| 4951 | |
| 4952 | StringCharAtGenerator char_at_generator_; |
| 4953 | }; |
| 4954 | |
| 4955 | |
| 4956 | // This generates code that performs a String.prototype.charAt() call |
| 4957 | // or returns a smi in order to trigger conversion. |
| 4958 | void CodeGenerator::GenerateStringCharAt(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4959 | Comment(masm_, "[ GenerateStringCharAt"); |
| 4960 | ASSERT(args->length() == 2); |
| 4961 | |
| 4962 | Load(args->at(0)); |
| 4963 | Load(args->at(1)); |
| 4964 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4965 | Register index = frame_->PopToRegister(); |
| 4966 | Register object = frame_->PopToRegister(index); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4967 | |
| 4968 | // We need three extra registers. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4969 | Register scratch1 = VirtualFrame::scratch0(); |
| 4970 | Register scratch2 = VirtualFrame::scratch1(); |
| 4971 | // Use r6 without notifying the virtual frame. |
| 4972 | Register result = r6; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4973 | |
| 4974 | DeferredStringCharAt* deferred = |
| 4975 | new DeferredStringCharAt(object, |
| 4976 | index, |
| 4977 | scratch1, |
| 4978 | scratch2, |
| 4979 | result); |
| 4980 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4981 | deferred->BindExit(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4982 | frame_->EmitPush(result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4986 | void CodeGenerator::GenerateIsArray(ZoneList<Expression*>* args) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4987 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4988 | Load(args->at(0)); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4989 | JumpTarget answer; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4990 | // We need the CC bits to come out as not_equal in the case where the |
| 4991 | // object is a smi. This can't be done with the usual test opcode so |
| 4992 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4993 | Register possible_array = frame_->PopToRegister(); |
| 4994 | Register scratch = VirtualFrame::scratch0(); |
| 4995 | __ and_(scratch, possible_array, Operand(kSmiTagMask)); |
| 4996 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4997 | answer.Branch(ne); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4998 | // It is a heap object - get the map. Check if the object is a JS array. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4999 | __ CompareObjectType(possible_array, scratch, scratch, JS_ARRAY_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5000 | answer.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5001 | cc_reg_ = eq; |
| 5002 | } |
| 5003 | |
| 5004 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 5005 | void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) { |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 5006 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5007 | Load(args->at(0)); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 5008 | JumpTarget answer; |
| 5009 | // We need the CC bits to come out as not_equal in the case where the |
| 5010 | // object is a smi. This can't be done with the usual test opcode so |
| 5011 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5012 | Register possible_regexp = frame_->PopToRegister(); |
| 5013 | Register scratch = VirtualFrame::scratch0(); |
| 5014 | __ and_(scratch, possible_regexp, Operand(kSmiTagMask)); |
| 5015 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 5016 | answer.Branch(ne); |
| 5017 | // It is a heap object - get the map. Check if the object is a regexp. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5018 | __ CompareObjectType(possible_regexp, scratch, scratch, JS_REGEXP_TYPE); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 5019 | answer.Bind(); |
| 5020 | cc_reg_ = eq; |
| 5021 | } |
| 5022 | |
| 5023 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5024 | void CodeGenerator::GenerateIsObject(ZoneList<Expression*>* args) { |
| 5025 | // This generates a fast version of: |
| 5026 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5027 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5028 | Load(args->at(0)); |
| 5029 | Register possible_object = frame_->PopToRegister(); |
| 5030 | __ tst(possible_object, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5031 | false_target()->Branch(eq); |
| 5032 | |
| 5033 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5034 | __ cmp(possible_object, ip); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5035 | true_target()->Branch(eq); |
| 5036 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5037 | Register map_reg = VirtualFrame::scratch0(); |
| 5038 | __ ldr(map_reg, FieldMemOperand(possible_object, HeapObject::kMapOffset)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5039 | // Undetectable objects behave like undefined when tested with typeof. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5040 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 5041 | __ tst(possible_object, Operand(1 << Map::kIsUndetectable)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5042 | false_target()->Branch(ne); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5043 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5044 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 5045 | __ cmp(possible_object, Operand(FIRST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5046 | false_target()->Branch(lt); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5047 | __ cmp(possible_object, Operand(LAST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5048 | cc_reg_ = le; |
| 5049 | } |
| 5050 | |
| 5051 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5052 | void CodeGenerator::GenerateIsSpecObject(ZoneList<Expression*>* args) { |
| 5053 | // This generates a fast version of: |
| 5054 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp' || |
| 5055 | // typeof(arg) == function). |
| 5056 | // It includes undetectable objects (as opposed to IsObject). |
| 5057 | ASSERT(args->length() == 1); |
| 5058 | Load(args->at(0)); |
| 5059 | Register value = frame_->PopToRegister(); |
| 5060 | __ tst(value, Operand(kSmiTagMask)); |
| 5061 | false_target()->Branch(eq); |
| 5062 | // Check that this is an object. |
| 5063 | __ ldr(value, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 5064 | __ ldrb(value, FieldMemOperand(value, Map::kInstanceTypeOffset)); |
| 5065 | __ cmp(value, Operand(FIRST_JS_OBJECT_TYPE)); |
| 5066 | cc_reg_ = ge; |
| 5067 | } |
| 5068 | |
| 5069 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5070 | // Deferred code to check whether the String JavaScript object is safe for using |
| 5071 | // default value of. This code is called after the bit caching this information |
| 5072 | // in the map has been checked with the map for the object in the map_result_ |
| 5073 | // register. On return the register map_result_ contains 1 for true and 0 for |
| 5074 | // false. |
| 5075 | class DeferredIsStringWrapperSafeForDefaultValueOf : public DeferredCode { |
| 5076 | public: |
| 5077 | DeferredIsStringWrapperSafeForDefaultValueOf(Register object, |
| 5078 | Register map_result, |
| 5079 | Register scratch1, |
| 5080 | Register scratch2) |
| 5081 | : object_(object), |
| 5082 | map_result_(map_result), |
| 5083 | scratch1_(scratch1), |
| 5084 | scratch2_(scratch2) { } |
| 5085 | |
| 5086 | virtual void Generate() { |
| 5087 | Label false_result; |
| 5088 | |
| 5089 | // Check that map is loaded as expected. |
| 5090 | if (FLAG_debug_code) { |
| 5091 | __ ldr(ip, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5092 | __ cmp(map_result_, ip); |
| 5093 | __ Assert(eq, "Map not in expected register"); |
| 5094 | } |
| 5095 | |
| 5096 | // Check for fast case object. Generate false result for slow case object. |
| 5097 | __ ldr(scratch1_, FieldMemOperand(object_, JSObject::kPropertiesOffset)); |
| 5098 | __ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset)); |
| 5099 | __ LoadRoot(ip, Heap::kHashTableMapRootIndex); |
| 5100 | __ cmp(scratch1_, ip); |
| 5101 | __ b(eq, &false_result); |
| 5102 | |
| 5103 | // Look for valueOf symbol in the descriptor array, and indicate false if |
| 5104 | // found. The type is not checked, so if it is a transition it is a false |
| 5105 | // negative. |
| 5106 | __ ldr(map_result_, |
| 5107 | FieldMemOperand(map_result_, Map::kInstanceDescriptorsOffset)); |
| 5108 | __ ldr(scratch2_, FieldMemOperand(map_result_, FixedArray::kLengthOffset)); |
| 5109 | // map_result_: descriptor array |
| 5110 | // scratch2_: length of descriptor array |
| 5111 | // Calculate the end of the descriptor array. |
| 5112 | STATIC_ASSERT(kSmiTag == 0); |
| 5113 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5114 | STATIC_ASSERT(kPointerSize == 4); |
| 5115 | __ add(scratch1_, |
| 5116 | map_result_, |
| 5117 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5118 | __ add(scratch1_, |
| 5119 | scratch1_, |
| 5120 | Operand(scratch2_, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5121 | |
| 5122 | // Calculate location of the first key name. |
| 5123 | __ add(map_result_, |
| 5124 | map_result_, |
| 5125 | Operand(FixedArray::kHeaderSize - kHeapObjectTag + |
| 5126 | DescriptorArray::kFirstIndex * kPointerSize)); |
| 5127 | // Loop through all the keys in the descriptor array. If one of these is the |
| 5128 | // symbol valueOf the result is false. |
| 5129 | Label entry, loop; |
| 5130 | // The use of ip to store the valueOf symbol asumes that it is not otherwise |
| 5131 | // used in the loop below. |
| 5132 | __ mov(ip, Operand(Factory::value_of_symbol())); |
| 5133 | __ jmp(&entry); |
| 5134 | __ bind(&loop); |
| 5135 | __ ldr(scratch2_, MemOperand(map_result_, 0)); |
| 5136 | __ cmp(scratch2_, ip); |
| 5137 | __ b(eq, &false_result); |
| 5138 | __ add(map_result_, map_result_, Operand(kPointerSize)); |
| 5139 | __ bind(&entry); |
| 5140 | __ cmp(map_result_, Operand(scratch1_)); |
| 5141 | __ b(ne, &loop); |
| 5142 | |
| 5143 | // Reload map as register map_result_ was used as temporary above. |
| 5144 | __ ldr(map_result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5145 | |
| 5146 | // If a valueOf property is not found on the object check that it's |
| 5147 | // prototype is the un-modified String prototype. If not result is false. |
| 5148 | __ ldr(scratch1_, FieldMemOperand(map_result_, Map::kPrototypeOffset)); |
| 5149 | __ tst(scratch1_, Operand(kSmiTagMask)); |
| 5150 | __ b(eq, &false_result); |
| 5151 | __ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset)); |
| 5152 | __ ldr(scratch2_, |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5153 | ContextOperand(cp, Context::GLOBAL_INDEX)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5154 | __ ldr(scratch2_, |
| 5155 | FieldMemOperand(scratch2_, GlobalObject::kGlobalContextOffset)); |
| 5156 | __ ldr(scratch2_, |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5157 | ContextOperand( |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5158 | scratch2_, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
| 5159 | __ cmp(scratch1_, scratch2_); |
| 5160 | __ b(ne, &false_result); |
| 5161 | |
| 5162 | // Set the bit in the map to indicate that it has been checked safe for |
| 5163 | // default valueOf and set true result. |
| 5164 | __ ldr(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset)); |
| 5165 | __ orr(scratch1_, |
| 5166 | scratch1_, |
| 5167 | Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 5168 | __ str(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset)); |
| 5169 | __ mov(map_result_, Operand(1)); |
| 5170 | __ jmp(exit_label()); |
| 5171 | __ bind(&false_result); |
| 5172 | // Set false result. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5173 | __ mov(map_result_, Operand(0, RelocInfo::NONE)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | private: |
| 5177 | Register object_; |
| 5178 | Register map_result_; |
| 5179 | Register scratch1_; |
| 5180 | Register scratch2_; |
| 5181 | }; |
| 5182 | |
| 5183 | |
| 5184 | void CodeGenerator::GenerateIsStringWrapperSafeForDefaultValueOf( |
| 5185 | ZoneList<Expression*>* args) { |
| 5186 | ASSERT(args->length() == 1); |
| 5187 | Load(args->at(0)); |
| 5188 | Register obj = frame_->PopToRegister(); // Pop the string wrapper. |
| 5189 | if (FLAG_debug_code) { |
| 5190 | __ AbortIfSmi(obj); |
| 5191 | } |
| 5192 | |
| 5193 | // Check whether this map has already been checked to be safe for default |
| 5194 | // valueOf. |
| 5195 | Register map_result = VirtualFrame::scratch0(); |
| 5196 | __ ldr(map_result, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 5197 | __ ldrb(ip, FieldMemOperand(map_result, Map::kBitField2Offset)); |
| 5198 | __ tst(ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 5199 | true_target()->Branch(ne); |
| 5200 | |
| 5201 | // We need an additional two scratch registers for the deferred code. |
| 5202 | Register scratch1 = VirtualFrame::scratch1(); |
| 5203 | // Use r6 without notifying the virtual frame. |
| 5204 | Register scratch2 = r6; |
| 5205 | |
| 5206 | DeferredIsStringWrapperSafeForDefaultValueOf* deferred = |
| 5207 | new DeferredIsStringWrapperSafeForDefaultValueOf( |
| 5208 | obj, map_result, scratch1, scratch2); |
| 5209 | deferred->Branch(eq); |
| 5210 | deferred->BindExit(); |
| 5211 | __ tst(map_result, Operand(map_result)); |
| 5212 | cc_reg_ = ne; |
| 5213 | } |
| 5214 | |
| 5215 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5216 | void CodeGenerator::GenerateIsFunction(ZoneList<Expression*>* args) { |
| 5217 | // This generates a fast version of: |
| 5218 | // (%_ClassOf(arg) === 'Function') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5219 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5220 | Load(args->at(0)); |
| 5221 | Register possible_function = frame_->PopToRegister(); |
| 5222 | __ tst(possible_function, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5223 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5224 | Register map_reg = VirtualFrame::scratch0(); |
| 5225 | Register scratch = VirtualFrame::scratch1(); |
| 5226 | __ CompareObjectType(possible_function, map_reg, scratch, JS_FUNCTION_TYPE); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5227 | cc_reg_ = eq; |
| 5228 | } |
| 5229 | |
| 5230 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5231 | void CodeGenerator::GenerateIsUndetectableObject(ZoneList<Expression*>* args) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5232 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5233 | Load(args->at(0)); |
| 5234 | Register possible_undetectable = frame_->PopToRegister(); |
| 5235 | __ tst(possible_undetectable, Operand(kSmiTagMask)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5236 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5237 | Register scratch = VirtualFrame::scratch0(); |
| 5238 | __ ldr(scratch, |
| 5239 | FieldMemOperand(possible_undetectable, HeapObject::kMapOffset)); |
| 5240 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5241 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5242 | cc_reg_ = ne; |
| 5243 | } |
| 5244 | |
| 5245 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5246 | void CodeGenerator::GenerateIsConstructCall(ZoneList<Expression*>* args) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5247 | ASSERT(args->length() == 0); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5248 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5249 | Register scratch0 = VirtualFrame::scratch0(); |
| 5250 | Register scratch1 = VirtualFrame::scratch1(); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5251 | // Get the frame pointer for the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5252 | __ ldr(scratch0, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5253 | |
| 5254 | // Skip the arguments adaptor frame if it exists. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5255 | __ ldr(scratch1, |
| 5256 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 5257 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5258 | __ ldr(scratch0, |
| 5259 | MemOperand(scratch0, StandardFrameConstants::kCallerFPOffset), eq); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5260 | |
| 5261 | // Check the marker in the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5262 | __ ldr(scratch1, |
| 5263 | MemOperand(scratch0, StandardFrameConstants::kMarkerOffset)); |
| 5264 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5265 | cc_reg_ = eq; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5269 | void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5270 | ASSERT(args->length() == 0); |
| 5271 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5272 | Register tos = frame_->GetTOSRegister(); |
| 5273 | Register scratch0 = VirtualFrame::scratch0(); |
| 5274 | Register scratch1 = VirtualFrame::scratch1(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5275 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5276 | // Check if the calling frame is an arguments adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5277 | __ ldr(scratch0, |
| 5278 | MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5279 | __ ldr(scratch1, |
| 5280 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 5281 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5282 | |
| 5283 | // Get the number of formal parameters. |
| 5284 | __ mov(tos, Operand(Smi::FromInt(scope()->num_parameters())), LeaveCC, ne); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5285 | |
| 5286 | // Arguments adaptor case: Read the arguments length from the |
| 5287 | // adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5288 | __ ldr(tos, |
| 5289 | MemOperand(scratch0, ArgumentsAdaptorFrameConstants::kLengthOffset), |
| 5290 | eq); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5291 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5292 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5296 | void CodeGenerator::GenerateArguments(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5297 | ASSERT(args->length() == 1); |
| 5298 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5299 | // Satisfy contract with ArgumentsAccessStub: |
| 5300 | // Load the key into r1 and the formal parameters count into r0. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5301 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5302 | frame_->PopToR1(); |
| 5303 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5304 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5305 | |
| 5306 | // Call the shared stub to get to arguments[key]. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5307 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5308 | frame_->CallStub(&stub, 0); |
| 5309 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5313 | void CodeGenerator::GenerateRandomHeapNumber( |
| 5314 | ZoneList<Expression*>* args) { |
| 5315 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 5316 | ASSERT(args->length() == 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5317 | |
| 5318 | Label slow_allocate_heapnumber; |
| 5319 | Label heapnumber_allocated; |
| 5320 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5321 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 5322 | __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5323 | __ jmp(&heapnumber_allocated); |
| 5324 | |
| 5325 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5326 | // Allocate a heap number. |
| 5327 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5328 | __ mov(r4, Operand(r0)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5329 | |
| 5330 | __ bind(&heapnumber_allocated); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5331 | |
| 5332 | // Convert 32 random bits in r0 to 0.(32 random bits) in a double |
| 5333 | // by computing: |
| 5334 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 5335 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5336 | __ PrepareCallCFunction(0, r1); |
| 5337 | __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
| 5338 | |
| 5339 | CpuFeatures::Scope scope(VFP3); |
| 5340 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 5341 | // Create this constant using mov/orr to avoid PC relative load. |
| 5342 | __ mov(r1, Operand(0x41000000)); |
| 5343 | __ orr(r1, r1, Operand(0x300000)); |
| 5344 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 5345 | __ vmov(d7, r0, r1); |
| 5346 | // Move 0x4130000000000000 to VFP. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5347 | __ mov(r0, Operand(0, RelocInfo::NONE)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5348 | __ vmov(d8, r0, r1); |
| 5349 | // Subtract and store the result in the heap number. |
| 5350 | __ vsub(d7, d7, d8); |
| 5351 | __ sub(r0, r4, Operand(kHeapObjectTag)); |
| 5352 | __ vstr(d7, r0, HeapNumber::kValueOffset); |
| 5353 | frame_->EmitPush(r4); |
| 5354 | } else { |
| 5355 | __ mov(r0, Operand(r4)); |
| 5356 | __ PrepareCallCFunction(1, r1); |
| 5357 | __ CallCFunction( |
| 5358 | ExternalReference::fill_heap_number_with_random_function(), 1); |
| 5359 | frame_->EmitPush(r0); |
| 5360 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5364 | void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) { |
| 5365 | ASSERT_EQ(2, args->length()); |
| 5366 | |
| 5367 | Load(args->at(0)); |
| 5368 | Load(args->at(1)); |
| 5369 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5370 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5371 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5372 | frame_->CallStub(&stub, 2); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5373 | frame_->EmitPush(r0); |
| 5374 | } |
| 5375 | |
| 5376 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5377 | void CodeGenerator::GenerateSubString(ZoneList<Expression*>* args) { |
| 5378 | ASSERT_EQ(3, args->length()); |
| 5379 | |
| 5380 | Load(args->at(0)); |
| 5381 | Load(args->at(1)); |
| 5382 | Load(args->at(2)); |
| 5383 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5384 | SubStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5385 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5386 | frame_->CallStub(&stub, 3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5387 | frame_->EmitPush(r0); |
| 5388 | } |
| 5389 | |
| 5390 | |
| 5391 | void CodeGenerator::GenerateStringCompare(ZoneList<Expression*>* args) { |
| 5392 | ASSERT_EQ(2, args->length()); |
| 5393 | |
| 5394 | Load(args->at(0)); |
| 5395 | Load(args->at(1)); |
| 5396 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5397 | StringCompareStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5398 | frame_->SpillAll(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5399 | frame_->CallStub(&stub, 2); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5400 | frame_->EmitPush(r0); |
| 5401 | } |
| 5402 | |
| 5403 | |
| 5404 | void CodeGenerator::GenerateRegExpExec(ZoneList<Expression*>* args) { |
| 5405 | ASSERT_EQ(4, args->length()); |
| 5406 | |
| 5407 | Load(args->at(0)); |
| 5408 | Load(args->at(1)); |
| 5409 | Load(args->at(2)); |
| 5410 | Load(args->at(3)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5411 | RegExpExecStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5412 | frame_->SpillAll(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5413 | frame_->CallStub(&stub, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5414 | frame_->EmitPush(r0); |
| 5415 | } |
| 5416 | |
| 5417 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5418 | void CodeGenerator::GenerateRegExpConstructResult(ZoneList<Expression*>* args) { |
| 5419 | // No stub. This code only occurs a few times in regexp.js. |
| 5420 | const int kMaxInlineLength = 100; |
| 5421 | ASSERT_EQ(3, args->length()); |
| 5422 | Load(args->at(0)); // Size of array, smi. |
| 5423 | Load(args->at(1)); // "index" property value. |
| 5424 | Load(args->at(2)); // "input" property value. |
| 5425 | { |
| 5426 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5427 | Label slowcase; |
| 5428 | Label done; |
| 5429 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 5430 | STATIC_ASSERT(kSmiTag == 0); |
| 5431 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5432 | __ tst(r1, Operand(kSmiTagMask)); |
| 5433 | __ b(ne, &slowcase); |
| 5434 | __ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 5435 | __ b(hi, &slowcase); |
| 5436 | // Smi-tagging is equivalent to multiplying by 2. |
| 5437 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 5438 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 5439 | // Elements: [Map][Length][..elements..] |
| 5440 | // Size of JSArray with two in-object properties and the header of a |
| 5441 | // FixedArray. |
| 5442 | int objects_size = |
| 5443 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 5444 | __ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize)); |
| 5445 | __ add(r2, r5, Operand(objects_size)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 5446 | __ AllocateInNewSpace( |
| 5447 | r2, // In: Size, in words. |
| 5448 | r0, // Out: Start of allocation (tagged). |
| 5449 | r3, // Scratch register. |
| 5450 | r4, // Scratch register. |
| 5451 | &slowcase, |
| 5452 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5453 | // r0: Start of allocated area, object-tagged. |
| 5454 | // r1: Number of elements in array, as smi. |
| 5455 | // r5: Number of elements, untagged. |
| 5456 | |
| 5457 | // Set JSArray map to global.regexp_result_map(). |
| 5458 | // Set empty properties FixedArray. |
| 5459 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 5460 | // Interleave operations for better latency. |
| 5461 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5462 | __ add(r3, r0, Operand(JSRegExpResult::kSize)); |
| 5463 | __ mov(r4, Operand(Factory::empty_fixed_array())); |
| 5464 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
| 5465 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 5466 | __ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5467 | __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5468 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5469 | |
| 5470 | // Set input, index and length fields from arguments. |
| 5471 | __ ldm(ia_w, sp, static_cast<RegList>(r2.bit() | r4.bit())); |
| 5472 | __ str(r1, FieldMemOperand(r0, JSArray::kLengthOffset)); |
| 5473 | __ add(sp, sp, Operand(kPointerSize)); |
| 5474 | __ str(r4, FieldMemOperand(r0, JSRegExpResult::kIndexOffset)); |
| 5475 | __ str(r2, FieldMemOperand(r0, JSRegExpResult::kInputOffset)); |
| 5476 | |
| 5477 | // Fill out the elements FixedArray. |
| 5478 | // r0: JSArray, tagged. |
| 5479 | // r3: FixedArray, tagged. |
| 5480 | // r5: Number of elements in array, untagged. |
| 5481 | |
| 5482 | // Set map. |
| 5483 | __ mov(r2, Operand(Factory::fixed_array_map())); |
| 5484 | __ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5485 | // Set FixedArray length. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5486 | __ mov(r6, Operand(r5, LSL, kSmiTagSize)); |
| 5487 | __ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5488 | // Fill contents of fixed-array with the-hole. |
| 5489 | __ mov(r2, Operand(Factory::the_hole_value())); |
| 5490 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5491 | // Fill fixed array elements with hole. |
| 5492 | // r0: JSArray, tagged. |
| 5493 | // r2: the hole. |
| 5494 | // r3: Start of elements in FixedArray. |
| 5495 | // r5: Number of elements to fill. |
| 5496 | Label loop; |
| 5497 | __ tst(r5, Operand(r5)); |
| 5498 | __ bind(&loop); |
| 5499 | __ b(le, &done); // Jump if r1 is negative or zero. |
| 5500 | __ sub(r5, r5, Operand(1), SetCC); |
| 5501 | __ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2)); |
| 5502 | __ jmp(&loop); |
| 5503 | |
| 5504 | __ bind(&slowcase); |
| 5505 | __ CallRuntime(Runtime::kRegExpConstructResult, 3); |
| 5506 | |
| 5507 | __ bind(&done); |
| 5508 | } |
| 5509 | frame_->Forget(3); |
| 5510 | frame_->EmitPush(r0); |
| 5511 | } |
| 5512 | |
| 5513 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5514 | class DeferredSearchCache: public DeferredCode { |
| 5515 | public: |
| 5516 | DeferredSearchCache(Register dst, Register cache, Register key) |
| 5517 | : dst_(dst), cache_(cache), key_(key) { |
| 5518 | set_comment("[ DeferredSearchCache"); |
| 5519 | } |
| 5520 | |
| 5521 | virtual void Generate(); |
| 5522 | |
| 5523 | private: |
| 5524 | Register dst_, cache_, key_; |
| 5525 | }; |
| 5526 | |
| 5527 | |
| 5528 | void DeferredSearchCache::Generate() { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 5529 | __ Push(cache_, key_); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5530 | __ CallRuntime(Runtime::kGetFromCache, 2); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5531 | __ Move(dst_, r0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | |
| 5535 | void CodeGenerator::GenerateGetFromCache(ZoneList<Expression*>* args) { |
| 5536 | ASSERT_EQ(2, args->length()); |
| 5537 | |
| 5538 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 5539 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 5540 | |
| 5541 | Handle<FixedArray> jsfunction_result_caches( |
| 5542 | Top::global_context()->jsfunction_result_caches()); |
| 5543 | if (jsfunction_result_caches->length() <= cache_id) { |
| 5544 | __ Abort("Attempt to use undefined cache."); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5545 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5546 | return; |
| 5547 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5548 | |
| 5549 | Load(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5550 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5551 | frame_->PopToR1(); |
| 5552 | frame_->SpillAll(); |
| 5553 | Register key = r1; // Just poped to r1 |
| 5554 | Register result = r0; // Free, as frame has just been spilled. |
| 5555 | Register scratch1 = VirtualFrame::scratch0(); |
| 5556 | Register scratch2 = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5557 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5558 | __ ldr(scratch1, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5559 | __ ldr(scratch1, |
| 5560 | FieldMemOperand(scratch1, GlobalObject::kGlobalContextOffset)); |
| 5561 | __ ldr(scratch1, |
| 5562 | ContextOperand(scratch1, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
| 5563 | __ ldr(scratch1, |
| 5564 | FieldMemOperand(scratch1, FixedArray::OffsetOfElementAt(cache_id))); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5565 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5566 | DeferredSearchCache* deferred = |
| 5567 | new DeferredSearchCache(result, scratch1, key); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5568 | |
| 5569 | const int kFingerOffset = |
| 5570 | FixedArray::OffsetOfElementAt(JSFunctionResultCache::kFingerIndex); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 5571 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5572 | __ ldr(result, FieldMemOperand(scratch1, kFingerOffset)); |
| 5573 | // result now holds finger offset as a smi. |
| 5574 | __ add(scratch2, scratch1, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5575 | // scratch2 now points to the start of fixed array elements. |
| 5576 | __ ldr(result, |
| 5577 | MemOperand( |
| 5578 | scratch2, result, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex)); |
| 5579 | // Note side effect of PreIndex: scratch2 now points to the key of the pair. |
| 5580 | __ cmp(key, result); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5581 | deferred->Branch(ne); |
| 5582 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5583 | __ ldr(result, MemOperand(scratch2, kPointerSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5584 | |
| 5585 | deferred->BindExit(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5586 | frame_->EmitPush(result); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5590 | void CodeGenerator::GenerateNumberToString(ZoneList<Expression*>* args) { |
| 5591 | ASSERT_EQ(args->length(), 1); |
| 5592 | |
| 5593 | // Load the argument on the stack and jump to the runtime. |
| 5594 | Load(args->at(0)); |
| 5595 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5596 | NumberToStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5597 | frame_->SpillAll(); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5598 | frame_->CallStub(&stub, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5599 | frame_->EmitPush(r0); |
| 5600 | } |
| 5601 | |
| 5602 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5603 | class DeferredSwapElements: public DeferredCode { |
| 5604 | public: |
| 5605 | DeferredSwapElements(Register object, Register index1, Register index2) |
| 5606 | : object_(object), index1_(index1), index2_(index2) { |
| 5607 | set_comment("[ DeferredSwapElements"); |
| 5608 | } |
| 5609 | |
| 5610 | virtual void Generate(); |
| 5611 | |
| 5612 | private: |
| 5613 | Register object_, index1_, index2_; |
| 5614 | }; |
| 5615 | |
| 5616 | |
| 5617 | void DeferredSwapElements::Generate() { |
| 5618 | __ push(object_); |
| 5619 | __ push(index1_); |
| 5620 | __ push(index2_); |
| 5621 | __ CallRuntime(Runtime::kSwapElements, 3); |
| 5622 | } |
| 5623 | |
| 5624 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5625 | void CodeGenerator::GenerateSwapElements(ZoneList<Expression*>* args) { |
| 5626 | Comment cmnt(masm_, "[ GenerateSwapElements"); |
| 5627 | |
| 5628 | ASSERT_EQ(3, args->length()); |
| 5629 | |
| 5630 | Load(args->at(0)); |
| 5631 | Load(args->at(1)); |
| 5632 | Load(args->at(2)); |
| 5633 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5634 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5635 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5636 | Register index2 = r2; |
| 5637 | Register index1 = r1; |
| 5638 | Register object = r0; |
| 5639 | Register tmp1 = r3; |
| 5640 | Register tmp2 = r4; |
| 5641 | |
| 5642 | frame_->EmitPop(index2); |
| 5643 | frame_->EmitPop(index1); |
| 5644 | frame_->EmitPop(object); |
| 5645 | |
| 5646 | DeferredSwapElements* deferred = |
| 5647 | new DeferredSwapElements(object, index1, index2); |
| 5648 | |
| 5649 | // Fetch the map and check if array is in fast case. |
| 5650 | // Check that object doesn't require security checks and |
| 5651 | // has no indexed interceptor. |
| 5652 | __ CompareObjectType(object, tmp1, tmp2, FIRST_JS_OBJECT_TYPE); |
| 5653 | deferred->Branch(lt); |
| 5654 | __ ldrb(tmp2, FieldMemOperand(tmp1, Map::kBitFieldOffset)); |
| 5655 | __ tst(tmp2, Operand(KeyedLoadIC::kSlowCaseBitFieldMask)); |
| 5656 | deferred->Branch(nz); |
| 5657 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5658 | // Check the object's elements are in fast case and writable. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5659 | __ ldr(tmp1, FieldMemOperand(object, JSObject::kElementsOffset)); |
| 5660 | __ ldr(tmp2, FieldMemOperand(tmp1, HeapObject::kMapOffset)); |
| 5661 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 5662 | __ cmp(tmp2, ip); |
| 5663 | deferred->Branch(ne); |
| 5664 | |
| 5665 | // Smi-tagging is equivalent to multiplying by 2. |
| 5666 | STATIC_ASSERT(kSmiTag == 0); |
| 5667 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5668 | |
| 5669 | // Check that both indices are smis. |
| 5670 | __ mov(tmp2, index1); |
| 5671 | __ orr(tmp2, tmp2, index2); |
| 5672 | __ tst(tmp2, Operand(kSmiTagMask)); |
| 5673 | deferred->Branch(nz); |
| 5674 | |
| 5675 | // Bring the offsets into the fixed array in tmp1 into index1 and |
| 5676 | // index2. |
| 5677 | __ mov(tmp2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5678 | __ add(index1, tmp2, Operand(index1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5679 | __ add(index2, tmp2, Operand(index2, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5680 | |
| 5681 | // Swap elements. |
| 5682 | Register tmp3 = object; |
| 5683 | object = no_reg; |
| 5684 | __ ldr(tmp3, MemOperand(tmp1, index1)); |
| 5685 | __ ldr(tmp2, MemOperand(tmp1, index2)); |
| 5686 | __ str(tmp3, MemOperand(tmp1, index2)); |
| 5687 | __ str(tmp2, MemOperand(tmp1, index1)); |
| 5688 | |
| 5689 | Label done; |
| 5690 | __ InNewSpace(tmp1, tmp2, eq, &done); |
| 5691 | // Possible optimization: do a check that both values are Smis |
| 5692 | // (or them and test against Smi mask.) |
| 5693 | |
| 5694 | __ mov(tmp2, tmp1); |
| 5695 | RecordWriteStub recordWrite1(tmp1, index1, tmp3); |
| 5696 | __ CallStub(&recordWrite1); |
| 5697 | |
| 5698 | RecordWriteStub recordWrite2(tmp2, index2, tmp3); |
| 5699 | __ CallStub(&recordWrite2); |
| 5700 | |
| 5701 | __ bind(&done); |
| 5702 | |
| 5703 | deferred->BindExit(); |
| 5704 | __ LoadRoot(tmp1, Heap::kUndefinedValueRootIndex); |
| 5705 | frame_->EmitPush(tmp1); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5709 | void CodeGenerator::GenerateCallFunction(ZoneList<Expression*>* args) { |
| 5710 | Comment cmnt(masm_, "[ GenerateCallFunction"); |
| 5711 | |
| 5712 | ASSERT(args->length() >= 2); |
| 5713 | |
| 5714 | int n_args = args->length() - 2; // for receiver and function. |
| 5715 | Load(args->at(0)); // receiver |
| 5716 | for (int i = 0; i < n_args; i++) { |
| 5717 | Load(args->at(i + 1)); |
| 5718 | } |
| 5719 | Load(args->at(n_args + 1)); // function |
| 5720 | frame_->CallJSFunction(n_args); |
| 5721 | frame_->EmitPush(r0); |
| 5722 | } |
| 5723 | |
| 5724 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5725 | void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) { |
| 5726 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5727 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5728 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5729 | TranscendentalCacheStub stub(TranscendentalCache::SIN); |
| 5730 | frame_->SpillAllButCopyTOSToR0(); |
| 5731 | frame_->CallStub(&stub, 1); |
| 5732 | } else { |
| 5733 | frame_->CallRuntime(Runtime::kMath_sin, 1); |
| 5734 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5735 | frame_->EmitPush(r0); |
| 5736 | } |
| 5737 | |
| 5738 | |
| 5739 | void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) { |
| 5740 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5741 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5742 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5743 | TranscendentalCacheStub stub(TranscendentalCache::COS); |
| 5744 | frame_->SpillAllButCopyTOSToR0(); |
| 5745 | frame_->CallStub(&stub, 1); |
| 5746 | } else { |
| 5747 | frame_->CallRuntime(Runtime::kMath_cos, 1); |
| 5748 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5749 | frame_->EmitPush(r0); |
| 5750 | } |
| 5751 | |
| 5752 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5753 | void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5754 | ASSERT(args->length() == 2); |
| 5755 | |
| 5756 | // Load the two objects into registers and perform the comparison. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5757 | Load(args->at(0)); |
| 5758 | Load(args->at(1)); |
| 5759 | Register lhs = frame_->PopToRegister(); |
| 5760 | Register rhs = frame_->PopToRegister(lhs); |
| 5761 | __ cmp(lhs, rhs); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5762 | cc_reg_ = eq; |
| 5763 | } |
| 5764 | |
| 5765 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 5766 | void CodeGenerator::GenerateIsRegExpEquivalent(ZoneList<Expression*>* args) { |
| 5767 | ASSERT(args->length() == 2); |
| 5768 | |
| 5769 | // Load the two objects into registers and perform the comparison. |
| 5770 | Load(args->at(0)); |
| 5771 | Load(args->at(1)); |
| 5772 | Register right = frame_->PopToRegister(); |
| 5773 | Register left = frame_->PopToRegister(right); |
| 5774 | Register tmp = frame_->scratch0(); |
| 5775 | Register tmp2 = frame_->scratch1(); |
| 5776 | |
| 5777 | // Jumps to done must have the eq flag set if the test is successful |
| 5778 | // and clear if the test has failed. |
| 5779 | Label done; |
| 5780 | |
| 5781 | // Fail if either is a non-HeapObject. |
| 5782 | __ cmp(left, Operand(right)); |
| 5783 | __ b(eq, &done); |
| 5784 | __ and_(tmp, left, Operand(right)); |
| 5785 | __ eor(tmp, tmp, Operand(kSmiTagMask)); |
| 5786 | __ tst(tmp, Operand(kSmiTagMask)); |
| 5787 | __ b(ne, &done); |
| 5788 | __ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 5789 | __ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset)); |
| 5790 | __ cmp(tmp2, Operand(JS_REGEXP_TYPE)); |
| 5791 | __ b(ne, &done); |
| 5792 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 5793 | __ cmp(tmp, Operand(tmp2)); |
| 5794 | __ b(ne, &done); |
| 5795 | __ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset)); |
| 5796 | __ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset)); |
| 5797 | __ cmp(tmp, tmp2); |
| 5798 | __ bind(&done); |
| 5799 | cc_reg_ = eq; |
| 5800 | } |
| 5801 | |
| 5802 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 5803 | void CodeGenerator::GenerateHasCachedArrayIndex(ZoneList<Expression*>* args) { |
| 5804 | ASSERT(args->length() == 1); |
| 5805 | Load(args->at(0)); |
| 5806 | Register value = frame_->PopToRegister(); |
| 5807 | Register tmp = frame_->scratch0(); |
| 5808 | __ ldr(tmp, FieldMemOperand(value, String::kHashFieldOffset)); |
| 5809 | __ tst(tmp, Operand(String::kContainsCachedArrayIndexMask)); |
| 5810 | cc_reg_ = eq; |
| 5811 | } |
| 5812 | |
| 5813 | |
| 5814 | void CodeGenerator::GenerateGetCachedArrayIndex(ZoneList<Expression*>* args) { |
| 5815 | ASSERT(args->length() == 1); |
| 5816 | Load(args->at(0)); |
| 5817 | Register value = frame_->PopToRegister(); |
| 5818 | |
| 5819 | __ ldr(value, FieldMemOperand(value, String::kHashFieldOffset)); |
| 5820 | __ IndexFromHash(value, value); |
| 5821 | frame_->EmitPush(value); |
| 5822 | } |
| 5823 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 5824 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame^] | 5825 | void CodeGenerator::GenerateFastAsciiArrayJoin(ZoneList<Expression*>* args) { |
| 5826 | ASSERT(args->length() == 2); |
| 5827 | Load(args->at(0)); |
| 5828 | Register value = frame_->PopToRegister(); |
| 5829 | __ LoadRoot(value, Heap::kUndefinedValueRootIndex); |
| 5830 | frame_->EmitPush(value); |
| 5831 | } |
| 5832 | |
| 5833 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5834 | void CodeGenerator::VisitCallRuntime(CallRuntime* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5835 | #ifdef DEBUG |
| 5836 | int original_height = frame_->height(); |
| 5837 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5838 | if (CheckForInlineRuntimeCall(node)) { |
| 5839 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 5840 | (!has_cc() && frame_->height() == original_height + 1)); |
| 5841 | return; |
| 5842 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5843 | |
| 5844 | ZoneList<Expression*>* args = node->arguments(); |
| 5845 | Comment cmnt(masm_, "[ CallRuntime"); |
| 5846 | Runtime::Function* function = node->function(); |
| 5847 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5848 | if (function == NULL) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5849 | // Prepare stack for calling JS runtime function. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5850 | // Push the builtins object found in the current global object. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5851 | Register scratch = VirtualFrame::scratch0(); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5852 | __ ldr(scratch, GlobalObjectOperand()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5853 | Register builtins = frame_->GetTOSRegister(); |
| 5854 | __ ldr(builtins, FieldMemOperand(scratch, GlobalObject::kBuiltinsOffset)); |
| 5855 | frame_->EmitPush(builtins); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5856 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5857 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5858 | // Push the arguments ("left-to-right"). |
| 5859 | int arg_count = args->length(); |
| 5860 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5861 | Load(args->at(i)); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5862 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5863 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5864 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5865 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5866 | if (function == NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5867 | // Call the JS runtime function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5868 | __ mov(r2, Operand(node->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5869 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 5870 | Handle<Code> stub = StubCache::ComputeCallInitialize(arg_count, in_loop); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5871 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5872 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5873 | frame_->EmitPush(r0); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5874 | } else { |
| 5875 | // Call the C runtime function. |
| 5876 | frame_->CallRuntime(function, arg_count); |
| 5877 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5878 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5879 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5880 | } |
| 5881 | |
| 5882 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5883 | void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5884 | #ifdef DEBUG |
| 5885 | int original_height = frame_->height(); |
| 5886 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5887 | Comment cmnt(masm_, "[ UnaryOperation"); |
| 5888 | |
| 5889 | Token::Value op = node->op(); |
| 5890 | |
| 5891 | if (op == Token::NOT) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5892 | LoadCondition(node->expression(), false_target(), true_target(), true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5893 | // LoadCondition may (and usually does) leave a test and branch to |
| 5894 | // be emitted by the caller. In that case, negate the condition. |
| 5895 | if (has_cc()) cc_reg_ = NegateCondition(cc_reg_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5896 | |
| 5897 | } else if (op == Token::DELETE) { |
| 5898 | Property* property = node->expression()->AsProperty(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5899 | Variable* variable = node->expression()->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5900 | if (property != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5901 | Load(property->obj()); |
| 5902 | Load(property->key()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5903 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5904 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5905 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5906 | } else if (variable != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5907 | Slot* slot = variable->AsSlot(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5908 | if (variable->is_global()) { |
| 5909 | LoadGlobal(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5910 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5911 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5912 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5913 | |
| 5914 | } else if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 5915 | // lookup the context holding the named variable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5916 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5917 | frame_->EmitPush(Operand(variable->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5918 | frame_->CallRuntime(Runtime::kLookupContext, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5919 | // r0: context |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5920 | frame_->EmitPush(r0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5921 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5922 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5923 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5924 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5925 | } else { |
| 5926 | // Default: Result of deleting non-global, not dynamically |
| 5927 | // introduced variables is false. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5928 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5929 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5930 | |
| 5931 | } else { |
| 5932 | // Default: Result of deleting expressions is true. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5933 | Load(node->expression()); // may have side-effects |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5934 | frame_->Drop(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5935 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5936 | } |
| 5937 | |
| 5938 | } else if (op == Token::TYPEOF) { |
| 5939 | // Special case for loading the typeof expression; see comment on |
| 5940 | // LoadTypeofExpression(). |
| 5941 | LoadTypeofExpression(node->expression()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5942 | frame_->CallRuntime(Runtime::kTypeof, 1); |
| 5943 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5944 | |
| 5945 | } else { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5946 | bool can_overwrite = node->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5947 | UnaryOverwriteMode overwrite = |
| 5948 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
| 5949 | |
| 5950 | bool no_negative_zero = node->expression()->no_negative_zero(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5951 | Load(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5952 | switch (op) { |
| 5953 | case Token::NOT: |
| 5954 | case Token::DELETE: |
| 5955 | case Token::TYPEOF: |
| 5956 | UNREACHABLE(); // handled above |
| 5957 | break; |
| 5958 | |
| 5959 | case Token::SUB: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5960 | frame_->PopToR0(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5961 | GenericUnaryOpStub stub( |
| 5962 | Token::SUB, |
| 5963 | overwrite, |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5964 | NO_UNARY_FLAGS, |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5965 | no_negative_zero ? kIgnoreNegativeZero : kStrictNegativeZero); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5966 | frame_->CallStub(&stub, 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5967 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5968 | break; |
| 5969 | } |
| 5970 | |
| 5971 | case Token::BIT_NOT: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5972 | Register tos = frame_->PopToRegister(); |
| 5973 | JumpTarget not_smi_label; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5974 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5975 | // Smi check. |
| 5976 | __ tst(tos, Operand(kSmiTagMask)); |
| 5977 | not_smi_label.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5978 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5979 | __ mvn(tos, Operand(tos)); |
| 5980 | __ bic(tos, tos, Operand(kSmiTagMask)); // Bit-clear inverted smi-tag. |
| 5981 | frame_->EmitPush(tos); |
| 5982 | // The fast case is the first to jump to the continue label, so it gets |
| 5983 | // to decide the virtual frame layout. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5984 | continue_label.Jump(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5985 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5986 | not_smi_label.Bind(); |
| 5987 | frame_->SpillAll(); |
| 5988 | __ Move(r0, tos); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5989 | GenericUnaryOpStub stub(Token::BIT_NOT, |
| 5990 | overwrite, |
| 5991 | NO_UNARY_SMI_CODE_IN_STUB); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5992 | frame_->CallStub(&stub, 0); |
| 5993 | frame_->EmitPush(r0); |
| 5994 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5995 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5996 | break; |
| 5997 | } |
| 5998 | |
| 5999 | case Token::VOID: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6000 | frame_->Drop(); |
| 6001 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6002 | break; |
| 6003 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 6004 | case Token::ADD: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6005 | Register tos = frame_->Peek(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 6006 | // Smi check. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6007 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6008 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6009 | continue_label.Branch(eq); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6010 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6011 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6012 | frame_->EmitPush(r0); |
| 6013 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6014 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6015 | break; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 6016 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6017 | default: |
| 6018 | UNREACHABLE(); |
| 6019 | } |
| 6020 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6021 | ASSERT(!has_valid_frame() || |
| 6022 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6023 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6024 | } |
| 6025 | |
| 6026 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6027 | void CodeGenerator::VisitCountOperation(CountOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6028 | #ifdef DEBUG |
| 6029 | int original_height = frame_->height(); |
| 6030 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6031 | Comment cmnt(masm_, "[ CountOperation"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6032 | VirtualFrame::RegisterAllocationScope scope(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6033 | |
| 6034 | bool is_postfix = node->is_postfix(); |
| 6035 | bool is_increment = node->op() == Token::INC; |
| 6036 | |
| 6037 | Variable* var = node->expression()->AsVariableProxy()->AsVariable(); |
| 6038 | bool is_const = (var != NULL && var->mode() == Variable::CONST); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6039 | bool is_slot = (var != NULL && var->mode() == Variable::VAR); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6040 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 6041 | if (!is_const && is_slot && type_info(var->AsSlot()).IsSmi()) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6042 | // The type info declares that this variable is always a Smi. That |
| 6043 | // means it is a Smi both before and after the increment/decrement. |
| 6044 | // Lets make use of that to make a very minimal count. |
| 6045 | Reference target(this, node->expression(), !is_const); |
| 6046 | ASSERT(!target.is_illegal()); |
| 6047 | target.GetValue(); // Pushes the value. |
| 6048 | Register value = frame_->PopToRegister(); |
| 6049 | if (is_postfix) frame_->EmitPush(value); |
| 6050 | if (is_increment) { |
| 6051 | __ add(value, value, Operand(Smi::FromInt(1))); |
| 6052 | } else { |
| 6053 | __ sub(value, value, Operand(Smi::FromInt(1))); |
| 6054 | } |
| 6055 | frame_->EmitPush(value); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6056 | target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6057 | if (is_postfix) frame_->Pop(); |
| 6058 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 6059 | return; |
| 6060 | } |
| 6061 | |
| 6062 | // If it's a postfix expression and its result is not ignored and the |
| 6063 | // reference is non-trivial, then push a placeholder on the stack now |
| 6064 | // to hold the result of the expression. |
| 6065 | bool placeholder_pushed = false; |
| 6066 | if (!is_slot && is_postfix) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6067 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6068 | placeholder_pushed = true; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6069 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6070 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6071 | // A constant reference is not saved to, so a constant reference is not a |
| 6072 | // compound assignment reference. |
| 6073 | { Reference target(this, node->expression(), !is_const); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6074 | if (target.is_illegal()) { |
| 6075 | // Spoof the virtual frame to have the expected height (one higher |
| 6076 | // than on entry). |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6077 | if (!placeholder_pushed) frame_->EmitPush(Operand(Smi::FromInt(0))); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6078 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6079 | return; |
| 6080 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6081 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6082 | // This pushes 0, 1 or 2 words on the object to be used later when updating |
| 6083 | // the target. It also pushes the current value of the target. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6084 | target.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6085 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6086 | JumpTarget slow; |
| 6087 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6088 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6089 | Register value = frame_->PopToRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6090 | |
| 6091 | // Postfix: Store the old value as the result. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6092 | if (placeholder_pushed) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6093 | frame_->SetElementAt(value, target.size()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6094 | } else if (is_postfix) { |
| 6095 | frame_->EmitPush(value); |
| 6096 | __ mov(VirtualFrame::scratch0(), value); |
| 6097 | value = VirtualFrame::scratch0(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6098 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6099 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6100 | // Check for smi operand. |
| 6101 | __ tst(value, Operand(kSmiTagMask)); |
| 6102 | slow.Branch(ne); |
| 6103 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6104 | // Perform optimistic increment/decrement. |
| 6105 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6106 | __ add(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6107 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6108 | __ sub(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | // If the increment/decrement didn't overflow, we're done. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6112 | exit.Branch(vc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6113 | |
| 6114 | // Revert optimistic increment/decrement. |
| 6115 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6116 | __ sub(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6117 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6118 | __ add(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6119 | } |
| 6120 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6121 | // Slow case: Convert to number. At this point the |
| 6122 | // value to be incremented is in the value register.. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6123 | slow.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6124 | |
| 6125 | // Convert the operand to a number. |
| 6126 | frame_->EmitPush(value); |
| 6127 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 6128 | { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6129 | VirtualFrame::SpilledScope spilled(frame_); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6130 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6131 | |
| 6132 | if (is_postfix) { |
| 6133 | // Postfix: store to result (on the stack). |
| 6134 | __ str(r0, frame_->ElementAt(target.size())); |
| 6135 | } |
| 6136 | |
| 6137 | // Compute the new value. |
| 6138 | frame_->EmitPush(r0); |
| 6139 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
| 6140 | if (is_increment) { |
| 6141 | frame_->CallRuntime(Runtime::kNumberAdd, 2); |
| 6142 | } else { |
| 6143 | frame_->CallRuntime(Runtime::kNumberSub, 2); |
| 6144 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6145 | } |
| 6146 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6147 | __ Move(value, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6148 | // Store the new value in the target if not const. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6149 | // At this point the answer is in the value register. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6150 | exit.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6151 | frame_->EmitPush(value); |
| 6152 | // Set the target with the result, leaving the result on |
| 6153 | // top of the stack. Removes the target from the stack if |
| 6154 | // it has a non-zero size. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6155 | if (!is_const) target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | // Postfix: Discard the new value and use the old. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6159 | if (is_postfix) frame_->Pop(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6160 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6164 | void CodeGenerator::GenerateLogicalBooleanOperation(BinaryOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6165 | // According to ECMA-262 section 11.11, page 58, the binary logical |
| 6166 | // operators must yield the result of one of the two expressions |
| 6167 | // before any ToBoolean() conversions. This means that the value |
| 6168 | // produced by a && or || operator is not necessarily a boolean. |
| 6169 | |
| 6170 | // NOTE: If the left hand side produces a materialized value (not in |
| 6171 | // the CC register), we force the right hand side to do the |
| 6172 | // same. This is necessary because we may have to branch to the exit |
| 6173 | // after evaluating the left hand side (due to the shortcut |
| 6174 | // semantics), but the compiler must (statically) know if the result |
| 6175 | // of compiling the binary operation is materialized or not. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6176 | if (node->op() == Token::AND) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6177 | JumpTarget is_true; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6178 | LoadCondition(node->left(), &is_true, false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6179 | if (has_valid_frame() && !has_cc()) { |
| 6180 | // The left-hand side result is on top of the virtual frame. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6181 | JumpTarget pop_and_continue; |
| 6182 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6183 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6184 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6185 | // Avoid popping the result if it converts to 'false' using the |
| 6186 | // standard ToBoolean() conversion as described in ECMA-262, |
| 6187 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6188 | ToBoolean(&pop_and_continue, &exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6189 | Branch(false, &exit); |
| 6190 | |
| 6191 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6192 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6193 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6194 | |
| 6195 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6196 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6197 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6198 | |
| 6199 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6200 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6201 | } else if (has_cc() || is_true.is_linked()) { |
| 6202 | // The left-hand side is either (a) partially compiled to |
| 6203 | // control flow with a final branch left to emit or (b) fully |
| 6204 | // compiled to control flow and possibly true. |
| 6205 | if (has_cc()) { |
| 6206 | Branch(false, false_target()); |
| 6207 | } |
| 6208 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6209 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6210 | } else { |
| 6211 | // Nothing to do. |
| 6212 | ASSERT(!has_valid_frame() && !has_cc() && !is_true.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6213 | } |
| 6214 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6215 | } else { |
| 6216 | ASSERT(node->op() == Token::OR); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6217 | JumpTarget is_false; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6218 | LoadCondition(node->left(), true_target(), &is_false, false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6219 | if (has_valid_frame() && !has_cc()) { |
| 6220 | // The left-hand side result is on top of the virtual frame. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6221 | JumpTarget pop_and_continue; |
| 6222 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6223 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6224 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6225 | // Avoid popping the result if it converts to 'true' using the |
| 6226 | // standard ToBoolean() conversion as described in ECMA-262, |
| 6227 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6228 | ToBoolean(&exit, &pop_and_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6229 | Branch(true, &exit); |
| 6230 | |
| 6231 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6232 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6233 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6234 | |
| 6235 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6236 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6237 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6238 | |
| 6239 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6240 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6241 | } else if (has_cc() || is_false.is_linked()) { |
| 6242 | // The left-hand side is either (a) partially compiled to |
| 6243 | // control flow with a final branch left to emit or (b) fully |
| 6244 | // compiled to control flow and possibly false. |
| 6245 | if (has_cc()) { |
| 6246 | Branch(true, true_target()); |
| 6247 | } |
| 6248 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6249 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6250 | } else { |
| 6251 | // Nothing to do. |
| 6252 | ASSERT(!has_valid_frame() && !has_cc() && !is_false.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6253 | } |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6254 | } |
| 6255 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6256 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6257 | |
| 6258 | void CodeGenerator::VisitBinaryOperation(BinaryOperation* node) { |
| 6259 | #ifdef DEBUG |
| 6260 | int original_height = frame_->height(); |
| 6261 | #endif |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6262 | Comment cmnt(masm_, "[ BinaryOperation"); |
| 6263 | |
| 6264 | if (node->op() == Token::AND || node->op() == Token::OR) { |
| 6265 | GenerateLogicalBooleanOperation(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6266 | } else { |
| 6267 | // Optimize for the case where (at least) one of the expressions |
| 6268 | // is a literal small integer. |
| 6269 | Literal* lliteral = node->left()->AsLiteral(); |
| 6270 | Literal* rliteral = node->right()->AsLiteral(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6271 | // NOTE: The code below assumes that the slow cases (calls to runtime) |
| 6272 | // never return a constant/immutable object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6273 | bool overwrite_left = node->left()->ResultOverwriteAllowed(); |
| 6274 | bool overwrite_right = node->right()->ResultOverwriteAllowed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6275 | |
| 6276 | if (rliteral != NULL && rliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6277 | VirtualFrame::RegisterAllocationScope scope(this); |
| 6278 | Load(node->left()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6279 | if (frame_->KnownSmiAt(0)) overwrite_left = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 6280 | SmiOperation(node->op(), |
| 6281 | rliteral->handle(), |
| 6282 | false, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6283 | overwrite_left ? OVERWRITE_LEFT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6284 | } else if (lliteral != NULL && lliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6285 | VirtualFrame::RegisterAllocationScope scope(this); |
| 6286 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6287 | if (frame_->KnownSmiAt(0)) overwrite_right = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 6288 | SmiOperation(node->op(), |
| 6289 | lliteral->handle(), |
| 6290 | true, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6291 | overwrite_right ? OVERWRITE_RIGHT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6292 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6293 | GenerateInlineSmi inline_smi = |
| 6294 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 6295 | if (lliteral != NULL) { |
| 6296 | ASSERT(!lliteral->handle()->IsSmi()); |
| 6297 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 6298 | } |
| 6299 | if (rliteral != NULL) { |
| 6300 | ASSERT(!rliteral->handle()->IsSmi()); |
| 6301 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 6302 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6303 | VirtualFrame::RegisterAllocationScope scope(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6304 | OverwriteMode overwrite_mode = NO_OVERWRITE; |
| 6305 | if (overwrite_left) { |
| 6306 | overwrite_mode = OVERWRITE_LEFT; |
| 6307 | } else if (overwrite_right) { |
| 6308 | overwrite_mode = OVERWRITE_RIGHT; |
| 6309 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6310 | Load(node->left()); |
| 6311 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6312 | GenericBinaryOperation(node->op(), overwrite_mode, inline_smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6313 | } |
| 6314 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6315 | ASSERT(!has_valid_frame() || |
| 6316 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6317 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6321 | void CodeGenerator::VisitThisFunction(ThisFunction* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6322 | #ifdef DEBUG |
| 6323 | int original_height = frame_->height(); |
| 6324 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6325 | frame_->EmitPush(MemOperand(frame_->Function())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6326 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6330 | void CodeGenerator::VisitCompareOperation(CompareOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6331 | #ifdef DEBUG |
| 6332 | int original_height = frame_->height(); |
| 6333 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6334 | Comment cmnt(masm_, "[ CompareOperation"); |
| 6335 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6336 | VirtualFrame::RegisterAllocationScope nonspilled_scope(this); |
| 6337 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6338 | // Get the expressions from the node. |
| 6339 | Expression* left = node->left(); |
| 6340 | Expression* right = node->right(); |
| 6341 | Token::Value op = node->op(); |
| 6342 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6343 | // To make typeof testing for natives implemented in JavaScript really |
| 6344 | // efficient, we generate special code for expressions of the form: |
| 6345 | // 'typeof <expression> == <string>'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6346 | UnaryOperation* operation = left->AsUnaryOperation(); |
| 6347 | if ((op == Token::EQ || op == Token::EQ_STRICT) && |
| 6348 | (operation != NULL && operation->op() == Token::TYPEOF) && |
| 6349 | (right->AsLiteral() != NULL && |
| 6350 | right->AsLiteral()->handle()->IsString())) { |
| 6351 | Handle<String> check(String::cast(*right->AsLiteral()->handle())); |
| 6352 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6353 | // Load the operand, move it to a register. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6354 | LoadTypeofExpression(operation->expression()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6355 | Register tos = frame_->PopToRegister(); |
| 6356 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6357 | Register scratch = VirtualFrame::scratch0(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6358 | |
| 6359 | if (check->Equals(Heap::number_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6360 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6361 | true_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6362 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6363 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6364 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6365 | cc_reg_ = eq; |
| 6366 | |
| 6367 | } else if (check->Equals(Heap::string_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6368 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6369 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6370 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6371 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6372 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6373 | // It can be an undetectable string object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6374 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6375 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 6376 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6377 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6378 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6379 | __ ldrb(scratch, FieldMemOperand(tos, Map::kInstanceTypeOffset)); |
| 6380 | __ cmp(scratch, Operand(FIRST_NONSTRING_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6381 | cc_reg_ = lt; |
| 6382 | |
| 6383 | } else if (check->Equals(Heap::boolean_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6384 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6385 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6386 | true_target()->Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6387 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6388 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6389 | cc_reg_ = eq; |
| 6390 | |
| 6391 | } else if (check->Equals(Heap::undefined_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6392 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6393 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6394 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6395 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6396 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6397 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6398 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6399 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6400 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 6401 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6402 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 6403 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6404 | |
| 6405 | cc_reg_ = eq; |
| 6406 | |
| 6407 | } else if (check->Equals(Heap::function_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6408 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6409 | false_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6410 | Register map_reg = scratch; |
| 6411 | __ CompareObjectType(tos, map_reg, tos, JS_FUNCTION_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6412 | true_target()->Branch(eq); |
| 6413 | // Regular expressions are callable so typeof == 'function'. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6414 | __ CompareInstanceType(map_reg, tos, JS_REGEXP_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6415 | cc_reg_ = eq; |
| 6416 | |
| 6417 | } else if (check->Equals(Heap::object_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6418 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6419 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6420 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6421 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6422 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6423 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6424 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6425 | Register map_reg = scratch; |
| 6426 | __ CompareObjectType(tos, map_reg, tos, JS_REGEXP_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6427 | false_target()->Branch(eq); |
| 6428 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6429 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6430 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 6431 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 6432 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6433 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6434 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6435 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 6436 | __ cmp(tos, Operand(FIRST_JS_OBJECT_TYPE)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6437 | false_target()->Branch(lt); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6438 | __ cmp(tos, Operand(LAST_JS_OBJECT_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6439 | cc_reg_ = le; |
| 6440 | |
| 6441 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6442 | // Uncommon case: typeof testing against a string literal that is |
| 6443 | // never returned from the typeof operator. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6444 | false_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6445 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6446 | ASSERT(!has_valid_frame() || |
| 6447 | (has_cc() && frame_->height() == original_height)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6448 | return; |
| 6449 | } |
| 6450 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6451 | switch (op) { |
| 6452 | case Token::EQ: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6453 | Comparison(eq, left, right, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6454 | break; |
| 6455 | |
| 6456 | case Token::LT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6457 | Comparison(lt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6458 | break; |
| 6459 | |
| 6460 | case Token::GT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6461 | Comparison(gt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6462 | break; |
| 6463 | |
| 6464 | case Token::LTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6465 | Comparison(le, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6466 | break; |
| 6467 | |
| 6468 | case Token::GTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6469 | Comparison(ge, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6470 | break; |
| 6471 | |
| 6472 | case Token::EQ_STRICT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6473 | Comparison(eq, left, right, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6474 | break; |
| 6475 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6476 | case Token::IN: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6477 | Load(left); |
| 6478 | Load(right); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6479 | frame_->InvokeBuiltin(Builtins::IN, CALL_JS, 2); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6480 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6481 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6482 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6483 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6484 | case Token::INSTANCEOF: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6485 | Load(left); |
| 6486 | Load(right); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6487 | InstanceofStub stub; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6488 | frame_->CallStub(&stub, 2); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6489 | // At this point if instanceof succeeded then r0 == 0. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6490 | __ tst(r0, Operand(r0)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6491 | cc_reg_ = eq; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6492 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6493 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6494 | |
| 6495 | default: |
| 6496 | UNREACHABLE(); |
| 6497 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6498 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 6499 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6503 | void CodeGenerator::VisitCompareToNull(CompareToNull* node) { |
| 6504 | #ifdef DEBUG |
| 6505 | int original_height = frame_->height(); |
| 6506 | #endif |
| 6507 | Comment cmnt(masm_, "[ CompareToNull"); |
| 6508 | |
| 6509 | Load(node->expression()); |
| 6510 | Register tos = frame_->PopToRegister(); |
| 6511 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 6512 | __ cmp(tos, ip); |
| 6513 | |
| 6514 | // The 'null' value is only equal to 'undefined' if using non-strict |
| 6515 | // comparisons. |
| 6516 | if (!node->is_strict()) { |
| 6517 | true_target()->Branch(eq); |
| 6518 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 6519 | __ cmp(tos, Operand(ip)); |
| 6520 | true_target()->Branch(eq); |
| 6521 | |
| 6522 | __ tst(tos, Operand(kSmiTagMask)); |
| 6523 | false_target()->Branch(eq); |
| 6524 | |
| 6525 | // It can be an undetectable object. |
| 6526 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 6527 | __ ldrb(tos, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6528 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 6529 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
| 6530 | } |
| 6531 | |
| 6532 | cc_reg_ = eq; |
| 6533 | ASSERT(has_cc() && frame_->height() == original_height); |
| 6534 | } |
| 6535 | |
| 6536 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6537 | class DeferredReferenceGetNamedValue: public DeferredCode { |
| 6538 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6539 | explicit DeferredReferenceGetNamedValue(Register receiver, |
| 6540 | Handle<String> name) |
| 6541 | : receiver_(receiver), name_(name) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6542 | set_comment("[ DeferredReferenceGetNamedValue"); |
| 6543 | } |
| 6544 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6545 | virtual void Generate(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6546 | |
| 6547 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6548 | Register receiver_; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6549 | Handle<String> name_; |
| 6550 | }; |
| 6551 | |
| 6552 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6553 | // Convention for this is that on entry the receiver is in a register that |
| 6554 | // is not used by the stack. On exit the answer is found in that same |
| 6555 | // register and the stack has the same height. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6556 | void DeferredReferenceGetNamedValue::Generate() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6557 | #ifdef DEBUG |
| 6558 | int expected_height = frame_state()->frame()->height(); |
| 6559 | #endif |
| 6560 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6561 | copied_frame.SpillAll(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6562 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6563 | Register scratch1 = VirtualFrame::scratch0(); |
| 6564 | Register scratch2 = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6565 | ASSERT(!receiver_.is(scratch1) && !receiver_.is(scratch2)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6566 | __ DecrementCounter(&Counters::named_load_inline, 1, scratch1, scratch2); |
| 6567 | __ IncrementCounter(&Counters::named_load_inline_miss, 1, scratch1, scratch2); |
| 6568 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6569 | // Ensure receiver in r0 and name in r2 to match load ic calling convention. |
| 6570 | __ Move(r0, receiver_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6571 | __ mov(r2, Operand(name_)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6572 | |
| 6573 | // The rest of the instructions in the deferred code must be together. |
| 6574 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6575 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 6576 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6577 | // The call must be followed by a nop(1) instruction to indicate that the |
| 6578 | // in-object has been inlined. |
| 6579 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6580 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6581 | // At this point the answer is in r0. We move it to the expected register |
| 6582 | // if necessary. |
| 6583 | __ Move(receiver_, r0); |
| 6584 | |
| 6585 | // Now go back to the frame that we entered with. This will not overwrite |
| 6586 | // the receiver register since that register was not in use when we came |
| 6587 | // in. The instructions emitted by this merge are skipped over by the |
| 6588 | // inline load patching mechanism when looking for the branch instruction |
| 6589 | // that tells it where the code to patch is. |
| 6590 | copied_frame.MergeTo(frame_state()->frame()); |
| 6591 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6592 | // Block the constant pool for one more instruction after leaving this |
| 6593 | // constant pool block scope to include the branch instruction ending the |
| 6594 | // deferred code. |
| 6595 | __ BlockConstPoolFor(1); |
| 6596 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6597 | ASSERT_EQ(expected_height, frame_state()->frame()->height()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6601 | class DeferredReferenceGetKeyedValue: public DeferredCode { |
| 6602 | public: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6603 | DeferredReferenceGetKeyedValue(Register key, Register receiver) |
| 6604 | : key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6605 | set_comment("[ DeferredReferenceGetKeyedValue"); |
| 6606 | } |
| 6607 | |
| 6608 | virtual void Generate(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6609 | |
| 6610 | private: |
| 6611 | Register key_; |
| 6612 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6613 | }; |
| 6614 | |
| 6615 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6616 | // Takes key and register in r0 and r1 or vice versa. Returns result |
| 6617 | // in r0. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6618 | void DeferredReferenceGetKeyedValue::Generate() { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6619 | ASSERT((key_.is(r0) && receiver_.is(r1)) || |
| 6620 | (key_.is(r1) && receiver_.is(r0))); |
| 6621 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6622 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6623 | copied_frame.SpillAll(); |
| 6624 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6625 | Register scratch1 = VirtualFrame::scratch0(); |
| 6626 | Register scratch2 = VirtualFrame::scratch1(); |
| 6627 | __ DecrementCounter(&Counters::keyed_load_inline, 1, scratch1, scratch2); |
| 6628 | __ IncrementCounter(&Counters::keyed_load_inline_miss, 1, scratch1, scratch2); |
| 6629 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6630 | // Ensure key in r0 and receiver in r1 to match keyed load ic calling |
| 6631 | // convention. |
| 6632 | if (key_.is(r1)) { |
| 6633 | __ Swap(r0, r1, ip); |
| 6634 | } |
| 6635 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6636 | // The rest of the instructions in the deferred code must be together. |
| 6637 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 6638 | // Call keyed load IC. It has the arguments key and receiver in r0 and r1. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6639 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
| 6640 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6641 | // The call must be followed by a nop instruction to indicate that the |
| 6642 | // keyed load has been inlined. |
| 6643 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6644 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6645 | // Now go back to the frame that we entered with. This will not overwrite |
| 6646 | // the receiver or key registers since they were not in use when we came |
| 6647 | // in. The instructions emitted by this merge are skipped over by the |
| 6648 | // inline load patching mechanism when looking for the branch instruction |
| 6649 | // that tells it where the code to patch is. |
| 6650 | copied_frame.MergeTo(frame_state()->frame()); |
| 6651 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6652 | // Block the constant pool for one more instruction after leaving this |
| 6653 | // constant pool block scope to include the branch instruction ending the |
| 6654 | // deferred code. |
| 6655 | __ BlockConstPoolFor(1); |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | |
| 6660 | class DeferredReferenceSetKeyedValue: public DeferredCode { |
| 6661 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6662 | DeferredReferenceSetKeyedValue(Register value, |
| 6663 | Register key, |
| 6664 | Register receiver) |
| 6665 | : value_(value), key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6666 | set_comment("[ DeferredReferenceSetKeyedValue"); |
| 6667 | } |
| 6668 | |
| 6669 | virtual void Generate(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6670 | |
| 6671 | private: |
| 6672 | Register value_; |
| 6673 | Register key_; |
| 6674 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6675 | }; |
| 6676 | |
| 6677 | |
| 6678 | void DeferredReferenceSetKeyedValue::Generate() { |
| 6679 | Register scratch1 = VirtualFrame::scratch0(); |
| 6680 | Register scratch2 = VirtualFrame::scratch1(); |
| 6681 | __ DecrementCounter(&Counters::keyed_store_inline, 1, scratch1, scratch2); |
| 6682 | __ IncrementCounter( |
| 6683 | &Counters::keyed_store_inline_miss, 1, scratch1, scratch2); |
| 6684 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6685 | // Ensure value in r0, key in r1 and receiver in r2 to match keyed store ic |
| 6686 | // calling convention. |
| 6687 | if (value_.is(r1)) { |
| 6688 | __ Swap(r0, r1, ip); |
| 6689 | } |
| 6690 | ASSERT(receiver_.is(r2)); |
| 6691 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6692 | // The rest of the instructions in the deferred code must be together. |
| 6693 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6694 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6695 | // r1 and r2. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6696 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 6697 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6698 | // The call must be followed by a nop instruction to indicate that the |
| 6699 | // keyed store has been inlined. |
| 6700 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6701 | |
| 6702 | // Block the constant pool for one more instruction after leaving this |
| 6703 | // constant pool block scope to include the branch instruction ending the |
| 6704 | // deferred code. |
| 6705 | __ BlockConstPoolFor(1); |
| 6706 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6710 | class DeferredReferenceSetNamedValue: public DeferredCode { |
| 6711 | public: |
| 6712 | DeferredReferenceSetNamedValue(Register value, |
| 6713 | Register receiver, |
| 6714 | Handle<String> name) |
| 6715 | : value_(value), receiver_(receiver), name_(name) { |
| 6716 | set_comment("[ DeferredReferenceSetNamedValue"); |
| 6717 | } |
| 6718 | |
| 6719 | virtual void Generate(); |
| 6720 | |
| 6721 | private: |
| 6722 | Register value_; |
| 6723 | Register receiver_; |
| 6724 | Handle<String> name_; |
| 6725 | }; |
| 6726 | |
| 6727 | |
| 6728 | // Takes value in r0, receiver in r1 and returns the result (the |
| 6729 | // value) in r0. |
| 6730 | void DeferredReferenceSetNamedValue::Generate() { |
| 6731 | // Record the entry frame and spill. |
| 6732 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6733 | copied_frame.SpillAll(); |
| 6734 | |
| 6735 | // Ensure value in r0, receiver in r1 to match store ic calling |
| 6736 | // convention. |
| 6737 | ASSERT(value_.is(r0) && receiver_.is(r1)); |
| 6738 | __ mov(r2, Operand(name_)); |
| 6739 | |
| 6740 | // The rest of the instructions in the deferred code must be together. |
| 6741 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6742 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6743 | // r1 and r2. |
| 6744 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 6745 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6746 | // The call must be followed by a nop instruction to indicate that the |
| 6747 | // named store has been inlined. |
| 6748 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6749 | |
| 6750 | // Go back to the frame we entered with. The instructions |
| 6751 | // generated by this merge are skipped over by the inline store |
| 6752 | // patching mechanism when looking for the branch instruction that |
| 6753 | // tells it where the code to patch is. |
| 6754 | copied_frame.MergeTo(frame_state()->frame()); |
| 6755 | |
| 6756 | // Block the constant pool for one more instruction after leaving this |
| 6757 | // constant pool block scope to include the branch instruction ending the |
| 6758 | // deferred code. |
| 6759 | __ BlockConstPoolFor(1); |
| 6760 | } |
| 6761 | } |
| 6762 | |
| 6763 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6764 | // Consumes the top of stack (the receiver) and pushes the result instead. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6765 | void CodeGenerator::EmitNamedLoad(Handle<String> name, bool is_contextual) { |
| 6766 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6767 | Comment cmnt(masm(), "[ Load from named Property"); |
| 6768 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6769 | frame_->CallLoadIC(name, |
| 6770 | is_contextual |
| 6771 | ? RelocInfo::CODE_TARGET_CONTEXT |
| 6772 | : RelocInfo::CODE_TARGET); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6773 | frame_->EmitPush(r0); // Push answer. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6774 | } else { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6775 | // Inline the in-object property case. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6776 | Comment cmnt(masm(), "[ Inlined named property load"); |
| 6777 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6778 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6779 | // having it in the instruction stream below where patching will occur. |
| 6780 | __ IncrementCounter(&Counters::named_load_inline, 1, |
| 6781 | frame_->scratch0(), frame_->scratch1()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6782 | |
| 6783 | // The following instructions are the inlined load of an in-object property. |
| 6784 | // Parts of this code is patched, so the exact instructions generated needs |
| 6785 | // to be fixed. Therefore the instruction pool is blocked when generating |
| 6786 | // this code |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6787 | |
| 6788 | // Load the receiver from the stack. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6789 | Register receiver = frame_->PopToRegister(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6790 | |
| 6791 | DeferredReferenceGetNamedValue* deferred = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6792 | new DeferredReferenceGetNamedValue(receiver, name); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6793 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6794 | #ifdef DEBUG |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6795 | int kInlinedNamedLoadInstructions = 7; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6796 | Label check_inlined_codesize; |
| 6797 | masm_->bind(&check_inlined_codesize); |
| 6798 | #endif |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6799 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6800 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6801 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6802 | __ tst(receiver, Operand(kSmiTagMask)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6803 | deferred->Branch(eq); |
| 6804 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6805 | Register scratch = VirtualFrame::scratch0(); |
| 6806 | Register scratch2 = VirtualFrame::scratch1(); |
| 6807 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6808 | // Check the map. The null map used below is patched by the inline cache |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6809 | // code. Therefore we can't use a LoadRoot call. |
| 6810 | __ ldr(scratch, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6811 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6812 | __ cmp(scratch, scratch2); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6813 | deferred->Branch(ne); |
| 6814 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6815 | // Initially use an invalid index. The index will be patched by the |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6816 | // inline cache code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6817 | __ ldr(receiver, MemOperand(receiver, 0)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6818 | |
| 6819 | // Make sure that the expected number of instructions are generated. |
| 6820 | ASSERT_EQ(kInlinedNamedLoadInstructions, |
| 6821 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6822 | } |
| 6823 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6824 | deferred->BindExit(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6825 | // At this point the receiver register has the result, either from the |
| 6826 | // deferred code or from the inlined code. |
| 6827 | frame_->EmitPush(receiver); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6828 | } |
| 6829 | } |
| 6830 | |
| 6831 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6832 | void CodeGenerator::EmitNamedStore(Handle<String> name, bool is_contextual) { |
| 6833 | #ifdef DEBUG |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6834 | int expected_height = frame()->height() - (is_contextual ? 1 : 2); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6835 | #endif |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6836 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6837 | Result result; |
| 6838 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6839 | frame()->CallStoreIC(name, is_contextual); |
| 6840 | } else { |
| 6841 | // Inline the in-object property case. |
| 6842 | JumpTarget slow, done; |
| 6843 | |
| 6844 | // Get the value and receiver from the stack. |
| 6845 | frame()->PopToR0(); |
| 6846 | Register value = r0; |
| 6847 | frame()->PopToR1(); |
| 6848 | Register receiver = r1; |
| 6849 | |
| 6850 | DeferredReferenceSetNamedValue* deferred = |
| 6851 | new DeferredReferenceSetNamedValue(value, receiver, name); |
| 6852 | |
| 6853 | // Check that the receiver is a heap object. |
| 6854 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6855 | deferred->Branch(eq); |
| 6856 | |
| 6857 | // The following instructions are the part of the inlined |
| 6858 | // in-object property store code which can be patched. Therefore |
| 6859 | // the exact number of instructions generated must be fixed, so |
| 6860 | // the constant pool is blocked while generating this code. |
| 6861 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6862 | Register scratch0 = VirtualFrame::scratch0(); |
| 6863 | Register scratch1 = VirtualFrame::scratch1(); |
| 6864 | |
| 6865 | // Check the map. Initially use an invalid map to force a |
| 6866 | // failure. The map check will be patched in the runtime system. |
| 6867 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6868 | |
| 6869 | #ifdef DEBUG |
| 6870 | Label check_inlined_codesize; |
| 6871 | masm_->bind(&check_inlined_codesize); |
| 6872 | #endif |
| 6873 | __ mov(scratch0, Operand(Factory::null_value())); |
| 6874 | __ cmp(scratch0, scratch1); |
| 6875 | deferred->Branch(ne); |
| 6876 | |
| 6877 | int offset = 0; |
| 6878 | __ str(value, MemOperand(receiver, offset)); |
| 6879 | |
| 6880 | // Update the write barrier and record its size. We do not use |
| 6881 | // the RecordWrite macro here because we want the offset |
| 6882 | // addition instruction first to make it easy to patch. |
| 6883 | Label record_write_start, record_write_done; |
| 6884 | __ bind(&record_write_start); |
| 6885 | // Add offset into the object. |
| 6886 | __ add(scratch0, receiver, Operand(offset)); |
| 6887 | // Test that the object is not in the new space. We cannot set |
| 6888 | // region marks for new space pages. |
| 6889 | __ InNewSpace(receiver, scratch1, eq, &record_write_done); |
| 6890 | // Record the actual write. |
| 6891 | __ RecordWriteHelper(receiver, scratch0, scratch1); |
| 6892 | __ bind(&record_write_done); |
| 6893 | // Clobber all input registers when running with the debug-code flag |
| 6894 | // turned on to provoke errors. |
| 6895 | if (FLAG_debug_code) { |
| 6896 | __ mov(receiver, Operand(BitCast<int32_t>(kZapValue))); |
| 6897 | __ mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 6898 | __ mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
| 6899 | } |
| 6900 | // Check that this is the first inlined write barrier or that |
| 6901 | // this inlined write barrier has the same size as all the other |
| 6902 | // inlined write barriers. |
| 6903 | ASSERT((inlined_write_barrier_size_ == -1) || |
| 6904 | (inlined_write_barrier_size_ == |
| 6905 | masm()->InstructionsGeneratedSince(&record_write_start))); |
| 6906 | inlined_write_barrier_size_ = |
| 6907 | masm()->InstructionsGeneratedSince(&record_write_start); |
| 6908 | |
| 6909 | // Make sure that the expected number of instructions are generated. |
| 6910 | ASSERT_EQ(GetInlinedNamedStoreInstructionsAfterPatch(), |
| 6911 | masm()->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6912 | } |
| 6913 | deferred->BindExit(); |
| 6914 | } |
| 6915 | ASSERT_EQ(expected_height, frame()->height()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6916 | } |
| 6917 | |
| 6918 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6919 | void CodeGenerator::EmitKeyedLoad() { |
| 6920 | if (loop_nesting() == 0) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6921 | Comment cmnt(masm_, "[ Load from keyed property"); |
| 6922 | frame_->CallKeyedLoadIC(); |
| 6923 | } else { |
| 6924 | // Inline the keyed load. |
| 6925 | Comment cmnt(masm_, "[ Inlined load from keyed property"); |
| 6926 | |
| 6927 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6928 | // having it in the instruction stream below where patching will occur. |
| 6929 | __ IncrementCounter(&Counters::keyed_load_inline, 1, |
| 6930 | frame_->scratch0(), frame_->scratch1()); |
| 6931 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6932 | // Load the key and receiver from the stack. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6933 | bool key_is_known_smi = frame_->KnownSmiAt(0); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6934 | Register key = frame_->PopToRegister(); |
| 6935 | Register receiver = frame_->PopToRegister(key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6936 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6937 | // The deferred code expects key and receiver in registers. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6938 | DeferredReferenceGetKeyedValue* deferred = |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6939 | new DeferredReferenceGetKeyedValue(key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6940 | |
| 6941 | // Check that the receiver is a heap object. |
| 6942 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6943 | deferred->Branch(eq); |
| 6944 | |
| 6945 | // The following instructions are the part of the inlined load keyed |
| 6946 | // property code which can be patched. Therefore the exact number of |
| 6947 | // instructions generated need to be fixed, so the constant pool is blocked |
| 6948 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6949 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6950 | Register scratch1 = VirtualFrame::scratch0(); |
| 6951 | Register scratch2 = VirtualFrame::scratch1(); |
| 6952 | // Check the map. The null map used below is patched by the inline cache |
| 6953 | // code. |
| 6954 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6955 | |
| 6956 | // Check that the key is a smi. |
| 6957 | if (!key_is_known_smi) { |
| 6958 | __ tst(key, Operand(kSmiTagMask)); |
| 6959 | deferred->Branch(ne); |
| 6960 | } |
| 6961 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6962 | #ifdef DEBUG |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6963 | Label check_inlined_codesize; |
| 6964 | masm_->bind(&check_inlined_codesize); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6965 | #endif |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6966 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6967 | __ cmp(scratch1, scratch2); |
| 6968 | deferred->Branch(ne); |
| 6969 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 6970 | // Get the elements array from the receiver. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6971 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 6972 | __ AssertFastElements(scratch1); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6973 | |
| 6974 | // Check that key is within bounds. Use unsigned comparison to handle |
| 6975 | // negative keys. |
| 6976 | __ ldr(scratch2, FieldMemOperand(scratch1, FixedArray::kLengthOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6977 | __ cmp(scratch2, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6978 | deferred->Branch(ls); // Unsigned less equal. |
| 6979 | |
| 6980 | // Load and check that the result is not the hole (key is a smi). |
| 6981 | __ LoadRoot(scratch2, Heap::kTheHoleValueRootIndex); |
| 6982 | __ add(scratch1, |
| 6983 | scratch1, |
| 6984 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6985 | __ ldr(scratch1, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6986 | MemOperand(scratch1, key, LSL, |
| 6987 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6988 | __ cmp(scratch1, scratch2); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6989 | deferred->Branch(eq); |
| 6990 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6991 | __ mov(r0, scratch1); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6992 | // Make sure that the expected number of instructions are generated. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6993 | ASSERT_EQ(GetInlinedKeyedLoadInstructionsAfterPatch(), |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6994 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6995 | } |
| 6996 | |
| 6997 | deferred->BindExit(); |
| 6998 | } |
| 6999 | } |
| 7000 | |
| 7001 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7002 | void CodeGenerator::EmitKeyedStore(StaticType* key_type, |
| 7003 | WriteBarrierCharacter wb_info) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7004 | // Generate inlined version of the keyed store if the code is in a loop |
| 7005 | // and the key is likely to be a smi. |
| 7006 | if (loop_nesting() > 0 && key_type->IsLikelySmi()) { |
| 7007 | // Inline the keyed store. |
| 7008 | Comment cmnt(masm_, "[ Inlined store to keyed property"); |
| 7009 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7010 | Register scratch1 = VirtualFrame::scratch0(); |
| 7011 | Register scratch2 = VirtualFrame::scratch1(); |
| 7012 | Register scratch3 = r3; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7013 | |
| 7014 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 7015 | // having it in the instruction stream below where patching will occur. |
| 7016 | __ IncrementCounter(&Counters::keyed_store_inline, 1, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7017 | scratch1, scratch2); |
| 7018 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7019 | |
| 7020 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7021 | // Load the value, key and receiver from the stack. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7022 | bool value_is_harmless = frame_->KnownSmiAt(0); |
| 7023 | if (wb_info == NEVER_NEWSPACE) value_is_harmless = true; |
| 7024 | bool key_is_smi = frame_->KnownSmiAt(1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7025 | Register value = frame_->PopToRegister(); |
| 7026 | Register key = frame_->PopToRegister(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 7027 | VirtualFrame::SpilledScope spilled(frame_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7028 | Register receiver = r2; |
| 7029 | frame_->EmitPop(receiver); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7030 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7031 | #ifdef DEBUG |
| 7032 | bool we_remembered_the_write_barrier = value_is_harmless; |
| 7033 | #endif |
| 7034 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7035 | // The deferred code expects value, key and receiver in registers. |
| 7036 | DeferredReferenceSetKeyedValue* deferred = |
| 7037 | new DeferredReferenceSetKeyedValue(value, key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7038 | |
| 7039 | // Check that the value is a smi. As this inlined code does not set the |
| 7040 | // write barrier it is only possible to store smi values. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7041 | if (!value_is_harmless) { |
| 7042 | // If the value is not likely to be a Smi then let's test the fixed array |
| 7043 | // for new space instead. See below. |
| 7044 | if (wb_info == LIKELY_SMI) { |
| 7045 | __ tst(value, Operand(kSmiTagMask)); |
| 7046 | deferred->Branch(ne); |
| 7047 | #ifdef DEBUG |
| 7048 | we_remembered_the_write_barrier = true; |
| 7049 | #endif |
| 7050 | } |
| 7051 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7052 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7053 | if (!key_is_smi) { |
| 7054 | // Check that the key is a smi. |
| 7055 | __ tst(key, Operand(kSmiTagMask)); |
| 7056 | deferred->Branch(ne); |
| 7057 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7058 | |
| 7059 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7060 | __ tst(receiver, Operand(kSmiTagMask)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7061 | deferred->Branch(eq); |
| 7062 | |
| 7063 | // Check that the receiver is a JSArray. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7064 | __ CompareObjectType(receiver, scratch1, scratch1, JS_ARRAY_TYPE); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7065 | deferred->Branch(ne); |
| 7066 | |
| 7067 | // Check that the key is within bounds. Both the key and the length of |
| 7068 | // the JSArray are smis. Use unsigned comparison to handle negative keys. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7069 | __ ldr(scratch1, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 7070 | __ cmp(scratch1, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7071 | deferred->Branch(ls); // Unsigned less equal. |
| 7072 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7073 | // Get the elements array from the receiver. |
| 7074 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 7075 | if (!value_is_harmless && wb_info != LIKELY_SMI) { |
| 7076 | Label ok; |
| 7077 | __ and_(scratch2, scratch1, Operand(ExternalReference::new_space_mask())); |
| 7078 | __ cmp(scratch2, Operand(ExternalReference::new_space_start())); |
| 7079 | __ tst(value, Operand(kSmiTagMask), ne); |
| 7080 | deferred->Branch(ne); |
| 7081 | #ifdef DEBUG |
| 7082 | we_remembered_the_write_barrier = true; |
| 7083 | #endif |
| 7084 | } |
| 7085 | // Check that the elements array is not a dictionary. |
| 7086 | __ ldr(scratch2, FieldMemOperand(scratch1, JSObject::kMapOffset)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7087 | // The following instructions are the part of the inlined store keyed |
| 7088 | // property code which can be patched. Therefore the exact number of |
| 7089 | // instructions generated need to be fixed, so the constant pool is blocked |
| 7090 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7091 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7092 | #ifdef DEBUG |
| 7093 | Label check_inlined_codesize; |
| 7094 | masm_->bind(&check_inlined_codesize); |
| 7095 | #endif |
| 7096 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7097 | // Read the fixed array map from the constant pool (not from the root |
| 7098 | // array) so that the value can be patched. When debugging, we patch this |
| 7099 | // comparison to always fail so that we will hit the IC call in the |
| 7100 | // deferred code which will allow the debugger to break for fast case |
| 7101 | // stores. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7102 | __ mov(scratch3, Operand(Factory::fixed_array_map())); |
| 7103 | __ cmp(scratch2, scratch3); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7104 | deferred->Branch(ne); |
| 7105 | |
| 7106 | // Store the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7107 | __ add(scratch1, scratch1, |
| 7108 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 7109 | __ str(value, |
| 7110 | MemOperand(scratch1, key, LSL, |
| 7111 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7112 | |
| 7113 | // Make sure that the expected number of instructions are generated. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7114 | ASSERT_EQ(kInlinedKeyedStoreInstructionsAfterPatch, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7115 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 7116 | } |
| 7117 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7118 | ASSERT(we_remembered_the_write_barrier); |
| 7119 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7120 | deferred->BindExit(); |
| 7121 | } else { |
| 7122 | frame()->CallKeyedStoreIC(); |
| 7123 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7124 | } |
| 7125 | |
| 7126 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 7127 | #ifdef DEBUG |
| 7128 | bool CodeGenerator::HasValidEntryRegisters() { return true; } |
| 7129 | #endif |
| 7130 | |
| 7131 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7132 | #undef __ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 7133 | #define __ ACCESS_MASM(masm) |
| 7134 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7135 | Handle<String> Reference::GetName() { |
| 7136 | ASSERT(type_ == NAMED); |
| 7137 | Property* property = expression_->AsProperty(); |
| 7138 | if (property == NULL) { |
| 7139 | // Global variable reference treated as a named property reference. |
| 7140 | VariableProxy* proxy = expression_->AsVariableProxy(); |
| 7141 | ASSERT(proxy->AsVariable() != NULL); |
| 7142 | ASSERT(proxy->AsVariable()->is_global()); |
| 7143 | return proxy->name(); |
| 7144 | } else { |
| 7145 | Literal* raw_name = property->key()->AsLiteral(); |
| 7146 | ASSERT(raw_name != NULL); |
| 7147 | return Handle<String>(String::cast(*raw_name->handle())); |
| 7148 | } |
| 7149 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7150 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7151 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7152 | void Reference::DupIfPersist() { |
| 7153 | if (persist_after_get_) { |
| 7154 | switch (type_) { |
| 7155 | case KEYED: |
| 7156 | cgen_->frame()->Dup2(); |
| 7157 | break; |
| 7158 | case NAMED: |
| 7159 | cgen_->frame()->Dup(); |
| 7160 | // Fall through. |
| 7161 | case UNLOADED: |
| 7162 | case ILLEGAL: |
| 7163 | case SLOT: |
| 7164 | // Do nothing. |
| 7165 | ; |
| 7166 | } |
| 7167 | } else { |
| 7168 | set_unloaded(); |
| 7169 | } |
| 7170 | } |
| 7171 | |
| 7172 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7173 | void Reference::GetValue() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 7174 | ASSERT(cgen_->HasValidEntryRegisters()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7175 | ASSERT(!is_illegal()); |
| 7176 | ASSERT(!cgen_->has_cc()); |
| 7177 | MacroAssembler* masm = cgen_->masm(); |
| 7178 | Property* property = expression_->AsProperty(); |
| 7179 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7180 | cgen_->CodeForSourcePosition(property->position()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | switch (type_) { |
| 7184 | case SLOT: { |
| 7185 | Comment cmnt(masm, "[ Load from Slot"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 7186 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->AsSlot(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7187 | ASSERT(slot != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7188 | DupIfPersist(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7189 | cgen_->LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7190 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7191 | } |
| 7192 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7193 | case NAMED: { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7194 | Variable* var = expression_->AsVariableProxy()->AsVariable(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7195 | bool is_global = var != NULL; |
| 7196 | ASSERT(!is_global || var->is_global()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7197 | Handle<String> name = GetName(); |
| 7198 | DupIfPersist(); |
| 7199 | cgen_->EmitNamedLoad(name, is_global); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7200 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7201 | } |
| 7202 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7203 | case KEYED: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7204 | ASSERT(property != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7205 | DupIfPersist(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7206 | cgen_->EmitKeyedLoad(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7207 | cgen_->frame()->EmitPush(r0); |
| 7208 | break; |
| 7209 | } |
| 7210 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7211 | default: |
| 7212 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7213 | } |
| 7214 | } |
| 7215 | |
| 7216 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7217 | void Reference::SetValue(InitState init_state, WriteBarrierCharacter wb_info) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7218 | ASSERT(!is_illegal()); |
| 7219 | ASSERT(!cgen_->has_cc()); |
| 7220 | MacroAssembler* masm = cgen_->masm(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 7221 | VirtualFrame* frame = cgen_->frame(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7222 | Property* property = expression_->AsProperty(); |
| 7223 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7224 | cgen_->CodeForSourcePosition(property->position()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7225 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7226 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7227 | switch (type_) { |
| 7228 | case SLOT: { |
| 7229 | Comment cmnt(masm, "[ Store to Slot"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 7230 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->AsSlot(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7231 | cgen_->StoreToSlot(slot, init_state); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7232 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7233 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7234 | } |
| 7235 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7236 | case NAMED: { |
| 7237 | Comment cmnt(masm, "[ Store to named Property"); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7238 | cgen_->EmitNamedStore(GetName(), false); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 7239 | frame->EmitPush(r0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 7240 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7241 | break; |
| 7242 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7243 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7244 | case KEYED: { |
| 7245 | Comment cmnt(masm, "[ Store to keyed Property"); |
| 7246 | Property* property = expression_->AsProperty(); |
| 7247 | ASSERT(property != NULL); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7248 | cgen_->CodeForSourcePosition(property->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7249 | cgen_->EmitKeyedStore(property->key()->type(), wb_info); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 7250 | frame->EmitPush(r0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7251 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7252 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7253 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7254 | |
| 7255 | default: |
| 7256 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7257 | } |
| 7258 | } |
| 7259 | |
| 7260 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7261 | const char* GenericBinaryOpStub::GetName() { |
| 7262 | if (name_ != NULL) return name_; |
| 7263 | const int len = 100; |
| 7264 | name_ = Bootstrapper::AllocateAutoDeletedArray(len); |
| 7265 | if (name_ == NULL) return "OOM"; |
| 7266 | const char* op_name = Token::Name(op_); |
| 7267 | const char* overwrite_name; |
| 7268 | switch (mode_) { |
| 7269 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 7270 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 7271 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 7272 | default: overwrite_name = "UnknownOverwrite"; break; |
| 7273 | } |
| 7274 | |
| 7275 | OS::SNPrintF(Vector<char>(name_, len), |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7276 | "GenericBinaryOpStub_%s_%s%s_%s", |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7277 | op_name, |
| 7278 | overwrite_name, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7279 | specialized_on_rhs_ ? "_ConstantRhs" : "", |
| 7280 | BinaryOpIC::GetName(runtime_operands_type_)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7281 | return name_; |
| 7282 | } |
| 7283 | |
| 7284 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7285 | #undef __ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7286 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7287 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7288 | |
| 7289 | #endif // V8_TARGET_ARCH_ARM |