erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 30 | #include "arm/lithium-codegen-arm.h" |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 31 | #include "arm/lithium-gap-resolver-arm.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 32 | #include "code-stubs.h" |
| 33 | #include "stub-cache.h" |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 34 | #include "hydrogen-osr.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 35 | |
| 36 | namespace v8 { |
| 37 | namespace internal { |
| 38 | |
| 39 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 40 | class SafepointGenerator V8_FINAL : public CallWrapper { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 41 | public: |
| 42 | SafepointGenerator(LCodeGen* codegen, |
| 43 | LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 44 | Safepoint::DeoptMode mode) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 45 | : codegen_(codegen), |
| 46 | pointers_(pointers), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 47 | deopt_mode_(mode) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 48 | virtual ~SafepointGenerator() {} |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 49 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 50 | virtual void BeforeCall(int call_size) const V8_OVERRIDE {} |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 51 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 52 | virtual void AfterCall() const V8_OVERRIDE { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 53 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | private: |
| 57 | LCodeGen* codegen_; |
| 58 | LPointerMap* pointers_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 59 | Safepoint::DeoptMode deopt_mode_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | |
| 63 | #define __ masm()-> |
| 64 | |
| 65 | bool LCodeGen::GenerateCode() { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 66 | LPhase phase("Z_Code generation", chunk()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 67 | ASSERT(is_unused()); |
| 68 | status_ = GENERATING; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 69 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 70 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 71 | // NONE indicates that the scope shouldn't actually generate code to set up |
| 72 | // the frame (that is done in GeneratePrologue). |
| 73 | FrameScope frame_scope(masm_, StackFrame::NONE); |
| 74 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 75 | return GeneratePrologue() && |
| 76 | GenerateBody() && |
| 77 | GenerateDeferredCode() && |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 78 | GenerateDeoptJumpTable() && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 79 | GenerateSafepointTable(); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 84 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 85 | code->set_stack_slots(GetStackSlotCount()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 86 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
machenbach@chromium.org | ddf3811 | 2013-12-04 09:42:52 +0000 | [diff] [blame] | 87 | RegisterDependentCodeForEmbeddedMaps(code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 88 | PopulateDeoptimizationData(code); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 89 | info()->CommitDependencies(code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 93 | void LCodeGen::Abort(BailoutReason reason) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 94 | info()->set_bailout_reason(reason); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 95 | status_ = ABORTED; |
| 96 | } |
| 97 | |
| 98 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 99 | void LCodeGen::SaveCallerDoubles() { |
| 100 | ASSERT(info()->saves_caller_doubles()); |
| 101 | ASSERT(NeedsEagerFrame()); |
| 102 | Comment(";;; Save clobbered callee double registers"); |
| 103 | int count = 0; |
| 104 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 105 | BitVector::Iterator save_iterator(doubles); |
| 106 | while (!save_iterator.Done()) { |
| 107 | __ vstr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), |
| 108 | MemOperand(sp, count * kDoubleSize)); |
| 109 | save_iterator.Advance(); |
| 110 | count++; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | |
| 115 | void LCodeGen::RestoreCallerDoubles() { |
| 116 | ASSERT(info()->saves_caller_doubles()); |
| 117 | ASSERT(NeedsEagerFrame()); |
| 118 | Comment(";;; Restore clobbered callee double registers"); |
| 119 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 120 | BitVector::Iterator save_iterator(doubles); |
| 121 | int count = 0; |
| 122 | while (!save_iterator.Done()) { |
| 123 | __ vldr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), |
| 124 | MemOperand(sp, count * kDoubleSize)); |
| 125 | save_iterator.Advance(); |
| 126 | count++; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 131 | bool LCodeGen::GeneratePrologue() { |
| 132 | ASSERT(is_generating()); |
| 133 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 134 | if (info()->IsOptimizing()) { |
| 135 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 136 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 137 | #ifdef DEBUG |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 138 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 139 | info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 140 | __ stop("stop_at"); |
| 141 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 144 | // r1: Callee's JS function. |
| 145 | // cp: Callee's context. |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 146 | // pp: Callee's constant pool pointer (if FLAG_enable_ool_constant_pool) |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 147 | // fp: Caller's frame pointer. |
| 148 | // lr: Caller's pc. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 149 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 150 | // Strict mode functions and builtins need to replace the receiver |
| 151 | // with undefined when called as functions (without an explicit |
| 152 | // receiver object). r5 is zero for method calls and non-zero for |
| 153 | // function calls. |
| 154 | if (!info_->is_classic_mode() || info_->is_native()) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 155 | __ cmp(r5, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 156 | int receiver_offset = scope()->num_parameters() * kPointerSize; |
| 157 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 158 | __ str(r2, MemOperand(sp, receiver_offset), ne); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 159 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 160 | } |
| 161 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 162 | info()->set_prologue_offset(masm_->pc_offset()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 163 | if (NeedsEagerFrame()) { |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 164 | __ Prologue(info()->IsStub() ? BUILD_STUB_FRAME : BUILD_FUNCTION_FRAME); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 165 | frame_is_built_ = true; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 166 | info_->AddNoFrameRange(0, masm_->pc_offset()); |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 167 | __ LoadConstantPoolPointerRegister(); |
ulan@chromium.org | fae3da5 | 2012-12-03 15:37:23 +0000 | [diff] [blame] | 168 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 169 | |
| 170 | // Reserve space for the stack slots needed by the code. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 171 | int slots = GetStackSlotCount(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 172 | if (slots > 0) { |
| 173 | if (FLAG_debug_code) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 174 | __ sub(sp, sp, Operand(slots * kPointerSize)); |
| 175 | __ push(r0); |
| 176 | __ push(r1); |
| 177 | __ add(r0, sp, Operand(slots * kPointerSize)); |
| 178 | __ mov(r1, Operand(kSlotsZapValue)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 179 | Label loop; |
| 180 | __ bind(&loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 181 | __ sub(r0, r0, Operand(kPointerSize)); |
| 182 | __ str(r1, MemOperand(r0, 2 * kPointerSize)); |
| 183 | __ cmp(r0, sp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 184 | __ b(ne, &loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 185 | __ pop(r1); |
| 186 | __ pop(r0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 187 | } else { |
| 188 | __ sub(sp, sp, Operand(slots * kPointerSize)); |
| 189 | } |
| 190 | } |
| 191 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 192 | if (info()->saves_caller_doubles()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 193 | SaveCallerDoubles(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 194 | } |
| 195 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 196 | // Possibly allocate a local context. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 197 | int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 198 | if (heap_slots > 0) { |
| 199 | Comment(";;; Allocate local context"); |
| 200 | // Argument to NewContext is the function, which is in r1. |
| 201 | __ push(r1); |
| 202 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 203 | FastNewContextStub stub(heap_slots); |
| 204 | __ CallStub(&stub); |
| 205 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 206 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 207 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 208 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 209 | // Context is returned in both r0 and cp. It replaces the context |
| 210 | // passed to us. It's saved in the stack and kept live in cp. |
| 211 | __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 212 | // Copy any necessary parameters into the context. |
| 213 | int num_parameters = scope()->num_parameters(); |
| 214 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 215 | Variable* var = scope()->parameter(i); |
| 216 | if (var->IsContextSlot()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 217 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 218 | (num_parameters - 1 - i) * kPointerSize; |
| 219 | // Load parameter from stack. |
| 220 | __ ldr(r0, MemOperand(fp, parameter_offset)); |
| 221 | // Store it in the context. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 222 | MemOperand target = ContextOperand(cp, var->index()); |
| 223 | __ str(r0, target); |
| 224 | // Update the write barrier. This clobbers r3 and r0. |
| 225 | __ RecordWriteContextSlot( |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 226 | cp, |
| 227 | target.offset(), |
| 228 | r0, |
| 229 | r3, |
| 230 | GetLinkRegisterState(), |
| 231 | kSaveFPRegs); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | Comment(";;; End allocate local context"); |
| 235 | } |
| 236 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 237 | // Trace the call. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 238 | if (FLAG_trace && info()->IsOptimizing()) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 239 | // We have not executed any compiled code yet, so cp still holds the |
| 240 | // incoming context. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 241 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 242 | } |
| 243 | return !is_aborted(); |
| 244 | } |
| 245 | |
| 246 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 247 | void LCodeGen::GenerateOsrPrologue() { |
| 248 | // Generate the OSR entry prologue at the first unknown OSR value, or if there |
| 249 | // are none, at the OSR entrypoint instruction. |
| 250 | if (osr_pc_offset_ >= 0) return; |
| 251 | |
| 252 | osr_pc_offset_ = masm()->pc_offset(); |
| 253 | |
| 254 | // Adjust the frame size, subsuming the unoptimized frame into the |
| 255 | // optimized frame. |
| 256 | int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); |
| 257 | ASSERT(slots >= 0); |
| 258 | __ sub(sp, sp, Operand(slots * kPointerSize)); |
| 259 | } |
| 260 | |
| 261 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 262 | bool LCodeGen::GenerateDeferredCode() { |
| 263 | ASSERT(is_generating()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 264 | if (deferred_.length() > 0) { |
| 265 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 266 | LDeferredCode* code = deferred_[i]; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 267 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 268 | HValue* value = |
| 269 | instructions_->at(code->instruction_index())->hydrogen_value(); |
| 270 | RecordAndWritePosition(value->position()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 271 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 272 | Comment(";;; <@%d,#%d> " |
| 273 | "-------------------- Deferred %s --------------------", |
| 274 | code->instruction_index(), |
| 275 | code->instr()->hydrogen_value()->id(), |
| 276 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 277 | __ bind(code->entry()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 278 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 279 | Comment(";;; Build frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 280 | ASSERT(!frame_is_built_); |
| 281 | ASSERT(info()->IsStub()); |
| 282 | frame_is_built_ = true; |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 283 | __ PushFixedFrame(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 284 | __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 285 | __ push(scratch0()); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 286 | __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 287 | Comment(";;; Deferred code"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 288 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 289 | code->Generate(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 290 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 291 | Comment(";;; Destroy frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 292 | ASSERT(frame_is_built_); |
| 293 | __ pop(ip); |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 294 | __ PopFixedFrame(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 295 | frame_is_built_ = false; |
| 296 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 297 | __ jmp(code->exit()); |
| 298 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 299 | } |
| 300 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 301 | // Force constant pool emission at the end of the deferred code to make |
| 302 | // sure that no constant pools are emitted after. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 303 | masm()->CheckConstPool(true, false); |
| 304 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 305 | return !is_aborted(); |
| 306 | } |
| 307 | |
| 308 | |
| 309 | bool LCodeGen::GenerateDeoptJumpTable() { |
| 310 | // Check that the jump table is accessible from everywhere in the function |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 311 | // code, i.e. that offsets to the table can be encoded in the 24bit signed |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 312 | // immediate of a branch instruction. |
| 313 | // To simplify we consider the code size from the first instruction to the |
| 314 | // end of the jump table. We also don't consider the pc load delta. |
| 315 | // Each entry in the jump table generates one instruction and inlines one |
| 316 | // 32bit data after it. |
| 317 | if (!is_int24((masm()->pc_offset() / Assembler::kInstrSize) + |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 318 | deopt_jump_table_.length() * 7)) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 319 | Abort(kGeneratedCodeIsTooLarge); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 320 | } |
| 321 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 322 | if (deopt_jump_table_.length() > 0) { |
| 323 | Comment(";;; -------------------- Jump table --------------------"); |
| 324 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 325 | Label table_start; |
| 326 | __ bind(&table_start); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 327 | Label needs_frame; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 328 | for (int i = 0; i < deopt_jump_table_.length(); i++) { |
| 329 | __ bind(&deopt_jump_table_[i].label); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 330 | Address entry = deopt_jump_table_[i].address; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 331 | Deoptimizer::BailoutType type = deopt_jump_table_[i].bailout_type; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 332 | int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 333 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 334 | Comment(";;; jump table entry %d.", i); |
| 335 | } else { |
| 336 | Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 337 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 338 | if (deopt_jump_table_[i].needs_frame) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 339 | ASSERT(!info()->saves_caller_doubles()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 340 | __ mov(ip, Operand(ExternalReference::ForDeoptEntry(entry))); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 341 | if (needs_frame.is_bound()) { |
| 342 | __ b(&needs_frame); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 343 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 344 | __ bind(&needs_frame); |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 345 | __ PushFixedFrame(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 346 | // This variant of deopt can only be used with stubs. Since we don't |
| 347 | // have a function pointer to install in the stack frame that we're |
| 348 | // building, install a special marker there instead. |
| 349 | ASSERT(info()->IsStub()); |
| 350 | __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 351 | __ push(scratch0()); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 352 | __ add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 353 | __ mov(lr, Operand(pc), LeaveCC, al); |
| 354 | __ mov(pc, ip); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 355 | } |
| 356 | } else { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 357 | if (info()->saves_caller_doubles()) { |
| 358 | ASSERT(info()->IsStub()); |
| 359 | RestoreCallerDoubles(); |
| 360 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 361 | __ mov(lr, Operand(pc), LeaveCC, al); |
| 362 | __ mov(pc, Operand(ExternalReference::ForDeoptEntry(entry))); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 363 | } |
| 364 | masm()->CheckConstPool(false, false); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 365 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 366 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 367 | // Force constant pool emission at the end of the deopt jump table to make |
| 368 | // sure that no constant pools are emitted after. |
| 369 | masm()->CheckConstPool(true, false); |
| 370 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 371 | // The deoptimization jump table is the last part of the instruction |
| 372 | // sequence. Mark the generated code as done unless we bailed out. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 373 | if (!is_aborted()) status_ = DONE; |
| 374 | return !is_aborted(); |
| 375 | } |
| 376 | |
| 377 | |
| 378 | bool LCodeGen::GenerateSafepointTable() { |
| 379 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 380 | safepoints_.Emit(masm(), GetStackSlotCount()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 381 | return !is_aborted(); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | Register LCodeGen::ToRegister(int index) const { |
| 386 | return Register::FromAllocationIndex(index); |
| 387 | } |
| 388 | |
| 389 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 390 | DwVfpRegister LCodeGen::ToDoubleRegister(int index) const { |
| 391 | return DwVfpRegister::FromAllocationIndex(index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
| 395 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 396 | ASSERT(op->IsRegister()); |
| 397 | return ToRegister(op->index()); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 402 | if (op->IsRegister()) { |
| 403 | return ToRegister(op->index()); |
| 404 | } else if (op->IsConstantOperand()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 405 | LConstantOperand* const_op = LConstantOperand::cast(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 406 | HConstant* constant = chunk_->LookupConstant(const_op); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 407 | Handle<Object> literal = constant->handle(isolate()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 408 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 409 | if (r.IsInteger32()) { |
| 410 | ASSERT(literal->IsNumber()); |
| 411 | __ mov(scratch, Operand(static_cast<int32_t>(literal->Number()))); |
| 412 | } else if (r.IsDouble()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 413 | Abort(kEmitLoadRegisterUnsupportedDoubleImmediate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 414 | } else { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 415 | ASSERT(r.IsSmiOrTagged()); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 416 | __ Move(scratch, literal); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 417 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 418 | return scratch; |
| 419 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 420 | __ ldr(scratch, ToMemOperand(op)); |
| 421 | return scratch; |
| 422 | } |
| 423 | UNREACHABLE(); |
| 424 | return scratch; |
| 425 | } |
| 426 | |
| 427 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 428 | DwVfpRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 429 | ASSERT(op->IsDoubleRegister()); |
| 430 | return ToDoubleRegister(op->index()); |
| 431 | } |
| 432 | |
| 433 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 434 | DwVfpRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, |
| 435 | SwVfpRegister flt_scratch, |
| 436 | DwVfpRegister dbl_scratch) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 437 | if (op->IsDoubleRegister()) { |
| 438 | return ToDoubleRegister(op->index()); |
| 439 | } else if (op->IsConstantOperand()) { |
| 440 | LConstantOperand* const_op = LConstantOperand::cast(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 441 | HConstant* constant = chunk_->LookupConstant(const_op); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 442 | Handle<Object> literal = constant->handle(isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 443 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 444 | if (r.IsInteger32()) { |
| 445 | ASSERT(literal->IsNumber()); |
| 446 | __ mov(ip, Operand(static_cast<int32_t>(literal->Number()))); |
| 447 | __ vmov(flt_scratch, ip); |
| 448 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
| 449 | return dbl_scratch; |
| 450 | } else if (r.IsDouble()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 451 | Abort(kUnsupportedDoubleImmediate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 452 | } else if (r.IsTagged()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 453 | Abort(kUnsupportedTaggedImmediate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 454 | } |
| 455 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 456 | // TODO(regis): Why is vldr not taking a MemOperand? |
| 457 | // __ vldr(dbl_scratch, ToMemOperand(op)); |
| 458 | MemOperand mem_op = ToMemOperand(op); |
| 459 | __ vldr(dbl_scratch, mem_op.rn(), mem_op.offset()); |
| 460 | return dbl_scratch; |
| 461 | } |
| 462 | UNREACHABLE(); |
| 463 | return dbl_scratch; |
| 464 | } |
| 465 | |
| 466 | |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 467 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 468 | HConstant* constant = chunk_->LookupConstant(op); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 469 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 470 | return constant->handle(isolate()); |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | |
| 474 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 475 | return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 479 | bool LCodeGen::IsSmi(LConstantOperand* op) const { |
| 480 | return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
| 481 | } |
| 482 | |
| 483 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 484 | int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 485 | return ToRepresentation(op, Representation::Integer32()); |
| 486 | } |
| 487 | |
| 488 | |
| 489 | int32_t LCodeGen::ToRepresentation(LConstantOperand* op, |
| 490 | const Representation& r) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 491 | HConstant* constant = chunk_->LookupConstant(op); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 492 | int32_t value = constant->Integer32Value(); |
| 493 | if (r.IsInteger32()) return value; |
| 494 | ASSERT(r.IsSmiOrTagged()); |
| 495 | return reinterpret_cast<int32_t>(Smi::FromInt(value)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 499 | Smi* LCodeGen::ToSmi(LConstantOperand* op) const { |
| 500 | HConstant* constant = chunk_->LookupConstant(op); |
| 501 | return Smi::FromInt(constant->Integer32Value()); |
| 502 | } |
| 503 | |
| 504 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 505 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 506 | HConstant* constant = chunk_->LookupConstant(op); |
| 507 | ASSERT(constant->HasDoubleValue()); |
| 508 | return constant->DoubleValue(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 512 | Operand LCodeGen::ToOperand(LOperand* op) { |
| 513 | if (op->IsConstantOperand()) { |
| 514 | LConstantOperand* const_op = LConstantOperand::cast(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 515 | HConstant* constant = chunk()->LookupConstant(const_op); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 516 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 517 | if (r.IsSmi()) { |
| 518 | ASSERT(constant->HasSmiValue()); |
| 519 | return Operand(Smi::FromInt(constant->Integer32Value())); |
| 520 | } else if (r.IsInteger32()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 521 | ASSERT(constant->HasInteger32Value()); |
| 522 | return Operand(constant->Integer32Value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 523 | } else if (r.IsDouble()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 524 | Abort(kToOperandUnsupportedDoubleImmediate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 525 | } |
| 526 | ASSERT(r.IsTagged()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 527 | return Operand(constant->handle(isolate())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 528 | } else if (op->IsRegister()) { |
| 529 | return Operand(ToRegister(op)); |
| 530 | } else if (op->IsDoubleRegister()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 531 | Abort(kToOperandIsDoubleRegisterUnimplemented); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 532 | return Operand::Zero(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 533 | } |
| 534 | // Stack slots not implemented, use ToMemOperand instead. |
| 535 | UNREACHABLE(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 536 | return Operand::Zero(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 540 | static int ArgumentsOffsetWithoutFrame(int index) { |
| 541 | ASSERT(index < 0); |
| 542 | return -(index + 1) * kPointerSize; |
| 543 | } |
| 544 | |
| 545 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 546 | MemOperand LCodeGen::ToMemOperand(LOperand* op) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 547 | ASSERT(!op->IsRegister()); |
| 548 | ASSERT(!op->IsDoubleRegister()); |
| 549 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 550 | if (NeedsEagerFrame()) { |
| 551 | return MemOperand(fp, StackSlotOffset(op->index())); |
| 552 | } else { |
| 553 | // Retrieve parameter without eager stack-frame relative to the |
| 554 | // stack-pointer. |
| 555 | return MemOperand(sp, ArgumentsOffsetWithoutFrame(op->index())); |
| 556 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 560 | MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { |
| 561 | ASSERT(op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 562 | if (NeedsEagerFrame()) { |
| 563 | return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize); |
| 564 | } else { |
| 565 | // Retrieve parameter without eager stack-frame relative to the |
| 566 | // stack-pointer. |
| 567 | return MemOperand( |
| 568 | sp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize); |
| 569 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 573 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 574 | Translation* translation) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 575 | if (environment == NULL) return; |
| 576 | |
| 577 | // The translation includes one command per value in the environment. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 578 | int translation_size = environment->translation_size(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 579 | // The output frame height does not include the parameters. |
| 580 | int height = translation_size - environment->parameter_count(); |
| 581 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 582 | WriteTranslation(environment->outer(), translation); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 583 | bool has_closure_id = !info()->closure().is_null() && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 584 | !info()->closure().is_identical_to(environment->closure()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 585 | int closure_id = has_closure_id |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 586 | ? DefineDeoptimizationLiteral(environment->closure()) |
| 587 | : Translation::kSelfLiteralId; |
| 588 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 589 | switch (environment->frame_type()) { |
| 590 | case JS_FUNCTION: |
| 591 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 592 | break; |
| 593 | case JS_CONSTRUCT: |
| 594 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 595 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 596 | case JS_GETTER: |
| 597 | ASSERT(translation_size == 1); |
| 598 | ASSERT(height == 0); |
| 599 | translation->BeginGetterStubFrame(closure_id); |
| 600 | break; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 601 | case JS_SETTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 602 | ASSERT(translation_size == 2); |
| 603 | ASSERT(height == 0); |
| 604 | translation->BeginSetterStubFrame(closure_id); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 605 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 606 | case STUB: |
| 607 | translation->BeginCompiledStubFrame(); |
| 608 | break; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 609 | case ARGUMENTS_ADAPTOR: |
| 610 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 611 | break; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 612 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 613 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 614 | int object_index = 0; |
| 615 | int dematerialized_index = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 616 | for (int i = 0; i < translation_size; ++i) { |
| 617 | LOperand* value = environment->values()->at(i); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 618 | AddToTranslation(environment, |
| 619 | translation, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 620 | value, |
| 621 | environment->HasTaggedValueAt(i), |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 622 | environment->HasUint32ValueAt(i), |
| 623 | &object_index, |
| 624 | &dematerialized_index); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 629 | void LCodeGen::AddToTranslation(LEnvironment* environment, |
| 630 | Translation* translation, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 631 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 632 | bool is_tagged, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 633 | bool is_uint32, |
| 634 | int* object_index_pointer, |
| 635 | int* dematerialized_index_pointer) { |
| 636 | if (op == LEnvironment::materialization_marker()) { |
| 637 | int object_index = (*object_index_pointer)++; |
| 638 | if (environment->ObjectIsDuplicateAt(object_index)) { |
| 639 | int dupe_of = environment->ObjectDuplicateOfAt(object_index); |
| 640 | translation->DuplicateObject(dupe_of); |
| 641 | return; |
| 642 | } |
| 643 | int object_length = environment->ObjectLengthAt(object_index); |
| 644 | if (environment->ObjectIsArgumentsAt(object_index)) { |
| 645 | translation->BeginArgumentsObject(object_length); |
| 646 | } else { |
| 647 | translation->BeginCapturedObject(object_length); |
| 648 | } |
| 649 | int dematerialized_index = *dematerialized_index_pointer; |
| 650 | int env_offset = environment->translation_size() + dematerialized_index; |
| 651 | *dematerialized_index_pointer += object_length; |
| 652 | for (int i = 0; i < object_length; ++i) { |
| 653 | LOperand* value = environment->values()->at(env_offset + i); |
| 654 | AddToTranslation(environment, |
| 655 | translation, |
| 656 | value, |
| 657 | environment->HasTaggedValueAt(env_offset + i), |
| 658 | environment->HasUint32ValueAt(env_offset + i), |
| 659 | object_index_pointer, |
| 660 | dematerialized_index_pointer); |
| 661 | } |
| 662 | return; |
| 663 | } |
| 664 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 665 | if (op->IsStackSlot()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 666 | if (is_tagged) { |
| 667 | translation->StoreStackSlot(op->index()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 668 | } else if (is_uint32) { |
| 669 | translation->StoreUint32StackSlot(op->index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 670 | } else { |
| 671 | translation->StoreInt32StackSlot(op->index()); |
| 672 | } |
| 673 | } else if (op->IsDoubleStackSlot()) { |
| 674 | translation->StoreDoubleStackSlot(op->index()); |
| 675 | } else if (op->IsArgument()) { |
| 676 | ASSERT(is_tagged); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 677 | int src_index = GetStackSlotCount() + op->index(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 678 | translation->StoreStackSlot(src_index); |
| 679 | } else if (op->IsRegister()) { |
| 680 | Register reg = ToRegister(op); |
| 681 | if (is_tagged) { |
| 682 | translation->StoreRegister(reg); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 683 | } else if (is_uint32) { |
| 684 | translation->StoreUint32Register(reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 685 | } else { |
| 686 | translation->StoreInt32Register(reg); |
| 687 | } |
| 688 | } else if (op->IsDoubleRegister()) { |
| 689 | DoubleRegister reg = ToDoubleRegister(op); |
| 690 | translation->StoreDoubleRegister(reg); |
| 691 | } else if (op->IsConstantOperand()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 692 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 693 | int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 694 | translation->StoreLiteral(src_index); |
| 695 | } else { |
| 696 | UNREACHABLE(); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | |
| 701 | void LCodeGen::CallCode(Handle<Code> code, |
| 702 | RelocInfo::Mode mode, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 703 | LInstruction* instr, |
| 704 | TargetAddressStorageMode storage_mode) { |
| 705 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT, storage_mode); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | |
| 709 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 710 | RelocInfo::Mode mode, |
| 711 | LInstruction* instr, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 712 | SafepointMode safepoint_mode, |
| 713 | TargetAddressStorageMode storage_mode) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 714 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 715 | ASSERT(instr != NULL); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 716 | // Block literal pool emission to ensure nop indicating no inlined smi code |
| 717 | // is in the correct position. |
| 718 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 719 | __ Call(code, mode, TypeFeedbackId::None(), al, storage_mode); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 720 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 721 | |
| 722 | // Signal that we don't inline smi code before these stubs in the |
| 723 | // optimizing code generator. |
| 724 | if (code->kind() == Code::BINARY_OP_IC || |
| 725 | code->kind() == Code::COMPARE_IC) { |
| 726 | __ nop(); |
| 727 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 731 | void LCodeGen::CallRuntime(const Runtime::Function* function, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | int num_arguments, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 733 | LInstruction* instr, |
| 734 | SaveFPRegsMode save_doubles) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 735 | ASSERT(instr != NULL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 736 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 737 | __ CallRuntime(function, num_arguments, save_doubles); |
| 738 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 739 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 743 | void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
| 744 | if (context->IsRegister()) { |
| 745 | __ Move(cp, ToRegister(context)); |
| 746 | } else if (context->IsStackSlot()) { |
| 747 | __ ldr(cp, ToMemOperand(context)); |
jkummerow@chromium.org | 32aa03c | 2013-10-01 08:21:50 +0000 | [diff] [blame] | 748 | } else if (context->IsConstantOperand()) { |
| 749 | HConstant* constant = |
| 750 | chunk_->LookupConstant(LConstantOperand::cast(context)); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 751 | __ Move(cp, Handle<Object>::cast(constant->handle(isolate()))); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 752 | } else { |
| 753 | UNREACHABLE(); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 758 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 759 | int argc, |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 760 | LInstruction* instr, |
| 761 | LOperand* context) { |
| 762 | LoadContextFromDeferred(context); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 763 | __ CallRuntimeSaveDoubles(id); |
| 764 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 765 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 769 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 770 | Safepoint::DeoptMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 771 | if (!environment->HasBeenRegistered()) { |
| 772 | // Physical stack frame layout: |
| 773 | // -x ............. -4 0 ..................................... y |
| 774 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 775 | |
| 776 | // Layout of the environment: |
| 777 | // 0 ..................................................... size-1 |
| 778 | // [parameters] [locals] [expression stack including arguments] |
| 779 | |
| 780 | // Layout of the translation: |
| 781 | // 0 ........................................................ size - 1 + 4 |
| 782 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 783 | // |>------------ translation_size ------------<| |
| 784 | |
| 785 | int frame_count = 0; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 786 | int jsframe_count = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 787 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 788 | ++frame_count; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 789 | if (e->frame_type() == JS_FUNCTION) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 790 | ++jsframe_count; |
| 791 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 792 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 793 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 794 | WriteTranslation(environment, &translation); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 795 | int deoptimization_index = deoptimizations_.length(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 796 | int pc_offset = masm()->pc_offset(); |
| 797 | environment->Register(deoptimization_index, |
| 798 | translation.index(), |
| 799 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 800 | deoptimizations_.Add(environment, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 805 | void LCodeGen::DeoptimizeIf(Condition condition, |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 806 | LEnvironment* environment, |
| 807 | Deoptimizer::BailoutType bailout_type) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 808 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 809 | ASSERT(environment->HasBeenRegistered()); |
| 810 | int id = environment->deoptimization_index(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 811 | ASSERT(info()->IsOptimizing() || info()->IsStub()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 812 | Address entry = |
| 813 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 814 | if (entry == NULL) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 815 | Abort(kBailoutWasNotPrepared); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 819 | if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { |
| 820 | Register scratch = scratch0(); |
| 821 | ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
| 822 | |
| 823 | // Store the condition on the stack if necessary |
| 824 | if (condition != al) { |
| 825 | __ mov(scratch, Operand::Zero(), LeaveCC, NegateCondition(condition)); |
| 826 | __ mov(scratch, Operand(1), LeaveCC, condition); |
| 827 | __ push(scratch); |
| 828 | } |
| 829 | |
| 830 | __ push(r1); |
| 831 | __ mov(scratch, Operand(count)); |
| 832 | __ ldr(r1, MemOperand(scratch)); |
| 833 | __ sub(r1, r1, Operand(1), SetCC); |
| 834 | __ movw(r1, FLAG_deopt_every_n_times, eq); |
| 835 | __ str(r1, MemOperand(scratch)); |
| 836 | __ pop(r1); |
| 837 | |
| 838 | if (condition != al) { |
| 839 | // Clean up the stack before the deoptimizer call |
| 840 | __ pop(scratch); |
| 841 | } |
| 842 | |
| 843 | __ Call(entry, RelocInfo::RUNTIME_ENTRY, eq); |
| 844 | |
| 845 | // 'Restore' the condition in a slightly hacky way. (It would be better |
| 846 | // to use 'msr' and 'mrs' instructions here, but they are not supported by |
| 847 | // our ARM simulator). |
| 848 | if (condition != al) { |
| 849 | condition = ne; |
| 850 | __ cmp(scratch, Operand::Zero()); |
| 851 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 852 | } |
| 853 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 854 | if (info()->ShouldTrapOnDeopt()) { |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 855 | __ stop("trap_on_deopt", condition); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 856 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 857 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 858 | ASSERT(info()->IsStub() || frame_is_built_); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 859 | // Go through jump table if we need to handle condition, build frame, or |
| 860 | // restore caller doubles. |
| 861 | if (condition == al && frame_is_built_ && |
| 862 | !info()->saves_caller_doubles()) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 863 | __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 864 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 865 | // We often have several deopts to the same entry, reuse the last |
| 866 | // jump entry if this is the case. |
| 867 | if (deopt_jump_table_.is_empty() || |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 868 | (deopt_jump_table_.last().address != entry) || |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 869 | (deopt_jump_table_.last().bailout_type != bailout_type) || |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 870 | (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 871 | Deoptimizer::JumpTableEntry table_entry(entry, |
| 872 | bailout_type, |
| 873 | !frame_is_built_); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 874 | deopt_jump_table_.Add(table_entry, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 875 | } |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 876 | __ b(condition, &deopt_jump_table_.last().label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 881 | void LCodeGen::DeoptimizeIf(Condition condition, |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 882 | LEnvironment* environment) { |
| 883 | Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 884 | ? Deoptimizer::LAZY |
| 885 | : Deoptimizer::EAGER; |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 886 | DeoptimizeIf(condition, environment, bailout_type); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 890 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 891 | int length = deoptimizations_.length(); |
| 892 | if (length == 0) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 893 | Handle<DeoptimizationInputData> data = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 894 | factory()->NewDeoptimizationInputData(length, TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 895 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 896 | Handle<ByteArray> translations = |
| 897 | translations_.CreateByteArray(isolate()->factory()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 898 | data->SetTranslationByteArray(*translations); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 899 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 900 | |
| 901 | Handle<FixedArray> literals = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 902 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 903 | { AllowDeferredHandleDereference copy_handles; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 904 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 905 | literals->set(i, *deoptimization_literals_[i]); |
| 906 | } |
| 907 | data->SetLiteralArray(*literals); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 908 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 909 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 910 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 911 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 912 | |
| 913 | // Populate the deoptimization entries. |
| 914 | for (int i = 0; i < length; i++) { |
| 915 | LEnvironment* env = deoptimizations_[i]; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 916 | data->SetAstId(i, env->ast_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 917 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 918 | data->SetArgumentsStackHeight(i, |
| 919 | Smi::FromInt(env->arguments_stack_height())); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 920 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 921 | } |
| 922 | code->set_deoptimization_data(*data); |
| 923 | } |
| 924 | |
| 925 | |
| 926 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 927 | int result = deoptimization_literals_.length(); |
| 928 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 929 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 930 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 931 | deoptimization_literals_.Add(literal, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 932 | return result; |
| 933 | } |
| 934 | |
| 935 | |
| 936 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 937 | ASSERT(deoptimization_literals_.length() == 0); |
| 938 | |
| 939 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 940 | chunk()->inlined_closures(); |
| 941 | |
| 942 | for (int i = 0, length = inlined_closures->length(); |
| 943 | i < length; |
| 944 | i++) { |
| 945 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 946 | } |
| 947 | |
| 948 | inlined_function_count_ = deoptimization_literals_.length(); |
| 949 | } |
| 950 | |
| 951 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 952 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 953 | LInstruction* instr, SafepointMode safepoint_mode) { |
| 954 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 955 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 956 | } else { |
| 957 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 958 | RecordSafepointWithRegisters( |
| 959 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 964 | void LCodeGen::RecordSafepoint( |
| 965 | LPointerMap* pointers, |
| 966 | Safepoint::Kind kind, |
| 967 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 968 | Safepoint::DeoptMode deopt_mode) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 969 | ASSERT(expected_safepoint_kind_ == kind); |
| 970 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 971 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 972 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 973 | kind, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 974 | for (int i = 0; i < operands->length(); i++) { |
| 975 | LOperand* pointer = operands->at(i); |
| 976 | if (pointer->IsStackSlot()) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 977 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 978 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 979 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 980 | } |
| 981 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | |
| 985 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 986 | Safepoint::DeoptMode deopt_mode) { |
| 987 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 991 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 992 | LPointerMap empty_pointers(zone()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 993 | RecordSafepoint(&empty_pointers, deopt_mode); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 997 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 998 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 999 | Safepoint::DeoptMode deopt_mode) { |
| 1000 | RecordSafepoint( |
| 1001 | pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1005 | void LCodeGen::RecordSafepointWithRegistersAndDoubles( |
| 1006 | LPointerMap* pointers, |
| 1007 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1008 | Safepoint::DeoptMode deopt_mode) { |
| 1009 | RecordSafepoint( |
| 1010 | pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1014 | void LCodeGen::RecordAndWritePosition(int position) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1015 | if (position == RelocInfo::kNoPosition) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1016 | masm()->positions_recorder()->RecordPosition(position); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1017 | masm()->positions_recorder()->WriteRecordedPositions(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1021 | static const char* LabelType(LLabel* label) { |
| 1022 | if (label->is_loop_header()) return " (loop header)"; |
| 1023 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 1024 | return ""; |
| 1025 | } |
| 1026 | |
| 1027 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1028 | void LCodeGen::DoLabel(LLabel* label) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1029 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1030 | current_instruction_, |
| 1031 | label->hydrogen_value()->id(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1032 | label->block_id(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1033 | LabelType(label)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1034 | __ bind(label->label()); |
| 1035 | current_block_ = label->block_id(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1036 | DoGap(label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1041 | resolver_.Resolve(move); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | void LCodeGen::DoGap(LGap* gap) { |
| 1046 | for (int i = LGap::FIRST_INNER_POSITION; |
| 1047 | i <= LGap::LAST_INNER_POSITION; |
| 1048 | i++) { |
| 1049 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 1050 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 1051 | if (move != NULL) DoParallelMove(move); |
| 1052 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1056 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 1057 | DoGap(instr); |
| 1058 | } |
| 1059 | |
| 1060 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1061 | void LCodeGen::DoParameter(LParameter* instr) { |
| 1062 | // Nothing to do. |
| 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | void LCodeGen::DoCallStub(LCallStub* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1067 | ASSERT(ToRegister(instr->context()).is(cp)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1068 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 1069 | switch (instr->hydrogen()->major_key()) { |
| 1070 | case CodeStub::RegExpConstructResult: { |
| 1071 | RegExpConstructResultStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1072 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1073 | break; |
| 1074 | } |
| 1075 | case CodeStub::RegExpExec: { |
| 1076 | RegExpExecStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1077 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1078 | break; |
| 1079 | } |
| 1080 | case CodeStub::SubString: { |
| 1081 | SubStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1082 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1083 | break; |
| 1084 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1085 | case CodeStub::StringCompare: { |
| 1086 | StringCompareStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1087 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1088 | break; |
| 1089 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1090 | default: |
| 1091 | UNREACHABLE(); |
| 1092 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | |
| 1096 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1097 | GenerateOsrPrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | |
| 1101 | void LCodeGen::DoModI(LModI* instr) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1102 | HMod* hmod = instr->hydrogen(); |
| 1103 | HValue* left = hmod->left(); |
| 1104 | HValue* right = hmod->right(); |
| 1105 | if (hmod->HasPowerOf2Divisor()) { |
| 1106 | // TODO(svenpanne) We should really do the strength reduction on the |
| 1107 | // Hydrogen level. |
| 1108 | Register left_reg = ToRegister(instr->left()); |
| 1109 | Register result_reg = ToRegister(instr->result()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1110 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1111 | // Note: The code below even works when right contains kMinInt. |
| 1112 | int32_t divisor = Abs(right->GetInteger32Constant()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1113 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1114 | Label left_is_not_negative, done; |
| 1115 | if (left->CanBeNegative()) { |
| 1116 | __ cmp(left_reg, Operand::Zero()); |
| 1117 | __ b(pl, &left_is_not_negative); |
| 1118 | __ rsb(result_reg, left_reg, Operand::Zero()); |
| 1119 | __ and_(result_reg, result_reg, Operand(divisor - 1)); |
| 1120 | __ rsb(result_reg, result_reg, Operand::Zero(), SetCC); |
| 1121 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1122 | DeoptimizeIf(eq, instr->environment()); |
| 1123 | } |
| 1124 | __ b(&done); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1125 | } |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1126 | |
| 1127 | __ bind(&left_is_not_negative); |
| 1128 | __ and_(result_reg, left_reg, Operand(divisor - 1)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1129 | __ bind(&done); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1130 | } else if (CpuFeatures::IsSupported(SUDIV)) { |
| 1131 | CpuFeatureScope scope(masm(), SUDIV); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1132 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1133 | Register left_reg = ToRegister(instr->left()); |
| 1134 | Register right_reg = ToRegister(instr->right()); |
| 1135 | Register result_reg = ToRegister(instr->result()); |
| 1136 | |
| 1137 | Label done; |
| 1138 | // Check for x % 0, sdiv might signal an exception. We have to deopt in this |
| 1139 | // case because we can't return a NaN. |
| 1140 | if (right->CanBeZero()) { |
| 1141 | __ cmp(right_reg, Operand::Zero()); |
| 1142 | DeoptimizeIf(eq, instr->environment()); |
| 1143 | } |
| 1144 | |
| 1145 | // Check for kMinInt % -1, sdiv will return kMinInt, which is not what we |
| 1146 | // want. We have to deopt if we care about -0, because we can't return that. |
| 1147 | if (left->RangeCanInclude(kMinInt) && right->RangeCanInclude(-1)) { |
| 1148 | Label no_overflow_possible; |
| 1149 | __ cmp(left_reg, Operand(kMinInt)); |
| 1150 | __ b(ne, &no_overflow_possible); |
| 1151 | __ cmp(right_reg, Operand(-1)); |
| 1152 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1153 | DeoptimizeIf(eq, instr->environment()); |
| 1154 | } else { |
| 1155 | __ b(ne, &no_overflow_possible); |
| 1156 | __ mov(result_reg, Operand::Zero()); |
| 1157 | __ jmp(&done); |
| 1158 | } |
| 1159 | __ bind(&no_overflow_possible); |
| 1160 | } |
| 1161 | |
| 1162 | // For 'r3 = r1 % r2' we can have the following ARM code: |
| 1163 | // sdiv r3, r1, r2 |
| 1164 | // mls r3, r3, r2, r1 |
| 1165 | |
| 1166 | __ sdiv(result_reg, left_reg, right_reg); |
| 1167 | __ mls(result_reg, result_reg, right_reg, left_reg); |
| 1168 | |
| 1169 | // If we care about -0, test if the dividend is <0 and the result is 0. |
| 1170 | if (left->CanBeNegative() && |
| 1171 | hmod->CanBeZero() && |
| 1172 | hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1173 | __ cmp(result_reg, Operand::Zero()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1174 | __ b(ne, &done); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1175 | __ cmp(left_reg, Operand::Zero()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1176 | DeoptimizeIf(lt, instr->environment()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1177 | } |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1178 | __ bind(&done); |
| 1179 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1180 | } else { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1181 | // General case, without any SDIV support. |
| 1182 | Register left_reg = ToRegister(instr->left()); |
| 1183 | Register right_reg = ToRegister(instr->right()); |
| 1184 | Register result_reg = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1185 | Register scratch = scratch0(); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1186 | ASSERT(!scratch.is(left_reg)); |
| 1187 | ASSERT(!scratch.is(right_reg)); |
| 1188 | ASSERT(!scratch.is(result_reg)); |
| 1189 | DwVfpRegister dividend = ToDoubleRegister(instr->temp()); |
| 1190 | DwVfpRegister divisor = ToDoubleRegister(instr->temp2()); |
| 1191 | ASSERT(!divisor.is(dividend)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1192 | LowDwVfpRegister quotient = double_scratch0(); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1193 | ASSERT(!quotient.is(dividend)); |
| 1194 | ASSERT(!quotient.is(divisor)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1195 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1196 | Label done; |
| 1197 | // Check for x % 0, we have to deopt in this case because we can't return a |
| 1198 | // NaN. |
| 1199 | if (right->CanBeZero()) { |
| 1200 | __ cmp(right_reg, Operand::Zero()); |
| 1201 | DeoptimizeIf(eq, instr->environment()); |
| 1202 | } |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1203 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1204 | __ Move(result_reg, left_reg); |
| 1205 | // Load the arguments in VFP registers. The divisor value is preloaded |
| 1206 | // before. Be careful that 'right_reg' is only live on entry. |
| 1207 | // TODO(svenpanne) The last comments seems to be wrong nowadays. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1208 | __ vmov(double_scratch0().low(), left_reg); |
| 1209 | __ vcvt_f64_s32(dividend, double_scratch0().low()); |
| 1210 | __ vmov(double_scratch0().low(), right_reg); |
| 1211 | __ vcvt_f64_s32(divisor, double_scratch0().low()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1212 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1213 | // We do not care about the sign of the divisor. Note that we still handle |
| 1214 | // the kMinInt % -1 case correctly, though. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1215 | __ vabs(divisor, divisor); |
| 1216 | // Compute the quotient and round it to a 32bit integer. |
| 1217 | __ vdiv(quotient, dividend, divisor); |
| 1218 | __ vcvt_s32_f64(quotient.low(), quotient); |
| 1219 | __ vcvt_f64_s32(quotient, quotient.low()); |
| 1220 | |
| 1221 | // Compute the remainder in result. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1222 | __ vmul(double_scratch0(), divisor, quotient); |
| 1223 | __ vcvt_s32_f64(double_scratch0().low(), double_scratch0()); |
| 1224 | __ vmov(scratch, double_scratch0().low()); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1225 | __ sub(result_reg, left_reg, scratch, SetCC); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1226 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1227 | // If we care about -0, test if the dividend is <0 and the result is 0. |
| 1228 | if (left->CanBeNegative() && |
| 1229 | hmod->CanBeZero() && |
| 1230 | hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1231 | __ b(ne, &done); |
| 1232 | __ cmp(left_reg, Operand::Zero()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1233 | DeoptimizeIf(mi, instr->environment()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1234 | } |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1235 | __ bind(&done); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1236 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1240 | void LCodeGen::EmitSignedIntegerDivisionByConstant( |
| 1241 | Register result, |
| 1242 | Register dividend, |
| 1243 | int32_t divisor, |
| 1244 | Register remainder, |
| 1245 | Register scratch, |
| 1246 | LEnvironment* environment) { |
| 1247 | ASSERT(!AreAliased(dividend, scratch, ip)); |
| 1248 | ASSERT(LChunkBuilder::HasMagicNumberForDivisor(divisor)); |
| 1249 | |
| 1250 | uint32_t divisor_abs = abs(divisor); |
| 1251 | |
| 1252 | int32_t power_of_2_factor = |
| 1253 | CompilerIntrinsics::CountTrailingZeros(divisor_abs); |
| 1254 | |
| 1255 | switch (divisor_abs) { |
| 1256 | case 0: |
| 1257 | DeoptimizeIf(al, environment); |
| 1258 | return; |
| 1259 | |
| 1260 | case 1: |
| 1261 | if (divisor > 0) { |
| 1262 | __ Move(result, dividend); |
| 1263 | } else { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1264 | __ rsb(result, dividend, Operand::Zero(), SetCC); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1265 | DeoptimizeIf(vs, environment); |
| 1266 | } |
| 1267 | // Compute the remainder. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1268 | __ mov(remainder, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1269 | return; |
| 1270 | |
| 1271 | default: |
| 1272 | if (IsPowerOf2(divisor_abs)) { |
| 1273 | // Branch and condition free code for integer division by a power |
| 1274 | // of two. |
| 1275 | int32_t power = WhichPowerOf2(divisor_abs); |
| 1276 | if (power > 1) { |
| 1277 | __ mov(scratch, Operand(dividend, ASR, power - 1)); |
| 1278 | } |
| 1279 | __ add(scratch, dividend, Operand(scratch, LSR, 32 - power)); |
| 1280 | __ mov(result, Operand(scratch, ASR, power)); |
| 1281 | // Negate if necessary. |
| 1282 | // We don't need to check for overflow because the case '-1' is |
| 1283 | // handled separately. |
| 1284 | if (divisor < 0) { |
| 1285 | ASSERT(divisor != -1); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1286 | __ rsb(result, result, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1287 | } |
| 1288 | // Compute the remainder. |
| 1289 | if (divisor > 0) { |
| 1290 | __ sub(remainder, dividend, Operand(result, LSL, power)); |
| 1291 | } else { |
| 1292 | __ add(remainder, dividend, Operand(result, LSL, power)); |
| 1293 | } |
| 1294 | return; |
| 1295 | } else { |
| 1296 | // Use magic numbers for a few specific divisors. |
| 1297 | // Details and proofs can be found in: |
| 1298 | // - Hacker's Delight, Henry S. Warren, Jr. |
| 1299 | // - The PowerPC Compiler Writer’s Guide |
| 1300 | // and probably many others. |
| 1301 | // |
| 1302 | // We handle |
| 1303 | // <divisor with magic numbers> * <power of 2> |
| 1304 | // but not |
| 1305 | // <divisor with magic numbers> * <other divisor with magic numbers> |
| 1306 | DivMagicNumbers magic_numbers = |
| 1307 | DivMagicNumberFor(divisor_abs >> power_of_2_factor); |
| 1308 | // Branch and condition free code for integer division by a power |
| 1309 | // of two. |
| 1310 | const int32_t M = magic_numbers.M; |
| 1311 | const int32_t s = magic_numbers.s + power_of_2_factor; |
| 1312 | |
| 1313 | __ mov(ip, Operand(M)); |
| 1314 | __ smull(ip, scratch, dividend, ip); |
| 1315 | if (M < 0) { |
| 1316 | __ add(scratch, scratch, Operand(dividend)); |
| 1317 | } |
| 1318 | if (s > 0) { |
| 1319 | __ mov(scratch, Operand(scratch, ASR, s)); |
| 1320 | } |
| 1321 | __ add(result, scratch, Operand(dividend, LSR, 31)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1322 | if (divisor < 0) __ rsb(result, result, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1323 | // Compute the remainder. |
| 1324 | __ mov(ip, Operand(divisor)); |
| 1325 | // This sequence could be replaced with 'mls' when |
| 1326 | // it gets implemented. |
| 1327 | __ mul(scratch, result, ip); |
| 1328 | __ sub(remainder, dividend, scratch); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1334 | void LCodeGen::DoDivI(LDivI* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1335 | if (instr->hydrogen()->HasPowerOf2Divisor()) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1336 | const Register dividend = ToRegister(instr->left()); |
| 1337 | const Register result = ToRegister(instr->result()); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1338 | int32_t divisor = instr->hydrogen()->right()->GetInteger32Constant(); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1339 | int32_t test_value = 0; |
| 1340 | int32_t power = 0; |
| 1341 | |
| 1342 | if (divisor > 0) { |
| 1343 | test_value = divisor - 1; |
| 1344 | power = WhichPowerOf2(divisor); |
| 1345 | } else { |
| 1346 | // Check for (0 / -x) that will produce negative zero. |
| 1347 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1348 | __ cmp(dividend, Operand::Zero()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1349 | DeoptimizeIf(eq, instr->environment()); |
| 1350 | } |
| 1351 | // Check for (kMinInt / -1). |
| 1352 | if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1353 | __ cmp(dividend, Operand(kMinInt)); |
| 1354 | DeoptimizeIf(eq, instr->environment()); |
| 1355 | } |
| 1356 | test_value = - divisor - 1; |
| 1357 | power = WhichPowerOf2(-divisor); |
| 1358 | } |
| 1359 | |
| 1360 | if (test_value != 0) { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1361 | if (instr->hydrogen()->CheckFlag( |
| 1362 | HInstruction::kAllUsesTruncatingToInt32)) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1363 | __ sub(result, dividend, Operand::Zero(), SetCC); |
| 1364 | __ rsb(result, result, Operand::Zero(), LeaveCC, lt); |
| 1365 | __ mov(result, Operand(result, ASR, power)); |
| 1366 | if (divisor > 0) __ rsb(result, result, Operand::Zero(), LeaveCC, lt); |
| 1367 | if (divisor < 0) __ rsb(result, result, Operand::Zero(), LeaveCC, gt); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1368 | return; // Don't fall through to "__ rsb" below. |
| 1369 | } else { |
| 1370 | // Deoptimize if remainder is not 0. |
| 1371 | __ tst(dividend, Operand(test_value)); |
| 1372 | DeoptimizeIf(ne, instr->environment()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1373 | __ mov(result, Operand(dividend, ASR, power)); |
| 1374 | if (divisor < 0) __ rsb(result, result, Operand(0)); |
| 1375 | } |
| 1376 | } else { |
| 1377 | if (divisor < 0) { |
| 1378 | __ rsb(result, dividend, Operand(0)); |
| 1379 | } else { |
| 1380 | __ Move(result, dividend); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1381 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1382 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1383 | |
| 1384 | return; |
| 1385 | } |
| 1386 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1387 | const Register left = ToRegister(instr->left()); |
| 1388 | const Register right = ToRegister(instr->right()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1389 | const Register result = ToRegister(instr->result()); |
| 1390 | |
| 1391 | // Check for x / 0. |
| 1392 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1393 | __ cmp(right, Operand::Zero()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1394 | DeoptimizeIf(eq, instr->environment()); |
| 1395 | } |
| 1396 | |
| 1397 | // Check for (0 / -x) that will produce negative zero. |
| 1398 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1399 | Label positive; |
| 1400 | if (!instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1401 | // Do the test only if it hadn't be done above. |
| 1402 | __ cmp(right, Operand::Zero()); |
| 1403 | } |
| 1404 | __ b(pl, &positive); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1405 | __ cmp(left, Operand::Zero()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1406 | DeoptimizeIf(eq, instr->environment()); |
| 1407 | __ bind(&positive); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1410 | // Check for (kMinInt / -1). |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 1411 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow) && |
| 1412 | (!CpuFeatures::IsSupported(SUDIV) || |
| 1413 | !instr->hydrogen()->CheckFlag(HValue::kAllUsesTruncatingToInt32))) { |
| 1414 | // We don't need to check for overflow when truncating with sdiv |
| 1415 | // support because, on ARM, sdiv kMinInt, -1 -> kMinInt. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1416 | __ cmp(left, Operand(kMinInt)); |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 1417 | __ cmp(right, Operand(-1), eq); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1418 | DeoptimizeIf(eq, instr->environment()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1421 | if (CpuFeatures::IsSupported(SUDIV)) { |
| 1422 | CpuFeatureScope scope(masm(), SUDIV); |
| 1423 | __ sdiv(result, left, right); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1424 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1425 | if (!instr->hydrogen()->CheckFlag( |
| 1426 | HInstruction::kAllUsesTruncatingToInt32)) { |
| 1427 | // Compute remainder and deopt if it's not zero. |
| 1428 | const Register remainder = scratch0(); |
| 1429 | __ mls(remainder, result, right, left); |
| 1430 | __ cmp(remainder, Operand::Zero()); |
| 1431 | DeoptimizeIf(ne, instr->environment()); |
| 1432 | } |
| 1433 | } else { |
| 1434 | const DoubleRegister vleft = ToDoubleRegister(instr->temp()); |
| 1435 | const DoubleRegister vright = double_scratch0(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1436 | __ vmov(double_scratch0().low(), left); |
| 1437 | __ vcvt_f64_s32(vleft, double_scratch0().low()); |
| 1438 | __ vmov(double_scratch0().low(), right); |
| 1439 | __ vcvt_f64_s32(vright, double_scratch0().low()); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1440 | __ vdiv(vleft, vleft, vright); // vleft now contains the result. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1441 | __ vcvt_s32_f64(double_scratch0().low(), vleft); |
| 1442 | __ vmov(result, double_scratch0().low()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1443 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1444 | if (!instr->hydrogen()->CheckFlag( |
| 1445 | HInstruction::kAllUsesTruncatingToInt32)) { |
| 1446 | // Deopt if exact conversion to integer was not possible. |
| 1447 | // Use vright as scratch register. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1448 | __ vcvt_f64_s32(double_scratch0(), double_scratch0().low()); |
| 1449 | __ VFPCompareAndSetFlags(vleft, double_scratch0()); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1450 | DeoptimizeIf(ne, instr->environment()); |
| 1451 | } |
| 1452 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1456 | void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
| 1457 | DwVfpRegister addend = ToDoubleRegister(instr->addend()); |
| 1458 | DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1459 | DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1460 | |
| 1461 | // This is computed in-place. |
| 1462 | ASSERT(addend.is(ToDoubleRegister(instr->result()))); |
| 1463 | |
| 1464 | __ vmla(addend, multiplier, multiplicand); |
| 1465 | } |
| 1466 | |
| 1467 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1468 | void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) { |
| 1469 | DwVfpRegister minuend = ToDoubleRegister(instr->minuend()); |
| 1470 | DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1471 | DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1472 | |
| 1473 | // This is computed in-place. |
| 1474 | ASSERT(minuend.is(ToDoubleRegister(instr->result()))); |
| 1475 | |
| 1476 | __ vmls(minuend, multiplier, multiplicand); |
| 1477 | } |
| 1478 | |
| 1479 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1480 | void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
| 1481 | const Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1482 | const Register left = ToRegister(instr->left()); |
| 1483 | const Register remainder = ToRegister(instr->temp()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1484 | const Register scratch = scratch0(); |
| 1485 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1486 | if (!CpuFeatures::IsSupported(SUDIV)) { |
| 1487 | // If the CPU doesn't support sdiv instruction, we only optimize when we |
| 1488 | // have magic numbers for the divisor. The standard integer division routine |
| 1489 | // is usually slower than transitionning to VFP. |
| 1490 | ASSERT(instr->right()->IsConstantOperand()); |
| 1491 | int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); |
| 1492 | ASSERT(LChunkBuilder::HasMagicNumberForDivisor(divisor)); |
| 1493 | if (divisor < 0) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1494 | __ cmp(left, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1495 | DeoptimizeIf(eq, instr->environment()); |
| 1496 | } |
| 1497 | EmitSignedIntegerDivisionByConstant(result, |
| 1498 | left, |
| 1499 | divisor, |
| 1500 | remainder, |
| 1501 | scratch, |
| 1502 | instr->environment()); |
| 1503 | // We performed a truncating division. Correct the result if necessary. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1504 | __ cmp(remainder, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1505 | __ teq(remainder, Operand(divisor), ne); |
| 1506 | __ sub(result, result, Operand(1), LeaveCC, mi); |
| 1507 | } else { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1508 | CpuFeatureScope scope(masm(), SUDIV); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1509 | const Register right = ToRegister(instr->right()); |
| 1510 | |
| 1511 | // Check for x / 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1512 | __ cmp(right, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1513 | DeoptimizeIf(eq, instr->environment()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1514 | |
| 1515 | // Check for (kMinInt / -1). |
| 1516 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1517 | __ cmp(left, Operand(kMinInt)); |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 1518 | __ cmp(right, Operand(-1), eq); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1519 | DeoptimizeIf(eq, instr->environment()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | // Check for (0 / -x) that will produce negative zero. |
| 1523 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1524 | __ cmp(right, Operand::Zero()); |
| 1525 | __ cmp(left, Operand::Zero(), mi); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1526 | // "right" can't be null because the code would have already been |
| 1527 | // deoptimized. The Z flag is set only if (right < 0) and (left == 0). |
| 1528 | // In this case we need to deoptimize to produce a -0. |
| 1529 | DeoptimizeIf(eq, instr->environment()); |
| 1530 | } |
| 1531 | |
| 1532 | Label done; |
| 1533 | __ sdiv(result, left, right); |
| 1534 | // If both operands have the same sign then we are done. |
| 1535 | __ eor(remainder, left, Operand(right), SetCC); |
| 1536 | __ b(pl, &done); |
| 1537 | |
| 1538 | // Check if the result needs to be corrected. |
| 1539 | __ mls(remainder, result, right, left); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1540 | __ cmp(remainder, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1541 | __ sub(result, result, Operand(1), LeaveCC, ne); |
| 1542 | |
| 1543 | __ bind(&done); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1544 | } |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1548 | void LCodeGen::DoMulI(LMulI* instr) { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1549 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1550 | // Note that result may alias left. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1551 | Register left = ToRegister(instr->left()); |
| 1552 | LOperand* right_op = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1553 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1554 | bool bailout_on_minus_zero = |
| 1555 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1556 | bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1557 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1558 | if (right_op->IsConstantOperand()) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1559 | int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1560 | |
| 1561 | if (bailout_on_minus_zero && (constant < 0)) { |
| 1562 | // The case of a null constant will be handled separately. |
| 1563 | // If constant is negative and left is null, the result should be -0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1564 | __ cmp(left, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1565 | DeoptimizeIf(eq, instr->environment()); |
| 1566 | } |
| 1567 | |
| 1568 | switch (constant) { |
| 1569 | case -1: |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1570 | if (overflow) { |
| 1571 | __ rsb(result, left, Operand::Zero(), SetCC); |
| 1572 | DeoptimizeIf(vs, instr->environment()); |
| 1573 | } else { |
| 1574 | __ rsb(result, left, Operand::Zero()); |
| 1575 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1576 | break; |
| 1577 | case 0: |
| 1578 | if (bailout_on_minus_zero) { |
| 1579 | // If left is strictly negative and the constant is null, the |
| 1580 | // result is -0. Deoptimize if required, otherwise return 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1581 | __ cmp(left, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1582 | DeoptimizeIf(mi, instr->environment()); |
| 1583 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1584 | __ mov(result, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1585 | break; |
| 1586 | case 1: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1587 | __ Move(result, left); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1588 | break; |
| 1589 | default: |
| 1590 | // Multiplying by powers of two and powers of two plus or minus |
| 1591 | // one can be done faster with shifted operands. |
| 1592 | // For other constants we emit standard code. |
| 1593 | int32_t mask = constant >> 31; |
| 1594 | uint32_t constant_abs = (constant + mask) ^ mask; |
| 1595 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1596 | if (IsPowerOf2(constant_abs)) { |
| 1597 | int32_t shift = WhichPowerOf2(constant_abs); |
| 1598 | __ mov(result, Operand(left, LSL, shift)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1599 | // Correct the sign of the result is the constant is negative. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1600 | if (constant < 0) __ rsb(result, result, Operand::Zero()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1601 | } else if (IsPowerOf2(constant_abs - 1)) { |
| 1602 | int32_t shift = WhichPowerOf2(constant_abs - 1); |
| 1603 | __ add(result, left, Operand(left, LSL, shift)); |
| 1604 | // Correct the sign of the result is the constant is negative. |
| 1605 | if (constant < 0) __ rsb(result, result, Operand::Zero()); |
| 1606 | } else if (IsPowerOf2(constant_abs + 1)) { |
| 1607 | int32_t shift = WhichPowerOf2(constant_abs + 1); |
| 1608 | __ rsb(result, left, Operand(left, LSL, shift)); |
| 1609 | // Correct the sign of the result is the constant is negative. |
| 1610 | if (constant < 0) __ rsb(result, result, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1611 | } else { |
| 1612 | // Generate standard code. |
| 1613 | __ mov(ip, Operand(constant)); |
| 1614 | __ mul(result, left, ip); |
| 1615 | } |
| 1616 | } |
| 1617 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1618 | } else { |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1619 | ASSERT(right_op->IsRegister()); |
| 1620 | Register right = ToRegister(right_op); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1621 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1622 | if (overflow) { |
| 1623 | Register scratch = scratch0(); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1624 | // scratch:result = left * right. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1625 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1626 | __ SmiUntag(result, left); |
| 1627 | __ smull(result, scratch, result, right); |
| 1628 | } else { |
| 1629 | __ smull(result, scratch, left, right); |
| 1630 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1631 | __ cmp(scratch, Operand(result, ASR, 31)); |
| 1632 | DeoptimizeIf(ne, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1633 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1634 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1635 | __ SmiUntag(result, left); |
| 1636 | __ mul(result, result, right); |
| 1637 | } else { |
| 1638 | __ mul(result, left, right); |
| 1639 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | if (bailout_on_minus_zero) { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1643 | Label done; |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1644 | __ teq(left, Operand(right)); |
| 1645 | __ b(pl, &done); |
| 1646 | // Bail out if the result is minus zero. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1647 | __ cmp(result, Operand::Zero()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1648 | DeoptimizeIf(eq, instr->environment()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1649 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1650 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | |
| 1655 | void LCodeGen::DoBitI(LBitI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1656 | LOperand* left_op = instr->left(); |
| 1657 | LOperand* right_op = instr->right(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1658 | ASSERT(left_op->IsRegister()); |
| 1659 | Register left = ToRegister(left_op); |
| 1660 | Register result = ToRegister(instr->result()); |
| 1661 | Operand right(no_reg); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1662 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1663 | if (right_op->IsStackSlot() || right_op->IsArgument()) { |
| 1664 | right = Operand(EmitLoadRegister(right_op, ip)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1665 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1666 | ASSERT(right_op->IsRegister() || right_op->IsConstantOperand()); |
| 1667 | right = ToOperand(right_op); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1670 | switch (instr->op()) { |
| 1671 | case Token::BIT_AND: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1672 | __ and_(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1673 | break; |
| 1674 | case Token::BIT_OR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1675 | __ orr(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1676 | break; |
| 1677 | case Token::BIT_XOR: |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1678 | if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) { |
| 1679 | __ mvn(result, Operand(left)); |
| 1680 | } else { |
| 1681 | __ eor(result, left, right); |
| 1682 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1683 | break; |
| 1684 | default: |
| 1685 | UNREACHABLE(); |
| 1686 | break; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | |
| 1691 | void LCodeGen::DoShiftI(LShiftI* instr) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1692 | // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
| 1693 | // result may alias either of them. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1694 | LOperand* right_op = instr->right(); |
| 1695 | Register left = ToRegister(instr->left()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1696 | Register result = ToRegister(instr->result()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1697 | Register scratch = scratch0(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1698 | if (right_op->IsRegister()) { |
| 1699 | // Mask the right_op operand. |
| 1700 | __ and_(scratch, ToRegister(right_op), Operand(0x1F)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1701 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1702 | case Token::ROR: |
| 1703 | __ mov(result, Operand(left, ROR, scratch)); |
| 1704 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1705 | case Token::SAR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1706 | __ mov(result, Operand(left, ASR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1707 | break; |
| 1708 | case Token::SHR: |
| 1709 | if (instr->can_deopt()) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1710 | __ mov(result, Operand(left, LSR, scratch), SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1711 | DeoptimizeIf(mi, instr->environment()); |
| 1712 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1713 | __ mov(result, Operand(left, LSR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1714 | } |
| 1715 | break; |
| 1716 | case Token::SHL: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1717 | __ mov(result, Operand(left, LSL, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1718 | break; |
| 1719 | default: |
| 1720 | UNREACHABLE(); |
| 1721 | break; |
| 1722 | } |
| 1723 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1724 | // Mask the right_op operand. |
| 1725 | int value = ToInteger32(LConstantOperand::cast(right_op)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1726 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1727 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1728 | case Token::ROR: |
| 1729 | if (shift_count != 0) { |
| 1730 | __ mov(result, Operand(left, ROR, shift_count)); |
| 1731 | } else { |
| 1732 | __ Move(result, left); |
| 1733 | } |
| 1734 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1735 | case Token::SAR: |
| 1736 | if (shift_count != 0) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1737 | __ mov(result, Operand(left, ASR, shift_count)); |
| 1738 | } else { |
| 1739 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1740 | } |
| 1741 | break; |
| 1742 | case Token::SHR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1743 | if (shift_count != 0) { |
| 1744 | __ mov(result, Operand(left, LSR, shift_count)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1745 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1746 | if (instr->can_deopt()) { |
| 1747 | __ tst(left, Operand(0x80000000)); |
| 1748 | DeoptimizeIf(ne, instr->environment()); |
| 1749 | } |
| 1750 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1751 | } |
| 1752 | break; |
| 1753 | case Token::SHL: |
| 1754 | if (shift_count != 0) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1755 | if (instr->hydrogen_value()->representation().IsSmi() && |
| 1756 | instr->can_deopt()) { |
| 1757 | if (shift_count != 1) { |
| 1758 | __ mov(result, Operand(left, LSL, shift_count - 1)); |
| 1759 | __ SmiTag(result, result, SetCC); |
| 1760 | } else { |
| 1761 | __ SmiTag(result, left, SetCC); |
| 1762 | } |
| 1763 | DeoptimizeIf(vs, instr->environment()); |
| 1764 | } else { |
| 1765 | __ mov(result, Operand(left, LSL, shift_count)); |
| 1766 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1767 | } else { |
| 1768 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | } |
| 1770 | break; |
| 1771 | default: |
| 1772 | UNREACHABLE(); |
| 1773 | break; |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | |
| 1779 | void LCodeGen::DoSubI(LSubI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1780 | LOperand* left = instr->left(); |
| 1781 | LOperand* right = instr->right(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1782 | LOperand* result = instr->result(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1783 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1784 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
| 1785 | |
| 1786 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1787 | Register right_reg = EmitLoadRegister(right, ip); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1788 | __ sub(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1789 | } else { |
| 1790 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1791 | __ sub(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | if (can_overflow) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1795 | DeoptimizeIf(vs, instr->environment()); |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1800 | void LCodeGen::DoRSubI(LRSubI* instr) { |
| 1801 | LOperand* left = instr->left(); |
| 1802 | LOperand* right = instr->right(); |
| 1803 | LOperand* result = instr->result(); |
| 1804 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1805 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
| 1806 | |
| 1807 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1808 | Register right_reg = EmitLoadRegister(right, ip); |
| 1809 | __ rsb(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
| 1810 | } else { |
| 1811 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
| 1812 | __ rsb(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
| 1813 | } |
| 1814 | |
| 1815 | if (can_overflow) { |
| 1816 | DeoptimizeIf(vs, instr->environment()); |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1821 | void LCodeGen::DoConstantI(LConstantI* instr) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1822 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1823 | } |
| 1824 | |
| 1825 | |
| 1826 | void LCodeGen::DoConstantS(LConstantS* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1827 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1828 | } |
| 1829 | |
| 1830 | |
| 1831 | void LCodeGen::DoConstantD(LConstantD* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1832 | ASSERT(instr->result()->IsDoubleRegister()); |
| 1833 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 1834 | double v = instr->value(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1835 | __ Vmov(result, v, scratch0()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1839 | void LCodeGen::DoConstantE(LConstantE* instr) { |
| 1840 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1841 | } |
| 1842 | |
| 1843 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1844 | void LCodeGen::DoConstantT(LConstantT* instr) { |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1845 | Handle<Object> value = instr->value(isolate()); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1846 | AllowDeferredHandleDereference smi_check; |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 1847 | __ Move(ToRegister(instr->result()), value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1851 | void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 1852 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1853 | Register map = ToRegister(instr->value()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1854 | __ EnumLength(result, map); |
| 1855 | } |
| 1856 | |
| 1857 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1858 | void LCodeGen::DoElementsKind(LElementsKind* instr) { |
| 1859 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1860 | Register input = ToRegister(instr->value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1861 | |
| 1862 | // Load map into |result|. |
| 1863 | __ ldr(result, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 1864 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 1865 | // but the following bit field extraction takes care of that anyway. |
| 1866 | __ ldr(result, FieldMemOperand(result, Map::kBitField2Offset)); |
| 1867 | // Retrieve elements_kind from bit field 2. |
| 1868 | __ ubfx(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount); |
| 1869 | } |
| 1870 | |
| 1871 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1872 | void LCodeGen::DoValueOf(LValueOf* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1873 | Register input = ToRegister(instr->value()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1874 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1875 | Register map = ToRegister(instr->temp()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1876 | Label done; |
| 1877 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1878 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 1879 | // If the object is a smi return the object. |
| 1880 | __ SmiTst(input); |
| 1881 | __ Move(result, input, eq); |
| 1882 | __ b(eq, &done); |
| 1883 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1884 | |
| 1885 | // If the object is not a value type, return the object. |
| 1886 | __ CompareObjectType(input, map, map, JS_VALUE_TYPE); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1887 | __ Move(result, input, ne); |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 1888 | __ ldr(result, FieldMemOperand(input, JSValue::kValueOffset), eq); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1889 | |
| 1890 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1894 | void LCodeGen::DoDateField(LDateField* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1895 | Register object = ToRegister(instr->date()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1896 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1897 | Register scratch = ToRegister(instr->temp()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1898 | Smi* index = instr->index(); |
| 1899 | Label runtime, done; |
| 1900 | ASSERT(object.is(result)); |
| 1901 | ASSERT(object.is(r0)); |
| 1902 | ASSERT(!scratch.is(scratch0())); |
| 1903 | ASSERT(!scratch.is(object)); |
| 1904 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1905 | __ SmiTst(object); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1906 | DeoptimizeIf(eq, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1907 | __ CompareObjectType(object, scratch, scratch, JS_DATE_TYPE); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1908 | DeoptimizeIf(ne, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1909 | |
| 1910 | if (index->value() == 0) { |
| 1911 | __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset)); |
| 1912 | } else { |
| 1913 | if (index->value() < JSDate::kFirstUncachedField) { |
| 1914 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 1915 | __ mov(scratch, Operand(stamp)); |
| 1916 | __ ldr(scratch, MemOperand(scratch)); |
| 1917 | __ ldr(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); |
| 1918 | __ cmp(scratch, scratch0()); |
| 1919 | __ b(ne, &runtime); |
| 1920 | __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset + |
| 1921 | kPointerSize * index->value())); |
| 1922 | __ jmp(&done); |
| 1923 | } |
| 1924 | __ bind(&runtime); |
| 1925 | __ PrepareCallCFunction(2, scratch); |
| 1926 | __ mov(r1, Operand(index)); |
| 1927 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 1928 | __ bind(&done); |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1933 | MemOperand LCodeGen::BuildSeqStringOperand(Register string, |
| 1934 | LOperand* index, |
| 1935 | String::Encoding encoding) { |
| 1936 | if (index->IsConstantOperand()) { |
| 1937 | int offset = ToInteger32(LConstantOperand::cast(index)); |
| 1938 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 1939 | offset *= kUC16Size; |
| 1940 | } |
| 1941 | STATIC_ASSERT(kCharSize == 1); |
| 1942 | return FieldMemOperand(string, SeqString::kHeaderSize + offset); |
| 1943 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1944 | Register scratch = scratch0(); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1945 | ASSERT(!scratch.is(string)); |
| 1946 | ASSERT(!scratch.is(ToRegister(index))); |
| 1947 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1948 | __ add(scratch, string, Operand(ToRegister(index))); |
| 1949 | } else { |
| 1950 | STATIC_ASSERT(kUC16Size == 2); |
| 1951 | __ add(scratch, string, Operand(ToRegister(index), LSL, 1)); |
| 1952 | } |
| 1953 | return FieldMemOperand(scratch, SeqString::kHeaderSize); |
| 1954 | } |
| 1955 | |
| 1956 | |
| 1957 | void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
| 1958 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1959 | Register string = ToRegister(instr->string()); |
| 1960 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1961 | |
| 1962 | if (FLAG_debug_code) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1963 | Register scratch = scratch0(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1964 | __ ldr(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 1965 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1966 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1967 | __ and_(scratch, scratch, |
| 1968 | Operand(kStringRepresentationMask | kStringEncodingMask)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1969 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1970 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1971 | __ cmp(scratch, Operand(encoding == String::ONE_BYTE_ENCODING |
| 1972 | ? one_byte_seq_type : two_byte_seq_type)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1973 | __ Check(eq, kUnexpectedStringType); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1976 | MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 1977 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1978 | __ ldrb(result, operand); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1979 | } else { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1980 | __ ldrh(result, operand); |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | |
| 1985 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 1986 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1987 | Register string = ToRegister(instr->string()); |
| 1988 | Register value = ToRegister(instr->value()); |
| 1989 | |
| 1990 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1991 | Register index = ToRegister(instr->index()); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1992 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1993 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1994 | int encoding_mask = |
| 1995 | instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING |
| 1996 | ? one_byte_seq_type : two_byte_seq_type; |
| 1997 | __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 2001 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 2002 | __ strb(value, operand); |
| 2003 | } else { |
| 2004 | __ strh(value, operand); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2005 | } |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2009 | void LCodeGen::DoThrow(LThrow* instr) { |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2010 | __ push(ToRegister(instr->value())); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2011 | ASSERT(ToRegister(instr->context()).is(cp)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2012 | CallRuntime(Runtime::kThrow, 1, instr); |
| 2013 | |
| 2014 | if (FLAG_debug_code) { |
| 2015 | __ stop("Unreachable code."); |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | void LCodeGen::DoAddI(LAddI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2021 | LOperand* left = instr->left(); |
| 2022 | LOperand* right = instr->right(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2023 | LOperand* result = instr->result(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2024 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 2025 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2026 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2027 | if (right->IsStackSlot() || right->IsArgument()) { |
| 2028 | Register right_reg = EmitLoadRegister(right, ip); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2029 | __ add(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2030 | } else { |
| 2031 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2032 | __ add(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2033 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2034 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2035 | if (can_overflow) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2036 | DeoptimizeIf(vs, instr->environment()); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2041 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2042 | LOperand* left = instr->left(); |
| 2043 | LOperand* right = instr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2044 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2045 | if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2046 | Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2047 | Register left_reg = ToRegister(left); |
| 2048 | Operand right_op = (right->IsRegister() || right->IsConstantOperand()) |
| 2049 | ? ToOperand(right) |
| 2050 | : Operand(EmitLoadRegister(right, ip)); |
| 2051 | Register result_reg = ToRegister(instr->result()); |
| 2052 | __ cmp(left_reg, right_op); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2053 | __ Move(result_reg, left_reg, condition); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2054 | __ mov(result_reg, right_op, LeaveCC, NegateCondition(condition)); |
| 2055 | } else { |
| 2056 | ASSERT(instr->hydrogen()->representation().IsDouble()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2057 | DwVfpRegister left_reg = ToDoubleRegister(left); |
| 2058 | DwVfpRegister right_reg = ToDoubleRegister(right); |
| 2059 | DwVfpRegister result_reg = ToDoubleRegister(instr->result()); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2060 | Label result_is_nan, return_left, return_right, check_zero, done; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2061 | __ VFPCompareAndSetFlags(left_reg, right_reg); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2062 | if (operation == HMathMinMax::kMathMin) { |
| 2063 | __ b(mi, &return_left); |
| 2064 | __ b(gt, &return_right); |
| 2065 | } else { |
| 2066 | __ b(mi, &return_right); |
| 2067 | __ b(gt, &return_left); |
| 2068 | } |
| 2069 | __ b(vs, &result_is_nan); |
| 2070 | // Left equals right => check for -0. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2071 | __ VFPCompareAndSetFlags(left_reg, 0.0); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2072 | if (left_reg.is(result_reg) || right_reg.is(result_reg)) { |
| 2073 | __ b(ne, &done); // left == right != 0. |
| 2074 | } else { |
| 2075 | __ b(ne, &return_left); // left == right != 0. |
| 2076 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2077 | // At this point, both left and right are either 0 or -0. |
| 2078 | if (operation == HMathMinMax::kMathMin) { |
| 2079 | // We could use a single 'vorr' instruction here if we had NEON support. |
| 2080 | __ vneg(left_reg, left_reg); |
| 2081 | __ vsub(result_reg, left_reg, right_reg); |
| 2082 | __ vneg(result_reg, result_reg); |
| 2083 | } else { |
| 2084 | // Since we operate on +0 and/or -0, vadd and vand have the same effect; |
| 2085 | // the decision for vadd is easy because vand is a NEON instruction. |
| 2086 | __ vadd(result_reg, left_reg, right_reg); |
| 2087 | } |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2088 | __ b(&done); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2089 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2090 | __ bind(&result_is_nan); |
| 2091 | __ vadd(result_reg, left_reg, right_reg); |
| 2092 | __ b(&done); |
| 2093 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2094 | __ bind(&return_right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2095 | __ Move(result_reg, right_reg); |
| 2096 | if (!left_reg.is(result_reg)) { |
| 2097 | __ b(&done); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2098 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2099 | |
| 2100 | __ bind(&return_left); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2101 | __ Move(result_reg, left_reg); |
| 2102 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2103 | __ bind(&done); |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2108 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2109 | DwVfpRegister left = ToDoubleRegister(instr->left()); |
| 2110 | DwVfpRegister right = ToDoubleRegister(instr->right()); |
| 2111 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2112 | switch (instr->op()) { |
| 2113 | case Token::ADD: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2114 | __ vadd(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2115 | break; |
| 2116 | case Token::SUB: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2117 | __ vsub(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2118 | break; |
| 2119 | case Token::MUL: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2120 | __ vmul(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2121 | break; |
| 2122 | case Token::DIV: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2123 | __ vdiv(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2124 | break; |
| 2125 | case Token::MOD: { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2126 | __ PrepareCallCFunction(0, 2, scratch0()); |
| 2127 | __ SetCallCDoubleArguments(left, right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2128 | __ CallCFunction( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 2129 | ExternalReference::mod_two_doubles_operation(isolate()), |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2130 | 0, 2); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2131 | // Move the result in the double result register. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2132 | __ GetCFunctionDoubleResult(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2133 | break; |
| 2134 | } |
| 2135 | default: |
| 2136 | UNREACHABLE(); |
| 2137 | break; |
| 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | |
| 2142 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2143 | ASSERT(ToRegister(instr->context()).is(cp)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2144 | ASSERT(ToRegister(instr->left()).is(r1)); |
| 2145 | ASSERT(ToRegister(instr->right()).is(r0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2146 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2147 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2148 | BinaryOpICStub stub(instr->op(), NO_OVERWRITE); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2149 | // Block literal pool emission to ensure nop indicating no inlined smi code |
| 2150 | // is in the correct position. |
| 2151 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2152 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2153 | __ nop(); // Signals no inlined code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2157 | template<class InstrType> |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2158 | void LCodeGen::EmitBranch(InstrType instr, Condition condition) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2159 | int left_block = instr->TrueDestination(chunk_); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2160 | int right_block = instr->FalseDestination(chunk_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2161 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2162 | int next_block = GetNextEmittedBlock(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2163 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2164 | if (right_block == left_block || condition == al) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2165 | EmitGoto(left_block); |
| 2166 | } else if (left_block == next_block) { |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2167 | __ b(NegateCondition(condition), chunk_->GetAssemblyLabel(right_block)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2168 | } else if (right_block == next_block) { |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2169 | __ b(condition, chunk_->GetAssemblyLabel(left_block)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2170 | } else { |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2171 | __ b(condition, chunk_->GetAssemblyLabel(left_block)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2172 | __ b(chunk_->GetAssemblyLabel(right_block)); |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2177 | template<class InstrType> |
| 2178 | void LCodeGen::EmitFalseBranch(InstrType instr, Condition condition) { |
| 2179 | int false_block = instr->FalseDestination(chunk_); |
| 2180 | __ b(condition, chunk_->GetAssemblyLabel(false_block)); |
| 2181 | } |
| 2182 | |
| 2183 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2184 | void LCodeGen::DoDebugBreak(LDebugBreak* instr) { |
| 2185 | __ stop("LBreak"); |
| 2186 | } |
| 2187 | |
| 2188 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2189 | void LCodeGen::DoBranch(LBranch* instr) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2190 | Representation r = instr->hydrogen()->value()->representation(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2191 | if (r.IsInteger32() || r.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2192 | ASSERT(!info()->IsStub()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2193 | Register reg = ToRegister(instr->value()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2194 | __ cmp(reg, Operand::Zero()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2195 | EmitBranch(instr, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2196 | } else if (r.IsDouble()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2197 | ASSERT(!info()->IsStub()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2198 | DwVfpRegister reg = ToDoubleRegister(instr->value()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2199 | // Test the double value. Zero and NaN are false. |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2200 | __ VFPCompareAndSetFlags(reg, 0.0); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2201 | __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN -> false) |
| 2202 | EmitBranch(instr, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2203 | } else { |
| 2204 | ASSERT(r.IsTagged()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2205 | Register reg = ToRegister(instr->value()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2206 | HType type = instr->hydrogen()->value()->type(); |
| 2207 | if (type.IsBoolean()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2208 | ASSERT(!info()->IsStub()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2209 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2210 | EmitBranch(instr, eq); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2211 | } else if (type.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2212 | ASSERT(!info()->IsStub()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2213 | __ cmp(reg, Operand::Zero()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2214 | EmitBranch(instr, ne); |
| 2215 | } else if (type.IsJSArray()) { |
| 2216 | ASSERT(!info()->IsStub()); |
| 2217 | EmitBranch(instr, al); |
| 2218 | } else if (type.IsHeapNumber()) { |
| 2219 | ASSERT(!info()->IsStub()); |
| 2220 | DwVfpRegister dbl_scratch = double_scratch0(); |
| 2221 | __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2222 | // Test the double value. Zero and NaN are false. |
| 2223 | __ VFPCompareAndSetFlags(dbl_scratch, 0.0); |
| 2224 | __ cmp(r0, r0, vs); // If NaN, set the Z flag. (NaN) |
| 2225 | EmitBranch(instr, ne); |
| 2226 | } else if (type.IsString()) { |
| 2227 | ASSERT(!info()->IsStub()); |
| 2228 | __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); |
| 2229 | __ cmp(ip, Operand::Zero()); |
| 2230 | EmitBranch(instr, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2231 | } else { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2232 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 2233 | // Avoid deopts in the case where we've never executed this path before. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2234 | if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2235 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2236 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 2237 | // undefined -> false. |
| 2238 | __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2239 | __ b(eq, instr->FalseLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2240 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2241 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 2242 | // Boolean -> its value. |
| 2243 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2244 | __ b(eq, instr->TrueLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2245 | __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2246 | __ b(eq, instr->FalseLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2247 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2248 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 2249 | // 'null' -> false. |
| 2250 | __ CompareRoot(reg, Heap::kNullValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2251 | __ b(eq, instr->FalseLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 2255 | // Smis: 0 -> false, all other -> true. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2256 | __ cmp(reg, Operand::Zero()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2257 | __ b(eq, instr->FalseLabel(chunk_)); |
| 2258 | __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2259 | } else if (expected.NeedsMap()) { |
| 2260 | // If we need a map later and have a Smi -> deopt. |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2261 | __ SmiTst(reg); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2262 | DeoptimizeIf(eq, instr->environment()); |
| 2263 | } |
| 2264 | |
| 2265 | const Register map = scratch0(); |
| 2266 | if (expected.NeedsMap()) { |
| 2267 | __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2268 | |
| 2269 | if (expected.CanBeUndetectable()) { |
| 2270 | // Undetectable -> false. |
| 2271 | __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 2272 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2273 | __ b(ne, instr->FalseLabel(chunk_)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2274 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 2278 | // spec object -> true. |
| 2279 | __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2280 | __ b(ge, instr->TrueLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 2284 | // String value -> false iff empty. |
| 2285 | Label not_string; |
| 2286 | __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
| 2287 | __ b(ge, ¬_string); |
| 2288 | __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2289 | __ cmp(ip, Operand::Zero()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2290 | __ b(ne, instr->TrueLabel(chunk_)); |
| 2291 | __ b(instr->FalseLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2292 | __ bind(¬_string); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2295 | if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 2296 | // Symbol value -> true. |
| 2297 | __ CompareInstanceType(map, ip, SYMBOL_TYPE); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2298 | __ b(eq, instr->TrueLabel(chunk_)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2301 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 2302 | // heap number -> false iff +0, -0, or NaN. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2303 | DwVfpRegister dbl_scratch = double_scratch0(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2304 | Label not_heap_number; |
| 2305 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 2306 | __ b(ne, ¬_heap_number); |
| 2307 | __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2308 | __ VFPCompareAndSetFlags(dbl_scratch, 0.0); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2309 | __ cmp(r0, r0, vs); // NaN -> false. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2310 | __ b(eq, instr->FalseLabel(chunk_)); // +0, -0 -> false. |
| 2311 | __ b(instr->TrueLabel(chunk_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2312 | __ bind(¬_heap_number); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2315 | if (!expected.IsGeneric()) { |
| 2316 | // We've seen something for the first time -> deopt. |
| 2317 | // This can only happen if we are not generic already. |
| 2318 | DeoptimizeIf(al, instr->environment()); |
| 2319 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2325 | void LCodeGen::EmitGoto(int block) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2326 | if (!IsNextEmittedBlock(block)) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2327 | __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2332 | void LCodeGen::DoGoto(LGoto* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2333 | EmitGoto(instr->block_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | |
| 2337 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2338 | Condition cond = kNoCondition; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2339 | switch (op) { |
| 2340 | case Token::EQ: |
| 2341 | case Token::EQ_STRICT: |
| 2342 | cond = eq; |
| 2343 | break; |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 2344 | case Token::NE: |
| 2345 | case Token::NE_STRICT: |
| 2346 | cond = ne; |
| 2347 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2348 | case Token::LT: |
| 2349 | cond = is_unsigned ? lo : lt; |
| 2350 | break; |
| 2351 | case Token::GT: |
| 2352 | cond = is_unsigned ? hi : gt; |
| 2353 | break; |
| 2354 | case Token::LTE: |
| 2355 | cond = is_unsigned ? ls : le; |
| 2356 | break; |
| 2357 | case Token::GTE: |
| 2358 | cond = is_unsigned ? hs : ge; |
| 2359 | break; |
| 2360 | case Token::IN: |
| 2361 | case Token::INSTANCEOF: |
| 2362 | default: |
| 2363 | UNREACHABLE(); |
| 2364 | } |
| 2365 | return cond; |
| 2366 | } |
| 2367 | |
| 2368 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2369 | void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2370 | LOperand* left = instr->left(); |
| 2371 | LOperand* right = instr->right(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2372 | Condition cond = TokenToCondition(instr->op(), false); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2373 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2374 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2375 | // We can statically evaluate the comparison. |
| 2376 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2377 | double right_val = ToDouble(LConstantOperand::cast(right)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2378 | int next_block = EvalComparison(instr->op(), left_val, right_val) ? |
| 2379 | instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2380 | EmitGoto(next_block); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2381 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2382 | if (instr->is_double()) { |
| 2383 | // Compare left and right operands as doubles and load the |
| 2384 | // resulting flags into the normal status register. |
| 2385 | __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 2386 | // If a NaN is involved, i.e. the result is unordered (V set), |
| 2387 | // jump to false block label. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2388 | __ b(vs, instr->FalseLabel(chunk_)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2389 | } else { |
| 2390 | if (right->IsConstantOperand()) { |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2391 | int32_t value = ToInteger32(LConstantOperand::cast(right)); |
| 2392 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2393 | __ cmp(ToRegister(left), Operand(Smi::FromInt(value))); |
| 2394 | } else { |
| 2395 | __ cmp(ToRegister(left), Operand(value)); |
| 2396 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2397 | } else if (left->IsConstantOperand()) { |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2398 | int32_t value = ToInteger32(LConstantOperand::cast(left)); |
| 2399 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2400 | __ cmp(ToRegister(right), Operand(Smi::FromInt(value))); |
| 2401 | } else { |
| 2402 | __ cmp(ToRegister(right), Operand(value)); |
| 2403 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2404 | // We transposed the operands. Reverse the condition. |
| 2405 | cond = ReverseCondition(cond); |
| 2406 | } else { |
| 2407 | __ cmp(ToRegister(left), ToRegister(right)); |
| 2408 | } |
| 2409 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2410 | EmitBranch(instr, cond); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2411 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 2415 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2416 | Register left = ToRegister(instr->left()); |
| 2417 | Register right = ToRegister(instr->right()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2418 | |
| 2419 | __ cmp(left, Operand(right)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2420 | EmitBranch(instr, eq); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2424 | void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
| 2425 | if (instr->hydrogen()->representation().IsTagged()) { |
| 2426 | Register input_reg = ToRegister(instr->object()); |
| 2427 | __ mov(ip, Operand(factory()->the_hole_value())); |
| 2428 | __ cmp(input_reg, ip); |
| 2429 | EmitBranch(instr, eq); |
| 2430 | return; |
| 2431 | } |
| 2432 | |
| 2433 | DwVfpRegister input_reg = ToDoubleRegister(instr->object()); |
| 2434 | __ VFPCompareAndSetFlags(input_reg, input_reg); |
| 2435 | EmitFalseBranch(instr, vc); |
| 2436 | |
| 2437 | Register scratch = scratch0(); |
| 2438 | __ VmovHigh(scratch, input_reg); |
| 2439 | __ cmp(scratch, Operand(kHoleNanUpper32)); |
| 2440 | EmitBranch(instr, eq); |
| 2441 | } |
| 2442 | |
| 2443 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2444 | void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { |
| 2445 | Representation rep = instr->hydrogen()->value()->representation(); |
| 2446 | ASSERT(!rep.IsInteger32()); |
| 2447 | Register scratch = ToRegister(instr->temp()); |
| 2448 | |
| 2449 | if (rep.IsDouble()) { |
| 2450 | DwVfpRegister value = ToDoubleRegister(instr->value()); |
| 2451 | __ VFPCompareAndSetFlags(value, 0.0); |
| 2452 | EmitFalseBranch(instr, ne); |
| 2453 | __ VmovHigh(scratch, value); |
| 2454 | __ cmp(scratch, Operand(0x80000000)); |
| 2455 | } else { |
| 2456 | Register value = ToRegister(instr->value()); |
| 2457 | __ CheckMap(value, |
| 2458 | scratch, |
| 2459 | Heap::kHeapNumberMapRootIndex, |
| 2460 | instr->FalseLabel(chunk()), |
| 2461 | DO_SMI_CHECK); |
| 2462 | __ ldr(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset)); |
| 2463 | __ ldr(ip, FieldMemOperand(value, HeapNumber::kMantissaOffset)); |
| 2464 | __ cmp(scratch, Operand(0x80000000)); |
| 2465 | __ cmp(ip, Operand(0x00000000), eq); |
| 2466 | } |
| 2467 | EmitBranch(instr, eq); |
| 2468 | } |
| 2469 | |
| 2470 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2471 | Condition LCodeGen::EmitIsObject(Register input, |
| 2472 | Register temp1, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2473 | Label* is_not_object, |
| 2474 | Label* is_object) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2475 | Register temp2 = scratch0(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2476 | __ JumpIfSmi(input, is_not_object); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2477 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2478 | __ LoadRoot(temp2, Heap::kNullValueRootIndex); |
| 2479 | __ cmp(input, temp2); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2480 | __ b(eq, is_object); |
| 2481 | |
| 2482 | // Load map. |
| 2483 | __ ldr(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2484 | // Undetectable objects behave like undefined. |
| 2485 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
| 2486 | __ tst(temp2, Operand(1 << Map::kIsUndetectable)); |
| 2487 | __ b(ne, is_not_object); |
| 2488 | |
| 2489 | // Load instance type and check that it is in object type range. |
| 2490 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2491 | __ cmp(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2492 | __ b(lt, is_not_object); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2493 | __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2494 | return le; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2498 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2499 | Register reg = ToRegister(instr->value()); |
| 2500 | Register temp1 = ToRegister(instr->temp()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2501 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2502 | Condition true_cond = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2503 | EmitIsObject(reg, temp1, |
| 2504 | instr->FalseLabel(chunk_), instr->TrueLabel(chunk_)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2505 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2506 | EmitBranch(instr, true_cond); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2510 | Condition LCodeGen::EmitIsString(Register input, |
| 2511 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2512 | Label* is_not_string, |
| 2513 | SmiCheck check_needed = INLINE_SMI_CHECK) { |
| 2514 | if (check_needed == INLINE_SMI_CHECK) { |
| 2515 | __ JumpIfSmi(input, is_not_string); |
| 2516 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2517 | __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE); |
| 2518 | |
| 2519 | return lt; |
| 2520 | } |
| 2521 | |
| 2522 | |
| 2523 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2524 | Register reg = ToRegister(instr->value()); |
| 2525 | Register temp1 = ToRegister(instr->temp()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2526 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2527 | SmiCheck check_needed = |
| 2528 | instr->hydrogen()->value()->IsHeapObject() |
| 2529 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2530 | Condition true_cond = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2531 | EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2532 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2533 | EmitBranch(instr, true_cond); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2537 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2538 | Register input_reg = EmitLoadRegister(instr->value(), ip); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 2539 | __ SmiTst(input_reg); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2540 | EmitBranch(instr, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2544 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2545 | Register input = ToRegister(instr->value()); |
| 2546 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2547 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2548 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2549 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2550 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2551 | __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2552 | __ ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); |
| 2553 | __ tst(temp, Operand(1 << Map::kIsUndetectable)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2554 | EmitBranch(instr, ne); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2558 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2559 | switch (op) { |
| 2560 | case Token::EQ_STRICT: |
| 2561 | case Token::EQ: |
| 2562 | return eq; |
| 2563 | case Token::LT: |
| 2564 | return lt; |
| 2565 | case Token::GT: |
| 2566 | return gt; |
| 2567 | case Token::LTE: |
| 2568 | return le; |
| 2569 | case Token::GTE: |
| 2570 | return ge; |
| 2571 | default: |
| 2572 | UNREACHABLE(); |
| 2573 | return kNoCondition; |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | |
| 2578 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2579 | ASSERT(ToRegister(instr->context()).is(cp)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2580 | Token::Value op = instr->op(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2581 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2582 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2583 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2584 | // This instruction also signals no smi code inlined. |
| 2585 | __ cmp(r0, Operand::Zero()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2586 | |
| 2587 | Condition condition = ComputeCompareCondition(op); |
| 2588 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2589 | EmitBranch(instr, condition); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2593 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2594 | InstanceType from = instr->from(); |
| 2595 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2596 | if (from == FIRST_TYPE) return to; |
| 2597 | ASSERT(from == to || to == LAST_TYPE); |
| 2598 | return from; |
| 2599 | } |
| 2600 | |
| 2601 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2602 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2603 | InstanceType from = instr->from(); |
| 2604 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2605 | if (from == to) return eq; |
| 2606 | if (to == LAST_TYPE) return hs; |
| 2607 | if (from == FIRST_TYPE) return ls; |
| 2608 | UNREACHABLE(); |
| 2609 | return eq; |
| 2610 | } |
| 2611 | |
| 2612 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2613 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2614 | Register scratch = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2615 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2616 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2617 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2618 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2619 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2620 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2621 | __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2622 | EmitBranch(instr, BranchCondition(instr->hydrogen())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2626 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2627 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2628 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2629 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2630 | __ AssertString(input); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2631 | |
| 2632 | __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset)); |
| 2633 | __ IndexFromHash(result, result); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2637 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2638 | LHasCachedArrayIndexAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2639 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2640 | Register scratch = scratch0(); |
| 2641 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2642 | __ ldr(scratch, |
| 2643 | FieldMemOperand(input, String::kHashFieldOffset)); |
| 2644 | __ tst(scratch, Operand(String::kContainsCachedArrayIndexMask)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2645 | EmitBranch(instr, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2649 | // Branches to a label or falls through with the answer in flags. Trashes |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2650 | // the temp registers, but not the input. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2651 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2652 | Label* is_false, |
| 2653 | Handle<String>class_name, |
| 2654 | Register input, |
| 2655 | Register temp, |
| 2656 | Register temp2) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2657 | ASSERT(!input.is(temp)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2658 | ASSERT(!input.is(temp2)); |
| 2659 | ASSERT(!temp.is(temp2)); |
| 2660 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2661 | __ JumpIfSmi(input, is_false); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2662 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2663 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2664 | // Assuming the following assertions, we can use the same compares to test |
| 2665 | // for both being a function type and being in the object type range. |
| 2666 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2667 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2668 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2669 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2670 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2671 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2672 | __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE); |
| 2673 | __ b(lt, is_false); |
| 2674 | __ b(eq, is_true); |
| 2675 | __ cmp(temp2, Operand(LAST_SPEC_OBJECT_TYPE)); |
| 2676 | __ b(eq, is_true); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2677 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2678 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2679 | // actual type and do a signed compare with the width of the type range. |
| 2680 | __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2681 | __ ldrb(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset)); |
| 2682 | __ sub(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2683 | __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2684 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2685 | __ b(gt, is_false); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2686 | } |
| 2687 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2688 | // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2689 | // Check if the constructor in the map is a function. |
| 2690 | __ ldr(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
| 2691 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2692 | // Objects with a non-function constructor have class 'Object'. |
| 2693 | __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2694 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2695 | __ b(ne, is_true); |
| 2696 | } else { |
| 2697 | __ b(ne, is_false); |
| 2698 | } |
| 2699 | |
| 2700 | // temp now contains the constructor function. Grab the |
| 2701 | // instance class name from there. |
| 2702 | __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2703 | __ ldr(temp, FieldMemOperand(temp, |
| 2704 | SharedFunctionInfo::kInstanceClassNameOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2705 | // The class name we are testing against is internalized since it's a literal. |
| 2706 | // The name in the constructor is internalized because of the way the context |
| 2707 | // is booted. This routine isn't expected to work for random API-created |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2708 | // classes and it doesn't have to because you can't access it with natives |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2709 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2710 | // identity comparison. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2711 | __ cmp(temp, Operand(class_name)); |
| 2712 | // End with the answer in flags. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2716 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2717 | Register input = ToRegister(instr->value()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2718 | Register temp = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2719 | Register temp2 = ToRegister(instr->temp()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2720 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2721 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2722 | EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2723 | class_name, input, temp, temp2); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2724 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2725 | EmitBranch(instr, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | |
| 2729 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2730 | Register reg = ToRegister(instr->value()); |
| 2731 | Register temp = ToRegister(instr->temp()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2732 | |
| 2733 | __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2734 | __ cmp(temp, Operand(instr->map())); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2735 | EmitBranch(instr, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | |
| 2739 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2740 | ASSERT(ToRegister(instr->context()).is(cp)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2741 | ASSERT(ToRegister(instr->left()).is(r0)); // Object is in r0. |
| 2742 | ASSERT(ToRegister(instr->right()).is(r1)); // Function is in r1. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2743 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2744 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2745 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2746 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2747 | __ cmp(r0, Operand::Zero()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2748 | __ mov(r0, Operand(factory()->false_value()), LeaveCC, ne); |
| 2749 | __ mov(r0, Operand(factory()->true_value()), LeaveCC, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2753 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2754 | class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2755 | public: |
| 2756 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2757 | LInstanceOfKnownGlobal* instr) |
| 2758 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2759 | virtual void Generate() V8_OVERRIDE { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2760 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2761 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2762 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2763 | Label* map_check() { return &map_check_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2764 | private: |
| 2765 | LInstanceOfKnownGlobal* instr_; |
| 2766 | Label map_check_; |
| 2767 | }; |
| 2768 | |
| 2769 | DeferredInstanceOfKnownGlobal* deferred; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2770 | deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2771 | |
| 2772 | Label done, false_result; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2773 | Register object = ToRegister(instr->value()); |
| 2774 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2775 | Register result = ToRegister(instr->result()); |
| 2776 | |
| 2777 | ASSERT(object.is(r0)); |
| 2778 | ASSERT(result.is(r0)); |
| 2779 | |
| 2780 | // A Smi is not instance of anything. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2781 | __ JumpIfSmi(object, &false_result); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2782 | |
| 2783 | // This is the inlined call site instanceof cache. The two occurences of the |
| 2784 | // hole value will be patched to the last map/result pair generated by the |
| 2785 | // instanceof stub. |
| 2786 | Label cache_miss; |
| 2787 | Register map = temp; |
| 2788 | __ ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2789 | { |
| 2790 | // Block constant pool emission to ensure the positions of instructions are |
| 2791 | // as expected by the patcher. See InstanceofStub::Generate(). |
| 2792 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
| 2793 | __ bind(deferred->map_check()); // Label for calculating code patching. |
| 2794 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2795 | // root array to force relocation to be able to later patch with |
| 2796 | // the cached map. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2797 | PredictableCodeSizeScope predictable(masm_, 5 * Assembler::kInstrSize); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2798 | Handle<Cell> cell = factory()->NewCell(factory()->the_hole_value()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2799 | __ mov(ip, Operand(Handle<Object>(cell))); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2800 | __ ldr(ip, FieldMemOperand(ip, PropertyCell::kValueOffset)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2801 | __ cmp(map, Operand(ip)); |
| 2802 | __ b(ne, &cache_miss); |
| 2803 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2804 | // root array to force relocation to be able to later patch |
| 2805 | // with true or false. |
| 2806 | __ mov(result, Operand(factory()->the_hole_value())); |
| 2807 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2808 | __ b(&done); |
| 2809 | |
| 2810 | // The inlined call site cache did not match. Check null and string before |
| 2811 | // calling the deferred code. |
| 2812 | __ bind(&cache_miss); |
| 2813 | // Null is not instance of anything. |
| 2814 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2815 | __ cmp(object, Operand(ip)); |
| 2816 | __ b(eq, &false_result); |
| 2817 | |
| 2818 | // String values is not instance of anything. |
| 2819 | Condition is_string = masm_->IsObjectStringType(object, temp); |
| 2820 | __ b(is_string, &false_result); |
| 2821 | |
| 2822 | // Go to the deferred code. |
| 2823 | __ b(deferred->entry()); |
| 2824 | |
| 2825 | __ bind(&false_result); |
| 2826 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 2827 | |
| 2828 | // Here result has either true or false. Deferred code also produces true or |
| 2829 | // false object. |
| 2830 | __ bind(deferred->exit()); |
| 2831 | __ bind(&done); |
| 2832 | } |
| 2833 | |
| 2834 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2835 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2836 | Label* map_check) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2837 | Register result = ToRegister(instr->result()); |
| 2838 | ASSERT(result.is(r0)); |
| 2839 | |
| 2840 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 2841 | flags = static_cast<InstanceofStub::Flags>( |
| 2842 | flags | InstanceofStub::kArgsInRegisters); |
| 2843 | flags = static_cast<InstanceofStub::Flags>( |
| 2844 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 2845 | flags = static_cast<InstanceofStub::Flags>( |
| 2846 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 2847 | InstanceofStub stub(flags); |
| 2848 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2849 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2850 | LoadContextFromDeferred(instr->context()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2851 | |
| 2852 | // Get the temp register reserved by the instruction. This needs to be r4 as |
| 2853 | // its slot of the pushing of safepoint registers is used to communicate the |
| 2854 | // offset to the location of the map check. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2855 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2856 | ASSERT(temp.is(r4)); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 2857 | __ Move(InstanceofStub::right(), instr->function()); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2858 | static const int kAdditionalDelta = 5; |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2859 | // Make sure that code size is predicable, since we use specific constants |
| 2860 | // offsets in the code to find embedded values.. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2861 | PredictableCodeSizeScope predictable(masm_, 6 * Assembler::kInstrSize); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2862 | int delta = masm_->InstructionsGeneratedSince(map_check) + kAdditionalDelta; |
| 2863 | Label before_push_delta; |
| 2864 | __ bind(&before_push_delta); |
| 2865 | __ BlockConstPoolFor(kAdditionalDelta); |
| 2866 | __ mov(temp, Operand(delta * kPointerSize)); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2867 | // The mov above can generate one or two instructions. The delta was computed |
| 2868 | // for two instructions, so we need to pad here in case of one instruction. |
| 2869 | if (masm_->InstructionsGeneratedSince(&before_push_delta) != 2) { |
| 2870 | ASSERT_EQ(1, masm_->InstructionsGeneratedSince(&before_push_delta)); |
| 2871 | __ nop(); |
| 2872 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2873 | __ StoreToSafepointRegisterSlot(temp, temp); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2874 | CallCodeGeneric(stub.GetCode(isolate()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2875 | RelocInfo::CODE_TARGET, |
| 2876 | instr, |
| 2877 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2878 | LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2879 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2880 | // Put the result value into the result register slot and |
| 2881 | // restore all registers. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2882 | __ StoreToSafepointRegisterSlot(result, result); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2885 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2886 | void LCodeGen::DoCmpT(LCmpT* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2887 | ASSERT(ToRegister(instr->context()).is(cp)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2888 | Token::Value op = instr->op(); |
| 2889 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2890 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2891 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2892 | // This instruction also signals no smi code inlined. |
| 2893 | __ cmp(r0, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2894 | |
| 2895 | Condition condition = ComputeCompareCondition(op); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2896 | __ LoadRoot(ToRegister(instr->result()), |
| 2897 | Heap::kTrueValueRootIndex, |
| 2898 | condition); |
| 2899 | __ LoadRoot(ToRegister(instr->result()), |
| 2900 | Heap::kFalseValueRootIndex, |
| 2901 | NegateCondition(condition)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2905 | void LCodeGen::DoReturn(LReturn* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2906 | if (FLAG_trace && info()->IsOptimizing()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2907 | // Push the return value on the stack as the parameter. |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2908 | // Runtime::TraceExit returns its parameter in r0. We're leaving the code |
| 2909 | // managed by the register allocator and tearing down the frame, it's |
| 2910 | // safe to write to the context register. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2911 | __ push(r0); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2912 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2913 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 2914 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2915 | if (info()->saves_caller_doubles()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2916 | RestoreCallerDoubles(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2917 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2918 | int no_frame_start = -1; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2919 | if (NeedsEagerFrame()) { |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 2920 | no_frame_start = masm_->LeaveFrame(StackFrame::JAVA_SCRIPT); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2921 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2922 | if (instr->has_constant_parameter_count()) { |
| 2923 | int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 2924 | int32_t sp_delta = (parameter_count + 1) * kPointerSize; |
| 2925 | if (sp_delta != 0) { |
| 2926 | __ add(sp, sp, Operand(sp_delta)); |
| 2927 | } |
| 2928 | } else { |
| 2929 | Register reg = ToRegister(instr->parameter_count()); |
| 2930 | // The argument count parameter is a smi |
| 2931 | __ SmiUntag(reg); |
| 2932 | __ add(sp, sp, Operand(reg, LSL, kPointerSizeLog2)); |
| 2933 | } |
| 2934 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2935 | __ Jump(lr); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2936 | |
| 2937 | if (no_frame_start != -1) { |
| 2938 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 2939 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2943 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2944 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2945 | __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell().handle()))); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2946 | __ ldr(result, FieldMemOperand(ip, Cell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2947 | if (instr->hydrogen()->RequiresHoleCheck()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2948 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2949 | __ cmp(result, ip); |
| 2950 | DeoptimizeIf(eq, instr->environment()); |
| 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2955 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2956 | ASSERT(ToRegister(instr->context()).is(cp)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2957 | ASSERT(ToRegister(instr->global_object()).is(r0)); |
| 2958 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2959 | |
| 2960 | __ mov(r2, Operand(instr->name())); |
| 2961 | RelocInfo::Mode mode = instr->for_typeof() ? RelocInfo::CODE_TARGET |
| 2962 | : RelocInfo::CODE_TARGET_CONTEXT; |
| 2963 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2964 | CallCode(ic, mode, instr); |
| 2965 | } |
| 2966 | |
| 2967 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2968 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2969 | Register value = ToRegister(instr->value()); |
| 2970 | Register cell = scratch0(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2971 | |
| 2972 | // Load the cell. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2973 | __ mov(cell, Operand(instr->hydrogen()->cell().handle())); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2974 | |
| 2975 | // If the cell we are storing to contains the hole it could have |
| 2976 | // been deleted from the property dictionary. In that case, we need |
| 2977 | // to update the property details in the property dictionary to mark |
| 2978 | // it as no longer deleted. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2979 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2980 | // We use a temp to check the payload (CompareRoot might clobber ip). |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2981 | Register payload = ToRegister(instr->temp()); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2982 | __ ldr(payload, FieldMemOperand(cell, Cell::kValueOffset)); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2983 | __ CompareRoot(payload, Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2984 | DeoptimizeIf(eq, instr->environment()); |
| 2985 | } |
| 2986 | |
| 2987 | // Store the value. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2988 | __ str(value, FieldMemOperand(cell, Cell::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2989 | // Cells are always rescanned, so no write barrier here. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2993 | void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 2994 | ASSERT(ToRegister(instr->context()).is(cp)); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2995 | ASSERT(ToRegister(instr->global_object()).is(r1)); |
| 2996 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 2997 | |
| 2998 | __ mov(r2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2999 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3000 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 3001 | : isolate()->builtins()->StoreIC_Initialize(); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3002 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
| 3003 | } |
| 3004 | |
| 3005 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3006 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3007 | Register context = ToRegister(instr->context()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3008 | Register result = ToRegister(instr->result()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3009 | __ ldr(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3010 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3011 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3012 | __ cmp(result, ip); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3013 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3014 | DeoptimizeIf(eq, instr->environment()); |
| 3015 | } else { |
| 3016 | __ mov(result, Operand(factory()->undefined_value()), LeaveCC, eq); |
| 3017 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3018 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3022 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 3023 | Register context = ToRegister(instr->context()); |
| 3024 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3025 | Register scratch = scratch0(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3026 | MemOperand target = ContextOperand(context, instr->slot_index()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3027 | |
| 3028 | Label skip_assignment; |
| 3029 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3030 | if (instr->hydrogen()->RequiresHoleCheck()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3031 | __ ldr(scratch, target); |
| 3032 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3033 | __ cmp(scratch, ip); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3034 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3035 | DeoptimizeIf(eq, instr->environment()); |
| 3036 | } else { |
| 3037 | __ b(ne, &skip_assignment); |
| 3038 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3039 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3040 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3041 | __ str(value, target); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3042 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3043 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3044 | instr->hydrogen()->value()->IsHeapObject() |
| 3045 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3046 | __ RecordWriteContextSlot(context, |
| 3047 | target.offset(), |
| 3048 | value, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3049 | scratch, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 3050 | GetLinkRegisterState(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3051 | kSaveFPRegs, |
| 3052 | EMIT_REMEMBERED_SET, |
| 3053 | check_needed); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3054 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3055 | |
| 3056 | __ bind(&skip_assignment); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3060 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3061 | HObjectAccess access = instr->hydrogen()->access(); |
| 3062 | int offset = access.offset(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3063 | Register object = ToRegister(instr->object()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3064 | |
| 3065 | if (access.IsExternalMemory()) { |
| 3066 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3067 | MemOperand operand = MemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3068 | __ Load(result, operand, access.representation()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3069 | return; |
| 3070 | } |
| 3071 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3072 | if (instr->hydrogen()->representation().IsDouble()) { |
| 3073 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3074 | __ vldr(result, FieldMemOperand(object, offset)); |
| 3075 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3078 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3079 | if (!access.IsInobject()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3080 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 3081 | object = result; |
| 3082 | } |
| 3083 | MemOperand operand = FieldMemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 3084 | __ Load(result, operand, access.representation()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | |
| 3088 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3089 | ASSERT(ToRegister(instr->context()).is(cp)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3090 | ASSERT(ToRegister(instr->object()).is(r0)); |
| 3091 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3092 | |
| 3093 | // Name is always in r2. |
| 3094 | __ mov(r2, Operand(instr->name())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3095 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3096 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3100 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3101 | Register scratch = scratch0(); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3102 | Register function = ToRegister(instr->function()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3103 | Register result = ToRegister(instr->result()); |
| 3104 | |
| 3105 | // Check that the function really is a function. Load map into the |
| 3106 | // result register. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3107 | __ CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3108 | DeoptimizeIf(ne, instr->environment()); |
| 3109 | |
| 3110 | // Make sure that the function has an instance prototype. |
| 3111 | Label non_instance; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3112 | __ ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 3113 | __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3114 | __ b(ne, &non_instance); |
| 3115 | |
| 3116 | // Get the prototype or initial map from the function. |
| 3117 | __ ldr(result, |
| 3118 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 3119 | |
| 3120 | // Check that the function has a prototype or an initial map. |
| 3121 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3122 | __ cmp(result, ip); |
| 3123 | DeoptimizeIf(eq, instr->environment()); |
| 3124 | |
| 3125 | // If the function does not have an initial map, we're done. |
| 3126 | Label done; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3127 | __ CompareObjectType(result, scratch, scratch, MAP_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3128 | __ b(ne, &done); |
| 3129 | |
| 3130 | // Get the prototype from the initial map. |
| 3131 | __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 3132 | __ jmp(&done); |
| 3133 | |
| 3134 | // Non-instance prototype: Fetch prototype from constructor field |
| 3135 | // in initial map. |
| 3136 | __ bind(&non_instance); |
| 3137 | __ ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 3138 | |
| 3139 | // All done. |
| 3140 | __ bind(&done); |
| 3141 | } |
| 3142 | |
| 3143 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3144 | void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
| 3145 | Register result = ToRegister(instr->result()); |
| 3146 | __ LoadRoot(result, instr->index()); |
| 3147 | } |
| 3148 | |
| 3149 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3150 | void LCodeGen::DoLoadExternalArrayPointer( |
| 3151 | LLoadExternalArrayPointer* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3152 | Register to_reg = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3153 | Register from_reg = ToRegister(instr->object()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3154 | __ ldr(to_reg, FieldMemOperand(from_reg, |
| 3155 | ExternalArray::kExternalPointerOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3159 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3160 | Register arguments = ToRegister(instr->arguments()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3161 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 3162 | // There are two words between the frame pointer and the last argument. |
| 3163 | // Subtracting from length accounts for one of them add one more. |
| 3164 | if (instr->length()->IsConstantOperand()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3165 | int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 3166 | if (instr->index()->IsConstantOperand()) { |
| 3167 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3168 | int index = (const_length - const_index) + 1; |
| 3169 | __ ldr(result, MemOperand(arguments, index * kPointerSize)); |
| 3170 | } else { |
| 3171 | Register index = ToRegister(instr->index()); |
| 3172 | __ rsb(result, index, Operand(const_length + 1)); |
| 3173 | __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); |
| 3174 | } |
| 3175 | } else if (instr->index()->IsConstantOperand()) { |
| 3176 | Register length = ToRegister(instr->length()); |
| 3177 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3178 | int loc = const_index - 1; |
| 3179 | if (loc != 0) { |
| 3180 | __ sub(result, length, Operand(loc)); |
| 3181 | __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); |
| 3182 | } else { |
| 3183 | __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2)); |
| 3184 | } |
| 3185 | } else { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3186 | Register length = ToRegister(instr->length()); |
| 3187 | Register index = ToRegister(instr->index()); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 3188 | __ sub(result, length, index); |
| 3189 | __ add(result, result, Operand(1)); |
| 3190 | __ ldr(result, MemOperand(arguments, result, LSL, kPointerSizeLog2)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3191 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3195 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
| 3196 | Register external_pointer = ToRegister(instr->elements()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3197 | Register key = no_reg; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3198 | ElementsKind elements_kind = instr->elements_kind(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3199 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3200 | int constant_key = 0; |
| 3201 | if (key_is_constant) { |
| 3202 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3203 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3204 | Abort(kArrayIndexConstantValueTooBig); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3205 | } |
| 3206 | } else { |
| 3207 | key = ToRegister(instr->key()); |
| 3208 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3209 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3210 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3211 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 3212 | int additional_offset = instr->additional_index() << element_size_shift; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3213 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3214 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 3215 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3216 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3217 | Operand operand = key_is_constant |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3218 | ? Operand(constant_key << element_size_shift) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3219 | : Operand(key, LSL, shift_size); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3220 | __ add(scratch0(), external_pointer, operand); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3221 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3222 | __ vldr(double_scratch0().low(), scratch0(), additional_offset); |
| 3223 | __ vcvt_f64_f32(result, double_scratch0().low()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3224 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
| 3225 | __ vldr(result, scratch0(), additional_offset); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3226 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3227 | } else { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3228 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3229 | MemOperand mem_operand = PrepareKeyedOperand( |
| 3230 | key, external_pointer, key_is_constant, constant_key, |
| 3231 | element_size_shift, shift_size, |
| 3232 | instr->additional_index(), additional_offset); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3233 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3234 | case EXTERNAL_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3235 | __ ldrsb(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3236 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3237 | case EXTERNAL_PIXEL_ELEMENTS: |
| 3238 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3239 | __ ldrb(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3240 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3241 | case EXTERNAL_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3242 | __ ldrsh(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3243 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3244 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3245 | __ ldrh(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3246 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3247 | case EXTERNAL_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3248 | __ ldr(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3249 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3250 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3251 | __ ldr(result, mem_operand); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3252 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 3253 | __ cmp(result, Operand(0x80000000)); |
| 3254 | DeoptimizeIf(cs, instr->environment()); |
| 3255 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3256 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3257 | case EXTERNAL_FLOAT_ELEMENTS: |
| 3258 | case EXTERNAL_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3259 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 3260 | case FAST_HOLEY_ELEMENTS: |
| 3261 | case FAST_HOLEY_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3262 | case FAST_DOUBLE_ELEMENTS: |
| 3263 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3264 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3265 | case DICTIONARY_ELEMENTS: |
| 3266 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3267 | UNREACHABLE(); |
| 3268 | break; |
| 3269 | } |
| 3270 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3274 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
| 3275 | Register elements = ToRegister(instr->elements()); |
| 3276 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3277 | Register key = no_reg; |
| 3278 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3279 | Register scratch = scratch0(); |
| 3280 | |
| 3281 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3282 | |
| 3283 | int base_offset = |
| 3284 | FixedDoubleArray::kHeaderSize - kHeapObjectTag + |
| 3285 | (instr->additional_index() << element_size_shift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3286 | if (key_is_constant) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3287 | int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3288 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3289 | Abort(kArrayIndexConstantValueTooBig); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3290 | } |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3291 | base_offset += constant_key << element_size_shift; |
| 3292 | } |
| 3293 | __ add(scratch, elements, Operand(base_offset)); |
| 3294 | |
| 3295 | if (!key_is_constant) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3296 | key = ToRegister(instr->key()); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3297 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
| 3298 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 3299 | __ add(scratch, scratch, Operand(key, LSL, shift_size)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3302 | __ vldr(result, scratch, 0); |
| 3303 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3304 | if (instr->hydrogen()->RequiresHoleCheck()) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3305 | __ ldr(scratch, MemOperand(scratch, sizeof(kHoleNanLower32))); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3306 | __ cmp(scratch, Operand(kHoleNanUpper32)); |
| 3307 | DeoptimizeIf(eq, instr->environment()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3308 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | |
| 3312 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3313 | Register elements = ToRegister(instr->elements()); |
| 3314 | Register result = ToRegister(instr->result()); |
| 3315 | Register scratch = scratch0(); |
| 3316 | Register store_base = scratch; |
| 3317 | int offset = 0; |
| 3318 | |
| 3319 | if (instr->key()->IsConstantOperand()) { |
| 3320 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 3321 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 3322 | instr->additional_index()); |
| 3323 | store_base = elements; |
| 3324 | } else { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3325 | Register key = ToRegister(instr->key()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3326 | // Even though the HLoadKeyed instruction forces the input |
| 3327 | // representation for the key to be an integer, the input gets replaced |
| 3328 | // during bound check elimination with the index argument to the bounds |
| 3329 | // check, which can be tagged, so that case must be handled here, too. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3330 | if (instr->hydrogen()->key()->representation().IsSmi()) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3331 | __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3332 | } else { |
| 3333 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 3334 | } |
| 3335 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 3336 | } |
| 3337 | __ ldr(result, FieldMemOperand(store_base, offset)); |
| 3338 | |
| 3339 | // Check for the hole value. |
| 3340 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3341 | if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3342 | __ SmiTst(result); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3343 | DeoptimizeIf(ne, instr->environment()); |
| 3344 | } else { |
| 3345 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 3346 | __ cmp(result, scratch); |
| 3347 | DeoptimizeIf(eq, instr->environment()); |
| 3348 | } |
| 3349 | } |
| 3350 | } |
| 3351 | |
| 3352 | |
| 3353 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
| 3354 | if (instr->is_external()) { |
| 3355 | DoLoadKeyedExternalArray(instr); |
| 3356 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3357 | DoLoadKeyedFixedDoubleArray(instr); |
| 3358 | } else { |
| 3359 | DoLoadKeyedFixedArray(instr); |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | |
| 3364 | MemOperand LCodeGen::PrepareKeyedOperand(Register key, |
| 3365 | Register base, |
| 3366 | bool key_is_constant, |
| 3367 | int constant_key, |
| 3368 | int element_size, |
| 3369 | int shift_size, |
| 3370 | int additional_index, |
| 3371 | int additional_offset) { |
| 3372 | if (additional_index != 0 && !key_is_constant) { |
| 3373 | additional_index *= 1 << (element_size - shift_size); |
| 3374 | __ add(scratch0(), key, Operand(additional_index)); |
| 3375 | } |
| 3376 | |
| 3377 | if (key_is_constant) { |
| 3378 | return MemOperand(base, |
| 3379 | (constant_key << element_size) + additional_offset); |
| 3380 | } |
| 3381 | |
| 3382 | if (additional_index == 0) { |
| 3383 | if (shift_size >= 0) { |
| 3384 | return MemOperand(base, key, LSL, shift_size); |
| 3385 | } else { |
| 3386 | ASSERT_EQ(-1, shift_size); |
| 3387 | return MemOperand(base, key, LSR, 1); |
| 3388 | } |
| 3389 | } |
| 3390 | |
| 3391 | if (shift_size >= 0) { |
| 3392 | return MemOperand(base, scratch0(), LSL, shift_size); |
| 3393 | } else { |
| 3394 | ASSERT_EQ(-1, shift_size); |
| 3395 | return MemOperand(base, scratch0(), LSR, 1); |
| 3396 | } |
| 3397 | } |
| 3398 | |
| 3399 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3400 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3401 | ASSERT(ToRegister(instr->context()).is(cp)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3402 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 3403 | ASSERT(ToRegister(instr->key()).is(r0)); |
| 3404 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3405 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3406 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | |
| 3410 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3411 | Register scratch = scratch0(); |
| 3412 | Register result = ToRegister(instr->result()); |
| 3413 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3414 | if (instr->hydrogen()->from_inlined()) { |
| 3415 | __ sub(result, sp, Operand(2 * kPointerSize)); |
| 3416 | } else { |
| 3417 | // Check if the calling frame is an arguments adaptor frame. |
| 3418 | Label done, adapted; |
| 3419 | __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3420 | __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 3421 | __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3422 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3423 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3424 | // frame below the adaptor frame if adapted. |
| 3425 | __ mov(result, fp, LeaveCC, ne); |
| 3426 | __ mov(result, scratch, LeaveCC, eq); |
| 3427 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | |
| 3431 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3432 | Register elem = ToRegister(instr->elements()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3433 | Register result = ToRegister(instr->result()); |
| 3434 | |
| 3435 | Label done; |
| 3436 | |
| 3437 | // If no arguments adaptor frame the number of arguments is fixed. |
| 3438 | __ cmp(fp, elem); |
| 3439 | __ mov(result, Operand(scope()->num_parameters())); |
| 3440 | __ b(eq, &done); |
| 3441 | |
| 3442 | // Arguments adaptor frame present. Get argument length from there. |
| 3443 | __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3444 | __ ldr(result, |
| 3445 | MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3446 | __ SmiUntag(result); |
| 3447 | |
| 3448 | // Argument length is in result register. |
| 3449 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3453 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3454 | Register receiver = ToRegister(instr->receiver()); |
| 3455 | Register function = ToRegister(instr->function()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3456 | Register result = ToRegister(instr->result()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3457 | Register scratch = scratch0(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3458 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3459 | // If the receiver is null or undefined, we have to pass the global |
| 3460 | // object as a receiver to normal functions. Values have to be |
| 3461 | // passed unchanged to builtins and strict-mode functions. |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3462 | Label global_object, result_in_receiver; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3463 | |
| 3464 | // Do not transform the receiver to object for strict mode |
| 3465 | // functions. |
| 3466 | __ ldr(scratch, |
| 3467 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3468 | __ ldr(scratch, |
| 3469 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 3470 | __ tst(scratch, |
| 3471 | Operand(1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize))); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3472 | __ b(ne, &result_in_receiver); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3473 | |
| 3474 | // Do not transform the receiver to object for builtins. |
| 3475 | __ tst(scratch, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize))); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3476 | __ b(ne, &result_in_receiver); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3477 | |
| 3478 | // Normal function. Replace undefined or null with global receiver. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3479 | __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
| 3480 | __ cmp(receiver, scratch); |
| 3481 | __ b(eq, &global_object); |
| 3482 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 3483 | __ cmp(receiver, scratch); |
| 3484 | __ b(eq, &global_object); |
| 3485 | |
| 3486 | // Deoptimize if the receiver is not a JS object. |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3487 | __ SmiTst(receiver); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3488 | DeoptimizeIf(eq, instr->environment()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3489 | __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE); |
| 3490 | DeoptimizeIf(lt, instr->environment()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3491 | __ b(&result_in_receiver); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3492 | |
| 3493 | __ bind(&global_object); |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame^] | 3494 | CallStubCompiler::FetchGlobalProxy(masm(), receiver, function); |
ulan@chromium.org | 19aca23 | 2013-12-30 09:24:30 +0000 | [diff] [blame] | 3495 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3496 | if (result.is(receiver)) { |
| 3497 | __ bind(&result_in_receiver); |
| 3498 | } else { |
| 3499 | Label result_ok; |
| 3500 | __ b(&result_ok); |
| 3501 | __ bind(&result_in_receiver); |
| 3502 | __ mov(result, receiver); |
| 3503 | __ bind(&result_ok); |
| 3504 | } |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | |
| 3508 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3509 | Register receiver = ToRegister(instr->receiver()); |
| 3510 | Register function = ToRegister(instr->function()); |
| 3511 | Register length = ToRegister(instr->length()); |
| 3512 | Register elements = ToRegister(instr->elements()); |
| 3513 | Register scratch = scratch0(); |
| 3514 | ASSERT(receiver.is(r0)); // Used for parameter count. |
| 3515 | ASSERT(function.is(r1)); // Required by InvokeFunction. |
| 3516 | ASSERT(ToRegister(instr->result()).is(r0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3517 | |
| 3518 | // Copy the arguments to this function possibly from the |
| 3519 | // adaptor frame below it. |
| 3520 | const uint32_t kArgumentsLimit = 1 * KB; |
| 3521 | __ cmp(length, Operand(kArgumentsLimit)); |
| 3522 | DeoptimizeIf(hi, instr->environment()); |
| 3523 | |
| 3524 | // Push the receiver and use the register to keep the original |
| 3525 | // number of arguments. |
| 3526 | __ push(receiver); |
| 3527 | __ mov(receiver, length); |
| 3528 | // The arguments are at a one pointer size offset from elements. |
| 3529 | __ add(elements, elements, Operand(1 * kPointerSize)); |
| 3530 | |
| 3531 | // Loop through the arguments pushing them onto the execution |
| 3532 | // stack. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3533 | Label invoke, loop; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3534 | // length is a small non-negative integer, due to the test above. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3535 | __ cmp(length, Operand::Zero()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3536 | __ b(eq, &invoke); |
| 3537 | __ bind(&loop); |
| 3538 | __ ldr(scratch, MemOperand(elements, length, LSL, 2)); |
| 3539 | __ push(scratch); |
| 3540 | __ sub(length, length, Operand(1), SetCC); |
| 3541 | __ b(ne, &loop); |
| 3542 | |
| 3543 | __ bind(&invoke); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3544 | ASSERT(instr->HasPointerMap()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3545 | LPointerMap* pointers = instr->pointer_map(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3546 | SafepointGenerator safepoint_generator( |
| 3547 | this, pointers, Safepoint::kLazyDeopt); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3548 | // The number of arguments is stored in receiver which is r0, as expected |
| 3549 | // by InvokeFunction. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3550 | ParameterCount actual(receiver); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3551 | __ InvokeFunction(function, actual, CALL_FUNCTION, |
| 3552 | safepoint_generator, CALL_AS_METHOD); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | |
| 3556 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3557 | LOperand* argument = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3558 | if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3559 | Abort(kDoPushArgumentNotImplementedForDoubleType); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3560 | } else { |
| 3561 | Register argument_reg = EmitLoadRegister(argument, ip); |
| 3562 | __ push(argument_reg); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3567 | void LCodeGen::DoDrop(LDrop* instr) { |
| 3568 | __ Drop(instr->count()); |
| 3569 | } |
| 3570 | |
| 3571 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3572 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3573 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3574 | __ ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3578 | void LCodeGen::DoContext(LContext* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3579 | // If there is a non-return use, the context must be moved to a register. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3580 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3581 | if (info()->IsOptimizing()) { |
| 3582 | __ ldr(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3583 | } else { |
| 3584 | // If there is no frame, the context must be in cp. |
| 3585 | ASSERT(result.is(cp)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3586 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | |
| 3590 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 3591 | Register context = ToRegister(instr->context()); |
| 3592 | Register result = ToRegister(instr->result()); |
| 3593 | __ ldr(result, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3594 | MemOperand(context, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3598 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3599 | ASSERT(ToRegister(instr->context()).is(cp)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3600 | __ push(cp); // The context is the first argument. |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3601 | __ Move(scratch0(), instr->hydrogen()->pairs()); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3602 | __ push(scratch0()); |
| 3603 | __ mov(scratch0(), Operand(Smi::FromInt(instr->hydrogen()->flags()))); |
| 3604 | __ push(scratch0()); |
| 3605 | CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
| 3606 | } |
| 3607 | |
| 3608 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3609 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3610 | Register context = ToRegister(instr->context()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3611 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3612 | __ ldr(result, ContextOperand(context, Context::GLOBAL_OBJECT_INDEX)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | |
| 3616 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3617 | Register global = ToRegister(instr->global_object()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3618 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3619 | __ ldr(result, FieldMemOperand(global, GlobalObject::kGlobalReceiverOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | |
| 3623 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3624 | int formal_parameter_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3625 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3626 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3627 | CallKind call_kind, |
| 3628 | R1State r1_state) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3629 | bool dont_adapt_arguments = |
| 3630 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3631 | bool can_invoke_directly = |
| 3632 | dont_adapt_arguments || formal_parameter_count == arity; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3633 | |
| 3634 | LPointerMap* pointers = instr->pointer_map(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3635 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3636 | if (can_invoke_directly) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3637 | if (r1_state == R1_UNINITIALIZED) { |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3638 | __ Move(r1, function); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3641 | // Change context. |
| 3642 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3643 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3644 | // Set r0 to arguments count if adaption is not needed. Assumes that r0 |
| 3645 | // is available to write to at this point. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3646 | if (dont_adapt_arguments) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3647 | __ mov(r0, Operand(arity)); |
| 3648 | } |
| 3649 | |
| 3650 | // Invoke function. |
| 3651 | __ SetCallKind(r5, call_kind); |
| 3652 | __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 3653 | __ Call(ip); |
| 3654 | |
| 3655 | // Set up deoptimization. |
| 3656 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3657 | } else { |
| 3658 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3659 | ParameterCount count(arity); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3660 | ParameterCount expected(formal_parameter_count); |
| 3661 | __ InvokeFunction( |
| 3662 | function, expected, count, CALL_FUNCTION, generator, call_kind); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3663 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | |
| 3667 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3668 | ASSERT(ToRegister(instr->result()).is(r0)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3669 | CallKnownFunction(instr->hydrogen()->function(), |
| 3670 | instr->hydrogen()->formal_parameter_count(), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3671 | instr->arity(), |
| 3672 | instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3673 | CALL_AS_METHOD, |
| 3674 | R1_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3678 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3679 | ASSERT(instr->context() != NULL); |
| 3680 | ASSERT(ToRegister(instr->context()).is(cp)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3681 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3682 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3683 | Register scratch = scratch0(); |
| 3684 | |
| 3685 | // Deoptimize if not a heap number. |
| 3686 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3687 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3688 | __ cmp(scratch, Operand(ip)); |
| 3689 | DeoptimizeIf(ne, instr->environment()); |
| 3690 | |
| 3691 | Label done; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3692 | Register exponent = scratch0(); |
| 3693 | scratch = no_reg; |
| 3694 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3695 | // Check the sign of the argument. If the argument is positive, just |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3696 | // return it. |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3697 | __ tst(exponent, Operand(HeapNumber::kSignMask)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3698 | // Move the input to the result if necessary. |
| 3699 | __ Move(result, input); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3700 | __ b(eq, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3701 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3702 | // Input is negative. Reverse its sign. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3703 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3704 | { |
| 3705 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3706 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3707 | // Registers were saved at the safepoint, so we can use |
| 3708 | // many scratch registers. |
| 3709 | Register tmp1 = input.is(r1) ? r0 : r1; |
| 3710 | Register tmp2 = input.is(r2) ? r0 : r2; |
| 3711 | Register tmp3 = input.is(r3) ? r0 : r3; |
| 3712 | Register tmp4 = input.is(r4) ? r0 : r4; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3713 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3714 | // exponent: floating point exponent value. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3715 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3716 | Label allocated, slow; |
| 3717 | __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 3718 | __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
| 3719 | __ b(&allocated); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3720 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3721 | // Slow case: Call the runtime system to do the number allocation. |
| 3722 | __ bind(&slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3723 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3724 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr, |
| 3725 | instr->context()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3726 | // Set the pointer to the new heap number in tmp. |
| 3727 | if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0)); |
| 3728 | // Restore input_reg after call to runtime. |
| 3729 | __ LoadFromSafepointRegisterSlot(input, input); |
| 3730 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3731 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3732 | __ bind(&allocated); |
| 3733 | // exponent: floating point exponent value. |
| 3734 | // tmp1: allocated heap number. |
| 3735 | __ bic(exponent, exponent, Operand(HeapNumber::kSignMask)); |
| 3736 | __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
| 3737 | __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3738 | __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3739 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3740 | __ StoreToSafepointRegisterSlot(tmp1, result); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3741 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3742 | |
| 3743 | __ bind(&done); |
| 3744 | } |
| 3745 | |
| 3746 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3747 | void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3748 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3749 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3750 | __ cmp(input, Operand::Zero()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3751 | __ Move(result, input, pl); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3752 | // We can make rsb conditional because the previous cmp instruction |
| 3753 | // will clear the V (overflow) flag and rsb won't set this flag |
| 3754 | // if input is positive. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3755 | __ rsb(result, input, Operand::Zero(), SetCC, mi); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3756 | // Deoptimize on overflow. |
| 3757 | DeoptimizeIf(vs, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3761 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3762 | // Class for deferred case. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3763 | class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3764 | public: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3765 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3766 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3767 | virtual void Generate() V8_OVERRIDE { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3768 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3769 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3770 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3771 | private: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3772 | LMathAbs* instr_; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3773 | }; |
| 3774 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3775 | Representation r = instr->hydrogen()->value()->representation(); |
| 3776 | if (r.IsDouble()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3777 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3778 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3779 | __ vabs(result, input); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3780 | } else if (r.IsSmiOrInteger32()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3781 | EmitIntegerMathAbs(instr); |
| 3782 | } else { |
| 3783 | // Representation is tagged. |
| 3784 | DeferredMathAbsTaggedHeapNumber* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3785 | new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3786 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3787 | // Smi check. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3788 | __ JumpIfNotSmi(input, deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3789 | // If smi, handle it directly. |
| 3790 | EmitIntegerMathAbs(instr); |
| 3791 | __ bind(deferred->exit()); |
| 3792 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3796 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3797 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3798 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3799 | Register input_high = scratch0(); |
| 3800 | Label done, exact; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3801 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3802 | __ TryInt32Floor(result, input, input_high, double_scratch0(), &done, &exact); |
| 3803 | DeoptimizeIf(al, instr->environment()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3804 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3805 | __ bind(&exact); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3806 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3807 | // Test for -0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3808 | __ cmp(result, Operand::Zero()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3809 | __ b(ne, &done); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3810 | __ cmp(input_high, Operand::Zero()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3811 | DeoptimizeIf(mi, instr->environment()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3812 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3813 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3817 | void LCodeGen::DoMathRound(LMathRound* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3818 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3819 | Register result = ToRegister(instr->result()); |
| 3820 | DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp()); |
| 3821 | DwVfpRegister input_plus_dot_five = double_scratch1; |
| 3822 | Register input_high = scratch0(); |
| 3823 | DwVfpRegister dot_five = double_scratch0(); |
| 3824 | Label convert, done; |
| 3825 | |
| 3826 | __ Vmov(dot_five, 0.5, scratch0()); |
| 3827 | __ vabs(double_scratch1, input); |
| 3828 | __ VFPCompareAndSetFlags(double_scratch1, dot_five); |
| 3829 | // If input is in [-0.5, -0], the result is -0. |
| 3830 | // If input is in [+0, +0.5[, the result is +0. |
| 3831 | // If the input is +0.5, the result is 1. |
| 3832 | __ b(hi, &convert); // Out of [-0.5, +0.5]. |
| 3833 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3834 | __ VmovHigh(input_high, input); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3835 | __ cmp(input_high, Operand::Zero()); |
| 3836 | DeoptimizeIf(mi, instr->environment()); // [-0.5, -0]. |
| 3837 | } |
| 3838 | __ VFPCompareAndSetFlags(input, dot_five); |
| 3839 | __ mov(result, Operand(1), LeaveCC, eq); // +0.5. |
| 3840 | // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on |
| 3841 | // flag kBailoutOnMinusZero. |
| 3842 | __ mov(result, Operand::Zero(), LeaveCC, ne); |
| 3843 | __ b(&done); |
| 3844 | |
| 3845 | __ bind(&convert); |
| 3846 | __ vadd(input_plus_dot_five, input, dot_five); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3847 | // Reuse dot_five (double_scratch0) as we no longer need this value. |
| 3848 | __ TryInt32Floor(result, input_plus_dot_five, input_high, double_scratch0(), |
| 3849 | &done, &done); |
| 3850 | DeoptimizeIf(al, instr->environment()); |
| 3851 | __ bind(&done); |
| 3852 | } |
| 3853 | |
| 3854 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3855 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3856 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3857 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3858 | __ vsqrt(result, input); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3862 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3863 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3864 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
machenbach@chromium.org | 9f18d91 | 2013-11-28 13:42:41 +0000 | [diff] [blame] | 3865 | DwVfpRegister temp = double_scratch0(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3866 | |
| 3867 | // Note that according to ECMA-262 15.8.2.13: |
| 3868 | // Math.pow(-Infinity, 0.5) == Infinity |
| 3869 | // Math.sqrt(-Infinity) == NaN |
| 3870 | Label done; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3871 | __ vmov(temp, -V8_INFINITY, scratch0()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3872 | __ VFPCompareAndSetFlags(input, temp); |
| 3873 | __ vneg(result, temp, eq); |
| 3874 | __ b(&done, eq); |
| 3875 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3876 | // Add +0 to convert -0 to +0. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3877 | __ vadd(result, input, kDoubleRegZero); |
| 3878 | __ vsqrt(result, result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3879 | __ bind(&done); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3883 | void LCodeGen::DoPower(LPower* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3884 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3885 | // Having marked this as a call, we can use any registers. |
| 3886 | // Just make sure that the input/output registers are the expected ones. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3887 | ASSERT(!instr->right()->IsDoubleRegister() || |
machenbach@chromium.org | 9f18d91 | 2013-11-28 13:42:41 +0000 | [diff] [blame] | 3888 | ToDoubleRegister(instr->right()).is(d1)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3889 | ASSERT(!instr->right()->IsRegister() || |
| 3890 | ToRegister(instr->right()).is(r2)); |
machenbach@chromium.org | 9f18d91 | 2013-11-28 13:42:41 +0000 | [diff] [blame] | 3891 | ASSERT(ToDoubleRegister(instr->left()).is(d0)); |
| 3892 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3893 | |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3894 | if (exponent_type.IsSmi()) { |
| 3895 | MathPowStub stub(MathPowStub::TAGGED); |
| 3896 | __ CallStub(&stub); |
| 3897 | } else if (exponent_type.IsTagged()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3898 | Label no_deopt; |
| 3899 | __ JumpIfSmi(r2, &no_deopt); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3900 | __ ldr(r6, FieldMemOperand(r2, HeapObject::kMapOffset)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3901 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3902 | __ cmp(r6, Operand(ip)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3903 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3904 | __ bind(&no_deopt); |
| 3905 | MathPowStub stub(MathPowStub::TAGGED); |
| 3906 | __ CallStub(&stub); |
| 3907 | } else if (exponent_type.IsInteger32()) { |
| 3908 | MathPowStub stub(MathPowStub::INTEGER); |
| 3909 | __ CallStub(&stub); |
| 3910 | } else { |
| 3911 | ASSERT(exponent_type.IsDouble()); |
| 3912 | MathPowStub stub(MathPowStub::DOUBLE); |
| 3913 | __ CallStub(&stub); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3914 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3918 | void LCodeGen::DoMathExp(LMathExp* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3919 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3920 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3921 | DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 3922 | DwVfpRegister double_scratch2 = double_scratch0(); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3923 | Register temp1 = ToRegister(instr->temp1()); |
| 3924 | Register temp2 = ToRegister(instr->temp2()); |
| 3925 | |
| 3926 | MathExpGenerator::EmitMathExp( |
| 3927 | masm(), input, result, double_scratch1, double_scratch2, |
| 3928 | temp1, temp2, scratch0()); |
| 3929 | } |
| 3930 | |
| 3931 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3932 | void LCodeGen::DoMathLog(LMathLog* instr) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3933 | __ PrepareCallCFunction(0, 1, scratch0()); |
| 3934 | __ SetCallCDoubleArguments(ToDoubleRegister(instr->value())); |
| 3935 | __ CallCFunction(ExternalReference::math_log_double_function(isolate()), |
| 3936 | 0, 1); |
| 3937 | __ GetCFunctionDoubleResult(ToDoubleRegister(instr->result())); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
| 3940 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3941 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3942 | ASSERT(ToRegister(instr->context()).is(cp)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3943 | ASSERT(ToRegister(instr->function()).is(r1)); |
| 3944 | ASSERT(instr->HasPointerMap()); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3945 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3946 | Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 3947 | if (known_function.is_null()) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3948 | LPointerMap* pointers = instr->pointer_map(); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3949 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3950 | ParameterCount count(instr->arity()); |
| 3951 | __ InvokeFunction(r1, count, CALL_FUNCTION, generator, CALL_AS_METHOD); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3952 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3953 | CallKnownFunction(known_function, |
| 3954 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3955 | instr->arity(), |
| 3956 | instr, |
| 3957 | CALL_AS_METHOD, |
| 3958 | R1_CONTAINS_TARGET); |
| 3959 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3963 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3964 | ASSERT(ToRegister(instr->context()).is(cp)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3965 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3966 | |
| 3967 | int arity = instr->arity(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3968 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3969 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arity); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3970 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | |
| 3974 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3975 | ASSERT(ToRegister(instr->context()).is(cp)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3976 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3977 | |
| 3978 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3979 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
| 3980 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3981 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3982 | __ mov(r2, Operand(instr->name())); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3983 | CallCode(ic, mode, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | |
| 3987 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3988 | ASSERT(ToRegister(instr->context()).is(cp)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3989 | ASSERT(ToRegister(instr->function()).is(r1)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3990 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3991 | |
| 3992 | int arity = instr->arity(); |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame^] | 3993 | CallFunctionFlags flags = |
| 3994 | instr->hydrogen()->IsContextualCall() ? |
| 3995 | RECEIVER_IS_IMPLICIT : NO_CALL_FUNCTION_FLAGS; |
| 3996 | CallFunctionStub stub(arity, flags); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 3997 | if (instr->hydrogen()->IsTailCall()) { |
| 3998 | if (NeedsEagerFrame()) __ mov(sp, fp); |
| 3999 | __ Jump(stub.GetCode(isolate()), RelocInfo::CODE_TARGET); |
| 4000 | } else { |
| 4001 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 4002 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | |
| 4006 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4007 | ASSERT(ToRegister(instr->context()).is(cp)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4008 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4009 | |
| 4010 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4011 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET_CONTEXT; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4012 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4013 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4014 | __ mov(r2, Operand(instr->name())); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4015 | CallCode(ic, mode, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | |
| 4019 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 4020 | ASSERT(ToRegister(instr->result()).is(r0)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4021 | CallKnownFunction(instr->hydrogen()->target(), |
| 4022 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4023 | instr->arity(), |
| 4024 | instr, |
| 4025 | CALL_AS_FUNCTION, |
| 4026 | R1_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | |
| 4030 | void LCodeGen::DoCallNew(LCallNew* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4031 | ASSERT(ToRegister(instr->context()).is(cp)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4032 | ASSERT(ToRegister(instr->constructor()).is(r1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4033 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4034 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4035 | __ mov(r0, Operand(instr->arity())); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4036 | // No cell in r2 for construct type feedback in optimized code |
| 4037 | Handle<Object> undefined_value(isolate()->factory()->undefined_value()); |
| 4038 | __ mov(r2, Operand(undefined_value)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4039 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4040 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4044 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4045 | ASSERT(ToRegister(instr->context()).is(cp)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4046 | ASSERT(ToRegister(instr->constructor()).is(r1)); |
| 4047 | ASSERT(ToRegister(instr->result()).is(r0)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4048 | |
| 4049 | __ mov(r0, Operand(instr->arity())); |
| 4050 | __ mov(r2, Operand(instr->hydrogen()->property_cell())); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4051 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4052 | AllocationSiteOverrideMode override_mode = |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4053 | (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4054 | ? DISABLE_ALLOCATION_SITES |
| 4055 | : DONT_OVERRIDE; |
| 4056 | ContextCheckMode context_mode = CONTEXT_CHECK_NOT_REQUIRED; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 4057 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4058 | if (instr->arity() == 0) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4059 | ArrayNoArgumentConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4060 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4061 | } else if (instr->arity() == 1) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4062 | Label done; |
| 4063 | if (IsFastPackedElementsKind(kind)) { |
| 4064 | Label packed_case; |
| 4065 | // We might need a change here |
| 4066 | // look at the first argument |
| 4067 | __ ldr(r5, MemOperand(sp, 0)); |
| 4068 | __ cmp(r5, Operand::Zero()); |
| 4069 | __ b(eq, &packed_case); |
| 4070 | |
| 4071 | ElementsKind holey_kind = GetHoleyElementsKind(kind); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4072 | ArraySingleArgumentConstructorStub stub(holey_kind, context_mode, |
| 4073 | override_mode); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4074 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4075 | __ jmp(&done); |
| 4076 | __ bind(&packed_case); |
| 4077 | } |
| 4078 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4079 | ArraySingleArgumentConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4080 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4081 | __ bind(&done); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4082 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4083 | ArrayNArgumentsConstructorStub stub(kind, context_mode, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4084 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4085 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4089 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 4090 | CallRuntime(instr->function(), instr->arity(), instr); |
| 4091 | } |
| 4092 | |
| 4093 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4094 | void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
| 4095 | Register function = ToRegister(instr->function()); |
| 4096 | Register code_object = ToRegister(instr->code_object()); |
| 4097 | __ add(code_object, code_object, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4098 | __ str(code_object, |
| 4099 | FieldMemOperand(function, JSFunction::kCodeEntryOffset)); |
| 4100 | } |
| 4101 | |
| 4102 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4103 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 4104 | Register result = ToRegister(instr->result()); |
| 4105 | Register base = ToRegister(instr->base_object()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4106 | if (instr->offset()->IsConstantOperand()) { |
| 4107 | LConstantOperand* offset = LConstantOperand::cast(instr->offset()); |
| 4108 | __ add(result, base, Operand(ToInteger32(offset))); |
| 4109 | } else { |
| 4110 | Register offset = ToRegister(instr->offset()); |
| 4111 | __ add(result, base, offset); |
| 4112 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4116 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4117 | Representation representation = instr->representation(); |
| 4118 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4119 | Register object = ToRegister(instr->object()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4120 | Register scratch = scratch0(); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4121 | HObjectAccess access = instr->hydrogen()->access(); |
| 4122 | int offset = access.offset(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4123 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4124 | if (access.IsExternalMemory()) { |
| 4125 | Register value = ToRegister(instr->value()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4126 | MemOperand operand = MemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4127 | __ Store(value, operand, representation); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4128 | return; |
| 4129 | } |
| 4130 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4131 | Handle<Map> transition = instr->transition(); |
| 4132 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4133 | if (FLAG_track_heap_object_fields && representation.IsHeapObject()) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4134 | Register value = ToRegister(instr->value()); |
| 4135 | if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 4136 | __ SmiTst(value); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4137 | DeoptimizeIf(eq, instr->environment()); |
| 4138 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4139 | } else if (FLAG_track_double_fields && representation.IsDouble()) { |
| 4140 | ASSERT(transition.is_null()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4141 | ASSERT(access.IsInobject()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4142 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4143 | DwVfpRegister value = ToDoubleRegister(instr->value()); |
| 4144 | __ vstr(value, FieldMemOperand(object, offset)); |
| 4145 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4146 | } |
| 4147 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4148 | if (!transition.is_null()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4149 | __ mov(scratch, Operand(transition)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4150 | __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4151 | if (instr->hydrogen()->NeedsWriteBarrierForMap()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4152 | Register temp = ToRegister(instr->temp()); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4153 | // Update the write barrier for the map field. |
| 4154 | __ RecordWriteField(object, |
| 4155 | HeapObject::kMapOffset, |
| 4156 | scratch, |
| 4157 | temp, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4158 | GetLinkRegisterState(), |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4159 | kSaveFPRegs, |
| 4160 | OMIT_REMEMBERED_SET, |
| 4161 | OMIT_SMI_CHECK); |
| 4162 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | // Do the store. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4166 | Register value = ToRegister(instr->value()); |
| 4167 | ASSERT(!object.is(value)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4168 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4169 | instr->hydrogen()->value()->IsHeapObject() |
| 4170 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4171 | if (access.IsInobject()) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4172 | MemOperand operand = FieldMemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4173 | __ Store(value, operand, representation); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4174 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4175 | // Update the write barrier for the object for in-object properties. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4176 | __ RecordWriteField(object, |
| 4177 | offset, |
| 4178 | value, |
| 4179 | scratch, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4180 | GetLinkRegisterState(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4181 | kSaveFPRegs, |
| 4182 | EMIT_REMEMBERED_SET, |
| 4183 | check_needed); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4184 | } |
| 4185 | } else { |
| 4186 | __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4187 | MemOperand operand = FieldMemOperand(scratch, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4188 | __ Store(value, operand, representation); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4189 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4190 | // Update the write barrier for the properties array. |
| 4191 | // object is used as a scratch register. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4192 | __ RecordWriteField(scratch, |
| 4193 | offset, |
| 4194 | value, |
| 4195 | object, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4196 | GetLinkRegisterState(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4197 | kSaveFPRegs, |
| 4198 | EMIT_REMEMBERED_SET, |
| 4199 | check_needed); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4200 | } |
| 4201 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | |
| 4205 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4206 | ASSERT(ToRegister(instr->context()).is(cp)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4207 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 4208 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 4209 | |
| 4210 | // Name is always in r2. |
| 4211 | __ mov(r2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4212 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4213 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 4214 | : isolate()->builtins()->StoreIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4215 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4219 | void LCodeGen::ApplyCheckIf(Condition condition, LBoundsCheck* check) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4220 | if (FLAG_debug_code && check->hydrogen()->skip_check()) { |
| 4221 | Label done; |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4222 | __ b(NegateCondition(condition), &done); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4223 | __ stop("eliminated bounds check failed"); |
| 4224 | __ bind(&done); |
| 4225 | } else { |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4226 | DeoptimizeIf(condition, check->environment()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4231 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4232 | if (instr->hydrogen()->skip_check()) return; |
| 4233 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 4234 | if (instr->index()->IsConstantOperand()) { |
| 4235 | int constant_index = |
| 4236 | ToInteger32(LConstantOperand::cast(instr->index())); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4237 | if (instr->hydrogen()->length()->representation().IsSmi()) { |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 4238 | __ mov(ip, Operand(Smi::FromInt(constant_index))); |
| 4239 | } else { |
| 4240 | __ mov(ip, Operand(constant_index)); |
| 4241 | } |
| 4242 | __ cmp(ip, ToRegister(instr->length())); |
| 4243 | } else { |
| 4244 | __ cmp(ToRegister(instr->index()), ToRegister(instr->length())); |
| 4245 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4246 | Condition condition = instr->hydrogen()->allow_equality() ? hi : hs; |
| 4247 | ApplyCheckIf(condition, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4251 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
| 4252 | Register external_pointer = ToRegister(instr->elements()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4253 | Register key = no_reg; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4254 | ElementsKind elements_kind = instr->elements_kind(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4255 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4256 | int constant_key = 0; |
| 4257 | if (key_is_constant) { |
| 4258 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4259 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4260 | Abort(kArrayIndexConstantValueTooBig); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4261 | } |
| 4262 | } else { |
| 4263 | key = ToRegister(instr->key()); |
| 4264 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4265 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4266 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4267 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 4268 | int additional_offset = instr->additional_index() << element_size_shift; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4269 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4270 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 4271 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4272 | Register address = scratch0(); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 4273 | DwVfpRegister value(ToDoubleRegister(instr->value())); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4274 | if (key_is_constant) { |
| 4275 | if (constant_key != 0) { |
| 4276 | __ add(address, external_pointer, |
| 4277 | Operand(constant_key << element_size_shift)); |
| 4278 | } else { |
| 4279 | address = external_pointer; |
| 4280 | } |
| 4281 | } else { |
| 4282 | __ add(address, external_pointer, Operand(key, LSL, shift_size)); |
| 4283 | } |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4284 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4285 | __ vcvt_f32_f64(double_scratch0().low(), value); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4286 | __ vstr(double_scratch0().low(), address, additional_offset); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4287 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4288 | __ vstr(value, address, additional_offset); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4289 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4290 | } else { |
| 4291 | Register value(ToRegister(instr->value())); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4292 | MemOperand mem_operand = PrepareKeyedOperand( |
| 4293 | key, external_pointer, key_is_constant, constant_key, |
| 4294 | element_size_shift, shift_size, |
| 4295 | instr->additional_index(), additional_offset); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4296 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4297 | case EXTERNAL_PIXEL_ELEMENTS: |
| 4298 | case EXTERNAL_BYTE_ELEMENTS: |
| 4299 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4300 | __ strb(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4301 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4302 | case EXTERNAL_SHORT_ELEMENTS: |
| 4303 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4304 | __ strh(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4305 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4306 | case EXTERNAL_INT_ELEMENTS: |
| 4307 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4308 | __ str(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4309 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4310 | case EXTERNAL_FLOAT_ELEMENTS: |
| 4311 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 4312 | case FAST_DOUBLE_ELEMENTS: |
| 4313 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4314 | case FAST_SMI_ELEMENTS: |
| 4315 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 4316 | case FAST_HOLEY_ELEMENTS: |
| 4317 | case FAST_HOLEY_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4318 | case DICTIONARY_ELEMENTS: |
| 4319 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4320 | UNREACHABLE(); |
| 4321 | break; |
| 4322 | } |
| 4323 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4327 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
| 4328 | DwVfpRegister value = ToDoubleRegister(instr->value()); |
| 4329 | Register elements = ToRegister(instr->elements()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4330 | Register scratch = scratch0(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4331 | DwVfpRegister double_scratch = double_scratch0(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4332 | bool key_is_constant = instr->key()->IsConstantOperand(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4333 | |
| 4334 | // Calculate the effective address of the slot in the array to store the |
| 4335 | // double value. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4336 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4337 | if (key_is_constant) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4338 | int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4339 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4340 | Abort(kArrayIndexConstantValueTooBig); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4341 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4342 | __ add(scratch, elements, |
| 4343 | Operand((constant_key << element_size_shift) + |
| 4344 | FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4345 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4346 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
| 4347 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 4348 | __ add(scratch, elements, |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 4349 | Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4350 | __ add(scratch, scratch, |
| 4351 | Operand(ToRegister(instr->key()), LSL, shift_size)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | if (instr->NeedsCanonicalization()) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4355 | // Force a canonical NaN. |
| 4356 | if (masm()->emit_debug_code()) { |
| 4357 | __ vmrs(ip); |
| 4358 | __ tst(ip, Operand(kVFPDefaultNaNModeControlBit)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4359 | __ Assert(ne, kDefaultNaNModeNotSet); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4360 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4361 | __ VFPCanonicalizeNaN(double_scratch, value); |
| 4362 | __ vstr(double_scratch, scratch, |
| 4363 | instr->additional_index() << element_size_shift); |
| 4364 | } else { |
| 4365 | __ vstr(value, scratch, instr->additional_index() << element_size_shift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4366 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | |
| 4370 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| 4371 | Register value = ToRegister(instr->value()); |
| 4372 | Register elements = ToRegister(instr->elements()); |
| 4373 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) |
| 4374 | : no_reg; |
| 4375 | Register scratch = scratch0(); |
| 4376 | Register store_base = scratch; |
| 4377 | int offset = 0; |
| 4378 | |
| 4379 | // Do the store. |
| 4380 | if (instr->key()->IsConstantOperand()) { |
| 4381 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4382 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 4383 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 4384 | instr->additional_index()); |
| 4385 | store_base = elements; |
| 4386 | } else { |
| 4387 | // Even though the HLoadKeyed instruction forces the input |
| 4388 | // representation for the key to be an integer, the input gets replaced |
| 4389 | // during bound check elimination with the index argument to the bounds |
| 4390 | // check, which can be tagged, so that case must be handled here, too. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4391 | if (instr->hydrogen()->key()->representation().IsSmi()) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 4392 | __ add(scratch, elements, Operand::PointerOffsetFromSmiKey(key)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4393 | } else { |
| 4394 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 4395 | } |
| 4396 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 4397 | } |
| 4398 | __ str(value, FieldMemOperand(store_base, offset)); |
| 4399 | |
| 4400 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4401 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4402 | instr->hydrogen()->value()->IsHeapObject() |
| 4403 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4404 | // Compute address of modified element and store it into key register. |
| 4405 | __ add(key, store_base, Operand(offset - kHeapObjectTag)); |
| 4406 | __ RecordWrite(elements, |
| 4407 | key, |
| 4408 | value, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4409 | GetLinkRegisterState(), |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4410 | kSaveFPRegs, |
| 4411 | EMIT_REMEMBERED_SET, |
| 4412 | check_needed); |
| 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | |
| 4417 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4418 | // By cases: external, fast double |
| 4419 | if (instr->is_external()) { |
| 4420 | DoStoreKeyedExternalArray(instr); |
| 4421 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4422 | DoStoreKeyedFixedDoubleArray(instr); |
| 4423 | } else { |
| 4424 | DoStoreKeyedFixedArray(instr); |
| 4425 | } |
| 4426 | } |
| 4427 | |
| 4428 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4429 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4430 | ASSERT(ToRegister(instr->context()).is(cp)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4431 | ASSERT(ToRegister(instr->object()).is(r2)); |
| 4432 | ASSERT(ToRegister(instr->key()).is(r1)); |
| 4433 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 4434 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4435 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4436 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4437 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4438 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4442 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4443 | Register object_reg = ToRegister(instr->object()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4444 | Register scratch = scratch0(); |
| 4445 | |
| 4446 | Handle<Map> from_map = instr->original_map(); |
| 4447 | Handle<Map> to_map = instr->transitioned_map(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4448 | ElementsKind from_kind = instr->from_kind(); |
| 4449 | ElementsKind to_kind = instr->to_kind(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4450 | |
| 4451 | Label not_applicable; |
| 4452 | __ ldr(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4453 | __ cmp(scratch, Operand(from_map)); |
| 4454 | __ b(ne, ¬_applicable); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4455 | |
| 4456 | if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4457 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
| 4458 | __ mov(new_map_reg, Operand(to_map)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4459 | __ str(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4460 | // Write barrier. |
| 4461 | __ RecordWriteField(object_reg, HeapObject::kMapOffset, new_map_reg, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4462 | scratch, GetLinkRegisterState(), kDontSaveFPRegs); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4463 | } else { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4464 | ASSERT(ToRegister(instr->context()).is(cp)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4465 | PushSafepointRegistersScope scope( |
| 4466 | this, Safepoint::kWithRegistersAndDoubles); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4467 | __ Move(r0, object_reg); |
| 4468 | __ Move(r1, to_map); |
| 4469 | TransitionElementsKindStub stub(from_kind, to_kind); |
| 4470 | __ CallStub(&stub); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4471 | RecordSafepointWithRegistersAndDoubles( |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4472 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4473 | } |
| 4474 | __ bind(¬_applicable); |
| 4475 | } |
| 4476 | |
| 4477 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4478 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4479 | Register object = ToRegister(instr->object()); |
| 4480 | Register temp = ToRegister(instr->temp()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4481 | Label no_memento_found; |
| 4482 | __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4483 | DeoptimizeIf(eq, instr->environment()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4484 | __ bind(&no_memento_found); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4488 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4489 | ASSERT(ToRegister(instr->context()).is(cp)); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 4490 | if (FLAG_new_string_add) { |
| 4491 | ASSERT(ToRegister(instr->left()).is(r1)); |
| 4492 | ASSERT(ToRegister(instr->right()).is(r0)); |
| 4493 | NewStringAddStub stub(instr->hydrogen()->flags(), |
| 4494 | isolate()->heap()->GetPretenureMode()); |
| 4495 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 4496 | } else { |
| 4497 | __ push(ToRegister(instr->left())); |
| 4498 | __ push(ToRegister(instr->right())); |
| 4499 | StringAddStub stub(instr->hydrogen()->flags()); |
| 4500 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
| 4501 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4505 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4506 | class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4507 | public: |
| 4508 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 4509 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4510 | virtual void Generate() V8_OVERRIDE { |
| 4511 | codegen()->DoDeferredStringCharCodeAt(instr_); |
| 4512 | } |
| 4513 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4514 | private: |
| 4515 | LStringCharCodeAt* instr_; |
| 4516 | }; |
| 4517 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4518 | DeferredStringCharCodeAt* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4519 | new(zone()) DeferredStringCharCodeAt(this, instr); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4520 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4521 | StringCharLoadGenerator::Generate(masm(), |
| 4522 | ToRegister(instr->string()), |
| 4523 | ToRegister(instr->index()), |
| 4524 | ToRegister(instr->result()), |
| 4525 | deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4526 | __ bind(deferred->exit()); |
| 4527 | } |
| 4528 | |
| 4529 | |
| 4530 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4531 | Register string = ToRegister(instr->string()); |
| 4532 | Register result = ToRegister(instr->result()); |
| 4533 | Register scratch = scratch0(); |
| 4534 | |
| 4535 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4536 | // result register contain a valid pointer because it is already |
| 4537 | // contained in the register pointer map. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4538 | __ mov(result, Operand::Zero()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4539 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4540 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4541 | __ push(string); |
| 4542 | // Push the index as a smi. This is safe because of the checks in |
| 4543 | // DoStringCharCodeAt above. |
| 4544 | if (instr->index()->IsConstantOperand()) { |
| 4545 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4546 | __ mov(scratch, Operand(Smi::FromInt(const_index))); |
| 4547 | __ push(scratch); |
| 4548 | } else { |
| 4549 | Register index = ToRegister(instr->index()); |
| 4550 | __ SmiTag(index); |
| 4551 | __ push(index); |
| 4552 | } |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4553 | CallRuntimeFromDeferred(Runtime::kStringCharCodeAt, 2, instr, |
| 4554 | instr->context()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4555 | __ AssertSmi(r0); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4556 | __ SmiUntag(r0); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4557 | __ StoreToSafepointRegisterSlot(r0, result); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4561 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4562 | class DeferredStringCharFromCode V8_FINAL : public LDeferredCode { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4563 | public: |
| 4564 | DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 4565 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4566 | virtual void Generate() V8_OVERRIDE { |
| 4567 | codegen()->DoDeferredStringCharFromCode(instr_); |
| 4568 | } |
| 4569 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4570 | private: |
| 4571 | LStringCharFromCode* instr_; |
| 4572 | }; |
| 4573 | |
| 4574 | DeferredStringCharFromCode* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4575 | new(zone()) DeferredStringCharFromCode(this, instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4576 | |
| 4577 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4578 | Register char_code = ToRegister(instr->char_code()); |
| 4579 | Register result = ToRegister(instr->result()); |
| 4580 | ASSERT(!char_code.is(result)); |
| 4581 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4582 | __ cmp(char_code, Operand(String::kMaxOneByteCharCode)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4583 | __ b(hi, deferred->entry()); |
| 4584 | __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 4585 | __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2)); |
| 4586 | __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 4587 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4588 | __ cmp(result, ip); |
| 4589 | __ b(eq, deferred->entry()); |
| 4590 | __ bind(deferred->exit()); |
| 4591 | } |
| 4592 | |
| 4593 | |
| 4594 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4595 | Register char_code = ToRegister(instr->char_code()); |
| 4596 | Register result = ToRegister(instr->result()); |
| 4597 | |
| 4598 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4599 | // result register contain a valid pointer because it is already |
| 4600 | // contained in the register pointer map. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4601 | __ mov(result, Operand::Zero()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4602 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4603 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4604 | __ SmiTag(char_code); |
| 4605 | __ push(char_code); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4606 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4607 | __ StoreToSafepointRegisterSlot(r0, result); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4611 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4612 | LOperand* input = instr->value(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4613 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 4614 | LOperand* output = instr->result(); |
| 4615 | ASSERT(output->IsDoubleRegister()); |
| 4616 | SwVfpRegister single_scratch = double_scratch0().low(); |
| 4617 | if (input->IsStackSlot()) { |
| 4618 | Register scratch = scratch0(); |
| 4619 | __ ldr(scratch, ToMemOperand(input)); |
| 4620 | __ vmov(single_scratch, scratch); |
| 4621 | } else { |
| 4622 | __ vmov(single_scratch, ToRegister(input)); |
| 4623 | } |
| 4624 | __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4628 | void LCodeGen::DoInteger32ToSmi(LInteger32ToSmi* instr) { |
| 4629 | LOperand* input = instr->value(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4630 | LOperand* output = instr->result(); |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 4631 | ASSERT(output->IsRegister()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4632 | if (!instr->hydrogen()->value()->HasRange() || |
| 4633 | !instr->hydrogen()->value()->range()->IsInSmiRange()) { |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 4634 | __ SmiTag(ToRegister(output), ToRegister(input), SetCC); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4635 | DeoptimizeIf(vs, instr->environment()); |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 4636 | } else { |
| 4637 | __ SmiTag(ToRegister(output), ToRegister(input)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4642 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4643 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4644 | LOperand* output = instr->result(); |
| 4645 | |
| 4646 | SwVfpRegister flt_scratch = double_scratch0().low(); |
| 4647 | __ vmov(flt_scratch, ToRegister(input)); |
| 4648 | __ vcvt_f64_u32(ToDoubleRegister(output), flt_scratch); |
| 4649 | } |
| 4650 | |
| 4651 | |
machenbach@chromium.org | ed29eb2 | 2013-10-31 13:30:00 +0000 | [diff] [blame] | 4652 | void LCodeGen::DoUint32ToSmi(LUint32ToSmi* instr) { |
| 4653 | LOperand* input = instr->value(); |
| 4654 | LOperand* output = instr->result(); |
| 4655 | if (!instr->hydrogen()->value()->HasRange() || |
| 4656 | !instr->hydrogen()->value()->range()->IsInSmiRange()) { |
| 4657 | __ tst(ToRegister(input), Operand(0xc0000000)); |
| 4658 | DeoptimizeIf(ne, instr->environment()); |
| 4659 | } |
| 4660 | __ SmiTag(ToRegister(output), ToRegister(input)); |
| 4661 | } |
| 4662 | |
| 4663 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4664 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4665 | class DeferredNumberTagI V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4666 | public: |
| 4667 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 4668 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4669 | virtual void Generate() V8_OVERRIDE { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4670 | codegen()->DoDeferredNumberTagI(instr_, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4671 | instr_->value(), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4672 | SIGNED_INT32); |
| 4673 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4674 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4675 | private: |
| 4676 | LNumberTagI* instr_; |
| 4677 | }; |
| 4678 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4679 | Register src = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4680 | Register dst = ToRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4681 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4682 | DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4683 | __ SmiTag(dst, src, SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4684 | __ b(vs, deferred->entry()); |
| 4685 | __ bind(deferred->exit()); |
| 4686 | } |
| 4687 | |
| 4688 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4689 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4690 | class DeferredNumberTagU V8_FINAL : public LDeferredCode { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4691 | public: |
| 4692 | DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4693 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4694 | virtual void Generate() V8_OVERRIDE { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4695 | codegen()->DoDeferredNumberTagI(instr_, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4696 | instr_->value(), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4697 | UNSIGNED_INT32); |
| 4698 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4699 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4700 | private: |
| 4701 | LNumberTagU* instr_; |
| 4702 | }; |
| 4703 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4704 | Register input = ToRegister(instr->value()); |
| 4705 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4706 | |
| 4707 | DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4708 | __ cmp(input, Operand(Smi::kMaxValue)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4709 | __ b(hi, deferred->entry()); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4710 | __ SmiTag(result, input); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4711 | __ bind(deferred->exit()); |
| 4712 | } |
| 4713 | |
| 4714 | |
| 4715 | void LCodeGen::DoDeferredNumberTagI(LInstruction* instr, |
| 4716 | LOperand* value, |
| 4717 | IntegerSignedness signedness) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4718 | Label slow; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4719 | Register src = ToRegister(value); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4720 | Register dst = ToRegister(instr->result()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4721 | LowDwVfpRegister dbl_scratch = double_scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4722 | |
| 4723 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4724 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4725 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4726 | Label done; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4727 | if (signedness == SIGNED_INT32) { |
| 4728 | // There was overflow, so bits 30 and 31 of the original integer |
| 4729 | // disagree. Try to allocate a heap number in new space and store |
| 4730 | // the value in there. If that fails, call the runtime system. |
| 4731 | if (dst.is(src)) { |
| 4732 | __ SmiUntag(src, dst); |
| 4733 | __ eor(src, src, Operand(0x80000000)); |
| 4734 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4735 | __ vmov(dbl_scratch.low(), src); |
| 4736 | __ vcvt_f64_s32(dbl_scratch, dbl_scratch.low()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4737 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4738 | __ vmov(dbl_scratch.low(), src); |
| 4739 | __ vcvt_f64_u32(dbl_scratch, dbl_scratch.low()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4740 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4741 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4742 | if (FLAG_inline_new) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4743 | __ LoadRoot(scratch0(), Heap::kHeapNumberMapRootIndex); |
| 4744 | __ AllocateHeapNumber(r5, r3, r4, scratch0(), &slow, DONT_TAG_RESULT); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4745 | __ Move(dst, r5); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4746 | __ b(&done); |
| 4747 | } |
| 4748 | |
| 4749 | // Slow case: Call the runtime system to do the number allocation. |
| 4750 | __ bind(&slow); |
| 4751 | |
| 4752 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 4753 | // register is stored, as this register is in the pointer map, but contains an |
| 4754 | // integer value. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4755 | __ mov(ip, Operand::Zero()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4756 | __ StoreToSafepointRegisterSlot(ip, dst); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4757 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4758 | // the environment's HContext or HInlinedContext value. |
| 4759 | // They only call Runtime::kAllocateHeapNumber. |
| 4760 | // The corresponding HChange instructions are added in a phase that does |
| 4761 | // not have easy access to the local context. |
| 4762 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4763 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 4764 | RecordSafepointWithRegisters( |
| 4765 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4766 | __ Move(dst, r0); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4767 | __ sub(dst, dst, Operand(kHeapObjectTag)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4768 | |
| 4769 | // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 4770 | // number. |
| 4771 | __ bind(&done); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4772 | __ vstr(dbl_scratch, dst, HeapNumber::kValueOffset); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4773 | __ add(dst, dst, Operand(kHeapObjectTag)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4774 | __ StoreToSafepointRegisterSlot(dst, dst); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | |
| 4778 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4779 | class DeferredNumberTagD V8_FINAL : public LDeferredCode { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4780 | public: |
| 4781 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 4782 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4783 | virtual void Generate() V8_OVERRIDE { |
| 4784 | codegen()->DoDeferredNumberTagD(instr_); |
| 4785 | } |
| 4786 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4787 | private: |
| 4788 | LNumberTagD* instr_; |
| 4789 | }; |
| 4790 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4791 | DwVfpRegister input_reg = ToDoubleRegister(instr->value()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4792 | Register scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4793 | Register reg = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4794 | Register temp1 = ToRegister(instr->temp()); |
| 4795 | Register temp2 = ToRegister(instr->temp2()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4796 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4797 | DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4798 | if (FLAG_inline_new) { |
| 4799 | __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4800 | // We want the untagged address first for performance |
| 4801 | __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(), |
| 4802 | DONT_TAG_RESULT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4803 | } else { |
| 4804 | __ jmp(deferred->entry()); |
| 4805 | } |
| 4806 | __ bind(deferred->exit()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4807 | __ vstr(input_reg, reg, HeapNumber::kValueOffset); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4808 | // Now that we have finished with the object's real address tag it |
| 4809 | __ add(reg, reg, Operand(kHeapObjectTag)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | |
| 4813 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 4814 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4815 | // result register contain a valid pointer because it is already |
| 4816 | // contained in the register pointer map. |
| 4817 | Register reg = ToRegister(instr->result()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4818 | __ mov(reg, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4819 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4820 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4821 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4822 | // the environment's HContext or HInlinedContext value. |
| 4823 | // They only call Runtime::kAllocateHeapNumber. |
| 4824 | // The corresponding HChange instructions are added in a phase that does |
| 4825 | // not have easy access to the local context. |
| 4826 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4827 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 4828 | RecordSafepointWithRegisters( |
| 4829 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4830 | __ sub(r0, r0, Operand(kHeapObjectTag)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4831 | __ StoreToSafepointRegisterSlot(r0, reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | |
| 4835 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4836 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4837 | __ SmiTag(ToRegister(instr->result()), ToRegister(instr->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | |
| 4841 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4842 | Register input = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4843 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4844 | if (instr->needs_check()) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4845 | STATIC_ASSERT(kHeapObjectTag == 1); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4846 | // If the input is a HeapObject, SmiUntag will set the carry flag. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4847 | __ SmiUntag(result, input, SetCC); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4848 | DeoptimizeIf(cs, instr->environment()); |
| 4849 | } else { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4850 | __ SmiUntag(result, input); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4851 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | |
| 4855 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4856 | DwVfpRegister result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4857 | bool can_convert_undefined_to_nan, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4858 | bool deoptimize_on_minus_zero, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4859 | LEnvironment* env, |
| 4860 | NumberUntagDMode mode) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4861 | Register scratch = scratch0(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4862 | SwVfpRegister flt_scratch = double_scratch0().low(); |
| 4863 | ASSERT(!result_reg.is(double_scratch0())); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4864 | Label convert, load_smi, done; |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4865 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4866 | // Smi check. |
| 4867 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4868 | // Heap number map check. |
| 4869 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4870 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 4871 | __ cmp(scratch, Operand(ip)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4872 | if (can_convert_undefined_to_nan) { |
| 4873 | __ b(ne, &convert); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4874 | } else { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4875 | DeoptimizeIf(ne, env); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4876 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4877 | // load heap number |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4878 | __ vldr(result_reg, input_reg, HeapNumber::kValueOffset - kHeapObjectTag); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4879 | if (deoptimize_on_minus_zero) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4880 | __ VmovLow(scratch, result_reg); |
| 4881 | __ cmp(scratch, Operand::Zero()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4882 | __ b(ne, &done); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4883 | __ VmovHigh(scratch, result_reg); |
| 4884 | __ cmp(scratch, Operand(HeapNumber::kSignMask)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4885 | DeoptimizeIf(eq, env); |
| 4886 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4887 | __ jmp(&done); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4888 | if (can_convert_undefined_to_nan) { |
| 4889 | __ bind(&convert); |
| 4890 | // Convert undefined (and hole) to NaN. |
| 4891 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4892 | __ cmp(input_reg, Operand(ip)); |
| 4893 | DeoptimizeIf(ne, env); |
| 4894 | __ LoadRoot(scratch, Heap::kNanValueRootIndex); |
| 4895 | __ vldr(result_reg, scratch, HeapNumber::kValueOffset - kHeapObjectTag); |
| 4896 | __ jmp(&done); |
| 4897 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4898 | } else { |
| 4899 | __ SmiUntag(scratch, input_reg); |
| 4900 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4901 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4902 | // Smi to double register conversion |
| 4903 | __ bind(&load_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4904 | // scratch: untagged value of input_reg |
| 4905 | __ vmov(flt_scratch, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4906 | __ vcvt_f64_s32(result_reg, flt_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4907 | __ bind(&done); |
| 4908 | } |
| 4909 | |
| 4910 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4911 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4912 | Register input_reg = ToRegister(instr->value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4913 | Register scratch1 = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4914 | Register scratch2 = ToRegister(instr->temp()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4915 | LowDwVfpRegister double_scratch = double_scratch0(); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 4916 | DwVfpRegister double_scratch2 = ToDoubleRegister(instr->temp2()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4917 | |
| 4918 | ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
| 4919 | ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
| 4920 | |
| 4921 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4922 | |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4923 | // The input was optimistically untagged; revert it. |
| 4924 | // The carry flag is set when we reach this deferred code as we just executed |
| 4925 | // SmiUntag(heap_object, SetCC) |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4926 | STATIC_ASSERT(kHeapObjectTag == 1); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 4927 | __ adc(scratch2, input_reg, Operand(input_reg)); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4928 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4929 | // Heap number map check. |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 4930 | __ ldr(scratch1, FieldMemOperand(scratch2, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4931 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4932 | __ cmp(scratch1, Operand(ip)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4933 | |
| 4934 | if (instr->truncating()) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4935 | // Performs a truncating conversion of a floating point number as used by |
| 4936 | // the JS bitwise operations. |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4937 | Label no_heap_number, check_bools, check_false; |
| 4938 | __ b(ne, &no_heap_number); |
| 4939 | __ TruncateHeapNumberToI(input_reg, scratch2); |
| 4940 | __ b(&done); |
| 4941 | |
| 4942 | // Check for Oddballs. Undefined/False is converted to zero and True to one |
| 4943 | // for truncating conversions. |
| 4944 | __ bind(&no_heap_number); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4945 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 4946 | __ cmp(scratch2, Operand(ip)); |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4947 | __ b(ne, &check_bools); |
| 4948 | __ mov(input_reg, Operand::Zero()); |
| 4949 | __ b(&done); |
| 4950 | |
| 4951 | __ bind(&check_bools); |
| 4952 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 4953 | __ cmp(scratch2, Operand(ip)); |
| 4954 | __ b(ne, &check_false); |
| 4955 | __ mov(input_reg, Operand(1)); |
| 4956 | __ b(&done); |
| 4957 | |
| 4958 | __ bind(&check_false); |
| 4959 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 4960 | __ cmp(scratch2, Operand(ip)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4961 | DeoptimizeIf(ne, instr->environment()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4962 | __ mov(input_reg, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4963 | __ b(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4964 | } else { |
| 4965 | // Deoptimize if we don't have a heap number. |
| 4966 | DeoptimizeIf(ne, instr->environment()); |
| 4967 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 4968 | __ sub(ip, scratch2, Operand(kHeapObjectTag)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4969 | __ vldr(double_scratch2, ip, HeapNumber::kValueOffset); |
| 4970 | __ TryDoubleToInt32Exact(input_reg, double_scratch2, double_scratch); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4971 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4972 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4973 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4974 | __ cmp(input_reg, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4975 | __ b(ne, &done); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4976 | __ VmovHigh(scratch1, double_scratch2); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4977 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4978 | DeoptimizeIf(ne, instr->environment()); |
| 4979 | } |
| 4980 | } |
| 4981 | __ bind(&done); |
| 4982 | } |
| 4983 | |
| 4984 | |
| 4985 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4986 | class DeferredTaggedToI V8_FINAL : public LDeferredCode { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4987 | public: |
| 4988 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 4989 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4990 | virtual void Generate() V8_OVERRIDE { |
| 4991 | codegen()->DoDeferredTaggedToI(instr_); |
| 4992 | } |
| 4993 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4994 | private: |
| 4995 | LTaggedToI* instr_; |
| 4996 | }; |
| 4997 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4998 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4999 | ASSERT(input->IsRegister()); |
| 5000 | ASSERT(input->Equals(instr->result())); |
| 5001 | |
| 5002 | Register input_reg = ToRegister(input); |
| 5003 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5004 | if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 5005 | __ SmiUntag(input_reg); |
| 5006 | } else { |
| 5007 | DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5008 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5009 | // Optimistically untag the input. |
| 5010 | // If the input is a HeapObject, SmiUntag will set the carry flag. |
| 5011 | __ SmiUntag(input_reg, SetCC); |
| 5012 | // Branch to deferred code if the input was tagged. |
| 5013 | // The deferred code will take care of restoring the tag. |
| 5014 | __ b(cs, deferred->entry()); |
| 5015 | __ bind(deferred->exit()); |
| 5016 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | |
| 5020 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5021 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5022 | ASSERT(input->IsRegister()); |
| 5023 | LOperand* result = instr->result(); |
| 5024 | ASSERT(result->IsDoubleRegister()); |
| 5025 | |
| 5026 | Register input_reg = ToRegister(input); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5027 | DwVfpRegister result_reg = ToDoubleRegister(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5028 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5029 | HValue* value = instr->hydrogen()->value(); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5030 | NumberUntagDMode mode = value->representation().IsSmi() |
| 5031 | ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5032 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5033 | EmitNumberUntagD(input_reg, result_reg, |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 5034 | instr->hydrogen()->can_convert_undefined_to_nan(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5035 | instr->hydrogen()->deoptimize_on_minus_zero(), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5036 | instr->environment(), |
| 5037 | mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | |
| 5041 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5042 | Register result_reg = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5043 | Register scratch1 = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5044 | DwVfpRegister double_input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 5045 | LowDwVfpRegister double_scratch = double_scratch0(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5046 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5047 | if (instr->truncating()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 5048 | __ TruncateDoubleToI(result_reg, double_input); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5049 | } else { |
| 5050 | __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch); |
| 5051 | // Deoptimize if the input wasn't a int32 (inside a double). |
| 5052 | DeoptimizeIf(ne, instr->environment()); |
| 5053 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5054 | Label done; |
| 5055 | __ cmp(result_reg, Operand::Zero()); |
| 5056 | __ b(ne, &done); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 5057 | __ VmovHigh(scratch1, double_input); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5058 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
| 5059 | DeoptimizeIf(ne, instr->environment()); |
| 5060 | __ bind(&done); |
| 5061 | } |
| 5062 | } |
| 5063 | } |
| 5064 | |
| 5065 | |
| 5066 | void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
| 5067 | Register result_reg = ToRegister(instr->result()); |
| 5068 | Register scratch1 = scratch0(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5069 | DwVfpRegister double_input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 5070 | LowDwVfpRegister double_scratch = double_scratch0(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 5071 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5072 | if (instr->truncating()) { |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 5073 | __ TruncateDoubleToI(result_reg, double_input); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5074 | } else { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5075 | __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch); |
| 5076 | // Deoptimize if the input wasn't a int32 (inside a double). |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5077 | DeoptimizeIf(ne, instr->environment()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5078 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5079 | Label done; |
| 5080 | __ cmp(result_reg, Operand::Zero()); |
| 5081 | __ b(ne, &done); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 5082 | __ VmovHigh(scratch1, double_input); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5083 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
| 5084 | DeoptimizeIf(ne, instr->environment()); |
| 5085 | __ bind(&done); |
| 5086 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5087 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5088 | __ SmiTag(result_reg, SetCC); |
| 5089 | DeoptimizeIf(vs, instr->environment()); |
| 5090 | } |
| 5091 | |
| 5092 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5093 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5094 | LOperand* input = instr->value(); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5095 | __ SmiTst(ToRegister(input)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5096 | DeoptimizeIf(ne, instr->environment()); |
| 5097 | } |
| 5098 | |
| 5099 | |
| 5100 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5101 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 5102 | LOperand* input = instr->value(); |
| 5103 | __ SmiTst(ToRegister(input)); |
| 5104 | DeoptimizeIf(eq, instr->environment()); |
| 5105 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | |
| 5109 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5110 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5111 | Register scratch = scratch0(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5112 | |
| 5113 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5114 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5115 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5116 | if (instr->hydrogen()->is_interval_check()) { |
| 5117 | InstanceType first; |
| 5118 | InstanceType last; |
| 5119 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 5120 | |
| 5121 | __ cmp(scratch, Operand(first)); |
| 5122 | |
| 5123 | // If there is only one type in the interval check for equality. |
| 5124 | if (first == last) { |
| 5125 | DeoptimizeIf(ne, instr->environment()); |
| 5126 | } else { |
| 5127 | DeoptimizeIf(lo, instr->environment()); |
| 5128 | // Omit check for the last type. |
| 5129 | if (last != LAST_TYPE) { |
| 5130 | __ cmp(scratch, Operand(last)); |
| 5131 | DeoptimizeIf(hi, instr->environment()); |
| 5132 | } |
| 5133 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5134 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5135 | uint8_t mask; |
| 5136 | uint8_t tag; |
| 5137 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 5138 | |
| 5139 | if (IsPowerOf2(mask)) { |
| 5140 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 5141 | __ tst(scratch, Operand(mask)); |
| 5142 | DeoptimizeIf(tag == 0 ? ne : eq, instr->environment()); |
| 5143 | } else { |
| 5144 | __ and_(scratch, scratch, Operand(mask)); |
| 5145 | __ cmp(scratch, Operand(tag)); |
| 5146 | DeoptimizeIf(ne, instr->environment()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5147 | } |
| 5148 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5152 | void LCodeGen::DoCheckValue(LCheckValue* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5153 | Register reg = ToRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5154 | Handle<HeapObject> object = instr->hydrogen()->object().handle(); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5155 | AllowDeferredHandleDereference smi_check; |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5156 | if (isolate()->heap()->InNewSpace(*object)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5157 | Register reg = ToRegister(instr->value()); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5158 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5159 | __ mov(ip, Operand(Handle<Object>(cell))); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5160 | __ ldr(ip, FieldMemOperand(ip, Cell::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5161 | __ cmp(reg, ip); |
| 5162 | } else { |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5163 | __ cmp(reg, Operand(object)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5164 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5165 | DeoptimizeIf(ne, instr->environment()); |
| 5166 | } |
| 5167 | |
| 5168 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5169 | void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
| 5170 | { |
| 5171 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 5172 | __ push(object); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5173 | __ mov(cp, Operand::Zero()); |
| 5174 | __ CallRuntimeSaveDoubles(Runtime::kMigrateInstance); |
| 5175 | RecordSafepointWithRegisters( |
| 5176 | instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5177 | __ StoreToSafepointRegisterSlot(r0, scratch0()); |
| 5178 | } |
| 5179 | __ tst(scratch0(), Operand(kSmiTagMask)); |
| 5180 | DeoptimizeIf(eq, instr->environment()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5184 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5185 | class DeferredCheckMaps V8_FINAL : public LDeferredCode { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5186 | public: |
| 5187 | DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) |
| 5188 | : LDeferredCode(codegen), instr_(instr), object_(object) { |
| 5189 | SetExit(check_maps()); |
| 5190 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5191 | virtual void Generate() V8_OVERRIDE { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5192 | codegen()->DoDeferredInstanceMigration(instr_, object_); |
| 5193 | } |
| 5194 | Label* check_maps() { return &check_maps_; } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5195 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5196 | private: |
| 5197 | LCheckMaps* instr_; |
| 5198 | Label check_maps_; |
| 5199 | Register object_; |
| 5200 | }; |
| 5201 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5202 | if (instr->hydrogen()->CanOmitMapChecks()) return; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5203 | Register map_reg = scratch0(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5204 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5205 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5206 | ASSERT(input->IsRegister()); |
| 5207 | Register reg = ToRegister(input); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5208 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5209 | __ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5210 | |
| 5211 | DeferredCheckMaps* deferred = NULL; |
| 5212 | if (instr->hydrogen()->has_migration_target()) { |
| 5213 | deferred = new(zone()) DeferredCheckMaps(this, instr, reg); |
| 5214 | __ bind(deferred->check_maps()); |
| 5215 | } |
| 5216 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5217 | UniqueSet<Map> map_set = instr->hydrogen()->map_set(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5218 | Label success; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5219 | for (int i = 0; i < map_set.size() - 1; i++) { |
| 5220 | Handle<Map> map = map_set.at(i).handle(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5221 | __ CompareMap(map_reg, map, &success); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5222 | __ b(eq, &success); |
| 5223 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5224 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5225 | Handle<Map> map = map_set.at(map_set.size() - 1).handle(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5226 | __ CompareMap(map_reg, map, &success); |
| 5227 | if (instr->hydrogen()->has_migration_target()) { |
| 5228 | __ b(ne, deferred->entry()); |
| 5229 | } else { |
| 5230 | DeoptimizeIf(ne, instr->environment()); |
| 5231 | } |
| 5232 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5233 | __ bind(&success); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5237 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5238 | DwVfpRegister value_reg = ToDoubleRegister(instr->unclamped()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5239 | Register result_reg = ToRegister(instr->result()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 5240 | __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | |
| 5244 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5245 | Register unclamped_reg = ToRegister(instr->unclamped()); |
| 5246 | Register result_reg = ToRegister(instr->result()); |
| 5247 | __ ClampUint8(result_reg, unclamped_reg); |
| 5248 | } |
| 5249 | |
| 5250 | |
| 5251 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 5252 | Register scratch = scratch0(); |
| 5253 | Register input_reg = ToRegister(instr->unclamped()); |
| 5254 | Register result_reg = ToRegister(instr->result()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5255 | DwVfpRegister temp_reg = ToDoubleRegister(instr->temp()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5256 | Label is_smi, done, heap_number; |
| 5257 | |
| 5258 | // Both smi and heap number cases are handled. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5259 | __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5260 | |
| 5261 | // Check for heap number |
| 5262 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 5263 | __ cmp(scratch, Operand(factory()->heap_number_map())); |
| 5264 | __ b(eq, &heap_number); |
| 5265 | |
| 5266 | // Check for undefined. Undefined is converted to zero for clamping |
| 5267 | // conversions. |
| 5268 | __ cmp(input_reg, Operand(factory()->undefined_value())); |
| 5269 | DeoptimizeIf(ne, instr->environment()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5270 | __ mov(result_reg, Operand::Zero()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5271 | __ jmp(&done); |
| 5272 | |
| 5273 | // Heap number |
| 5274 | __ bind(&heap_number); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 5275 | __ vldr(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 5276 | __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5277 | __ jmp(&done); |
| 5278 | |
| 5279 | // smi |
| 5280 | __ bind(&is_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5281 | __ ClampUint8(result_reg, result_reg); |
| 5282 | |
| 5283 | __ bind(&done); |
| 5284 | } |
| 5285 | |
| 5286 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5287 | void LCodeGen::DoAllocate(LAllocate* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5288 | class DeferredAllocate V8_FINAL : public LDeferredCode { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5289 | public: |
| 5290 | DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5291 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5292 | virtual void Generate() V8_OVERRIDE { |
| 5293 | codegen()->DoDeferredAllocate(instr_); |
| 5294 | } |
| 5295 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5296 | private: |
| 5297 | LAllocate* instr_; |
| 5298 | }; |
| 5299 | |
| 5300 | DeferredAllocate* deferred = |
| 5301 | new(zone()) DeferredAllocate(this, instr); |
| 5302 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5303 | Register result = ToRegister(instr->result()); |
| 5304 | Register scratch = ToRegister(instr->temp1()); |
| 5305 | Register scratch2 = ToRegister(instr->temp2()); |
| 5306 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5307 | // Allocate memory for the object. |
| 5308 | AllocationFlags flags = TAG_OBJECT; |
| 5309 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 5310 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 5311 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5312 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5313 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5314 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5315 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5316 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5317 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5318 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5319 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 5320 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5321 | if (instr->size()->IsConstantOperand()) { |
| 5322 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5323 | __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5324 | } else { |
| 5325 | Register size = ToRegister(instr->size()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5326 | __ Allocate(size, |
| 5327 | result, |
| 5328 | scratch, |
| 5329 | scratch2, |
| 5330 | deferred->entry(), |
| 5331 | flags); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | __ bind(deferred->exit()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5335 | |
| 5336 | if (instr->hydrogen()->MustPrefillWithFiller()) { |
| 5337 | if (instr->size()->IsConstantOperand()) { |
| 5338 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5339 | __ mov(scratch, Operand(size)); |
| 5340 | } else { |
| 5341 | scratch = ToRegister(instr->size()); |
| 5342 | } |
| 5343 | __ sub(scratch, scratch, Operand(kPointerSize)); |
| 5344 | __ sub(result, result, Operand(kHeapObjectTag)); |
| 5345 | Label loop; |
| 5346 | __ bind(&loop); |
| 5347 | __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 5348 | __ str(scratch2, MemOperand(result, scratch)); |
| 5349 | __ sub(scratch, scratch, Operand(kPointerSize)); |
| 5350 | __ cmp(scratch, Operand(0)); |
| 5351 | __ b(ge, &loop); |
| 5352 | __ add(result, result, Operand(kHeapObjectTag)); |
| 5353 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | |
| 5357 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5358 | Register result = ToRegister(instr->result()); |
| 5359 | |
| 5360 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5361 | // result register contain a valid pointer because it is already |
| 5362 | // contained in the register pointer map. |
| 5363 | __ mov(result, Operand(Smi::FromInt(0))); |
| 5364 | |
| 5365 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5366 | if (instr->size()->IsRegister()) { |
| 5367 | Register size = ToRegister(instr->size()); |
| 5368 | ASSERT(!size.is(result)); |
| 5369 | __ SmiTag(size); |
| 5370 | __ push(size); |
| 5371 | } else { |
| 5372 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5373 | __ Push(Smi::FromInt(size)); |
| 5374 | } |
| 5375 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5376 | int flags = AllocateDoubleAlignFlag::encode( |
| 5377 | instr->hydrogen()->MustAllocateDoubleAligned()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5378 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5379 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5380 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5381 | flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5382 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5383 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5384 | flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5385 | } else { |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5386 | flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5387 | } |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5388 | __ Push(Smi::FromInt(flags)); |
| 5389 | |
| 5390 | CallRuntimeFromDeferred( |
| 5391 | Runtime::kAllocateInTargetSpace, 2, instr, instr->context()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5392 | __ StoreToSafepointRegisterSlot(r0, result); |
| 5393 | } |
| 5394 | |
| 5395 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5396 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5397 | ASSERT(ToRegister(instr->value()).is(r0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5398 | __ push(r0); |
| 5399 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
| 5400 | } |
| 5401 | |
| 5402 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5403 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5404 | ASSERT(ToRegister(instr->context()).is(cp)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5405 | Label materialized; |
| 5406 | // Registers will be used as follows: |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5407 | // r6 = literals array. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5408 | // r1 = regexp literal. |
| 5409 | // r0 = regexp literal clone. |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5410 | // r2-5 are used as temporaries. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5411 | int literal_offset = |
| 5412 | FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 5413 | __ Move(r6, instr->hydrogen()->literals()); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5414 | __ ldr(r1, FieldMemOperand(r6, literal_offset)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5415 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5416 | __ cmp(r1, ip); |
| 5417 | __ b(ne, &materialized); |
| 5418 | |
| 5419 | // Create regexp literal using runtime function |
| 5420 | // Result will be in r0. |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5421 | __ mov(r5, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 5422 | __ mov(r4, Operand(instr->hydrogen()->pattern())); |
| 5423 | __ mov(r3, Operand(instr->hydrogen()->flags())); |
| 5424 | __ Push(r6, r5, r4, r3); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5425 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
| 5426 | __ mov(r1, r0); |
| 5427 | |
| 5428 | __ bind(&materialized); |
| 5429 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 5430 | Label allocated, runtime_allocate; |
| 5431 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5432 | __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5433 | __ jmp(&allocated); |
| 5434 | |
| 5435 | __ bind(&runtime_allocate); |
| 5436 | __ mov(r0, Operand(Smi::FromInt(size))); |
| 5437 | __ Push(r1, r0); |
| 5438 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 5439 | __ pop(r1); |
| 5440 | |
| 5441 | __ bind(&allocated); |
| 5442 | // Copy the content into the newly allocated memory. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 5443 | __ CopyFields(r0, r1, double_scratch0(), size / kPointerSize); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | |
| 5447 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5448 | ASSERT(ToRegister(instr->context()).is(cp)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5449 | // Use the fast case closure allocation code that allocates in new |
| 5450 | // space for nested functions that don't need literals cloning. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5451 | bool pretenure = instr->hydrogen()->pretenure(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5452 | if (!pretenure && instr->hydrogen()->has_no_literals()) { |
| 5453 | FastNewClosureStub stub(instr->hydrogen()->language_mode(), |
| 5454 | instr->hydrogen()->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 5455 | __ mov(r2, Operand(instr->hydrogen()->shared_info())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5456 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5457 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5458 | __ mov(r2, Operand(instr->hydrogen()->shared_info())); |
| 5459 | __ mov(r1, Operand(pretenure ? factory()->true_value() |
| 5460 | : factory()->false_value())); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5461 | __ Push(cp, r2, r1); |
| 5462 | CallRuntime(Runtime::kNewClosure, 3, instr); |
| 5463 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | |
| 5467 | void LCodeGen::DoTypeof(LTypeof* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5468 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5469 | __ push(input); |
| 5470 | CallRuntime(Runtime::kTypeof, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5474 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5475 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5476 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5477 | Condition final_branch_condition = EmitTypeofIs(instr->TrueLabel(chunk_), |
| 5478 | instr->FalseLabel(chunk_), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5479 | input, |
| 5480 | instr->type_literal()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5481 | if (final_branch_condition != kNoCondition) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5482 | EmitBranch(instr, final_branch_condition); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5483 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | |
| 5487 | Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 5488 | Label* false_label, |
| 5489 | Register input, |
| 5490 | Handle<String> type_name) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5491 | Condition final_branch_condition = kNoCondition; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5492 | Register scratch = scratch0(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5493 | if (type_name->Equals(heap()->number_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5494 | __ JumpIfSmi(input, true_label); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5495 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5496 | __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5497 | final_branch_condition = eq; |
| 5498 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5499 | } else if (type_name->Equals(heap()->string_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5500 | __ JumpIfSmi(input, false_label); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5501 | __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5502 | __ b(ge, false_label); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5503 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5504 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5505 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5506 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5507 | } else if (type_name->Equals(heap()->symbol_string())) { |
| 5508 | __ JumpIfSmi(input, false_label); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5509 | __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5510 | final_branch_condition = eq; |
| 5511 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5512 | } else if (type_name->Equals(heap()->boolean_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5513 | __ CompareRoot(input, Heap::kTrueValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5514 | __ b(eq, true_label); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5515 | __ CompareRoot(input, Heap::kFalseValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5516 | final_branch_condition = eq; |
| 5517 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5518 | } else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5519 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5520 | final_branch_condition = eq; |
| 5521 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5522 | } else if (type_name->Equals(heap()->undefined_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5523 | __ CompareRoot(input, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5524 | __ b(eq, true_label); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5525 | __ JumpIfSmi(input, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5526 | // Check for undetectable objects => true. |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5527 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5528 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5529 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5530 | final_branch_condition = ne; |
| 5531 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5532 | } else if (type_name->Equals(heap()->function_string())) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5533 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5534 | Register type_reg = scratch; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5535 | __ JumpIfSmi(input, false_label); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5536 | __ CompareObjectType(input, scratch, type_reg, JS_FUNCTION_TYPE); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5537 | __ b(eq, true_label); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5538 | __ cmp(type_reg, Operand(JS_FUNCTION_PROXY_TYPE)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5539 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5540 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5541 | } else if (type_name->Equals(heap()->object_string())) { |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5542 | Register map = scratch; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5543 | __ JumpIfSmi(input, false_label); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5544 | if (!FLAG_harmony_typeof) { |
| 5545 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5546 | __ b(eq, true_label); |
| 5547 | } |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5548 | __ CheckObjectTypeRange(input, |
| 5549 | map, |
| 5550 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 5551 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 5552 | false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5553 | // Check for undetectable objects => false. |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5554 | __ ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 5555 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5556 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5557 | |
| 5558 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5559 | __ b(false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | return final_branch_condition; |
| 5563 | } |
| 5564 | |
| 5565 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5566 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5567 | Register temp1 = ToRegister(instr->temp()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5568 | |
| 5569 | EmitIsConstructCall(temp1, scratch0()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5570 | EmitBranch(instr, eq); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | |
| 5574 | void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { |
| 5575 | ASSERT(!temp1.is(temp2)); |
| 5576 | // Get the frame pointer for the calling frame. |
| 5577 | __ ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5578 | |
| 5579 | // Skip the arguments adaptor frame if it exists. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5580 | __ ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); |
| 5581 | __ cmp(temp2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ulan@chromium.org | 9ca3017 | 2014-01-02 12:10:54 +0000 | [diff] [blame] | 5582 | __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset), eq); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5583 | |
| 5584 | // Check the marker in the calling frame. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5585 | __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); |
| 5586 | __ cmp(temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 5587 | } |
| 5588 | |
| 5589 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5590 | void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5591 | if (info()->IsStub()) return; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5592 | // Ensure that we have enough space after the previous lazy-bailout |
| 5593 | // instruction for patching the code here. |
| 5594 | int current_pc = masm()->pc_offset(); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5595 | if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5596 | // Block literal pool emission for duration of padding. |
| 5597 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5598 | int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5599 | ASSERT_EQ(0, padding_size % Assembler::kInstrSize); |
| 5600 | while (padding_size > 0) { |
| 5601 | __ nop(); |
| 5602 | padding_size -= Assembler::kInstrSize; |
| 5603 | } |
| 5604 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5608 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5609 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ulan@chromium.org | 6fe0fda | 2013-07-23 13:34:19 +0000 | [diff] [blame] | 5610 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5611 | ASSERT(instr->HasEnvironment()); |
| 5612 | LEnvironment* env = instr->environment(); |
| 5613 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5614 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | |
| 5618 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5619 | Deoptimizer::BailoutType type = instr->hydrogen()->type(); |
| 5620 | // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the |
| 5621 | // needed return address), even though the implementation of LAZY and EAGER is |
| 5622 | // now identical. When LAZY is eventually completely folded into EAGER, remove |
| 5623 | // the special case below. |
| 5624 | if (info()->IsStub() && type == Deoptimizer::EAGER) { |
| 5625 | type = Deoptimizer::LAZY; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 5626 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5627 | |
| 5628 | Comment(";;; deoptimize: %s", instr->hydrogen()->reason()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5629 | DeoptimizeIf(al, instr->environment(), type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5630 | } |
| 5631 | |
| 5632 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5633 | void LCodeGen::DoDummy(LDummy* instr) { |
| 5634 | // Nothing to see here, move on! |
| 5635 | } |
| 5636 | |
| 5637 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5638 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 5639 | // Nothing to see here, move on! |
| 5640 | } |
| 5641 | |
| 5642 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5643 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5644 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5645 | LoadContextFromDeferred(instr->context()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5646 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 5647 | RecordSafepointWithLazyDeopt( |
| 5648 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 5649 | ASSERT(instr->HasEnvironment()); |
| 5650 | LEnvironment* env = instr->environment(); |
| 5651 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5655 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5656 | class DeferredStackCheck V8_FINAL : public LDeferredCode { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5657 | public: |
| 5658 | DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
| 5659 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5660 | virtual void Generate() V8_OVERRIDE { |
| 5661 | codegen()->DoDeferredStackCheck(instr_); |
| 5662 | } |
| 5663 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5664 | private: |
| 5665 | LStackCheck* instr_; |
| 5666 | }; |
| 5667 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5668 | ASSERT(instr->HasEnvironment()); |
| 5669 | LEnvironment* env = instr->environment(); |
| 5670 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 5671 | // prepare for lazy deoptimization explicitly here. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5672 | if (instr->hydrogen()->is_function_entry()) { |
| 5673 | // Perform stack overflow check. |
| 5674 | Label done; |
| 5675 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 5676 | __ cmp(sp, Operand(ip)); |
| 5677 | __ b(hs, &done); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5678 | PredictableCodeSizeScope predictable(masm_, 2 * Assembler::kInstrSize); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5679 | ASSERT(instr->context()->IsRegister()); |
| 5680 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 5681 | CallCode(isolate()->builtins()->StackCheck(), |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 5682 | RelocInfo::CODE_TARGET, |
| 5683 | instr); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5684 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ulan@chromium.org | 6fe0fda | 2013-07-23 13:34:19 +0000 | [diff] [blame] | 5685 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5686 | __ bind(&done); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5687 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5688 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5689 | } else { |
| 5690 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 5691 | // Perform stack overflow check if this goto needs it before jumping. |
| 5692 | DeferredStackCheck* deferred_stack_check = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5693 | new(zone()) DeferredStackCheck(this, instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5694 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 5695 | __ cmp(sp, Operand(ip)); |
| 5696 | __ b(lo, deferred_stack_check->entry()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5697 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
ulan@chromium.org | 6fe0fda | 2013-07-23 13:34:19 +0000 | [diff] [blame] | 5698 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5699 | __ bind(instr->done_label()); |
| 5700 | deferred_stack_check->SetExit(instr->done_label()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5701 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5702 | // Don't record a deoptimization index for the safepoint here. |
| 5703 | // This will be done explicitly when emitting call and the safepoint in |
| 5704 | // the deferred code. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5705 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | |
| 5709 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 5710 | // This is a pseudo-instruction that ensures that the environment here is |
| 5711 | // properly registered for deoptimization and records the assembler's PC |
| 5712 | // offset. |
| 5713 | LEnvironment* environment = instr->environment(); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 5714 | |
| 5715 | // If the environment were already registered, we would have no way of |
| 5716 | // backpatching it with the spill slot operands. |
| 5717 | ASSERT(!environment->HasBeenRegistered()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5718 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5719 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 5720 | GenerateOsrPrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5724 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
| 5725 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5726 | __ cmp(r0, ip); |
| 5727 | DeoptimizeIf(eq, instr->environment()); |
| 5728 | |
| 5729 | Register null_value = r5; |
| 5730 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 5731 | __ cmp(r0, null_value); |
| 5732 | DeoptimizeIf(eq, instr->environment()); |
| 5733 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5734 | __ SmiTst(r0); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5735 | DeoptimizeIf(eq, instr->environment()); |
| 5736 | |
| 5737 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 5738 | __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE); |
| 5739 | DeoptimizeIf(le, instr->environment()); |
| 5740 | |
| 5741 | Label use_cache, call_runtime; |
| 5742 | __ CheckEnumCache(null_value, &call_runtime); |
| 5743 | |
| 5744 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5745 | __ b(&use_cache); |
| 5746 | |
| 5747 | // Get the set of properties to enumerate. |
| 5748 | __ bind(&call_runtime); |
| 5749 | __ push(r0); |
| 5750 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 5751 | |
| 5752 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5753 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 5754 | __ cmp(r1, ip); |
| 5755 | DeoptimizeIf(ne, instr->environment()); |
| 5756 | __ bind(&use_cache); |
| 5757 | } |
| 5758 | |
| 5759 | |
| 5760 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5761 | Register map = ToRegister(instr->map()); |
| 5762 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5763 | Label load_cache, done; |
| 5764 | __ EnumLength(result, map); |
| 5765 | __ cmp(result, Operand(Smi::FromInt(0))); |
| 5766 | __ b(ne, &load_cache); |
| 5767 | __ mov(result, Operand(isolate()->factory()->empty_fixed_array())); |
| 5768 | __ jmp(&done); |
| 5769 | |
| 5770 | __ bind(&load_cache); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5771 | __ LoadInstanceDescriptors(map, result); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5772 | __ ldr(result, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 5773 | FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5774 | __ ldr(result, |
| 5775 | FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5776 | __ cmp(result, Operand::Zero()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5777 | DeoptimizeIf(eq, instr->environment()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5778 | |
| 5779 | __ bind(&done); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5780 | } |
| 5781 | |
| 5782 | |
| 5783 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5784 | Register object = ToRegister(instr->value()); |
| 5785 | Register map = ToRegister(instr->map()); |
| 5786 | __ ldr(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5787 | __ cmp(map, scratch0()); |
| 5788 | DeoptimizeIf(ne, instr->environment()); |
| 5789 | } |
| 5790 | |
| 5791 | |
| 5792 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 5793 | Register object = ToRegister(instr->object()); |
| 5794 | Register index = ToRegister(instr->index()); |
| 5795 | Register result = ToRegister(instr->result()); |
| 5796 | Register scratch = scratch0(); |
| 5797 | |
| 5798 | Label out_of_object, done; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5799 | __ cmp(index, Operand::Zero()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5800 | __ b(lt, &out_of_object); |
| 5801 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5802 | __ add(scratch, object, Operand::PointerOffsetFromSmiKey(index)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5803 | __ ldr(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
| 5804 | |
| 5805 | __ b(&done); |
| 5806 | |
| 5807 | __ bind(&out_of_object); |
| 5808 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 5809 | // Index is equal to negated out of object property index plus 1. |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5810 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); |
| 5811 | __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5812 | __ ldr(result, FieldMemOperand(scratch, |
| 5813 | FixedArray::kHeaderSize - kPointerSize)); |
| 5814 | __ bind(&done); |
| 5815 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5816 | |
| 5817 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5818 | #undef __ |
| 5819 | |
| 5820 | } } // namespace v8::internal |