machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved.7 |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "mips/lithium-codegen-mips.h" |
| 31 | #include "mips/lithium-gap-resolver-mips.h" |
| 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" |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +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 { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 41 | public: |
| 42 | SafepointGenerator(LCodeGen* codegen, |
| 43 | LPointerMap* pointers, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 44 | Safepoint::DeoptMode mode) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 45 | : codegen_(codegen), |
| 46 | pointers_(pointers), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 47 | deopt_mode_(mode) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 48 | virtual ~SafepointGenerator() {} |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +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 {} |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 51 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 52 | virtual void AfterCall() const V8_OVERRIDE { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 53 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | private: |
| 57 | LCodeGen* codegen_; |
| 58 | LPointerMap* pointers_; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 59 | Safepoint::DeoptMode deopt_mode_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +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()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 67 | ASSERT(is_unused()); |
| 68 | status_ = GENERATING; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 69 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +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 | |
| 75 | return GeneratePrologue() && |
| 76 | GenerateBody() && |
| 77 | GenerateDeferredCode() && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 78 | GenerateDeoptJumpTable() && |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 79 | GenerateSafepointTable(); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 84 | ASSERT(is_done()); |
| 85 | code->set_stack_slots(GetStackSlotCount()); |
| 86 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 87 | if (code->is_optimized_code()) RegisterWeakObjectsInOptimizedCode(code); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 88 | PopulateDeoptimizationData(code); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 89 | info()->CommitDependencies(code); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 93 | void LChunkBuilder::Abort(BailoutReason reason) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 94 | info()->set_bailout_reason(reason); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +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 | __ sdc1(DoubleRegister::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 | __ ldc1(DoubleRegister::FromAllocationIndex(save_iterator.Current()), |
| 124 | MemOperand(sp, count * kDoubleSize)); |
| 125 | save_iterator.Advance(); |
| 126 | count++; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 131 | bool LCodeGen::GeneratePrologue() { |
| 132 | ASSERT(is_generating()); |
| 133 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 134 | if (info()->IsOptimizing()) { |
| 135 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 136 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 137 | #ifdef DEBUG |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 138 | if (strlen(FLAG_stop_at) > 0 && |
| 139 | info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
| 140 | __ stop("stop_at"); |
| 141 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 144 | // a1: Callee's JS function. |
| 145 | // cp: Callee's context. |
| 146 | // fp: Caller's frame pointer. |
| 147 | // lr: Caller's pc. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 148 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 149 | // Sloppy mode functions and builtins need to replace the receiver with the |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 150 | // global proxy when called as functions (without an explicit receiver |
| 151 | // object). |
| 152 | if (info_->this_has_uses() && |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 153 | info_->strict_mode() == SLOPPY && |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 154 | !info_->is_native()) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 155 | Label ok; |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 156 | int receiver_offset = info_->scope()->num_parameters() * kPointerSize; |
| 157 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 158 | __ lw(a2, MemOperand(sp, receiver_offset)); |
| 159 | __ Branch(&ok, ne, a2, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 160 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 161 | __ lw(a2, GlobalObjectOperand()); |
| 162 | __ lw(a2, FieldMemOperand(a2, GlobalObject::kGlobalReceiverOffset)); |
| 163 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 164 | __ sw(a2, MemOperand(sp, receiver_offset)); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 165 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 166 | __ bind(&ok); |
| 167 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 168 | } |
| 169 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 170 | info()->set_prologue_offset(masm_->pc_offset()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 171 | if (NeedsEagerFrame()) { |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 172 | __ Prologue(info()->IsStub() ? BUILD_STUB_FRAME : BUILD_FUNCTION_FRAME); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 173 | frame_is_built_ = true; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 174 | info_->AddNoFrameRange(0, masm_->pc_offset()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 175 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 176 | |
| 177 | // Reserve space for the stack slots needed by the code. |
| 178 | int slots = GetStackSlotCount(); |
| 179 | if (slots > 0) { |
| 180 | if (FLAG_debug_code) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 181 | __ Subu(sp, sp, Operand(slots * kPointerSize)); |
machenbach@chromium.org | 6f1040e | 2014-02-04 07:54:22 +0000 | [diff] [blame] | 182 | __ Push(a0, a1); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 183 | __ Addu(a0, sp, Operand(slots * kPointerSize)); |
| 184 | __ li(a1, Operand(kSlotsZapValue)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 185 | Label loop; |
| 186 | __ bind(&loop); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 187 | __ Subu(a0, a0, Operand(kPointerSize)); |
| 188 | __ sw(a1, MemOperand(a0, 2 * kPointerSize)); |
| 189 | __ Branch(&loop, ne, a0, Operand(sp)); |
machenbach@chromium.org | 6f1040e | 2014-02-04 07:54:22 +0000 | [diff] [blame] | 190 | __ Pop(a0, a1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 191 | } else { |
| 192 | __ Subu(sp, sp, Operand(slots * kPointerSize)); |
| 193 | } |
| 194 | } |
| 195 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 196 | if (info()->saves_caller_doubles()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 197 | SaveCallerDoubles(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 198 | } |
| 199 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 200 | // Possibly allocate a local context. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 201 | int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 202 | if (heap_slots > 0) { |
| 203 | Comment(";;; Allocate local context"); |
| 204 | // Argument to NewContext is the function, which is in a1. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 205 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 206 | FastNewContextStub stub(heap_slots); |
| 207 | __ CallStub(&stub); |
| 208 | } else { |
palfia@homejinni.com | cc96b0e | 2014-01-23 17:24:54 +0000 | [diff] [blame] | 209 | __ push(a1); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 210 | __ CallRuntime(Runtime::kHiddenNewFunctionContext, 1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 211 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 212 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
palfia@homejinni.com | cc96b0e | 2014-01-23 17:24:54 +0000 | [diff] [blame] | 213 | // Context is returned in both v0. It replaces the context passed to us. |
| 214 | // It's saved in the stack and kept live in cp. |
| 215 | __ mov(cp, v0); |
| 216 | __ sw(v0, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 217 | // Copy any necessary parameters into the context. |
| 218 | int num_parameters = scope()->num_parameters(); |
| 219 | for (int i = 0; i < num_parameters; i++) { |
| 220 | Variable* var = scope()->parameter(i); |
| 221 | if (var->IsContextSlot()) { |
| 222 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 223 | (num_parameters - 1 - i) * kPointerSize; |
| 224 | // Load parameter from stack. |
| 225 | __ lw(a0, MemOperand(fp, parameter_offset)); |
| 226 | // Store it in the context. |
| 227 | MemOperand target = ContextOperand(cp, var->index()); |
| 228 | __ sw(a0, target); |
| 229 | // Update the write barrier. This clobbers a3 and a0. |
| 230 | __ RecordWriteContextSlot( |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 231 | cp, target.offset(), a0, a3, GetRAState(), kSaveFPRegs); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | Comment(";;; End allocate local context"); |
| 235 | } |
| 236 | |
| 237 | // Trace the call. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 238 | if (FLAG_trace && info()->IsOptimizing()) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 239 | // We have not executed any compiled code yet, so cp still holds the |
| 240 | // incoming context. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +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 | __ Subu(sp, sp, Operand(slots * kPointerSize)); |
| 259 | } |
| 260 | |
| 261 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 262 | void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 263 | if (instr->IsCall()) { |
| 264 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
| 265 | } |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 266 | if (!instr->IsLazyBailout() && !instr->IsGap()) { |
| 267 | safepoints_.BumpLastLazySafepointIndex(); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 272 | bool LCodeGen::GenerateDeferredCode() { |
| 273 | ASSERT(is_generating()); |
| 274 | if (deferred_.length() > 0) { |
| 275 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 276 | LDeferredCode* code = deferred_[i]; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 277 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 278 | HValue* value = |
| 279 | instructions_->at(code->instruction_index())->hydrogen_value(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 280 | RecordAndWritePosition( |
| 281 | chunk()->graph()->SourcePositionToScriptPosition(value->position())); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 282 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 283 | Comment(";;; <@%d,#%d> " |
| 284 | "-------------------- Deferred %s --------------------", |
| 285 | code->instruction_index(), |
| 286 | code->instr()->hydrogen_value()->id(), |
| 287 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 288 | __ bind(code->entry()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 289 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 290 | Comment(";;; Build frame"); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 291 | ASSERT(!frame_is_built_); |
| 292 | ASSERT(info()->IsStub()); |
| 293 | frame_is_built_ = true; |
| 294 | __ MultiPush(cp.bit() | fp.bit() | ra.bit()); |
| 295 | __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 296 | __ push(scratch0()); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 297 | __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 298 | Comment(";;; Deferred code"); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 299 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 300 | code->Generate(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 301 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 302 | Comment(";;; Destroy frame"); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 303 | ASSERT(frame_is_built_); |
| 304 | __ pop(at); |
| 305 | __ MultiPop(cp.bit() | fp.bit() | ra.bit()); |
| 306 | frame_is_built_ = false; |
| 307 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 308 | __ jmp(code->exit()); |
| 309 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 310 | } |
| 311 | // Deferred code is the last part of the instruction sequence. Mark |
| 312 | // the generated code as done unless we bailed out. |
| 313 | if (!is_aborted()) status_ = DONE; |
| 314 | return !is_aborted(); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | bool LCodeGen::GenerateDeoptJumpTable() { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 319 | if (deopt_jump_table_.length() > 0) { |
| 320 | Comment(";;; -------------------- Jump table --------------------"); |
| 321 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 322 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 323 | Label table_start; |
| 324 | __ bind(&table_start); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 325 | Label needs_frame; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 326 | for (int i = 0; i < deopt_jump_table_.length(); i++) { |
| 327 | __ bind(&deopt_jump_table_[i].label); |
| 328 | Address entry = deopt_jump_table_[i].address; |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 329 | Deoptimizer::BailoutType type = deopt_jump_table_[i].bailout_type; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 330 | int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 331 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 332 | Comment(";;; jump table entry %d.", i); |
| 333 | } else { |
| 334 | Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 335 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 336 | __ li(t9, Operand(ExternalReference::ForDeoptEntry(entry))); |
| 337 | if (deopt_jump_table_[i].needs_frame) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 338 | ASSERT(!info()->saves_caller_doubles()); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 339 | if (needs_frame.is_bound()) { |
| 340 | __ Branch(&needs_frame); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 341 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 342 | __ bind(&needs_frame); |
| 343 | __ MultiPush(cp.bit() | fp.bit() | ra.bit()); |
| 344 | // This variant of deopt can only be used with stubs. Since we don't |
| 345 | // have a function pointer to install in the stack frame that we're |
| 346 | // building, install a special marker there instead. |
| 347 | ASSERT(info()->IsStub()); |
| 348 | __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 349 | __ push(scratch0()); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 350 | __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 351 | __ Call(t9); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 352 | } |
| 353 | } else { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 354 | if (info()->saves_caller_doubles()) { |
| 355 | ASSERT(info()->IsStub()); |
| 356 | RestoreCallerDoubles(); |
| 357 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 358 | __ Call(t9); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | __ RecordComment("]"); |
| 362 | |
| 363 | // The deoptimization jump table is the last part of the instruction |
| 364 | // sequence. Mark the generated code as done unless we bailed out. |
| 365 | if (!is_aborted()) status_ = DONE; |
| 366 | return !is_aborted(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | |
| 370 | bool LCodeGen::GenerateSafepointTable() { |
| 371 | ASSERT(is_done()); |
| 372 | safepoints_.Emit(masm(), GetStackSlotCount()); |
| 373 | return !is_aborted(); |
| 374 | } |
| 375 | |
| 376 | |
| 377 | Register LCodeGen::ToRegister(int index) const { |
| 378 | return Register::FromAllocationIndex(index); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | DoubleRegister LCodeGen::ToDoubleRegister(int index) const { |
| 383 | return DoubleRegister::FromAllocationIndex(index); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 388 | ASSERT(op->IsRegister()); |
| 389 | return ToRegister(op->index()); |
| 390 | } |
| 391 | |
| 392 | |
| 393 | Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 394 | if (op->IsRegister()) { |
| 395 | return ToRegister(op->index()); |
| 396 | } else if (op->IsConstantOperand()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 397 | LConstantOperand* const_op = LConstantOperand::cast(op); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 398 | HConstant* constant = chunk_->LookupConstant(const_op); |
palfia@homejinni.com | 8b6c786 | 2013-09-10 15:12:05 +0000 | [diff] [blame] | 399 | Handle<Object> literal = constant->handle(isolate()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 400 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 401 | if (r.IsInteger32()) { |
| 402 | ASSERT(literal->IsNumber()); |
| 403 | __ li(scratch, Operand(static_cast<int32_t>(literal->Number()))); |
palfia@homejinni.com | 09b3454 | 2013-08-01 08:07:42 +0000 | [diff] [blame] | 404 | } else if (r.IsSmi()) { |
| 405 | ASSERT(constant->HasSmiValue()); |
| 406 | __ li(scratch, Operand(Smi::FromInt(constant->Integer32Value()))); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 407 | } else if (r.IsDouble()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 408 | Abort(kEmitLoadRegisterUnsupportedDoubleImmediate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 409 | } else { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 410 | ASSERT(r.IsSmiOrTagged()); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 411 | __ li(scratch, literal); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 412 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 413 | return scratch; |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 414 | } else if (op->IsStackSlot()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 415 | __ lw(scratch, ToMemOperand(op)); |
| 416 | return scratch; |
| 417 | } |
| 418 | UNREACHABLE(); |
| 419 | return scratch; |
| 420 | } |
| 421 | |
| 422 | |
| 423 | DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 424 | ASSERT(op->IsDoubleRegister()); |
| 425 | return ToDoubleRegister(op->index()); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | DoubleRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, |
| 430 | FloatRegister flt_scratch, |
| 431 | DoubleRegister dbl_scratch) { |
| 432 | if (op->IsDoubleRegister()) { |
| 433 | return ToDoubleRegister(op->index()); |
| 434 | } else if (op->IsConstantOperand()) { |
| 435 | LConstantOperand* const_op = LConstantOperand::cast(op); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 436 | HConstant* constant = chunk_->LookupConstant(const_op); |
palfia@homejinni.com | 8b6c786 | 2013-09-10 15:12:05 +0000 | [diff] [blame] | 437 | Handle<Object> literal = constant->handle(isolate()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 438 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 439 | if (r.IsInteger32()) { |
| 440 | ASSERT(literal->IsNumber()); |
| 441 | __ li(at, Operand(static_cast<int32_t>(literal->Number()))); |
| 442 | __ mtc1(at, flt_scratch); |
| 443 | __ cvt_d_w(dbl_scratch, flt_scratch); |
| 444 | return dbl_scratch; |
| 445 | } else if (r.IsDouble()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 446 | Abort(kUnsupportedDoubleImmediate); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 447 | } else if (r.IsTagged()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 448 | Abort(kUnsupportedTaggedImmediate); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 449 | } |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 450 | } else if (op->IsStackSlot()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 451 | MemOperand mem_op = ToMemOperand(op); |
| 452 | __ ldc1(dbl_scratch, mem_op); |
| 453 | return dbl_scratch; |
| 454 | } |
| 455 | UNREACHABLE(); |
| 456 | return dbl_scratch; |
| 457 | } |
| 458 | |
| 459 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 460 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 461 | HConstant* constant = chunk_->LookupConstant(op); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 462 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
palfia@homejinni.com | 8b6c786 | 2013-09-10 15:12:05 +0000 | [diff] [blame] | 463 | return constant->handle(isolate()); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | |
| 467 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 468 | return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 472 | bool LCodeGen::IsSmi(LConstantOperand* op) const { |
| 473 | return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
| 474 | } |
| 475 | |
| 476 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 477 | int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 478 | return ToRepresentation(op, Representation::Integer32()); |
| 479 | } |
| 480 | |
| 481 | |
| 482 | int32_t LCodeGen::ToRepresentation(LConstantOperand* op, |
| 483 | const Representation& r) const { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 484 | HConstant* constant = chunk_->LookupConstant(op); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 485 | int32_t value = constant->Integer32Value(); |
| 486 | if (r.IsInteger32()) return value; |
| 487 | ASSERT(r.IsSmiOrTagged()); |
| 488 | return reinterpret_cast<int32_t>(Smi::FromInt(value)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 492 | Smi* LCodeGen::ToSmi(LConstantOperand* op) const { |
| 493 | HConstant* constant = chunk_->LookupConstant(op); |
| 494 | return Smi::FromInt(constant->Integer32Value()); |
| 495 | } |
| 496 | |
| 497 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 498 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 499 | HConstant* constant = chunk_->LookupConstant(op); |
| 500 | ASSERT(constant->HasDoubleValue()); |
| 501 | return constant->DoubleValue(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | |
| 505 | Operand LCodeGen::ToOperand(LOperand* op) { |
| 506 | if (op->IsConstantOperand()) { |
| 507 | LConstantOperand* const_op = LConstantOperand::cast(op); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 508 | HConstant* constant = chunk()->LookupConstant(const_op); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 509 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 510 | if (r.IsSmi()) { |
| 511 | ASSERT(constant->HasSmiValue()); |
| 512 | return Operand(Smi::FromInt(constant->Integer32Value())); |
| 513 | } else if (r.IsInteger32()) { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 514 | ASSERT(constant->HasInteger32Value()); |
| 515 | return Operand(constant->Integer32Value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 516 | } else if (r.IsDouble()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 517 | Abort(kToOperandUnsupportedDoubleImmediate); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 518 | } |
| 519 | ASSERT(r.IsTagged()); |
palfia@homejinni.com | 8b6c786 | 2013-09-10 15:12:05 +0000 | [diff] [blame] | 520 | return Operand(constant->handle(isolate())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 521 | } else if (op->IsRegister()) { |
| 522 | return Operand(ToRegister(op)); |
| 523 | } else if (op->IsDoubleRegister()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 524 | Abort(kToOperandIsDoubleRegisterUnimplemented); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 525 | return Operand(0); |
| 526 | } |
| 527 | // Stack slots not implemented, use ToMemOperand instead. |
| 528 | UNREACHABLE(); |
| 529 | return Operand(0); |
| 530 | } |
| 531 | |
| 532 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 533 | static int ArgumentsOffsetWithoutFrame(int index) { |
| 534 | ASSERT(index < 0); |
| 535 | return -(index + 1) * kPointerSize; |
| 536 | } |
| 537 | |
| 538 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 539 | MemOperand LCodeGen::ToMemOperand(LOperand* op) const { |
| 540 | ASSERT(!op->IsRegister()); |
| 541 | ASSERT(!op->IsDoubleRegister()); |
| 542 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 543 | if (NeedsEagerFrame()) { |
| 544 | return MemOperand(fp, StackSlotOffset(op->index())); |
| 545 | } else { |
| 546 | // Retrieve parameter without eager stack-frame relative to the |
| 547 | // stack-pointer. |
| 548 | return MemOperand(sp, ArgumentsOffsetWithoutFrame(op->index())); |
| 549 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | |
| 553 | MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { |
| 554 | ASSERT(op->IsDoubleStackSlot()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 555 | if (NeedsEagerFrame()) { |
| 556 | return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize); |
| 557 | } else { |
| 558 | // Retrieve parameter without eager stack-frame relative to the |
| 559 | // stack-pointer. |
| 560 | return MemOperand( |
| 561 | sp, ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize); |
| 562 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | |
| 566 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 567 | Translation* translation) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 568 | if (environment == NULL) return; |
| 569 | |
| 570 | // The translation includes one command per value in the environment. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 571 | int translation_size = environment->translation_size(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 572 | // The output frame height does not include the parameters. |
| 573 | int height = translation_size - environment->parameter_count(); |
| 574 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 575 | WriteTranslation(environment->outer(), translation); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 576 | bool has_closure_id = !info()->closure().is_null() && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 577 | !info()->closure().is_identical_to(environment->closure()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 578 | int closure_id = has_closure_id |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 579 | ? DefineDeoptimizationLiteral(environment->closure()) |
| 580 | : Translation::kSelfLiteralId; |
| 581 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 582 | switch (environment->frame_type()) { |
| 583 | case JS_FUNCTION: |
| 584 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 585 | break; |
| 586 | case JS_CONSTRUCT: |
| 587 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 588 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 589 | case JS_GETTER: |
| 590 | ASSERT(translation_size == 1); |
| 591 | ASSERT(height == 0); |
| 592 | translation->BeginGetterStubFrame(closure_id); |
| 593 | break; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 594 | case JS_SETTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 595 | ASSERT(translation_size == 2); |
| 596 | ASSERT(height == 0); |
| 597 | translation->BeginSetterStubFrame(closure_id); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 598 | break; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 599 | case STUB: |
| 600 | translation->BeginCompiledStubFrame(); |
| 601 | break; |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 602 | case ARGUMENTS_ADAPTOR: |
| 603 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 604 | break; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 605 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 606 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 607 | int object_index = 0; |
| 608 | int dematerialized_index = 0; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 609 | for (int i = 0; i < translation_size; ++i) { |
| 610 | LOperand* value = environment->values()->at(i); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 611 | AddToTranslation(environment, |
| 612 | translation, |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 613 | value, |
| 614 | environment->HasTaggedValueAt(i), |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 615 | environment->HasUint32ValueAt(i), |
| 616 | &object_index, |
| 617 | &dematerialized_index); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
| 621 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 622 | void LCodeGen::AddToTranslation(LEnvironment* environment, |
| 623 | Translation* translation, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 624 | LOperand* op, |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 625 | bool is_tagged, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 626 | bool is_uint32, |
| 627 | int* object_index_pointer, |
| 628 | int* dematerialized_index_pointer) { |
| 629 | if (op == LEnvironment::materialization_marker()) { |
| 630 | int object_index = (*object_index_pointer)++; |
| 631 | if (environment->ObjectIsDuplicateAt(object_index)) { |
| 632 | int dupe_of = environment->ObjectDuplicateOfAt(object_index); |
| 633 | translation->DuplicateObject(dupe_of); |
| 634 | return; |
| 635 | } |
| 636 | int object_length = environment->ObjectLengthAt(object_index); |
| 637 | if (environment->ObjectIsArgumentsAt(object_index)) { |
| 638 | translation->BeginArgumentsObject(object_length); |
| 639 | } else { |
| 640 | translation->BeginCapturedObject(object_length); |
| 641 | } |
| 642 | int dematerialized_index = *dematerialized_index_pointer; |
| 643 | int env_offset = environment->translation_size() + dematerialized_index; |
| 644 | *dematerialized_index_pointer += object_length; |
| 645 | for (int i = 0; i < object_length; ++i) { |
| 646 | LOperand* value = environment->values()->at(env_offset + i); |
| 647 | AddToTranslation(environment, |
| 648 | translation, |
| 649 | value, |
| 650 | environment->HasTaggedValueAt(env_offset + i), |
| 651 | environment->HasUint32ValueAt(env_offset + i), |
| 652 | object_index_pointer, |
| 653 | dematerialized_index_pointer); |
| 654 | } |
| 655 | return; |
| 656 | } |
| 657 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 658 | if (op->IsStackSlot()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 659 | if (is_tagged) { |
| 660 | translation->StoreStackSlot(op->index()); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 661 | } else if (is_uint32) { |
| 662 | translation->StoreUint32StackSlot(op->index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 663 | } else { |
| 664 | translation->StoreInt32StackSlot(op->index()); |
| 665 | } |
| 666 | } else if (op->IsDoubleStackSlot()) { |
| 667 | translation->StoreDoubleStackSlot(op->index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 668 | } else if (op->IsRegister()) { |
| 669 | Register reg = ToRegister(op); |
| 670 | if (is_tagged) { |
| 671 | translation->StoreRegister(reg); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 672 | } else if (is_uint32) { |
| 673 | translation->StoreUint32Register(reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 674 | } else { |
| 675 | translation->StoreInt32Register(reg); |
| 676 | } |
| 677 | } else if (op->IsDoubleRegister()) { |
| 678 | DoubleRegister reg = ToDoubleRegister(op); |
| 679 | translation->StoreDoubleRegister(reg); |
| 680 | } else if (op->IsConstantOperand()) { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 681 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
palfia@homejinni.com | 8b6c786 | 2013-09-10 15:12:05 +0000 | [diff] [blame] | 682 | int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 683 | translation->StoreLiteral(src_index); |
| 684 | } else { |
| 685 | UNREACHABLE(); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | |
| 690 | void LCodeGen::CallCode(Handle<Code> code, |
| 691 | RelocInfo::Mode mode, |
| 692 | LInstruction* instr) { |
| 693 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 698 | RelocInfo::Mode mode, |
| 699 | LInstruction* instr, |
| 700 | SafepointMode safepoint_mode) { |
| 701 | ASSERT(instr != NULL); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 702 | __ Call(code, mode); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 703 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
| 707 | void LCodeGen::CallRuntime(const Runtime::Function* function, |
| 708 | int num_arguments, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 709 | LInstruction* instr, |
| 710 | SaveFPRegsMode save_doubles) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 711 | ASSERT(instr != NULL); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 712 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 713 | __ CallRuntime(function, num_arguments, save_doubles); |
| 714 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 715 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 719 | void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
| 720 | if (context->IsRegister()) { |
| 721 | __ Move(cp, ToRegister(context)); |
| 722 | } else if (context->IsStackSlot()) { |
| 723 | __ lw(cp, ToMemOperand(context)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 724 | } else if (context->IsConstantOperand()) { |
| 725 | HConstant* constant = |
| 726 | chunk_->LookupConstant(LConstantOperand::cast(context)); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 727 | __ li(cp, Handle<Object>::cast(constant->handle(isolate()))); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 728 | } else { |
| 729 | UNREACHABLE(); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 734 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 735 | int argc, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 736 | LInstruction* instr, |
| 737 | LOperand* context) { |
| 738 | LoadContextFromDeferred(context); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 739 | __ CallRuntimeSaveDoubles(id); |
| 740 | RecordSafepointWithRegisters( |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 741 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 745 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 746 | Safepoint::DeoptMode mode) { |
machenbach@chromium.org | da0c828 | 2014-04-03 07:05:51 +0000 | [diff] [blame] | 747 | environment->set_has_been_used(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 748 | if (!environment->HasBeenRegistered()) { |
| 749 | // Physical stack frame layout: |
| 750 | // -x ............. -4 0 ..................................... y |
| 751 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 752 | |
| 753 | // Layout of the environment: |
| 754 | // 0 ..................................................... size-1 |
| 755 | // [parameters] [locals] [expression stack including arguments] |
| 756 | |
| 757 | // Layout of the translation: |
| 758 | // 0 ........................................................ size - 1 + 4 |
| 759 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 760 | // |>------------ translation_size ------------<| |
| 761 | |
| 762 | int frame_count = 0; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 763 | int jsframe_count = 0; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 764 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 765 | ++frame_count; |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 766 | if (e->frame_type() == JS_FUNCTION) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 767 | ++jsframe_count; |
| 768 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 769 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 770 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 771 | WriteTranslation(environment, &translation); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 772 | int deoptimization_index = deoptimizations_.length(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 773 | int pc_offset = masm()->pc_offset(); |
| 774 | environment->Register(deoptimization_index, |
| 775 | translation.index(), |
| 776 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 777 | deoptimizations_.Add(environment, zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | |
| 781 | |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 782 | void LCodeGen::DeoptimizeIf(Condition condition, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 783 | LEnvironment* environment, |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 784 | Deoptimizer::BailoutType bailout_type, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 785 | Register src1, |
| 786 | const Operand& src2) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 787 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 788 | ASSERT(environment->HasBeenRegistered()); |
| 789 | int id = environment->deoptimization_index(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 790 | ASSERT(info()->IsOptimizing() || info()->IsStub()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 791 | Address entry = |
| 792 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 793 | if (entry == NULL) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 794 | Abort(kBailoutWasNotPrepared); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 795 | return; |
| 796 | } |
| 797 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 798 | if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { |
| 799 | Register scratch = scratch0(); |
| 800 | ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
| 801 | Label no_deopt; |
| 802 | __ Push(a1, scratch); |
| 803 | __ li(scratch, Operand(count)); |
| 804 | __ lw(a1, MemOperand(scratch)); |
| 805 | __ Subu(a1, a1, Operand(1)); |
| 806 | __ Branch(&no_deopt, ne, a1, Operand(zero_reg)); |
| 807 | __ li(a1, Operand(FLAG_deopt_every_n_times)); |
| 808 | __ sw(a1, MemOperand(scratch)); |
| 809 | __ Pop(a1, scratch); |
| 810 | |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 811 | __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 812 | __ bind(&no_deopt); |
| 813 | __ sw(a1, MemOperand(scratch)); |
| 814 | __ Pop(a1, scratch); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 815 | } |
| 816 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 817 | if (info()->ShouldTrapOnDeopt()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 818 | Label skip; |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 819 | if (condition != al) { |
| 820 | __ Branch(&skip, NegateCondition(condition), src1, src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 821 | } |
| 822 | __ stop("trap_on_deopt"); |
| 823 | __ bind(&skip); |
| 824 | } |
| 825 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 826 | ASSERT(info()->IsStub() || frame_is_built_); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 827 | // Go through jump table if we need to handle condition, build frame, or |
| 828 | // restore caller doubles. |
| 829 | if (condition == al && frame_is_built_ && |
| 830 | !info()->saves_caller_doubles()) { |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 831 | __ Call(entry, RelocInfo::RUNTIME_ENTRY, condition, src1, src2); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 832 | } else { |
| 833 | // We often have several deopts to the same entry, reuse the last |
| 834 | // jump entry if this is the case. |
| 835 | if (deopt_jump_table_.is_empty() || |
| 836 | (deopt_jump_table_.last().address != entry) || |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 837 | (deopt_jump_table_.last().bailout_type != bailout_type) || |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 838 | (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 839 | Deoptimizer::JumpTableEntry table_entry(entry, |
| 840 | bailout_type, |
| 841 | !frame_is_built_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 842 | deopt_jump_table_.Add(table_entry, zone()); |
| 843 | } |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 844 | __ Branch(&deopt_jump_table_.last().label, condition, src1, src2); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 845 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 849 | void LCodeGen::DeoptimizeIf(Condition condition, |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 850 | LEnvironment* environment, |
| 851 | Register src1, |
| 852 | const Operand& src2) { |
| 853 | Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 854 | ? Deoptimizer::LAZY |
| 855 | : Deoptimizer::EAGER; |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 856 | DeoptimizeIf(condition, environment, bailout_type, src1, src2); |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 860 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 861 | int length = deoptimizations_.length(); |
| 862 | if (length == 0) return; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 863 | Handle<DeoptimizationInputData> data = |
| 864 | factory()->NewDeoptimizationInputData(length, TENURED); |
| 865 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 866 | Handle<ByteArray> translations = |
| 867 | translations_.CreateByteArray(isolate()->factory()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 868 | data->SetTranslationByteArray(*translations); |
| 869 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 870 | data->SetOptimizationId(Smi::FromInt(info_->optimization_id())); |
| 871 | if (info_->IsOptimizing()) { |
| 872 | // Reference to shared function info does not change between phases. |
| 873 | AllowDeferredHandleDereference allow_handle_dereference; |
| 874 | data->SetSharedFunctionInfo(*info_->shared_info()); |
| 875 | } else { |
| 876 | data->SetSharedFunctionInfo(Smi::FromInt(0)); |
| 877 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 878 | |
| 879 | Handle<FixedArray> literals = |
| 880 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 881 | { AllowDeferredHandleDereference copy_handles; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 882 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 883 | literals->set(i, *deoptimization_literals_[i]); |
| 884 | } |
| 885 | data->SetLiteralArray(*literals); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 886 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 887 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 888 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 889 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 890 | |
| 891 | // Populate the deoptimization entries. |
| 892 | for (int i = 0; i < length; i++) { |
| 893 | LEnvironment* env = deoptimizations_[i]; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 894 | data->SetAstId(i, env->ast_id()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 895 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 896 | data->SetArgumentsStackHeight(i, |
| 897 | Smi::FromInt(env->arguments_stack_height())); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 898 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 899 | } |
| 900 | code->set_deoptimization_data(*data); |
| 901 | } |
| 902 | |
| 903 | |
| 904 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 905 | int result = deoptimization_literals_.length(); |
| 906 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 907 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 908 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 909 | deoptimization_literals_.Add(literal, zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 910 | return result; |
| 911 | } |
| 912 | |
| 913 | |
| 914 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 915 | ASSERT(deoptimization_literals_.length() == 0); |
| 916 | |
| 917 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 918 | chunk()->inlined_closures(); |
| 919 | |
| 920 | for (int i = 0, length = inlined_closures->length(); |
| 921 | i < length; |
| 922 | i++) { |
| 923 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 924 | } |
| 925 | |
| 926 | inlined_function_count_ = deoptimization_literals_.length(); |
| 927 | } |
| 928 | |
| 929 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 930 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 931 | LInstruction* instr, SafepointMode safepoint_mode) { |
| 932 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 933 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 934 | } else { |
| 935 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 936 | RecordSafepointWithRegisters( |
| 937 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 942 | void LCodeGen::RecordSafepoint( |
| 943 | LPointerMap* pointers, |
| 944 | Safepoint::Kind kind, |
| 945 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 946 | Safepoint::DeoptMode deopt_mode) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 947 | ASSERT(expected_safepoint_kind_ == kind); |
| 948 | |
| 949 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
| 950 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 951 | kind, arguments, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 952 | for (int i = 0; i < operands->length(); i++) { |
| 953 | LOperand* pointer = operands->at(i); |
| 954 | if (pointer->IsStackSlot()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 955 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 956 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 957 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | |
| 963 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 964 | Safepoint::DeoptMode deopt_mode) { |
| 965 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 969 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 970 | LPointerMap empty_pointers(zone()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 971 | RecordSafepoint(&empty_pointers, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | |
| 975 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 976 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 977 | Safepoint::DeoptMode deopt_mode) { |
| 978 | RecordSafepoint( |
| 979 | pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | |
| 983 | void LCodeGen::RecordSafepointWithRegistersAndDoubles( |
| 984 | LPointerMap* pointers, |
| 985 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 986 | Safepoint::DeoptMode deopt_mode) { |
| 987 | RecordSafepoint( |
| 988 | pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 992 | void LCodeGen::RecordAndWritePosition(int position) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 993 | if (position == RelocInfo::kNoPosition) return; |
| 994 | masm()->positions_recorder()->RecordPosition(position); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 995 | masm()->positions_recorder()->WriteRecordedPositions(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 999 | static const char* LabelType(LLabel* label) { |
| 1000 | if (label->is_loop_header()) return " (loop header)"; |
| 1001 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 1002 | return ""; |
| 1003 | } |
| 1004 | |
| 1005 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1006 | void LCodeGen::DoLabel(LLabel* label) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1007 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1008 | current_instruction_, |
| 1009 | label->hydrogen_value()->id(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1010 | label->block_id(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1011 | LabelType(label)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1012 | __ bind(label->label()); |
| 1013 | current_block_ = label->block_id(); |
| 1014 | DoGap(label); |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
| 1019 | resolver_.Resolve(move); |
| 1020 | } |
| 1021 | |
| 1022 | |
| 1023 | void LCodeGen::DoGap(LGap* gap) { |
| 1024 | for (int i = LGap::FIRST_INNER_POSITION; |
| 1025 | i <= LGap::LAST_INNER_POSITION; |
| 1026 | i++) { |
| 1027 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 1028 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 1029 | if (move != NULL) DoParallelMove(move); |
| 1030 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 1035 | DoGap(instr); |
| 1036 | } |
| 1037 | |
| 1038 | |
| 1039 | void LCodeGen::DoParameter(LParameter* instr) { |
| 1040 | // Nothing to do. |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | void LCodeGen::DoCallStub(LCallStub* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1045 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1046 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 1047 | switch (instr->hydrogen()->major_key()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1048 | case CodeStub::RegExpExec: { |
| 1049 | RegExpExecStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1050 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1051 | break; |
| 1052 | } |
| 1053 | case CodeStub::SubString: { |
| 1054 | SubStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1055 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1056 | break; |
| 1057 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1058 | case CodeStub::StringCompare: { |
| 1059 | StringCompareStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1060 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1061 | break; |
| 1062 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1063 | default: |
| 1064 | UNREACHABLE(); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1070 | GenerateOsrPrologue(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1074 | void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) { |
| 1075 | Register dividend = ToRegister(instr->dividend()); |
| 1076 | int32_t divisor = instr->divisor(); |
| 1077 | ASSERT(dividend.is(ToRegister(instr->result()))); |
| 1078 | |
| 1079 | // Theoretically, a variation of the branch-free code for integer division by |
| 1080 | // a power of 2 (calculating the remainder via an additional multiplication |
| 1081 | // (which gets simplified to an 'and') and subtraction) should be faster, and |
| 1082 | // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to |
| 1083 | // indicate that positive dividends are heavily favored, so the branching |
| 1084 | // version performs better. |
| 1085 | HMod* hmod = instr->hydrogen(); |
| 1086 | int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); |
| 1087 | Label dividend_is_not_negative, done; |
| 1088 | |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1089 | if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1090 | __ Branch(÷nd_is_not_negative, ge, dividend, Operand(zero_reg)); |
| 1091 | // Note: The code below even works when right contains kMinInt. |
| 1092 | __ subu(dividend, zero_reg, dividend); |
| 1093 | __ And(dividend, dividend, Operand(mask)); |
| 1094 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1095 | DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg)); |
| 1096 | } |
| 1097 | __ Branch(USE_DELAY_SLOT, &done); |
| 1098 | __ subu(dividend, zero_reg, dividend); |
| 1099 | } |
| 1100 | |
| 1101 | __ bind(÷nd_is_not_negative); |
| 1102 | __ And(dividend, dividend, Operand(mask)); |
| 1103 | __ bind(&done); |
| 1104 | } |
| 1105 | |
| 1106 | |
machenbach@chromium.org | 00a4ad7 | 2014-03-17 08:13:32 +0000 | [diff] [blame] | 1107 | void LCodeGen::DoModByConstI(LModByConstI* instr) { |
| 1108 | Register dividend = ToRegister(instr->dividend()); |
| 1109 | int32_t divisor = instr->divisor(); |
| 1110 | Register result = ToRegister(instr->result()); |
| 1111 | ASSERT(!dividend.is(result)); |
| 1112 | |
| 1113 | if (divisor == 0) { |
| 1114 | DeoptimizeIf(al, instr->environment()); |
| 1115 | return; |
| 1116 | } |
| 1117 | |
machenbach@chromium.org | 69f64b1 | 2014-03-20 01:04:55 +0000 | [diff] [blame] | 1118 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
machenbach@chromium.org | 00a4ad7 | 2014-03-17 08:13:32 +0000 | [diff] [blame] | 1119 | __ Mul(result, result, Operand(Abs(divisor))); |
| 1120 | __ Subu(result, dividend, Operand(result)); |
| 1121 | |
| 1122 | // Check for negative zero. |
| 1123 | HMod* hmod = instr->hydrogen(); |
| 1124 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1125 | Label remainder_not_zero; |
| 1126 | __ Branch(&remainder_not_zero, ne, result, Operand(zero_reg)); |
| 1127 | DeoptimizeIf(lt, instr->environment(), dividend, Operand(zero_reg)); |
| 1128 | __ bind(&remainder_not_zero); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1133 | void LCodeGen::DoModI(LModI* instr) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1134 | HMod* hmod = instr->hydrogen(); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1135 | const Register left_reg = ToRegister(instr->left()); |
| 1136 | const Register right_reg = ToRegister(instr->right()); |
| 1137 | const Register result_reg = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1138 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1139 | // div runs in the background while we check for special cases. |
| 1140 | __ div(left_reg, right_reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1141 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1142 | Label done; |
| 1143 | // Check for x % 0, we have to deopt in this case because we can't return a |
| 1144 | // NaN. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1145 | if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1146 | DeoptimizeIf(eq, instr->environment(), right_reg, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1147 | } |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1148 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1149 | // Check for kMinInt % -1, div will return kMinInt, which is not what we |
| 1150 | // want. We have to deopt if we care about -0, because we can't return that. |
| 1151 | if (hmod->CheckFlag(HValue::kCanOverflow)) { |
| 1152 | Label no_overflow_possible; |
| 1153 | __ Branch(&no_overflow_possible, ne, left_reg, Operand(kMinInt)); |
| 1154 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1155 | DeoptimizeIf(eq, instr->environment(), right_reg, Operand(-1)); |
| 1156 | } else { |
| 1157 | __ Branch(&no_overflow_possible, ne, right_reg, Operand(-1)); |
| 1158 | __ Branch(USE_DELAY_SLOT, &done); |
| 1159 | __ mov(result_reg, zero_reg); |
| 1160 | } |
| 1161 | __ bind(&no_overflow_possible); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1164 | // If we care about -0, test if the dividend is <0 and the result is 0. |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1165 | __ Branch(USE_DELAY_SLOT, &done, ge, left_reg, Operand(zero_reg)); |
| 1166 | __ mfhi(result_reg); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1167 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1168 | DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg)); |
| 1169 | } |
| 1170 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | |
machenbach@chromium.org | 00a4ad7 | 2014-03-17 08:13:32 +0000 | [diff] [blame] | 1174 | void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { |
| 1175 | Register dividend = ToRegister(instr->dividend()); |
| 1176 | int32_t divisor = instr->divisor(); |
| 1177 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | ed1a631 | 2014-04-02 00:05:15 +0000 | [diff] [blame] | 1178 | ASSERT(divisor == kMinInt || IsPowerOf2(Abs(divisor))); |
machenbach@chromium.org | 00a4ad7 | 2014-03-17 08:13:32 +0000 | [diff] [blame] | 1179 | ASSERT(!result.is(dividend)); |
| 1180 | |
| 1181 | // Check for (0 / -x) that will produce negative zero. |
| 1182 | HDiv* hdiv = instr->hydrogen(); |
| 1183 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1184 | DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg)); |
| 1185 | } |
| 1186 | // Check for (kMinInt / -1). |
| 1187 | if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { |
| 1188 | DeoptimizeIf(eq, instr->environment(), dividend, Operand(kMinInt)); |
| 1189 | } |
| 1190 | // Deoptimize if remainder will not be 0. |
| 1191 | if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && |
| 1192 | divisor != 1 && divisor != -1) { |
| 1193 | int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1); |
| 1194 | __ And(at, dividend, Operand(mask)); |
| 1195 | DeoptimizeIf(ne, instr->environment(), at, Operand(zero_reg)); |
| 1196 | } |
| 1197 | |
| 1198 | if (divisor == -1) { // Nice shortcut, not needed for correctness. |
| 1199 | __ Subu(result, zero_reg, dividend); |
| 1200 | return; |
| 1201 | } |
| 1202 | uint16_t shift = WhichPowerOf2Abs(divisor); |
| 1203 | if (shift == 0) { |
| 1204 | __ Move(result, dividend); |
| 1205 | } else if (shift == 1) { |
| 1206 | __ srl(result, dividend, 31); |
| 1207 | __ Addu(result, dividend, Operand(result)); |
| 1208 | } else { |
| 1209 | __ sra(result, dividend, 31); |
| 1210 | __ srl(result, result, 32 - shift); |
| 1211 | __ Addu(result, dividend, Operand(result)); |
| 1212 | } |
| 1213 | if (shift > 0) __ sra(result, result, shift); |
| 1214 | if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | void LCodeGen::DoDivByConstI(LDivByConstI* instr) { |
| 1219 | Register dividend = ToRegister(instr->dividend()); |
| 1220 | int32_t divisor = instr->divisor(); |
| 1221 | Register result = ToRegister(instr->result()); |
| 1222 | ASSERT(!dividend.is(result)); |
| 1223 | |
| 1224 | if (divisor == 0) { |
| 1225 | DeoptimizeIf(al, instr->environment()); |
| 1226 | return; |
| 1227 | } |
| 1228 | |
| 1229 | // Check for (0 / -x) that will produce negative zero. |
| 1230 | HDiv* hdiv = instr->hydrogen(); |
| 1231 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1232 | DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg)); |
| 1233 | } |
| 1234 | |
machenbach@chromium.org | 69f64b1 | 2014-03-20 01:04:55 +0000 | [diff] [blame] | 1235 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
machenbach@chromium.org | 00a4ad7 | 2014-03-17 08:13:32 +0000 | [diff] [blame] | 1236 | if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1237 | |
| 1238 | if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1239 | __ Mul(scratch0(), result, Operand(divisor)); |
| 1240 | __ Subu(scratch0(), scratch0(), dividend); |
| 1241 | DeoptimizeIf(ne, instr->environment(), scratch0(), Operand(zero_reg)); |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1246 | // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1247 | void LCodeGen::DoDivI(LDivI* instr) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1248 | HBinaryOperation* hdiv = instr->hydrogen(); |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1249 | Register dividend = ToRegister(instr->dividend()); |
| 1250 | Register divisor = ToRegister(instr->divisor()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1251 | const Register result = ToRegister(instr->result()); |
| 1252 | |
| 1253 | // On MIPS div is asynchronous - it will run in the background while we |
| 1254 | // check for special cases. |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1255 | __ div(dividend, divisor); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1256 | |
| 1257 | // Check for x / 0. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1258 | if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1259 | DeoptimizeIf(eq, instr->environment(), divisor, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | // Check for (0 / -x) that will produce negative zero. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1263 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1264 | Label left_not_zero; |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1265 | __ Branch(&left_not_zero, ne, dividend, Operand(zero_reg)); |
| 1266 | DeoptimizeIf(lt, instr->environment(), divisor, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1267 | __ bind(&left_not_zero); |
| 1268 | } |
| 1269 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1270 | // Check for (kMinInt / -1). |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1271 | if (hdiv->CheckFlag(HValue::kCanOverflow) && |
| 1272 | !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1273 | Label left_not_min_int; |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1274 | __ Branch(&left_not_min_int, ne, dividend, Operand(kMinInt)); |
| 1275 | DeoptimizeIf(eq, instr->environment(), divisor, Operand(-1)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1276 | __ bind(&left_not_min_int); |
| 1277 | } |
| 1278 | |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1279 | if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1280 | __ mfhi(result); |
| 1281 | DeoptimizeIf(ne, instr->environment(), result, Operand(zero_reg)); |
machenbach@chromium.org | 00a4ad7 | 2014-03-17 08:13:32 +0000 | [diff] [blame] | 1282 | __ mflo(result); |
| 1283 | } else { |
| 1284 | __ mflo(result); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1285 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1289 | void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
| 1290 | DoubleRegister addend = ToDoubleRegister(instr->addend()); |
| 1291 | DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1292 | DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1293 | |
| 1294 | // This is computed in-place. |
| 1295 | ASSERT(addend.is(ToDoubleRegister(instr->result()))); |
| 1296 | |
| 1297 | __ madd_d(addend, addend, multiplier, multiplicand); |
| 1298 | } |
| 1299 | |
| 1300 | |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1301 | void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { |
| 1302 | Register dividend = ToRegister(instr->dividend()); |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1303 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1304 | int32_t divisor = instr->divisor(); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1305 | Register scratch = scratch0(); |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1306 | ASSERT(!scratch.is(dividend)); |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1307 | |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1308 | // If the divisor is positive, things are easy: There can be no deopts and we |
| 1309 | // can simply do an arithmetic right shift. |
| 1310 | if (divisor == 1) return; |
| 1311 | uint16_t shift = WhichPowerOf2Abs(divisor); |
| 1312 | if (divisor > 1) { |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1313 | __ sra(result, dividend, shift); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1314 | return; |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1315 | } |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1316 | |
| 1317 | // If the divisor is negative, we have to negate and handle edge cases. |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1318 | if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { |
| 1319 | __ Move(scratch, dividend); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1320 | } |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1321 | __ Subu(result, zero_reg, dividend); |
| 1322 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1323 | DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); |
| 1324 | } |
| 1325 | if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) { |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1326 | // Note that we could emit branch-free code, but that would need one more |
| 1327 | // register. |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1328 | __ Xor(at, scratch, result); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1329 | if (divisor == -1) { |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1330 | DeoptimizeIf(ge, instr->environment(), at, Operand(zero_reg)); |
| 1331 | __ sra(result, dividend, shift); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1332 | } else { |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1333 | Label no_overflow, done; |
| 1334 | __ Branch(&no_overflow, lt, at, Operand(zero_reg)); |
| 1335 | __ li(result, Operand(kMinInt / divisor)); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1336 | __ Branch(&done); |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1337 | __ bind(&no_overflow); |
| 1338 | __ sra(result, dividend, shift); |
| 1339 | __ bind(&done); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1340 | } |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 1341 | } else { |
| 1342 | __ sra(result, dividend, shift); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1343 | } |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1347 | void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
| 1348 | Register dividend = ToRegister(instr->dividend()); |
| 1349 | int32_t divisor = instr->divisor(); |
| 1350 | Register result = ToRegister(instr->result()); |
| 1351 | ASSERT(!dividend.is(result)); |
| 1352 | |
| 1353 | if (divisor == 0) { |
| 1354 | DeoptimizeIf(al, instr->environment()); |
| 1355 | return; |
| 1356 | } |
| 1357 | |
| 1358 | // Check for (0 / -x) that will produce negative zero. |
| 1359 | HMathFloorOfDiv* hdiv = instr->hydrogen(); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1360 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1361 | DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg)); |
| 1362 | } |
| 1363 | |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 1364 | // Easy case: We need no dynamic check for the dividend and the flooring |
| 1365 | // division is the same as the truncating division. |
| 1366 | if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 1367 | (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 1368 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1369 | if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1370 | return; |
| 1371 | } |
| 1372 | |
| 1373 | // In the general case we may need to adjust before and after the truncating |
| 1374 | // division to get a flooring division. |
| 1375 | Register temp = ToRegister(instr->temp()); |
| 1376 | ASSERT(!temp.is(dividend) && !temp.is(result)); |
| 1377 | Label needs_adjustment, done; |
| 1378 | __ Branch(&needs_adjustment, divisor > 0 ? lt : gt, |
| 1379 | dividend, Operand(zero_reg)); |
| 1380 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1381 | if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1382 | __ jmp(&done); |
| 1383 | __ bind(&needs_adjustment); |
| 1384 | __ Addu(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
| 1385 | __ TruncatingDiv(result, temp, Abs(divisor)); |
| 1386 | if (divisor < 0) __ Subu(result, zero_reg, result); |
| 1387 | __ Subu(result, result, Operand(1)); |
| 1388 | __ bind(&done); |
machenbach@chromium.org | bcc3672 | 2014-03-11 07:52:26 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1392 | // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
| 1393 | void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
| 1394 | HBinaryOperation* hdiv = instr->hydrogen(); |
| 1395 | Register dividend = ToRegister(instr->dividend()); |
| 1396 | Register divisor = ToRegister(instr->divisor()); |
| 1397 | const Register result = ToRegister(instr->result()); |
| 1398 | |
| 1399 | // On MIPS div is asynchronous - it will run in the background while we |
| 1400 | // check for special cases. |
| 1401 | __ div(dividend, divisor); |
| 1402 | |
| 1403 | // Check for x / 0. |
| 1404 | if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1405 | DeoptimizeIf(eq, instr->environment(), divisor, Operand(zero_reg)); |
| 1406 | } |
| 1407 | |
| 1408 | // Check for (0 / -x) that will produce negative zero. |
| 1409 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1410 | Label left_not_zero; |
| 1411 | __ Branch(&left_not_zero, ne, dividend, Operand(zero_reg)); |
| 1412 | DeoptimizeIf(lt, instr->environment(), divisor, Operand(zero_reg)); |
| 1413 | __ bind(&left_not_zero); |
| 1414 | } |
| 1415 | |
| 1416 | // Check for (kMinInt / -1). |
| 1417 | if (hdiv->CheckFlag(HValue::kCanOverflow) && |
| 1418 | !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
| 1419 | Label left_not_min_int; |
| 1420 | __ Branch(&left_not_min_int, ne, dividend, Operand(kMinInt)); |
| 1421 | DeoptimizeIf(eq, instr->environment(), divisor, Operand(-1)); |
| 1422 | __ bind(&left_not_min_int); |
| 1423 | } |
| 1424 | |
| 1425 | // We performed a truncating division. Correct the result if necessary. |
| 1426 | Label done; |
| 1427 | Register remainder = scratch0(); |
| 1428 | __ mfhi(remainder); |
| 1429 | __ mflo(result); |
| 1430 | __ Branch(&done, eq, remainder, Operand(zero_reg), USE_DELAY_SLOT); |
| 1431 | __ Xor(remainder, remainder, Operand(divisor)); |
| 1432 | __ Branch(&done, ge, remainder, Operand(zero_reg)); |
| 1433 | __ Subu(result, result, Operand(1)); |
| 1434 | __ bind(&done); |
| 1435 | } |
| 1436 | |
| 1437 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1438 | void LCodeGen::DoMulI(LMulI* instr) { |
| 1439 | Register scratch = scratch0(); |
| 1440 | Register result = ToRegister(instr->result()); |
| 1441 | // Note that result may alias left. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1442 | Register left = ToRegister(instr->left()); |
| 1443 | LOperand* right_op = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1444 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1445 | bool bailout_on_minus_zero = |
| 1446 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1447 | bool overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1448 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1449 | if (right_op->IsConstantOperand()) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1450 | int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1451 | |
| 1452 | if (bailout_on_minus_zero && (constant < 0)) { |
| 1453 | // The case of a null constant will be handled separately. |
| 1454 | // If constant is negative and left is null, the result should be -0. |
| 1455 | DeoptimizeIf(eq, instr->environment(), left, Operand(zero_reg)); |
| 1456 | } |
| 1457 | |
| 1458 | switch (constant) { |
| 1459 | case -1: |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1460 | if (overflow) { |
| 1461 | __ SubuAndCheckForOverflow(result, zero_reg, left, scratch); |
| 1462 | DeoptimizeIf(lt, instr->environment(), scratch, Operand(zero_reg)); |
| 1463 | } else { |
| 1464 | __ Subu(result, zero_reg, left); |
| 1465 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1466 | break; |
| 1467 | case 0: |
| 1468 | if (bailout_on_minus_zero) { |
| 1469 | // If left is strictly negative and the constant is null, the |
| 1470 | // result is -0. Deoptimize if required, otherwise return 0. |
| 1471 | DeoptimizeIf(lt, instr->environment(), left, Operand(zero_reg)); |
| 1472 | } |
| 1473 | __ mov(result, zero_reg); |
| 1474 | break; |
| 1475 | case 1: |
| 1476 | // Nothing to do. |
| 1477 | __ Move(result, left); |
| 1478 | break; |
| 1479 | default: |
| 1480 | // Multiplying by powers of two and powers of two plus or minus |
| 1481 | // one can be done faster with shifted operands. |
| 1482 | // For other constants we emit standard code. |
| 1483 | int32_t mask = constant >> 31; |
| 1484 | uint32_t constant_abs = (constant + mask) ^ mask; |
| 1485 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1486 | if (IsPowerOf2(constant_abs)) { |
| 1487 | int32_t shift = WhichPowerOf2(constant_abs); |
| 1488 | __ sll(result, left, shift); |
| 1489 | // Correct the sign of the result if the constant is negative. |
| 1490 | if (constant < 0) __ Subu(result, zero_reg, result); |
| 1491 | } else if (IsPowerOf2(constant_abs - 1)) { |
| 1492 | int32_t shift = WhichPowerOf2(constant_abs - 1); |
| 1493 | __ sll(scratch, left, shift); |
| 1494 | __ Addu(result, scratch, left); |
| 1495 | // Correct the sign of the result if the constant is negative. |
| 1496 | if (constant < 0) __ Subu(result, zero_reg, result); |
| 1497 | } else if (IsPowerOf2(constant_abs + 1)) { |
| 1498 | int32_t shift = WhichPowerOf2(constant_abs + 1); |
| 1499 | __ sll(scratch, left, shift); |
| 1500 | __ Subu(result, scratch, left); |
| 1501 | // Correct the sign of the result if the constant is negative. |
| 1502 | if (constant < 0) __ Subu(result, zero_reg, result); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1503 | } else { |
| 1504 | // Generate standard code. |
| 1505 | __ li(at, constant); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1506 | __ Mul(result, left, at); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | } else { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1511 | ASSERT(right_op->IsRegister()); |
| 1512 | Register right = ToRegister(right_op); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1513 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1514 | if (overflow) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1515 | // hi:lo = left * right. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1516 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1517 | __ SmiUntag(result, left); |
| 1518 | __ mult(result, right); |
| 1519 | __ mfhi(scratch); |
| 1520 | __ mflo(result); |
| 1521 | } else { |
| 1522 | __ mult(left, right); |
| 1523 | __ mfhi(scratch); |
| 1524 | __ mflo(result); |
| 1525 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1526 | __ sra(at, result, 31); |
| 1527 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(at)); |
| 1528 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1529 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1530 | __ SmiUntag(result, left); |
| 1531 | __ Mul(result, result, right); |
| 1532 | } else { |
| 1533 | __ Mul(result, left, right); |
| 1534 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | if (bailout_on_minus_zero) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1538 | Label done; |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1539 | __ Xor(at, left, right); |
| 1540 | __ Branch(&done, ge, at, Operand(zero_reg)); |
| 1541 | // Bail out if the result is minus zero. |
| 1542 | DeoptimizeIf(eq, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1543 | instr->environment(), |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1544 | result, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1545 | Operand(zero_reg)); |
| 1546 | __ bind(&done); |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | void LCodeGen::DoBitI(LBitI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1553 | LOperand* left_op = instr->left(); |
| 1554 | LOperand* right_op = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1555 | ASSERT(left_op->IsRegister()); |
| 1556 | Register left = ToRegister(left_op); |
| 1557 | Register result = ToRegister(instr->result()); |
| 1558 | Operand right(no_reg); |
| 1559 | |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 1560 | if (right_op->IsStackSlot()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1561 | right = Operand(EmitLoadRegister(right_op, at)); |
| 1562 | } else { |
| 1563 | ASSERT(right_op->IsRegister() || right_op->IsConstantOperand()); |
| 1564 | right = ToOperand(right_op); |
| 1565 | } |
| 1566 | |
| 1567 | switch (instr->op()) { |
| 1568 | case Token::BIT_AND: |
| 1569 | __ And(result, left, right); |
| 1570 | break; |
| 1571 | case Token::BIT_OR: |
| 1572 | __ Or(result, left, right); |
| 1573 | break; |
| 1574 | case Token::BIT_XOR: |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1575 | if (right_op->IsConstantOperand() && right.immediate() == int32_t(~0)) { |
| 1576 | __ Nor(result, zero_reg, left); |
| 1577 | } else { |
| 1578 | __ Xor(result, left, right); |
| 1579 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1580 | break; |
| 1581 | default: |
| 1582 | UNREACHABLE(); |
| 1583 | break; |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | |
| 1588 | void LCodeGen::DoShiftI(LShiftI* instr) { |
| 1589 | // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
| 1590 | // result may alias either of them. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1591 | LOperand* right_op = instr->right(); |
| 1592 | Register left = ToRegister(instr->left()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1593 | Register result = ToRegister(instr->result()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1594 | Register scratch = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1595 | |
| 1596 | if (right_op->IsRegister()) { |
| 1597 | // No need to mask the right operand on MIPS, it is built into the variable |
| 1598 | // shift instructions. |
| 1599 | switch (instr->op()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1600 | case Token::ROR: |
| 1601 | __ Ror(result, left, Operand(ToRegister(right_op))); |
| 1602 | break; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1603 | case Token::SAR: |
| 1604 | __ srav(result, left, ToRegister(right_op)); |
| 1605 | break; |
| 1606 | case Token::SHR: |
| 1607 | __ srlv(result, left, ToRegister(right_op)); |
| 1608 | if (instr->can_deopt()) { |
| 1609 | DeoptimizeIf(lt, instr->environment(), result, Operand(zero_reg)); |
| 1610 | } |
| 1611 | break; |
| 1612 | case Token::SHL: |
| 1613 | __ sllv(result, left, ToRegister(right_op)); |
| 1614 | break; |
| 1615 | default: |
| 1616 | UNREACHABLE(); |
| 1617 | break; |
| 1618 | } |
| 1619 | } else { |
| 1620 | // Mask the right_op operand. |
| 1621 | int value = ToInteger32(LConstantOperand::cast(right_op)); |
| 1622 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1623 | switch (instr->op()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1624 | case Token::ROR: |
| 1625 | if (shift_count != 0) { |
| 1626 | __ Ror(result, left, Operand(shift_count)); |
| 1627 | } else { |
| 1628 | __ Move(result, left); |
| 1629 | } |
| 1630 | break; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1631 | case Token::SAR: |
| 1632 | if (shift_count != 0) { |
| 1633 | __ sra(result, left, shift_count); |
| 1634 | } else { |
| 1635 | __ Move(result, left); |
| 1636 | } |
| 1637 | break; |
| 1638 | case Token::SHR: |
| 1639 | if (shift_count != 0) { |
| 1640 | __ srl(result, left, shift_count); |
| 1641 | } else { |
| 1642 | if (instr->can_deopt()) { |
| 1643 | __ And(at, left, Operand(0x80000000)); |
| 1644 | DeoptimizeIf(ne, instr->environment(), at, Operand(zero_reg)); |
| 1645 | } |
| 1646 | __ Move(result, left); |
| 1647 | } |
| 1648 | break; |
| 1649 | case Token::SHL: |
| 1650 | if (shift_count != 0) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1651 | if (instr->hydrogen_value()->representation().IsSmi() && |
| 1652 | instr->can_deopt()) { |
| 1653 | if (shift_count != 1) { |
| 1654 | __ sll(result, left, shift_count - 1); |
| 1655 | __ SmiTagCheckOverflow(result, result, scratch); |
| 1656 | } else { |
| 1657 | __ SmiTagCheckOverflow(result, left, scratch); |
| 1658 | } |
| 1659 | DeoptimizeIf(lt, instr->environment(), scratch, Operand(zero_reg)); |
| 1660 | } else { |
| 1661 | __ sll(result, left, shift_count); |
| 1662 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1663 | } else { |
| 1664 | __ Move(result, left); |
| 1665 | } |
| 1666 | break; |
| 1667 | default: |
| 1668 | UNREACHABLE(); |
| 1669 | break; |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | |
| 1675 | void LCodeGen::DoSubI(LSubI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1676 | LOperand* left = instr->left(); |
| 1677 | LOperand* right = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1678 | LOperand* result = instr->result(); |
| 1679 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1680 | |
| 1681 | if (!can_overflow) { |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 1682 | if (right->IsStackSlot()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1683 | Register right_reg = EmitLoadRegister(right, at); |
| 1684 | __ Subu(ToRegister(result), ToRegister(left), Operand(right_reg)); |
| 1685 | } else { |
| 1686 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
| 1687 | __ Subu(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1688 | } |
| 1689 | } else { // can_overflow. |
| 1690 | Register overflow = scratch0(); |
| 1691 | Register scratch = scratch1(); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 1692 | if (right->IsStackSlot() || right->IsConstantOperand()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1693 | Register right_reg = EmitLoadRegister(right, scratch); |
| 1694 | __ SubuAndCheckForOverflow(ToRegister(result), |
| 1695 | ToRegister(left), |
| 1696 | right_reg, |
| 1697 | overflow); // Reg at also used as scratch. |
| 1698 | } else { |
| 1699 | ASSERT(right->IsRegister()); |
| 1700 | // Due to overflow check macros not supporting constant operands, |
| 1701 | // handling the IsConstantOperand case was moved to prev if clause. |
| 1702 | __ SubuAndCheckForOverflow(ToRegister(result), |
| 1703 | ToRegister(left), |
| 1704 | ToRegister(right), |
| 1705 | overflow); // Reg at also used as scratch. |
| 1706 | } |
| 1707 | DeoptimizeIf(lt, instr->environment(), overflow, Operand(zero_reg)); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | |
| 1712 | void LCodeGen::DoConstantI(LConstantI* instr) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1713 | __ li(ToRegister(instr->result()), Operand(instr->value())); |
| 1714 | } |
| 1715 | |
| 1716 | |
| 1717 | void LCodeGen::DoConstantS(LConstantS* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1718 | __ li(ToRegister(instr->result()), Operand(instr->value())); |
| 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | void LCodeGen::DoConstantD(LConstantD* instr) { |
| 1723 | ASSERT(instr->result()->IsDoubleRegister()); |
| 1724 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1725 | double v = instr->value(); |
| 1726 | __ Move(result, v); |
| 1727 | } |
| 1728 | |
| 1729 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1730 | void LCodeGen::DoConstantE(LConstantE* instr) { |
| 1731 | __ li(ToRegister(instr->result()), Operand(instr->value())); |
| 1732 | } |
| 1733 | |
| 1734 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1735 | void LCodeGen::DoConstantT(LConstantT* instr) { |
palfia@homejinni.com | 8b6c786 | 2013-09-10 15:12:05 +0000 | [diff] [blame] | 1736 | Handle<Object> value = instr->value(isolate()); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1737 | AllowDeferredHandleDereference smi_check; |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1738 | __ li(ToRegister(instr->result()), value); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1742 | void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 1743 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1744 | Register map = ToRegister(instr->value()); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1745 | __ EnumLength(result, map); |
| 1746 | } |
| 1747 | |
| 1748 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1749 | void LCodeGen::DoDateField(LDateField* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1750 | Register object = ToRegister(instr->date()); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1751 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1752 | Register scratch = ToRegister(instr->temp()); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1753 | Smi* index = instr->index(); |
| 1754 | Label runtime, done; |
| 1755 | ASSERT(object.is(a0)); |
| 1756 | ASSERT(result.is(v0)); |
| 1757 | ASSERT(!scratch.is(scratch0())); |
| 1758 | ASSERT(!scratch.is(object)); |
| 1759 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1760 | __ SmiTst(object, at); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1761 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1762 | __ GetObjectType(object, scratch, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1763 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(JS_DATE_TYPE)); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1764 | |
| 1765 | if (index->value() == 0) { |
| 1766 | __ lw(result, FieldMemOperand(object, JSDate::kValueOffset)); |
| 1767 | } else { |
| 1768 | if (index->value() < JSDate::kFirstUncachedField) { |
| 1769 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 1770 | __ li(scratch, Operand(stamp)); |
| 1771 | __ lw(scratch, MemOperand(scratch)); |
| 1772 | __ lw(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); |
| 1773 | __ Branch(&runtime, ne, scratch, Operand(scratch0())); |
| 1774 | __ lw(result, FieldMemOperand(object, JSDate::kValueOffset + |
| 1775 | kPointerSize * index->value())); |
| 1776 | __ jmp(&done); |
| 1777 | } |
| 1778 | __ bind(&runtime); |
| 1779 | __ PrepareCallCFunction(2, scratch); |
| 1780 | __ li(a1, Operand(index)); |
| 1781 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 1782 | __ bind(&done); |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1787 | MemOperand LCodeGen::BuildSeqStringOperand(Register string, |
| 1788 | LOperand* index, |
| 1789 | String::Encoding encoding) { |
| 1790 | if (index->IsConstantOperand()) { |
| 1791 | int offset = ToInteger32(LConstantOperand::cast(index)); |
| 1792 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 1793 | offset *= kUC16Size; |
| 1794 | } |
| 1795 | STATIC_ASSERT(kCharSize == 1); |
| 1796 | return FieldMemOperand(string, SeqString::kHeaderSize + offset); |
| 1797 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1798 | Register scratch = scratch0(); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1799 | ASSERT(!scratch.is(string)); |
| 1800 | ASSERT(!scratch.is(ToRegister(index))); |
| 1801 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1802 | __ Addu(scratch, string, ToRegister(index)); |
| 1803 | } else { |
| 1804 | STATIC_ASSERT(kUC16Size == 2); |
| 1805 | __ sll(scratch, ToRegister(index), 1); |
| 1806 | __ Addu(scratch, string, scratch); |
| 1807 | } |
| 1808 | return FieldMemOperand(scratch, SeqString::kHeaderSize); |
| 1809 | } |
| 1810 | |
| 1811 | |
| 1812 | void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
| 1813 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1814 | Register string = ToRegister(instr->string()); |
| 1815 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1816 | |
| 1817 | if (FLAG_debug_code) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1818 | Register scratch = scratch0(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1819 | __ lw(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 1820 | __ lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1821 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1822 | __ And(scratch, scratch, |
| 1823 | Operand(kStringRepresentationMask | kStringEncodingMask)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1824 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1825 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1826 | __ Subu(at, scratch, Operand(encoding == String::ONE_BYTE_ENCODING |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1827 | ? one_byte_seq_type : two_byte_seq_type)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1828 | __ Check(eq, kUnexpectedStringType, at, Operand(zero_reg)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1831 | MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 1832 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1833 | __ lbu(result, operand); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1834 | } else { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1835 | __ lhu(result, operand); |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | |
| 1840 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 1841 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1842 | Register string = ToRegister(instr->string()); |
| 1843 | Register value = ToRegister(instr->value()); |
| 1844 | |
| 1845 | if (FLAG_debug_code) { |
| 1846 | Register scratch = scratch0(); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1847 | Register index = ToRegister(instr->index()); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1848 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1849 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1850 | int encoding_mask = |
| 1851 | instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING |
| 1852 | ? one_byte_seq_type : two_byte_seq_type; |
| 1853 | __ EmitSeqStringSetCharCheck(string, index, value, scratch, encoding_mask); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 1857 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1858 | __ sb(value, operand); |
| 1859 | } else { |
| 1860 | __ sh(value, operand); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1861 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1865 | void LCodeGen::DoAddI(LAddI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1866 | LOperand* left = instr->left(); |
| 1867 | LOperand* right = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1868 | LOperand* result = instr->result(); |
| 1869 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1870 | |
| 1871 | if (!can_overflow) { |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 1872 | if (right->IsStackSlot()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1873 | Register right_reg = EmitLoadRegister(right, at); |
| 1874 | __ Addu(ToRegister(result), ToRegister(left), Operand(right_reg)); |
| 1875 | } else { |
| 1876 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
| 1877 | __ Addu(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1878 | } |
| 1879 | } else { // can_overflow. |
| 1880 | Register overflow = scratch0(); |
| 1881 | Register scratch = scratch1(); |
| 1882 | if (right->IsStackSlot() || |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1883 | right->IsConstantOperand()) { |
| 1884 | Register right_reg = EmitLoadRegister(right, scratch); |
| 1885 | __ AdduAndCheckForOverflow(ToRegister(result), |
| 1886 | ToRegister(left), |
| 1887 | right_reg, |
| 1888 | overflow); // Reg at also used as scratch. |
| 1889 | } else { |
| 1890 | ASSERT(right->IsRegister()); |
| 1891 | // Due to overflow check macros not supporting constant operands, |
| 1892 | // handling the IsConstantOperand case was moved to prev if clause. |
| 1893 | __ AdduAndCheckForOverflow(ToRegister(result), |
| 1894 | ToRegister(left), |
| 1895 | ToRegister(right), |
| 1896 | overflow); // Reg at also used as scratch. |
| 1897 | } |
| 1898 | DeoptimizeIf(lt, instr->environment(), overflow, Operand(zero_reg)); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1903 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1904 | LOperand* left = instr->left(); |
| 1905 | LOperand* right = instr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1906 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
| 1907 | Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1908 | if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1909 | Register left_reg = ToRegister(left); |
| 1910 | Operand right_op = (right->IsRegister() || right->IsConstantOperand()) |
| 1911 | ? ToOperand(right) |
| 1912 | : Operand(EmitLoadRegister(right, at)); |
| 1913 | Register result_reg = ToRegister(instr->result()); |
| 1914 | Label return_right, done; |
| 1915 | if (!result_reg.is(left_reg)) { |
| 1916 | __ Branch(&return_right, NegateCondition(condition), left_reg, right_op); |
| 1917 | __ mov(result_reg, left_reg); |
| 1918 | __ Branch(&done); |
| 1919 | } |
| 1920 | __ Branch(&done, condition, left_reg, right_op); |
| 1921 | __ bind(&return_right); |
| 1922 | __ Addu(result_reg, zero_reg, right_op); |
| 1923 | __ bind(&done); |
| 1924 | } else { |
| 1925 | ASSERT(instr->hydrogen()->representation().IsDouble()); |
| 1926 | FPURegister left_reg = ToDoubleRegister(left); |
| 1927 | FPURegister right_reg = ToDoubleRegister(right); |
| 1928 | FPURegister result_reg = ToDoubleRegister(instr->result()); |
| 1929 | Label check_nan_left, check_zero, return_left, return_right, done; |
| 1930 | __ BranchF(&check_zero, &check_nan_left, eq, left_reg, right_reg); |
| 1931 | __ BranchF(&return_left, NULL, condition, left_reg, right_reg); |
| 1932 | __ Branch(&return_right); |
| 1933 | |
| 1934 | __ bind(&check_zero); |
| 1935 | // left == right != 0. |
| 1936 | __ BranchF(&return_left, NULL, ne, left_reg, kDoubleRegZero); |
| 1937 | // At this point, both left and right are either 0 or -0. |
| 1938 | if (operation == HMathMinMax::kMathMin) { |
| 1939 | __ neg_d(left_reg, left_reg); |
| 1940 | __ sub_d(result_reg, left_reg, right_reg); |
| 1941 | __ neg_d(result_reg, result_reg); |
| 1942 | } else { |
| 1943 | __ add_d(result_reg, left_reg, right_reg); |
| 1944 | } |
| 1945 | __ Branch(&done); |
| 1946 | |
| 1947 | __ bind(&check_nan_left); |
| 1948 | // left == NaN. |
| 1949 | __ BranchF(NULL, &return_left, eq, left_reg, left_reg); |
| 1950 | __ bind(&return_right); |
| 1951 | if (!right_reg.is(result_reg)) { |
| 1952 | __ mov_d(result_reg, right_reg); |
| 1953 | } |
| 1954 | __ Branch(&done); |
| 1955 | |
| 1956 | __ bind(&return_left); |
| 1957 | if (!left_reg.is(result_reg)) { |
| 1958 | __ mov_d(result_reg, left_reg); |
| 1959 | } |
| 1960 | __ bind(&done); |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1965 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1966 | DoubleRegister left = ToDoubleRegister(instr->left()); |
| 1967 | DoubleRegister right = ToDoubleRegister(instr->right()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1968 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1969 | switch (instr->op()) { |
| 1970 | case Token::ADD: |
| 1971 | __ add_d(result, left, right); |
| 1972 | break; |
| 1973 | case Token::SUB: |
| 1974 | __ sub_d(result, left, right); |
| 1975 | break; |
| 1976 | case Token::MUL: |
| 1977 | __ mul_d(result, left, right); |
| 1978 | break; |
| 1979 | case Token::DIV: |
| 1980 | __ div_d(result, left, right); |
| 1981 | break; |
| 1982 | case Token::MOD: { |
| 1983 | // Save a0-a3 on the stack. |
| 1984 | RegList saved_regs = a0.bit() | a1.bit() | a2.bit() | a3.bit(); |
| 1985 | __ MultiPush(saved_regs); |
| 1986 | |
| 1987 | __ PrepareCallCFunction(0, 2, scratch0()); |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame] | 1988 | __ MovToFloatParameters(left, right); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1989 | __ CallCFunction( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1990 | ExternalReference::mod_two_doubles_operation(isolate()), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1991 | 0, 2); |
| 1992 | // Move the result in the double result register. |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame] | 1993 | __ MovFromFloatResult(result); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1994 | |
| 1995 | // Restore saved register. |
| 1996 | __ MultiPop(saved_regs); |
| 1997 | break; |
| 1998 | } |
| 1999 | default: |
| 2000 | UNREACHABLE(); |
| 2001 | break; |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | |
| 2006 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2007 | ASSERT(ToRegister(instr->context()).is(cp)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2008 | ASSERT(ToRegister(instr->left()).is(a1)); |
| 2009 | ASSERT(ToRegister(instr->right()).is(a0)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2010 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 2011 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2012 | BinaryOpICStub stub(instr->op(), NO_OVERWRITE); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2013 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2014 | // Other arch use a nop here, to signal that there is no inlined |
| 2015 | // patchable code. Mips does not need the nop, since our marker |
| 2016 | // instruction (andi zero_reg) will never be used in normal code. |
| 2017 | } |
| 2018 | |
| 2019 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2020 | template<class InstrType> |
| 2021 | void LCodeGen::EmitBranch(InstrType instr, |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2022 | Condition condition, |
| 2023 | Register src1, |
| 2024 | const Operand& src2) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2025 | int left_block = instr->TrueDestination(chunk_); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2026 | int right_block = instr->FalseDestination(chunk_); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2027 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2028 | int next_block = GetNextEmittedBlock(); |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2029 | if (right_block == left_block || condition == al) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2030 | EmitGoto(left_block); |
| 2031 | } else if (left_block == next_block) { |
| 2032 | __ Branch(chunk_->GetAssemblyLabel(right_block), |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2033 | NegateCondition(condition), src1, src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2034 | } else if (right_block == next_block) { |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2035 | __ Branch(chunk_->GetAssemblyLabel(left_block), condition, src1, src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2036 | } else { |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2037 | __ Branch(chunk_->GetAssemblyLabel(left_block), condition, src1, src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2038 | __ Branch(chunk_->GetAssemblyLabel(right_block)); |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2043 | template<class InstrType> |
| 2044 | void LCodeGen::EmitBranchF(InstrType instr, |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2045 | Condition condition, |
| 2046 | FPURegister src1, |
| 2047 | FPURegister src2) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2048 | int right_block = instr->FalseDestination(chunk_); |
| 2049 | int left_block = instr->TrueDestination(chunk_); |
| 2050 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2051 | int next_block = GetNextEmittedBlock(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2052 | if (right_block == left_block) { |
| 2053 | EmitGoto(left_block); |
| 2054 | } else if (left_block == next_block) { |
| 2055 | __ BranchF(chunk_->GetAssemblyLabel(right_block), NULL, |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2056 | NegateCondition(condition), src1, src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2057 | } else if (right_block == next_block) { |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2058 | __ BranchF(chunk_->GetAssemblyLabel(left_block), NULL, |
| 2059 | condition, src1, src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2060 | } else { |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2061 | __ BranchF(chunk_->GetAssemblyLabel(left_block), NULL, |
| 2062 | condition, src1, src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2063 | __ Branch(chunk_->GetAssemblyLabel(right_block)); |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2068 | template<class InstrType> |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2069 | void LCodeGen::EmitFalseBranch(InstrType instr, |
| 2070 | Condition condition, |
| 2071 | Register src1, |
| 2072 | const Operand& src2) { |
| 2073 | int false_block = instr->FalseDestination(chunk_); |
| 2074 | __ Branch(chunk_->GetAssemblyLabel(false_block), condition, src1, src2); |
| 2075 | } |
| 2076 | |
| 2077 | |
| 2078 | template<class InstrType> |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2079 | void LCodeGen::EmitFalseBranchF(InstrType instr, |
| 2080 | Condition condition, |
| 2081 | FPURegister src1, |
| 2082 | FPURegister src2) { |
| 2083 | int false_block = instr->FalseDestination(chunk_); |
| 2084 | __ BranchF(chunk_->GetAssemblyLabel(false_block), NULL, |
| 2085 | condition, src1, src2); |
| 2086 | } |
| 2087 | |
| 2088 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2089 | void LCodeGen::DoDebugBreak(LDebugBreak* instr) { |
| 2090 | __ stop("LDebugBreak"); |
| 2091 | } |
| 2092 | |
| 2093 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2094 | void LCodeGen::DoBranch(LBranch* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2095 | Representation r = instr->hydrogen()->value()->representation(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2096 | if (r.IsInteger32() || r.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2097 | ASSERT(!info()->IsStub()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2098 | Register reg = ToRegister(instr->value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2099 | EmitBranch(instr, ne, reg, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2100 | } else if (r.IsDouble()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2101 | ASSERT(!info()->IsStub()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2102 | DoubleRegister reg = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2103 | // Test the double value. Zero and NaN are false. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2104 | EmitBranchF(instr, nue, reg, kDoubleRegZero); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2105 | } else { |
| 2106 | ASSERT(r.IsTagged()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2107 | Register reg = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2108 | HType type = instr->hydrogen()->value()->type(); |
| 2109 | if (type.IsBoolean()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2110 | ASSERT(!info()->IsStub()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2111 | __ LoadRoot(at, Heap::kTrueValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2112 | EmitBranch(instr, eq, reg, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2113 | } else if (type.IsSmi()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2114 | ASSERT(!info()->IsStub()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2115 | EmitBranch(instr, ne, reg, Operand(zero_reg)); |
| 2116 | } else if (type.IsJSArray()) { |
| 2117 | ASSERT(!info()->IsStub()); |
| 2118 | EmitBranch(instr, al, zero_reg, Operand(zero_reg)); |
| 2119 | } else if (type.IsHeapNumber()) { |
| 2120 | ASSERT(!info()->IsStub()); |
| 2121 | DoubleRegister dbl_scratch = double_scratch0(); |
| 2122 | __ ldc1(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2123 | // Test the double value. Zero and NaN are false. |
| 2124 | EmitBranchF(instr, nue, dbl_scratch, kDoubleRegZero); |
| 2125 | } else if (type.IsString()) { |
| 2126 | ASSERT(!info()->IsStub()); |
| 2127 | __ lw(at, FieldMemOperand(reg, String::kLengthOffset)); |
| 2128 | EmitBranch(instr, ne, at, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2129 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2130 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 2131 | // 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] | 2132 | if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2133 | |
| 2134 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 2135 | // undefined -> false. |
| 2136 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2137 | __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2138 | } |
| 2139 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 2140 | // Boolean -> its value. |
| 2141 | __ LoadRoot(at, Heap::kTrueValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2142 | __ Branch(instr->TrueLabel(chunk_), eq, reg, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2143 | __ LoadRoot(at, Heap::kFalseValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2144 | __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2145 | } |
| 2146 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 2147 | // 'null' -> false. |
| 2148 | __ LoadRoot(at, Heap::kNullValueRootIndex); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2149 | __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 2153 | // Smis: 0 -> false, all other -> true. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2154 | __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(zero_reg)); |
| 2155 | __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2156 | } else if (expected.NeedsMap()) { |
| 2157 | // If we need a map later and have a Smi -> deopt. |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 2158 | __ SmiTst(reg, at); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2159 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
| 2160 | } |
| 2161 | |
| 2162 | const Register map = scratch0(); |
| 2163 | if (expected.NeedsMap()) { |
| 2164 | __ lw(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2165 | if (expected.CanBeUndetectable()) { |
| 2166 | // Undetectable -> false. |
| 2167 | __ lbu(at, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 2168 | __ And(at, at, Operand(1 << Map::kIsUndetectable)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2169 | __ Branch(instr->FalseLabel(chunk_), ne, at, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 2174 | // spec object -> true. |
| 2175 | __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2176 | __ Branch(instr->TrueLabel(chunk_), |
| 2177 | ge, at, Operand(FIRST_SPEC_OBJECT_TYPE)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 2181 | // String value -> false iff empty. |
| 2182 | Label not_string; |
| 2183 | __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 2184 | __ Branch(¬_string, ge , at, Operand(FIRST_NONSTRING_TYPE)); |
| 2185 | __ lw(at, FieldMemOperand(reg, String::kLengthOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2186 | __ Branch(instr->TrueLabel(chunk_), ne, at, Operand(zero_reg)); |
| 2187 | __ Branch(instr->FalseLabel(chunk_)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2188 | __ bind(¬_string); |
| 2189 | } |
| 2190 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2191 | if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 2192 | // Symbol value -> true. |
| 2193 | const Register scratch = scratch1(); |
| 2194 | __ lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2195 | __ Branch(instr->TrueLabel(chunk_), eq, scratch, Operand(SYMBOL_TYPE)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2198 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 2199 | // heap number -> false iff +0, -0, or NaN. |
| 2200 | DoubleRegister dbl_scratch = double_scratch0(); |
| 2201 | Label not_heap_number; |
| 2202 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 2203 | __ Branch(¬_heap_number, ne, map, Operand(at)); |
| 2204 | __ ldc1(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2205 | __ BranchF(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2206 | ne, dbl_scratch, kDoubleRegZero); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2207 | // Falls through if dbl_scratch == 0. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2208 | __ Branch(instr->FalseLabel(chunk_)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2209 | __ bind(¬_heap_number); |
| 2210 | } |
| 2211 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2212 | if (!expected.IsGeneric()) { |
| 2213 | // We've seen something for the first time -> deopt. |
| 2214 | // This can only happen if we are not generic already. |
| 2215 | DeoptimizeIf(al, instr->environment(), zero_reg, Operand(zero_reg)); |
| 2216 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | |
| 2222 | void LCodeGen::EmitGoto(int block) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2223 | if (!IsNextEmittedBlock(block)) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2224 | __ jmp(chunk_->GetAssemblyLabel(LookupDestination(block))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | |
| 2229 | void LCodeGen::DoGoto(LGoto* instr) { |
| 2230 | EmitGoto(instr->block_id()); |
| 2231 | } |
| 2232 | |
| 2233 | |
| 2234 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
| 2235 | Condition cond = kNoCondition; |
| 2236 | switch (op) { |
| 2237 | case Token::EQ: |
| 2238 | case Token::EQ_STRICT: |
| 2239 | cond = eq; |
| 2240 | break; |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 2241 | case Token::NE: |
| 2242 | case Token::NE_STRICT: |
| 2243 | cond = ne; |
| 2244 | break; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2245 | case Token::LT: |
| 2246 | cond = is_unsigned ? lo : lt; |
| 2247 | break; |
| 2248 | case Token::GT: |
| 2249 | cond = is_unsigned ? hi : gt; |
| 2250 | break; |
| 2251 | case Token::LTE: |
| 2252 | cond = is_unsigned ? ls : le; |
| 2253 | break; |
| 2254 | case Token::GTE: |
| 2255 | cond = is_unsigned ? hs : ge; |
| 2256 | break; |
| 2257 | case Token::IN: |
| 2258 | case Token::INSTANCEOF: |
| 2259 | default: |
| 2260 | UNREACHABLE(); |
| 2261 | } |
| 2262 | return cond; |
| 2263 | } |
| 2264 | |
| 2265 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2266 | void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2267 | LOperand* left = instr->left(); |
| 2268 | LOperand* right = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2269 | Condition cond = TokenToCondition(instr->op(), false); |
| 2270 | |
| 2271 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2272 | // We can statically evaluate the comparison. |
| 2273 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2274 | double right_val = ToDouble(LConstantOperand::cast(right)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2275 | int next_block = EvalComparison(instr->op(), left_val, right_val) ? |
| 2276 | instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2277 | EmitGoto(next_block); |
| 2278 | } else { |
| 2279 | if (instr->is_double()) { |
| 2280 | // Compare left and right as doubles and load the |
| 2281 | // resulting flags into the normal status register. |
| 2282 | FPURegister left_reg = ToDoubleRegister(left); |
| 2283 | FPURegister right_reg = ToDoubleRegister(right); |
| 2284 | |
| 2285 | // If a NaN is involved, i.e. the result is unordered, |
| 2286 | // jump to false block label. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2287 | __ BranchF(NULL, instr->FalseLabel(chunk_), eq, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2288 | left_reg, right_reg); |
| 2289 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2290 | EmitBranchF(instr, cond, left_reg, right_reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2291 | } else { |
| 2292 | Register cmp_left; |
| 2293 | Operand cmp_right = Operand(0); |
| 2294 | |
| 2295 | if (right->IsConstantOperand()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2296 | int32_t value = ToInteger32(LConstantOperand::cast(right)); |
| 2297 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2298 | cmp_left = ToRegister(left); |
| 2299 | cmp_right = Operand(Smi::FromInt(value)); |
| 2300 | } else { |
| 2301 | cmp_left = ToRegister(left); |
| 2302 | cmp_right = Operand(value); |
| 2303 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2304 | } else if (left->IsConstantOperand()) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2305 | int32_t value = ToInteger32(LConstantOperand::cast(left)); |
| 2306 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2307 | cmp_left = ToRegister(right); |
| 2308 | cmp_right = Operand(Smi::FromInt(value)); |
| 2309 | } else { |
| 2310 | cmp_left = ToRegister(right); |
| 2311 | cmp_right = Operand(value); |
| 2312 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2313 | // We transposed the operands. Reverse the condition. |
| 2314 | cond = ReverseCondition(cond); |
| 2315 | } else { |
| 2316 | cmp_left = ToRegister(left); |
| 2317 | cmp_right = Operand(ToRegister(right)); |
| 2318 | } |
| 2319 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2320 | EmitBranch(instr, cond, cmp_left, cmp_right); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2321 | } |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | |
| 2326 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2327 | Register left = ToRegister(instr->left()); |
| 2328 | Register right = ToRegister(instr->right()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2329 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2330 | EmitBranch(instr, eq, left, Operand(right)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 2334 | void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
| 2335 | if (instr->hydrogen()->representation().IsTagged()) { |
| 2336 | Register input_reg = ToRegister(instr->object()); |
| 2337 | __ li(at, Operand(factory()->the_hole_value())); |
| 2338 | EmitBranch(instr, eq, input_reg, Operand(at)); |
| 2339 | return; |
| 2340 | } |
| 2341 | |
| 2342 | DoubleRegister input_reg = ToDoubleRegister(instr->object()); |
| 2343 | EmitFalseBranchF(instr, eq, input_reg, input_reg); |
| 2344 | |
| 2345 | Register scratch = scratch0(); |
| 2346 | __ FmoveHigh(scratch, input_reg); |
| 2347 | EmitBranch(instr, eq, scratch, Operand(kHoleNanUpper32)); |
| 2348 | } |
| 2349 | |
| 2350 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2351 | void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) { |
| 2352 | Representation rep = instr->hydrogen()->value()->representation(); |
| 2353 | ASSERT(!rep.IsInteger32()); |
| 2354 | Register scratch = ToRegister(instr->temp()); |
| 2355 | |
| 2356 | if (rep.IsDouble()) { |
| 2357 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 2358 | EmitFalseBranchF(instr, ne, value, kDoubleRegZero); |
| 2359 | __ FmoveHigh(scratch, value); |
| 2360 | __ li(at, 0x80000000); |
| 2361 | } else { |
| 2362 | Register value = ToRegister(instr->value()); |
| 2363 | __ CheckMap(value, |
| 2364 | scratch, |
| 2365 | Heap::kHeapNumberMapRootIndex, |
| 2366 | instr->FalseLabel(chunk()), |
| 2367 | DO_SMI_CHECK); |
| 2368 | __ lw(scratch, FieldMemOperand(value, HeapNumber::kExponentOffset)); |
| 2369 | EmitFalseBranch(instr, ne, scratch, Operand(0x80000000)); |
| 2370 | __ lw(scratch, FieldMemOperand(value, HeapNumber::kMantissaOffset)); |
| 2371 | __ mov(at, zero_reg); |
| 2372 | } |
| 2373 | EmitBranch(instr, eq, scratch, Operand(at)); |
| 2374 | } |
| 2375 | |
| 2376 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2377 | Condition LCodeGen::EmitIsObject(Register input, |
| 2378 | Register temp1, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2379 | Register temp2, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2380 | Label* is_not_object, |
| 2381 | Label* is_object) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2382 | __ JumpIfSmi(input, is_not_object); |
| 2383 | |
| 2384 | __ LoadRoot(temp2, Heap::kNullValueRootIndex); |
| 2385 | __ Branch(is_object, eq, input, Operand(temp2)); |
| 2386 | |
| 2387 | // Load map. |
| 2388 | __ lw(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2389 | // Undetectable objects behave like undefined. |
| 2390 | __ lbu(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
| 2391 | __ And(temp2, temp2, Operand(1 << Map::kIsUndetectable)); |
| 2392 | __ Branch(is_not_object, ne, temp2, Operand(zero_reg)); |
| 2393 | |
| 2394 | // Load instance type and check that it is in object type range. |
| 2395 | __ lbu(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
| 2396 | __ Branch(is_not_object, |
| 2397 | lt, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2398 | |
| 2399 | return le; |
| 2400 | } |
| 2401 | |
| 2402 | |
| 2403 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2404 | Register reg = ToRegister(instr->value()); |
| 2405 | Register temp1 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2406 | Register temp2 = scratch0(); |
| 2407 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2408 | Condition true_cond = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2409 | EmitIsObject(reg, temp1, temp2, |
| 2410 | instr->FalseLabel(chunk_), instr->TrueLabel(chunk_)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2411 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2412 | EmitBranch(instr, true_cond, temp2, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2413 | Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2414 | } |
| 2415 | |
| 2416 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2417 | Condition LCodeGen::EmitIsString(Register input, |
| 2418 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2419 | Label* is_not_string, |
| 2420 | SmiCheck check_needed = INLINE_SMI_CHECK) { |
| 2421 | if (check_needed == INLINE_SMI_CHECK) { |
| 2422 | __ JumpIfSmi(input, is_not_string); |
| 2423 | } |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2424 | __ GetObjectType(input, temp1, temp1); |
| 2425 | |
| 2426 | return lt; |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2431 | Register reg = ToRegister(instr->value()); |
| 2432 | Register temp1 = ToRegister(instr->temp()); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2433 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2434 | SmiCheck check_needed = |
| 2435 | instr->hydrogen()->value()->IsHeapObject() |
| 2436 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2437 | Condition true_cond = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2438 | EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2439 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2440 | EmitBranch(instr, true_cond, temp1, |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2441 | Operand(FIRST_NONSTRING_TYPE)); |
| 2442 | } |
| 2443 | |
| 2444 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2445 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2446 | Register input_reg = EmitLoadRegister(instr->value(), at); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2447 | __ And(at, input_reg, kSmiTagMask); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2448 | EmitBranch(instr, eq, at, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2453 | Register input = ToRegister(instr->value()); |
| 2454 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2455 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2456 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2457 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2458 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2459 | __ lw(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2460 | __ lbu(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); |
| 2461 | __ And(at, temp, Operand(1 << Map::kIsUndetectable)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2462 | EmitBranch(instr, ne, at, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2466 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2467 | switch (op) { |
| 2468 | case Token::EQ_STRICT: |
| 2469 | case Token::EQ: |
| 2470 | return eq; |
| 2471 | case Token::LT: |
| 2472 | return lt; |
| 2473 | case Token::GT: |
| 2474 | return gt; |
| 2475 | case Token::LTE: |
| 2476 | return le; |
| 2477 | case Token::GTE: |
| 2478 | return ge; |
| 2479 | default: |
| 2480 | UNREACHABLE(); |
| 2481 | return kNoCondition; |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2487 | ASSERT(ToRegister(instr->context()).is(cp)); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2488 | Token::Value op = instr->op(); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2489 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2490 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2491 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2492 | |
| 2493 | Condition condition = ComputeCompareCondition(op); |
| 2494 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2495 | EmitBranch(instr, condition, v0, Operand(zero_reg)); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2499 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
| 2500 | InstanceType from = instr->from(); |
| 2501 | InstanceType to = instr->to(); |
| 2502 | if (from == FIRST_TYPE) return to; |
| 2503 | ASSERT(from == to || to == LAST_TYPE); |
| 2504 | return from; |
| 2505 | } |
| 2506 | |
| 2507 | |
| 2508 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
| 2509 | InstanceType from = instr->from(); |
| 2510 | InstanceType to = instr->to(); |
| 2511 | if (from == to) return eq; |
| 2512 | if (to == LAST_TYPE) return hs; |
| 2513 | if (from == FIRST_TYPE) return ls; |
| 2514 | UNREACHABLE(); |
| 2515 | return eq; |
| 2516 | } |
| 2517 | |
| 2518 | |
| 2519 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
| 2520 | Register scratch = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2521 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2522 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2523 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 2524 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2525 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2526 | |
| 2527 | __ GetObjectType(input, scratch, scratch); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2528 | EmitBranch(instr, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2529 | BranchCondition(instr->hydrogen()), |
| 2530 | scratch, |
| 2531 | Operand(TestType(instr->hydrogen()))); |
| 2532 | } |
| 2533 | |
| 2534 | |
| 2535 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2536 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2537 | Register result = ToRegister(instr->result()); |
| 2538 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2539 | __ AssertString(input); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2540 | |
| 2541 | __ lw(result, FieldMemOperand(input, String::kHashFieldOffset)); |
| 2542 | __ IndexFromHash(result, result); |
| 2543 | } |
| 2544 | |
| 2545 | |
| 2546 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2547 | LHasCachedArrayIndexAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2548 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2549 | Register scratch = scratch0(); |
| 2550 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2551 | __ lw(scratch, |
| 2552 | FieldMemOperand(input, String::kHashFieldOffset)); |
| 2553 | __ And(at, scratch, Operand(String::kContainsCachedArrayIndexMask)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2554 | EmitBranch(instr, eq, at, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2558 | // Branches to a label or falls through with the answer in flags. Trashes |
| 2559 | // the temp registers, but not the input. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2560 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2561 | Label* is_false, |
| 2562 | Handle<String>class_name, |
| 2563 | Register input, |
| 2564 | Register temp, |
| 2565 | Register temp2) { |
| 2566 | ASSERT(!input.is(temp)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2567 | ASSERT(!input.is(temp2)); |
| 2568 | ASSERT(!temp.is(temp2)); |
| 2569 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2570 | __ JumpIfSmi(input, is_false); |
| 2571 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2572 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2573 | // Assuming the following assertions, we can use the same compares to test |
| 2574 | // for both being a function type and being in the object type range. |
| 2575 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2576 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2577 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2578 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2579 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2580 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2581 | |
| 2582 | __ GetObjectType(input, temp, temp2); |
| 2583 | __ Branch(is_false, lt, temp2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 2584 | __ Branch(is_true, eq, temp2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 2585 | __ Branch(is_true, eq, temp2, Operand(LAST_SPEC_OBJECT_TYPE)); |
| 2586 | } else { |
| 2587 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2588 | // actual type and do a signed compare with the width of the type range. |
| 2589 | __ GetObjectType(input, temp, temp2); |
| 2590 | __ Subu(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2591 | __ Branch(is_false, gt, temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2592 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2593 | } |
| 2594 | |
| 2595 | // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
| 2596 | // Check if the constructor in the map is a function. |
| 2597 | __ lw(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
| 2598 | |
| 2599 | // Objects with a non-function constructor have class 'Object'. |
| 2600 | __ GetObjectType(temp, temp2, temp2); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2601 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2602 | __ Branch(is_true, ne, temp2, Operand(JS_FUNCTION_TYPE)); |
| 2603 | } else { |
| 2604 | __ Branch(is_false, ne, temp2, Operand(JS_FUNCTION_TYPE)); |
| 2605 | } |
| 2606 | |
| 2607 | // temp now contains the constructor function. Grab the |
| 2608 | // instance class name from there. |
| 2609 | __ lw(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2610 | __ lw(temp, FieldMemOperand(temp, |
| 2611 | SharedFunctionInfo::kInstanceClassNameOffset)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2612 | // The class name we are testing against is internalized since it's a literal. |
| 2613 | // The name in the constructor is internalized because of the way the context |
| 2614 | // is booted. This routine isn't expected to work for random API-created |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2615 | // classes and it doesn't have to because you can't access it with natives |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2616 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2617 | // identity comparison. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2618 | |
| 2619 | // End with the address of this class_name instance in temp register. |
| 2620 | // On MIPS, the caller must do the comparison with Handle<String>class_name. |
| 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2625 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2626 | Register temp = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2627 | Register temp2 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2628 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2629 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2630 | EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2631 | class_name, input, temp, temp2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2632 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2633 | EmitBranch(instr, eq, temp, Operand(class_name)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | |
| 2637 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2638 | Register reg = ToRegister(instr->value()); |
| 2639 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2640 | |
| 2641 | __ lw(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2642 | EmitBranch(instr, eq, temp, Operand(instr->map())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | |
| 2646 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2647 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2648 | Label true_label, done; |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2649 | ASSERT(ToRegister(instr->left()).is(a0)); // Object is in a0. |
| 2650 | ASSERT(ToRegister(instr->right()).is(a1)); // Function is in a1. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2651 | Register result = ToRegister(instr->result()); |
| 2652 | ASSERT(result.is(v0)); |
| 2653 | |
| 2654 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2655 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2656 | |
| 2657 | __ Branch(&true_label, eq, result, Operand(zero_reg)); |
| 2658 | __ li(result, Operand(factory()->false_value())); |
| 2659 | __ Branch(&done); |
| 2660 | __ bind(&true_label); |
| 2661 | __ li(result, Operand(factory()->true_value())); |
| 2662 | __ bind(&done); |
| 2663 | } |
| 2664 | |
| 2665 | |
| 2666 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2667 | class DeferredInstanceOfKnownGlobal V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2668 | public: |
| 2669 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2670 | LInstanceOfKnownGlobal* instr) |
| 2671 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2672 | virtual void Generate() V8_OVERRIDE { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2673 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2674 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 2675 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2676 | Label* map_check() { return &map_check_; } |
| 2677 | |
| 2678 | private: |
| 2679 | LInstanceOfKnownGlobal* instr_; |
| 2680 | Label map_check_; |
| 2681 | }; |
| 2682 | |
| 2683 | DeferredInstanceOfKnownGlobal* deferred; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2684 | deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2685 | |
| 2686 | Label done, false_result; |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2687 | Register object = ToRegister(instr->value()); |
| 2688 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2689 | Register result = ToRegister(instr->result()); |
| 2690 | |
| 2691 | ASSERT(object.is(a0)); |
| 2692 | ASSERT(result.is(v0)); |
| 2693 | |
| 2694 | // A Smi is not instance of anything. |
| 2695 | __ JumpIfSmi(object, &false_result); |
| 2696 | |
| 2697 | // This is the inlined call site instanceof cache. The two occurences of the |
| 2698 | // hole value will be patched to the last map/result pair generated by the |
| 2699 | // instanceof stub. |
| 2700 | Label cache_miss; |
| 2701 | Register map = temp; |
| 2702 | __ lw(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2703 | |
| 2704 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 2705 | __ bind(deferred->map_check()); // Label for calculating code patching. |
| 2706 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2707 | // root array to force relocation to be able to later patch with |
| 2708 | // the cached map. |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2709 | Handle<Cell> cell = factory()->NewCell(factory()->the_hole_value()); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2710 | __ li(at, Operand(Handle<Object>(cell))); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2711 | __ lw(at, FieldMemOperand(at, PropertyCell::kValueOffset)); |
bmeurer@chromium.org | 25530ce | 2014-02-07 09:11:16 +0000 | [diff] [blame] | 2712 | __ BranchShort(&cache_miss, ne, map, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2713 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2714 | // root array to force relocation to be able to later patch |
bmeurer@chromium.org | 25530ce | 2014-02-07 09:11:16 +0000 | [diff] [blame] | 2715 | // with true or false. The distance from map check has to be constant. |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2716 | __ li(result, Operand(factory()->the_hole_value()), CONSTANT_SIZE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2717 | __ Branch(&done); |
| 2718 | |
| 2719 | // The inlined call site cache did not match. Check null and string before |
| 2720 | // calling the deferred code. |
| 2721 | __ bind(&cache_miss); |
| 2722 | // Null is not instance of anything. |
| 2723 | __ LoadRoot(temp, Heap::kNullValueRootIndex); |
| 2724 | __ Branch(&false_result, eq, object, Operand(temp)); |
| 2725 | |
| 2726 | // String values is not instance of anything. |
| 2727 | Condition cc = __ IsObjectStringType(object, temp, temp); |
| 2728 | __ Branch(&false_result, cc, temp, Operand(zero_reg)); |
| 2729 | |
| 2730 | // Go to the deferred code. |
| 2731 | __ Branch(deferred->entry()); |
| 2732 | |
| 2733 | __ bind(&false_result); |
| 2734 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 2735 | |
| 2736 | // Here result has either true or false. Deferred code also produces true or |
| 2737 | // false object. |
| 2738 | __ bind(deferred->exit()); |
| 2739 | __ bind(&done); |
| 2740 | } |
| 2741 | |
| 2742 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2743 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2744 | Label* map_check) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2745 | Register result = ToRegister(instr->result()); |
| 2746 | ASSERT(result.is(v0)); |
| 2747 | |
| 2748 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 2749 | flags = static_cast<InstanceofStub::Flags>( |
| 2750 | flags | InstanceofStub::kArgsInRegisters); |
| 2751 | flags = static_cast<InstanceofStub::Flags>( |
| 2752 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 2753 | flags = static_cast<InstanceofStub::Flags>( |
| 2754 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 2755 | InstanceofStub stub(flags); |
| 2756 | |
| 2757 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2758 | LoadContextFromDeferred(instr->context()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2759 | |
| 2760 | // Get the temp register reserved by the instruction. This needs to be t0 as |
| 2761 | // its slot of the pushing of safepoint registers is used to communicate the |
| 2762 | // offset to the location of the map check. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2763 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2764 | ASSERT(temp.is(t0)); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 2765 | __ li(InstanceofStub::right(), instr->function()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2766 | static const int kAdditionalDelta = 7; |
| 2767 | int delta = masm_->InstructionsGeneratedSince(map_check) + kAdditionalDelta; |
| 2768 | Label before_push_delta; |
| 2769 | __ bind(&before_push_delta); |
| 2770 | { |
| 2771 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2772 | __ li(temp, Operand(delta * kPointerSize), CONSTANT_SIZE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2773 | __ StoreToSafepointRegisterSlot(temp, temp); |
| 2774 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2775 | CallCodeGeneric(stub.GetCode(isolate()), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2776 | RelocInfo::CODE_TARGET, |
| 2777 | instr, |
| 2778 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
danno@chromium.org | e4bfb26 | 2012-05-04 10:50:07 +0000 | [diff] [blame] | 2779 | LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2780 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2781 | // Put the result value into the result register slot and |
| 2782 | // restore all registers. |
| 2783 | __ StoreToSafepointRegisterSlot(result, result); |
| 2784 | } |
| 2785 | |
| 2786 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2787 | void LCodeGen::DoCmpT(LCmpT* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2788 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2789 | Token::Value op = instr->op(); |
| 2790 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2791 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2792 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2793 | // On MIPS there is no need for a "no inlined smi code" marker (nop). |
| 2794 | |
| 2795 | Condition condition = ComputeCompareCondition(op); |
| 2796 | // A minor optimization that relies on LoadRoot always emitting one |
| 2797 | // instruction. |
| 2798 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2799 | Label done, check; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2800 | __ Branch(USE_DELAY_SLOT, &done, condition, v0, Operand(zero_reg)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2801 | __ bind(&check); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2802 | __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2803 | ASSERT_EQ(1, masm()->InstructionsGeneratedSince(&check)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2804 | __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2805 | __ bind(&done); |
| 2806 | } |
| 2807 | |
| 2808 | |
| 2809 | void LCodeGen::DoReturn(LReturn* instr) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2810 | if (FLAG_trace && info()->IsOptimizing()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2811 | // Push the return value on the stack as the parameter. |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2812 | // Runtime::TraceExit returns its parameter in v0. We're leaving the code |
| 2813 | // managed by the register allocator and tearing down the frame, it's |
| 2814 | // safe to write to the context register. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2815 | __ push(v0); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2816 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2817 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 2818 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2819 | if (info()->saves_caller_doubles()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 2820 | RestoreCallerDoubles(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2821 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2822 | int no_frame_start = -1; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2823 | if (NeedsEagerFrame()) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2824 | __ mov(sp, fp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2825 | no_frame_start = masm_->pc_offset(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2826 | __ Pop(ra, fp); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2827 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2828 | if (instr->has_constant_parameter_count()) { |
| 2829 | int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 2830 | int32_t sp_delta = (parameter_count + 1) * kPointerSize; |
| 2831 | if (sp_delta != 0) { |
| 2832 | __ Addu(sp, sp, Operand(sp_delta)); |
| 2833 | } |
| 2834 | } else { |
| 2835 | Register reg = ToRegister(instr->parameter_count()); |
| 2836 | // The argument count parameter is a smi |
| 2837 | __ SmiUntag(reg); |
| 2838 | __ sll(at, reg, kPointerSizeLog2); |
| 2839 | __ Addu(sp, sp, at); |
| 2840 | } |
| 2841 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2842 | __ Jump(ra); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2843 | |
| 2844 | if (no_frame_start != -1) { |
| 2845 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
| 2846 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | |
| 2850 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
| 2851 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2852 | __ li(at, Operand(Handle<Object>(instr->hydrogen()->cell().handle()))); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2853 | __ lw(result, FieldMemOperand(at, Cell::kValueOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2854 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2855 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 2856 | DeoptimizeIf(eq, instr->environment(), result, Operand(at)); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | |
| 2861 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2862 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2863 | ASSERT(ToRegister(instr->global_object()).is(a0)); |
| 2864 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 2865 | |
| 2866 | __ li(a2, Operand(instr->name())); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2867 | ContextualMode mode = instr->for_typeof() ? NOT_CONTEXTUAL : CONTEXTUAL; |
| 2868 | Handle<Code> ic = LoadIC::initialize_stub(isolate(), mode); |
| 2869 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | |
| 2873 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2874 | Register value = ToRegister(instr->value()); |
| 2875 | Register cell = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2876 | |
| 2877 | // Load the cell. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2878 | __ li(cell, Operand(instr->hydrogen()->cell().handle())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2879 | |
| 2880 | // If the cell we are storing to contains the hole it could have |
| 2881 | // been deleted from the property dictionary. In that case, we need |
| 2882 | // to update the property details in the property dictionary to mark |
| 2883 | // it as no longer deleted. |
| 2884 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2885 | // We use a temp to check the payload. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2886 | Register payload = ToRegister(instr->temp()); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2887 | __ lw(payload, FieldMemOperand(cell, Cell::kValueOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2888 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2889 | DeoptimizeIf(eq, instr->environment(), payload, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | // Store the value. |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2893 | __ sw(value, FieldMemOperand(cell, Cell::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2894 | // Cells are always rescanned, so no write barrier here. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2898 | |
| 2899 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
| 2900 | Register context = ToRegister(instr->context()); |
| 2901 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2902 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2903 | __ lw(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2904 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2905 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2906 | |
| 2907 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2908 | DeoptimizeIf(eq, instr->environment(), result, Operand(at)); |
| 2909 | } else { |
| 2910 | Label is_not_hole; |
| 2911 | __ Branch(&is_not_hole, ne, result, Operand(at)); |
| 2912 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 2913 | __ bind(&is_not_hole); |
| 2914 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2915 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | |
| 2919 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 2920 | Register context = ToRegister(instr->context()); |
| 2921 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2922 | Register scratch = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2923 | MemOperand target = ContextOperand(context, instr->slot_index()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2924 | |
| 2925 | Label skip_assignment; |
| 2926 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2927 | if (instr->hydrogen()->RequiresHoleCheck()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2928 | __ lw(scratch, target); |
| 2929 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2930 | |
| 2931 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2932 | DeoptimizeIf(eq, instr->environment(), scratch, Operand(at)); |
| 2933 | } else { |
| 2934 | __ Branch(&skip_assignment, ne, scratch, Operand(at)); |
| 2935 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2936 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2937 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2938 | __ sw(value, target); |
| 2939 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2940 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2941 | instr->hydrogen()->value()->IsHeapObject() |
| 2942 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2943 | __ RecordWriteContextSlot(context, |
| 2944 | target.offset(), |
| 2945 | value, |
| 2946 | scratch0(), |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 2947 | GetRAState(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2948 | kSaveFPRegs, |
| 2949 | EMIT_REMEMBERED_SET, |
| 2950 | check_needed); |
| 2951 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2952 | |
| 2953 | __ bind(&skip_assignment); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | |
| 2957 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2958 | HObjectAccess access = instr->hydrogen()->access(); |
| 2959 | int offset = access.offset(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2960 | Register object = ToRegister(instr->object()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2961 | |
| 2962 | if (access.IsExternalMemory()) { |
| 2963 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2964 | MemOperand operand = MemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2965 | __ Load(result, operand, access.representation()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2966 | return; |
| 2967 | } |
| 2968 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2969 | if (instr->hydrogen()->representation().IsDouble()) { |
| 2970 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 2971 | __ ldc1(result, FieldMemOperand(object, offset)); |
| 2972 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2973 | } |
| 2974 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2975 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2976 | if (!access.IsInobject()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2977 | __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2978 | object = result; |
| 2979 | } |
| 2980 | MemOperand operand = FieldMemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2981 | __ Load(result, operand, access.representation()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2985 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2986 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2987 | ASSERT(ToRegister(instr->object()).is(a0)); |
| 2988 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 2989 | |
| 2990 | // Name is always in a2. |
| 2991 | __ li(a2, Operand(instr->name())); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2992 | Handle<Code> ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2993 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2994 | } |
| 2995 | |
| 2996 | |
| 2997 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
| 2998 | Register scratch = scratch0(); |
| 2999 | Register function = ToRegister(instr->function()); |
| 3000 | Register result = ToRegister(instr->result()); |
| 3001 | |
| 3002 | // Check that the function really is a function. Load map into the |
| 3003 | // result register. |
| 3004 | __ GetObjectType(function, result, scratch); |
| 3005 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(JS_FUNCTION_TYPE)); |
| 3006 | |
| 3007 | // Make sure that the function has an instance prototype. |
| 3008 | Label non_instance; |
| 3009 | __ lbu(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 3010 | __ And(scratch, scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 3011 | __ Branch(&non_instance, ne, scratch, Operand(zero_reg)); |
| 3012 | |
| 3013 | // Get the prototype or initial map from the function. |
| 3014 | __ lw(result, |
| 3015 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 3016 | |
| 3017 | // Check that the function has a prototype or an initial map. |
| 3018 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 3019 | DeoptimizeIf(eq, instr->environment(), result, Operand(at)); |
| 3020 | |
| 3021 | // If the function does not have an initial map, we're done. |
| 3022 | Label done; |
| 3023 | __ GetObjectType(result, scratch, scratch); |
| 3024 | __ Branch(&done, ne, scratch, Operand(MAP_TYPE)); |
| 3025 | |
| 3026 | // Get the prototype from the initial map. |
| 3027 | __ lw(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 3028 | __ Branch(&done); |
| 3029 | |
| 3030 | // Non-instance prototype: Fetch prototype from constructor field |
| 3031 | // in initial map. |
| 3032 | __ bind(&non_instance); |
| 3033 | __ lw(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 3034 | |
| 3035 | // All done. |
| 3036 | __ bind(&done); |
| 3037 | } |
| 3038 | |
| 3039 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3040 | void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
| 3041 | Register result = ToRegister(instr->result()); |
| 3042 | __ LoadRoot(result, instr->index()); |
| 3043 | } |
| 3044 | |
| 3045 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3046 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
| 3047 | Register arguments = ToRegister(instr->arguments()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3048 | Register result = ToRegister(instr->result()); |
machenbach@chromium.org | 90dca01 | 2013-11-22 10:04:21 +0000 | [diff] [blame] | 3049 | // There are two words between the frame pointer and the last argument. |
| 3050 | // Subtracting from length accounts for one of them add one more. |
| 3051 | if (instr->length()->IsConstantOperand()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3052 | int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
machenbach@chromium.org | 90dca01 | 2013-11-22 10:04:21 +0000 | [diff] [blame] | 3053 | if (instr->index()->IsConstantOperand()) { |
| 3054 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3055 | int index = (const_length - const_index) + 1; |
| 3056 | __ lw(result, MemOperand(arguments, index * kPointerSize)); |
| 3057 | } else { |
| 3058 | Register index = ToRegister(instr->index()); |
| 3059 | __ li(at, Operand(const_length + 1)); |
| 3060 | __ Subu(result, at, index); |
| 3061 | __ sll(at, result, kPointerSizeLog2); |
| 3062 | __ Addu(at, arguments, at); |
| 3063 | __ lw(result, MemOperand(at)); |
| 3064 | } |
| 3065 | } else if (instr->index()->IsConstantOperand()) { |
| 3066 | Register length = ToRegister(instr->length()); |
| 3067 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3068 | int loc = const_index - 1; |
| 3069 | if (loc != 0) { |
| 3070 | __ Subu(result, length, Operand(loc)); |
| 3071 | __ sll(at, result, kPointerSizeLog2); |
| 3072 | __ Addu(at, arguments, at); |
| 3073 | __ lw(result, MemOperand(at)); |
| 3074 | } else { |
| 3075 | __ sll(at, length, kPointerSizeLog2); |
| 3076 | __ Addu(at, arguments, at); |
| 3077 | __ lw(result, MemOperand(at)); |
| 3078 | } |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3079 | } else { |
| 3080 | Register length = ToRegister(instr->length()); |
| 3081 | Register index = ToRegister(instr->index()); |
machenbach@chromium.org | 90dca01 | 2013-11-22 10:04:21 +0000 | [diff] [blame] | 3082 | __ Subu(result, length, index); |
| 3083 | __ Addu(result, result, 1); |
| 3084 | __ sll(at, result, kPointerSizeLog2); |
| 3085 | __ Addu(at, arguments, at); |
| 3086 | __ lw(result, MemOperand(at)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3087 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3091 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
| 3092 | Register external_pointer = ToRegister(instr->elements()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3093 | Register key = no_reg; |
| 3094 | ElementsKind elements_kind = instr->elements_kind(); |
| 3095 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3096 | int constant_key = 0; |
| 3097 | if (key_is_constant) { |
| 3098 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3099 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3100 | Abort(kArrayIndexConstantValueTooBig); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3101 | } |
| 3102 | } else { |
| 3103 | key = ToRegister(instr->key()); |
| 3104 | } |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 3105 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3106 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 3107 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3108 | int additional_offset = IsFixedTypedArrayElementsKind(elements_kind) |
| 3109 | ? FixedTypedArrayBase::kDataOffset - kHeapObjectTag |
| 3110 | : 0; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3111 | |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3112 | if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3113 | elements_kind == FLOAT32_ELEMENTS || |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3114 | elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3115 | elements_kind == FLOAT64_ELEMENTS) { |
| 3116 | int base_offset = |
| 3117 | (instr->additional_index() << element_size_shift) + additional_offset; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3118 | FPURegister result = ToDoubleRegister(instr->result()); |
| 3119 | if (key_is_constant) { |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 3120 | __ Addu(scratch0(), external_pointer, constant_key << element_size_shift); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3121 | } else { |
| 3122 | __ sll(scratch0(), key, shift_size); |
| 3123 | __ Addu(scratch0(), scratch0(), external_pointer); |
| 3124 | } |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3125 | if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3126 | elements_kind == FLOAT32_ELEMENTS) { |
| 3127 | __ lwc1(result, MemOperand(scratch0(), base_offset)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3128 | __ cvt_d_s(result, result); |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3129 | } else { // loading doubles, not floats. |
| 3130 | __ ldc1(result, MemOperand(scratch0(), base_offset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3131 | } |
| 3132 | } else { |
| 3133 | Register result = ToRegister(instr->result()); |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 3134 | MemOperand mem_operand = PrepareKeyedOperand( |
| 3135 | key, external_pointer, key_is_constant, constant_key, |
| 3136 | element_size_shift, shift_size, |
| 3137 | instr->additional_index(), additional_offset); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3138 | switch (elements_kind) { |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3139 | case EXTERNAL_INT8_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3140 | case INT8_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3141 | __ lb(result, mem_operand); |
| 3142 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3143 | case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
| 3144 | case EXTERNAL_UINT8_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3145 | case UINT8_ELEMENTS: |
| 3146 | case UINT8_CLAMPED_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3147 | __ lbu(result, mem_operand); |
| 3148 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3149 | case EXTERNAL_INT16_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3150 | case INT16_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3151 | __ lh(result, mem_operand); |
| 3152 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3153 | case EXTERNAL_UINT16_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3154 | case UINT16_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3155 | __ lhu(result, mem_operand); |
| 3156 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3157 | case EXTERNAL_INT32_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3158 | case INT32_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3159 | __ lw(result, mem_operand); |
| 3160 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3161 | case EXTERNAL_UINT32_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3162 | case UINT32_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3163 | __ lw(result, mem_operand); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3164 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 3165 | DeoptimizeIf(Ugreater_equal, instr->environment(), |
| 3166 | result, Operand(0x80000000)); |
| 3167 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3168 | break; |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3169 | case FLOAT32_ELEMENTS: |
| 3170 | case FLOAT64_ELEMENTS: |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 3171 | case EXTERNAL_FLOAT32_ELEMENTS: |
| 3172 | case EXTERNAL_FLOAT64_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3173 | case FAST_DOUBLE_ELEMENTS: |
| 3174 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3175 | case FAST_SMI_ELEMENTS: |
| 3176 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 3177 | case FAST_HOLEY_ELEMENTS: |
| 3178 | case FAST_HOLEY_SMI_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3179 | case DICTIONARY_ELEMENTS: |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 3180 | case SLOPPY_ARGUMENTS_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3181 | UNREACHABLE(); |
| 3182 | break; |
| 3183 | } |
| 3184 | } |
| 3185 | } |
| 3186 | |
| 3187 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3188 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
| 3189 | Register elements = ToRegister(instr->elements()); |
| 3190 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3191 | Register key = no_reg; |
| 3192 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3193 | Register scratch = scratch0(); |
| 3194 | |
| 3195 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3196 | |
| 3197 | int base_offset = |
| 3198 | FixedDoubleArray::kHeaderSize - kHeapObjectTag + |
| 3199 | (instr->additional_index() << element_size_shift); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3200 | if (key_is_constant) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3201 | int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3202 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3203 | Abort(kArrayIndexConstantValueTooBig); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3204 | } |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3205 | base_offset += constant_key << element_size_shift; |
| 3206 | } |
| 3207 | __ Addu(scratch, elements, Operand(base_offset)); |
| 3208 | |
| 3209 | if (!key_is_constant) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3210 | key = ToRegister(instr->key()); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3211 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
| 3212 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 3213 | __ sll(at, key, shift_size); |
| 3214 | __ Addu(scratch, scratch, at); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3215 | } |
| 3216 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3217 | __ ldc1(result, MemOperand(scratch)); |
| 3218 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3219 | if (instr->hydrogen()->RequiresHoleCheck()) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3220 | __ lw(scratch, MemOperand(scratch, sizeof(kHoleNanLower32))); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3221 | DeoptimizeIf(eq, instr->environment(), scratch, Operand(kHoleNanUpper32)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3222 | } |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | |
| 3226 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3227 | Register elements = ToRegister(instr->elements()); |
| 3228 | Register result = ToRegister(instr->result()); |
| 3229 | Register scratch = scratch0(); |
| 3230 | Register store_base = scratch; |
| 3231 | int offset = 0; |
| 3232 | |
| 3233 | if (instr->key()->IsConstantOperand()) { |
| 3234 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 3235 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 3236 | instr->additional_index()); |
| 3237 | store_base = elements; |
| 3238 | } else { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3239 | Register key = ToRegister(instr->key()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3240 | // Even though the HLoadKeyed instruction forces the input |
| 3241 | // representation for the key to be an integer, the input gets replaced |
| 3242 | // during bound check elimination with the index argument to the bounds |
| 3243 | // check, which can be tagged, so that case must be handled here, too. |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3244 | if (instr->hydrogen()->key()->representation().IsSmi()) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3245 | __ sll(scratch, key, kPointerSizeLog2 - kSmiTagSize); |
| 3246 | __ addu(scratch, elements, scratch); |
| 3247 | } else { |
| 3248 | __ sll(scratch, key, kPointerSizeLog2); |
| 3249 | __ addu(scratch, elements, scratch); |
| 3250 | } |
| 3251 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 3252 | } |
| 3253 | __ lw(result, FieldMemOperand(store_base, offset)); |
| 3254 | |
| 3255 | // Check for the hole value. |
| 3256 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3257 | if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 3258 | __ SmiTst(result, scratch); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3259 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg)); |
| 3260 | } else { |
| 3261 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 3262 | DeoptimizeIf(eq, instr->environment(), result, Operand(scratch)); |
| 3263 | } |
| 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | |
| 3268 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3269 | if (instr->is_typed_elements()) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3270 | DoLoadKeyedExternalArray(instr); |
| 3271 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3272 | DoLoadKeyedFixedDoubleArray(instr); |
| 3273 | } else { |
| 3274 | DoLoadKeyedFixedArray(instr); |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | |
| 3279 | MemOperand LCodeGen::PrepareKeyedOperand(Register key, |
| 3280 | Register base, |
| 3281 | bool key_is_constant, |
| 3282 | int constant_key, |
| 3283 | int element_size, |
| 3284 | int shift_size, |
| 3285 | int additional_index, |
| 3286 | int additional_offset) { |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3287 | int base_offset = (additional_index << element_size) + additional_offset; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3288 | if (key_is_constant) { |
| 3289 | return MemOperand(base, |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3290 | base_offset + (constant_key << element_size)); |
| 3291 | } |
| 3292 | |
| 3293 | if (additional_offset != 0) { |
| 3294 | if (shift_size >= 0) { |
| 3295 | __ sll(scratch0(), key, shift_size); |
| 3296 | __ Addu(scratch0(), scratch0(), Operand(base_offset)); |
| 3297 | } else { |
| 3298 | ASSERT_EQ(-1, shift_size); |
machenbach@chromium.org | ab43d2f | 2014-04-01 06:35:49 +0000 | [diff] [blame] | 3299 | // Key can be negative, so using sra here. |
| 3300 | __ sra(scratch0(), key, 1); |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 3301 | __ Addu(scratch0(), scratch0(), Operand(base_offset)); |
| 3302 | } |
| 3303 | __ Addu(scratch0(), base, scratch0()); |
| 3304 | return MemOperand(scratch0()); |
| 3305 | } |
| 3306 | |
| 3307 | if (additional_index != 0) { |
| 3308 | additional_index *= 1 << (element_size - shift_size); |
| 3309 | __ Addu(scratch0(), key, Operand(additional_index)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | if (additional_index == 0) { |
| 3313 | if (shift_size >= 0) { |
| 3314 | __ sll(scratch0(), key, shift_size); |
| 3315 | __ Addu(scratch0(), base, scratch0()); |
| 3316 | return MemOperand(scratch0()); |
| 3317 | } else { |
| 3318 | ASSERT_EQ(-1, shift_size); |
| 3319 | __ srl(scratch0(), key, 1); |
| 3320 | __ Addu(scratch0(), base, scratch0()); |
| 3321 | return MemOperand(scratch0()); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | if (shift_size >= 0) { |
| 3326 | __ sll(scratch0(), scratch0(), shift_size); |
| 3327 | __ Addu(scratch0(), base, scratch0()); |
| 3328 | return MemOperand(scratch0()); |
| 3329 | } else { |
| 3330 | ASSERT_EQ(-1, shift_size); |
| 3331 | __ srl(scratch0(), scratch0(), 1); |
| 3332 | __ Addu(scratch0(), base, scratch0()); |
| 3333 | return MemOperand(scratch0()); |
| 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3338 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3339 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3340 | ASSERT(ToRegister(instr->object()).is(a1)); |
| 3341 | ASSERT(ToRegister(instr->key()).is(a0)); |
| 3342 | |
| 3343 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
| 3344 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3345 | } |
| 3346 | |
| 3347 | |
| 3348 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
| 3349 | Register scratch = scratch0(); |
| 3350 | Register temp = scratch1(); |
| 3351 | Register result = ToRegister(instr->result()); |
| 3352 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3353 | if (instr->hydrogen()->from_inlined()) { |
| 3354 | __ Subu(result, sp, 2 * kPointerSize); |
| 3355 | } else { |
| 3356 | // Check if the calling frame is an arguments adaptor frame. |
| 3357 | Label done, adapted; |
| 3358 | __ lw(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3359 | __ lw(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 3360 | __ Xor(temp, result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3361 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3362 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3363 | // frame below the adaptor frame if adapted. |
| 3364 | __ Movn(result, fp, temp); // Move only if temp is not equal to zero (ne). |
| 3365 | __ Movz(result, scratch, temp); // Move only if temp is equal to zero (eq). |
| 3366 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | |
| 3370 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3371 | Register elem = ToRegister(instr->elements()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3372 | Register result = ToRegister(instr->result()); |
| 3373 | |
| 3374 | Label done; |
| 3375 | |
| 3376 | // If no arguments adaptor frame the number of arguments is fixed. |
| 3377 | __ Addu(result, zero_reg, Operand(scope()->num_parameters())); |
| 3378 | __ Branch(&done, eq, fp, Operand(elem)); |
| 3379 | |
| 3380 | // Arguments adaptor frame present. Get argument length from there. |
| 3381 | __ lw(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3382 | __ lw(result, |
| 3383 | MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3384 | __ SmiUntag(result); |
| 3385 | |
| 3386 | // Argument length is in result register. |
| 3387 | __ bind(&done); |
| 3388 | } |
| 3389 | |
| 3390 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3391 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3392 | Register receiver = ToRegister(instr->receiver()); |
| 3393 | Register function = ToRegister(instr->function()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3394 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3395 | Register scratch = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3396 | |
| 3397 | // If the receiver is null or undefined, we have to pass the global |
| 3398 | // object as a receiver to normal functions. Values have to be |
| 3399 | // passed unchanged to builtins and strict-mode functions. |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3400 | Label global_object, result_in_receiver; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3401 | |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3402 | if (!instr->hydrogen()->known_function()) { |
| 3403 | // Do not transform the receiver to object for strict mode |
| 3404 | // functions. |
| 3405 | __ lw(scratch, |
| 3406 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3407 | __ lw(scratch, |
| 3408 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3409 | |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3410 | // Do not transform the receiver to object for builtins. |
| 3411 | int32_t strict_mode_function_mask = |
| 3412 | 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize); |
| 3413 | int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize); |
| 3414 | __ And(scratch, scratch, Operand(strict_mode_function_mask | native_mask)); |
| 3415 | __ Branch(&result_in_receiver, ne, scratch, Operand(zero_reg)); |
| 3416 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3417 | |
| 3418 | // Normal function. Replace undefined or null with global receiver. |
| 3419 | __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
| 3420 | __ Branch(&global_object, eq, receiver, Operand(scratch)); |
| 3421 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 3422 | __ Branch(&global_object, eq, receiver, Operand(scratch)); |
| 3423 | |
| 3424 | // Deoptimize if the receiver is not a JS object. |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 3425 | __ SmiTst(receiver, scratch); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3426 | DeoptimizeIf(eq, instr->environment(), scratch, Operand(zero_reg)); |
| 3427 | |
| 3428 | __ GetObjectType(receiver, scratch, scratch); |
| 3429 | DeoptimizeIf(lt, instr->environment(), |
| 3430 | scratch, Operand(FIRST_SPEC_OBJECT_TYPE)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3431 | |
machenbach@chromium.org | 57a54ac | 2014-01-31 14:01:53 +0000 | [diff] [blame] | 3432 | __ Branch(&result_in_receiver); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3433 | __ bind(&global_object); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3434 | __ lw(result, FieldMemOperand(function, JSFunction::kContextOffset)); |
| 3435 | __ lw(result, |
| 3436 | ContextOperand(result, Context::GLOBAL_OBJECT_INDEX)); |
| 3437 | __ lw(result, |
| 3438 | FieldMemOperand(result, GlobalObject::kGlobalReceiverOffset)); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 3439 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 3440 | if (result.is(receiver)) { |
| 3441 | __ bind(&result_in_receiver); |
| 3442 | } else { |
| 3443 | Label result_ok; |
| 3444 | __ Branch(&result_ok); |
| 3445 | __ bind(&result_in_receiver); |
| 3446 | __ mov(result, receiver); |
| 3447 | __ bind(&result_ok); |
| 3448 | } |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 3451 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3452 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3453 | Register receiver = ToRegister(instr->receiver()); |
| 3454 | Register function = ToRegister(instr->function()); |
| 3455 | Register length = ToRegister(instr->length()); |
| 3456 | Register elements = ToRegister(instr->elements()); |
| 3457 | Register scratch = scratch0(); |
| 3458 | ASSERT(receiver.is(a0)); // Used for parameter count. |
| 3459 | ASSERT(function.is(a1)); // Required by InvokeFunction. |
| 3460 | ASSERT(ToRegister(instr->result()).is(v0)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3461 | |
| 3462 | // Copy the arguments to this function possibly from the |
| 3463 | // adaptor frame below it. |
| 3464 | const uint32_t kArgumentsLimit = 1 * KB; |
| 3465 | DeoptimizeIf(hi, instr->environment(), length, Operand(kArgumentsLimit)); |
| 3466 | |
| 3467 | // Push the receiver and use the register to keep the original |
| 3468 | // number of arguments. |
| 3469 | __ push(receiver); |
| 3470 | __ Move(receiver, length); |
| 3471 | // The arguments are at a one pointer size offset from elements. |
| 3472 | __ Addu(elements, elements, Operand(1 * kPointerSize)); |
| 3473 | |
| 3474 | // Loop through the arguments pushing them onto the execution |
| 3475 | // stack. |
| 3476 | Label invoke, loop; |
| 3477 | // length is a small non-negative integer, due to the test above. |
| 3478 | __ Branch(USE_DELAY_SLOT, &invoke, eq, length, Operand(zero_reg)); |
| 3479 | __ sll(scratch, length, 2); |
| 3480 | __ bind(&loop); |
| 3481 | __ Addu(scratch, elements, scratch); |
| 3482 | __ lw(scratch, MemOperand(scratch)); |
| 3483 | __ push(scratch); |
| 3484 | __ Subu(length, length, Operand(1)); |
| 3485 | __ Branch(USE_DELAY_SLOT, &loop, ne, length, Operand(zero_reg)); |
| 3486 | __ sll(scratch, length, 2); |
| 3487 | |
| 3488 | __ bind(&invoke); |
danno@chromium.org | e4bfb26 | 2012-05-04 10:50:07 +0000 | [diff] [blame] | 3489 | ASSERT(instr->HasPointerMap()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3490 | LPointerMap* pointers = instr->pointer_map(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3491 | SafepointGenerator safepoint_generator( |
| 3492 | this, pointers, Safepoint::kLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3493 | // The number of arguments is stored in receiver which is a0, as expected |
| 3494 | // by InvokeFunction. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3495 | ParameterCount actual(receiver); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3496 | __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | |
| 3500 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3501 | LOperand* argument = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3502 | if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3503 | Abort(kDoPushArgumentNotImplementedForDoubleType); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3504 | } else { |
| 3505 | Register argument_reg = EmitLoadRegister(argument, at); |
| 3506 | __ push(argument_reg); |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3511 | void LCodeGen::DoDrop(LDrop* instr) { |
| 3512 | __ Drop(instr->count()); |
| 3513 | } |
| 3514 | |
| 3515 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3516 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3517 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3518 | __ lw(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | void LCodeGen::DoContext(LContext* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3523 | // If there is a non-return use, the context must be moved to a register. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3524 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3525 | if (info()->IsOptimizing()) { |
| 3526 | __ lw(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3527 | } else { |
| 3528 | // If there is no frame, the context must be in cp. |
| 3529 | ASSERT(result.is(cp)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3530 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3534 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3535 | ASSERT(ToRegister(instr->context()).is(cp)); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 3536 | __ li(scratch0(), instr->hydrogen()->pairs()); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3537 | __ li(scratch1(), Operand(Smi::FromInt(instr->hydrogen()->flags()))); |
| 3538 | // The context is the first argument. |
| 3539 | __ Push(cp, scratch0(), scratch1()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3540 | CallRuntime(Runtime::kHiddenDeclareGlobals, 3, instr); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3544 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3545 | int formal_parameter_count, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3546 | int arity, |
| 3547 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3548 | A1State a1_state) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3549 | bool dont_adapt_arguments = |
| 3550 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3551 | bool can_invoke_directly = |
| 3552 | dont_adapt_arguments || formal_parameter_count == arity; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3553 | |
| 3554 | LPointerMap* pointers = instr->pointer_map(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3555 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3556 | if (can_invoke_directly) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3557 | if (a1_state == A1_UNINITIALIZED) { |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 3558 | __ li(a1, function); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3561 | // Change context. |
| 3562 | __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3563 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3564 | // Set r0 to arguments count if adaption is not needed. Assumes that r0 |
| 3565 | // is available to write to at this point. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3566 | if (dont_adapt_arguments) { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3567 | __ li(a0, Operand(arity)); |
| 3568 | } |
| 3569 | |
| 3570 | // Invoke function. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3571 | __ lw(at, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
| 3572 | __ Call(at); |
| 3573 | |
| 3574 | // Set up deoptimization. |
| 3575 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3576 | } else { |
| 3577 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3578 | ParameterCount count(arity); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3579 | ParameterCount expected(formal_parameter_count); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3580 | __ InvokeFunction(function, expected, count, CALL_FUNCTION, generator); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3581 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3585 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3586 | ASSERT(instr->context() != NULL); |
| 3587 | ASSERT(ToRegister(instr->context()).is(cp)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3588 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3589 | Register result = ToRegister(instr->result()); |
| 3590 | Register scratch = scratch0(); |
| 3591 | |
| 3592 | // Deoptimize if not a heap number. |
| 3593 | __ lw(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3594 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 3595 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(at)); |
| 3596 | |
| 3597 | Label done; |
| 3598 | Register exponent = scratch0(); |
| 3599 | scratch = no_reg; |
| 3600 | __ lw(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3601 | // Check the sign of the argument. If the argument is positive, just |
| 3602 | // return it. |
| 3603 | __ Move(result, input); |
| 3604 | __ And(at, exponent, Operand(HeapNumber::kSignMask)); |
| 3605 | __ Branch(&done, eq, at, Operand(zero_reg)); |
| 3606 | |
| 3607 | // Input is negative. Reverse its sign. |
| 3608 | // Preserve the value of all registers. |
| 3609 | { |
| 3610 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 3611 | |
| 3612 | // Registers were saved at the safepoint, so we can use |
| 3613 | // many scratch registers. |
| 3614 | Register tmp1 = input.is(a1) ? a0 : a1; |
| 3615 | Register tmp2 = input.is(a2) ? a0 : a2; |
| 3616 | Register tmp3 = input.is(a3) ? a0 : a3; |
| 3617 | Register tmp4 = input.is(t0) ? a0 : t0; |
| 3618 | |
| 3619 | // exponent: floating point exponent value. |
| 3620 | |
| 3621 | Label allocated, slow; |
| 3622 | __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 3623 | __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
| 3624 | __ Branch(&allocated); |
| 3625 | |
| 3626 | // Slow case: Call the runtime system to do the number allocation. |
| 3627 | __ bind(&slow); |
| 3628 | |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3629 | CallRuntimeFromDeferred(Runtime::kHiddenAllocateHeapNumber, 0, instr, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3630 | instr->context()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3631 | // Set the pointer to the new heap number in tmp. |
| 3632 | if (!tmp1.is(v0)) |
| 3633 | __ mov(tmp1, v0); |
| 3634 | // Restore input_reg after call to runtime. |
| 3635 | __ LoadFromSafepointRegisterSlot(input, input); |
| 3636 | __ lw(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3637 | |
| 3638 | __ bind(&allocated); |
| 3639 | // exponent: floating point exponent value. |
| 3640 | // tmp1: allocated heap number. |
| 3641 | __ And(exponent, exponent, Operand(~HeapNumber::kSignMask)); |
| 3642 | __ sw(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
| 3643 | __ lw(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3644 | __ sw(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
| 3645 | |
| 3646 | __ StoreToSafepointRegisterSlot(tmp1, result); |
| 3647 | } |
| 3648 | |
| 3649 | __ bind(&done); |
| 3650 | } |
| 3651 | |
| 3652 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3653 | void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3654 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3655 | Register result = ToRegister(instr->result()); |
| 3656 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 3657 | Label done; |
| 3658 | __ Branch(USE_DELAY_SLOT, &done, ge, input, Operand(zero_reg)); |
| 3659 | __ mov(result, input); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3660 | __ subu(result, zero_reg, input); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3661 | // Overflow if result is still negative, i.e. 0x80000000. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3662 | DeoptimizeIf(lt, instr->environment(), result, Operand(zero_reg)); |
| 3663 | __ bind(&done); |
| 3664 | } |
| 3665 | |
| 3666 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3667 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3668 | // Class for deferred case. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3669 | class DeferredMathAbsTaggedHeapNumber V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3670 | public: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3671 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3672 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3673 | virtual void Generate() V8_OVERRIDE { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3674 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3675 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3676 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3677 | private: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3678 | LMathAbs* instr_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3679 | }; |
| 3680 | |
| 3681 | Representation r = instr->hydrogen()->value()->representation(); |
| 3682 | if (r.IsDouble()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3683 | FPURegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3684 | FPURegister result = ToDoubleRegister(instr->result()); |
| 3685 | __ abs_d(result, input); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3686 | } else if (r.IsSmiOrInteger32()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3687 | EmitIntegerMathAbs(instr); |
| 3688 | } else { |
| 3689 | // Representation is tagged. |
| 3690 | DeferredMathAbsTaggedHeapNumber* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3691 | new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3692 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3693 | // Smi check. |
| 3694 | __ JumpIfNotSmi(input, deferred->entry()); |
| 3695 | // If smi, handle it directly. |
| 3696 | EmitIntegerMathAbs(instr); |
| 3697 | __ bind(deferred->exit()); |
| 3698 | } |
| 3699 | } |
| 3700 | |
| 3701 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3702 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3703 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3704 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3705 | Register scratch1 = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3706 | Register except_flag = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3707 | |
| 3708 | __ EmitFPUTruncate(kRoundToMinusInf, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3709 | result, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3710 | input, |
| 3711 | scratch1, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3712 | double_scratch0(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3713 | except_flag); |
| 3714 | |
| 3715 | // Deopt if the operation did not succeed. |
| 3716 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
| 3717 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3718 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3719 | // Test for -0. |
| 3720 | Label done; |
| 3721 | __ Branch(&done, ne, result, Operand(zero_reg)); |
| 3722 | __ mfc1(scratch1, input.high()); |
| 3723 | __ And(scratch1, scratch1, Operand(HeapNumber::kSignMask)); |
| 3724 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(zero_reg)); |
| 3725 | __ bind(&done); |
| 3726 | } |
| 3727 | } |
| 3728 | |
| 3729 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3730 | void LCodeGen::DoMathRound(LMathRound* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3731 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3732 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3733 | DoubleRegister double_scratch1 = ToDoubleRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3734 | Register scratch = scratch0(); |
| 3735 | Label done, check_sign_on_zero; |
| 3736 | |
| 3737 | // Extract exponent bits. |
| 3738 | __ mfc1(result, input.high()); |
| 3739 | __ Ext(scratch, |
| 3740 | result, |
| 3741 | HeapNumber::kExponentShift, |
| 3742 | HeapNumber::kExponentBits); |
| 3743 | |
| 3744 | // If the number is in ]-0.5, +0.5[, the result is +/- 0. |
| 3745 | Label skip1; |
| 3746 | __ Branch(&skip1, gt, scratch, Operand(HeapNumber::kExponentBias - 2)); |
| 3747 | __ mov(result, zero_reg); |
| 3748 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3749 | __ Branch(&check_sign_on_zero); |
| 3750 | } else { |
| 3751 | __ Branch(&done); |
| 3752 | } |
| 3753 | __ bind(&skip1); |
| 3754 | |
| 3755 | // The following conversion will not work with numbers |
| 3756 | // outside of ]-2^32, 2^32[. |
| 3757 | DeoptimizeIf(ge, instr->environment(), scratch, |
| 3758 | Operand(HeapNumber::kExponentBias + 32)); |
| 3759 | |
| 3760 | // Save the original sign for later comparison. |
| 3761 | __ And(scratch, result, Operand(HeapNumber::kSignMask)); |
| 3762 | |
| 3763 | __ Move(double_scratch0(), 0.5); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3764 | __ add_d(double_scratch0(), input, double_scratch0()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3765 | |
| 3766 | // Check sign of the result: if the sign changed, the input |
| 3767 | // value was in ]0.5, 0[ and the result should be -0. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3768 | __ mfc1(result, double_scratch0().high()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3769 | __ Xor(result, result, Operand(scratch)); |
| 3770 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3771 | // ARM uses 'mi' here, which is 'lt' |
| 3772 | DeoptimizeIf(lt, instr->environment(), result, |
| 3773 | Operand(zero_reg)); |
| 3774 | } else { |
| 3775 | Label skip2; |
| 3776 | // ARM uses 'mi' here, which is 'lt' |
| 3777 | // Negating it results in 'ge' |
| 3778 | __ Branch(&skip2, ge, result, Operand(zero_reg)); |
| 3779 | __ mov(result, zero_reg); |
| 3780 | __ Branch(&done); |
| 3781 | __ bind(&skip2); |
| 3782 | } |
| 3783 | |
| 3784 | Register except_flag = scratch; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3785 | __ EmitFPUTruncate(kRoundToMinusInf, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3786 | result, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3787 | double_scratch0(), |
| 3788 | at, |
| 3789 | double_scratch1, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3790 | except_flag); |
| 3791 | |
| 3792 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
| 3793 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3794 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3795 | // Test for -0. |
| 3796 | __ Branch(&done, ne, result, Operand(zero_reg)); |
| 3797 | __ bind(&check_sign_on_zero); |
| 3798 | __ mfc1(scratch, input.high()); |
| 3799 | __ And(scratch, scratch, Operand(HeapNumber::kSignMask)); |
| 3800 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg)); |
| 3801 | } |
| 3802 | __ bind(&done); |
| 3803 | } |
| 3804 | |
| 3805 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3806 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3807 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3808 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3809 | __ sqrt_d(result, input); |
| 3810 | } |
| 3811 | |
| 3812 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3813 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3814 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3815 | DoubleRegister result = ToDoubleRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3816 | DoubleRegister temp = ToDoubleRegister(instr->temp()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3817 | |
| 3818 | ASSERT(!input.is(result)); |
| 3819 | |
| 3820 | // Note that according to ECMA-262 15.8.2.13: |
| 3821 | // Math.pow(-Infinity, 0.5) == Infinity |
| 3822 | // Math.sqrt(-Infinity) == NaN |
| 3823 | Label done; |
| 3824 | __ Move(temp, -V8_INFINITY); |
| 3825 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, temp, input); |
| 3826 | // Set up Infinity in the delay slot. |
| 3827 | // result is overwritten if the branch is not taken. |
| 3828 | __ neg_d(result, temp); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3829 | |
| 3830 | // Add +0 to convert -0 to +0. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3831 | __ add_d(result, input, kDoubleRegZero); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3832 | __ sqrt_d(result, result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3833 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | |
| 3837 | void LCodeGen::DoPower(LPower* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3838 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3839 | // Having marked this as a call, we can use any registers. |
| 3840 | // Just make sure that the input/output registers are the expected ones. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3841 | ASSERT(!instr->right()->IsDoubleRegister() || |
| 3842 | ToDoubleRegister(instr->right()).is(f4)); |
| 3843 | ASSERT(!instr->right()->IsRegister() || |
| 3844 | ToRegister(instr->right()).is(a2)); |
| 3845 | ASSERT(ToDoubleRegister(instr->left()).is(f2)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3846 | ASSERT(ToDoubleRegister(instr->result()).is(f0)); |
| 3847 | |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 3848 | if (exponent_type.IsSmi()) { |
| 3849 | MathPowStub stub(MathPowStub::TAGGED); |
| 3850 | __ CallStub(&stub); |
| 3851 | } else if (exponent_type.IsTagged()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3852 | Label no_deopt; |
| 3853 | __ JumpIfSmi(a2, &no_deopt); |
| 3854 | __ lw(t3, FieldMemOperand(a2, HeapObject::kMapOffset)); |
bmeurer@chromium.org | 25530ce | 2014-02-07 09:11:16 +0000 | [diff] [blame] | 3855 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3856 | DeoptimizeIf(ne, instr->environment(), t3, Operand(at)); |
| 3857 | __ bind(&no_deopt); |
| 3858 | MathPowStub stub(MathPowStub::TAGGED); |
| 3859 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3860 | } else if (exponent_type.IsInteger32()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3861 | MathPowStub stub(MathPowStub::INTEGER); |
| 3862 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3863 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3864 | ASSERT(exponent_type.IsDouble()); |
| 3865 | MathPowStub stub(MathPowStub::DOUBLE); |
| 3866 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3867 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3871 | void LCodeGen::DoMathExp(LMathExp* instr) { |
| 3872 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3873 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3874 | DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 3875 | DoubleRegister double_scratch2 = double_scratch0(); |
| 3876 | Register temp1 = ToRegister(instr->temp1()); |
| 3877 | Register temp2 = ToRegister(instr->temp2()); |
| 3878 | |
| 3879 | MathExpGenerator::EmitMathExp( |
| 3880 | masm(), input, result, double_scratch1, double_scratch2, |
| 3881 | temp1, temp2, scratch0()); |
| 3882 | } |
| 3883 | |
| 3884 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3885 | void LCodeGen::DoMathLog(LMathLog* instr) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3886 | __ PrepareCallCFunction(0, 1, scratch0()); |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame] | 3887 | __ MovToFloatParameter(ToDoubleRegister(instr->value())); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3888 | __ CallCFunction(ExternalReference::math_log_double_function(isolate()), |
| 3889 | 0, 1); |
machenbach@chromium.org | 4ddd2f1 | 2014-01-14 08:13:44 +0000 | [diff] [blame] | 3890 | __ MovFromFloatResult(ToDoubleRegister(instr->result())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 3894 | void LCodeGen::DoMathClz32(LMathClz32* instr) { |
| 3895 | Register input = ToRegister(instr->value()); |
| 3896 | Register result = ToRegister(instr->result()); |
| 3897 | __ Clz(result, input); |
| 3898 | } |
| 3899 | |
| 3900 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3901 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3902 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3903 | ASSERT(ToRegister(instr->function()).is(a1)); |
| 3904 | ASSERT(instr->HasPointerMap()); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3905 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3906 | Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 3907 | if (known_function.is_null()) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3908 | LPointerMap* pointers = instr->pointer_map(); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3909 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3910 | ParameterCount count(instr->arity()); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3911 | __ InvokeFunction(a1, count, CALL_FUNCTION, generator); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3912 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3913 | CallKnownFunction(known_function, |
| 3914 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3915 | instr->arity(), |
| 3916 | instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3917 | A1_CONTAINS_TARGET); |
| 3918 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3922 | void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3923 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3924 | |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3925 | LPointerMap* pointers = instr->pointer_map(); |
| 3926 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3927 | |
| 3928 | if (instr->target()->IsConstantOperand()) { |
| 3929 | LConstantOperand* target = LConstantOperand::cast(instr->target()); |
| 3930 | Handle<Code> code = Handle<Code>::cast(ToHandle(target)); |
| 3931 | generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET)); |
| 3932 | __ Call(code, RelocInfo::CODE_TARGET); |
| 3933 | } else { |
| 3934 | ASSERT(instr->target()->IsRegister()); |
| 3935 | Register target = ToRegister(instr->target()); |
| 3936 | generator.BeforeCall(__ CallSize(target)); |
| 3937 | __ Addu(target, target, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3938 | __ Call(target); |
| 3939 | } |
| 3940 | generator.AfterCall(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3944 | void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { |
| 3945 | ASSERT(ToRegister(instr->function()).is(a1)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3946 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3947 | |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 3948 | if (instr->hydrogen()->pass_argument_count()) { |
| 3949 | __ li(a0, Operand(instr->arity())); |
| 3950 | } |
| 3951 | |
| 3952 | // Change context. |
| 3953 | __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 3954 | |
| 3955 | // Load the code entry address |
| 3956 | __ lw(at, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
| 3957 | __ Call(at); |
| 3958 | |
| 3959 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | |
| 3963 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3964 | ASSERT(ToRegister(instr->context()).is(cp)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3965 | ASSERT(ToRegister(instr->function()).is(a1)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3966 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3967 | |
| 3968 | int arity = instr->arity(); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 3969 | CallFunctionStub stub(arity, instr->hydrogen()->function_flags()); |
| 3970 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3974 | void LCodeGen::DoCallNew(LCallNew* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3975 | ASSERT(ToRegister(instr->context()).is(cp)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3976 | ASSERT(ToRegister(instr->constructor()).is(a1)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3977 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3978 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3979 | __ li(a0, Operand(instr->arity())); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3980 | // No cell in a2 for construct type feedback in optimized code |
machenbach@chromium.org | 69f64b1 | 2014-03-20 01:04:55 +0000 | [diff] [blame] | 3981 | __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3982 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3983 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3987 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 3988 | ASSERT(ToRegister(instr->context()).is(cp)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3989 | ASSERT(ToRegister(instr->constructor()).is(a1)); |
| 3990 | ASSERT(ToRegister(instr->result()).is(v0)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3991 | |
| 3992 | __ li(a0, Operand(instr->arity())); |
machenbach@chromium.org | 69f64b1 | 2014-03-20 01:04:55 +0000 | [diff] [blame] | 3993 | __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3994 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
palfia@homejinni.com | 07237aa | 2013-07-01 08:01:48 +0000 | [diff] [blame] | 3995 | AllocationSiteOverrideMode override_mode = |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 3996 | (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
palfia@homejinni.com | 07237aa | 2013-07-01 08:01:48 +0000 | [diff] [blame] | 3997 | ? DISABLE_ALLOCATION_SITES |
| 3998 | : DONT_OVERRIDE; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3999 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4000 | if (instr->arity() == 0) { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 4001 | ArrayNoArgumentConstructorStub stub(kind, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4002 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4003 | } else if (instr->arity() == 1) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 4004 | Label done; |
| 4005 | if (IsFastPackedElementsKind(kind)) { |
| 4006 | Label packed_case; |
| 4007 | // We might need a change here, |
| 4008 | // look at the first argument. |
| 4009 | __ lw(t1, MemOperand(sp, 0)); |
| 4010 | __ Branch(&packed_case, eq, t1, Operand(zero_reg)); |
| 4011 | |
| 4012 | ElementsKind holey_kind = GetHoleyElementsKind(kind); |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 4013 | ArraySingleArgumentConstructorStub stub(holey_kind, override_mode); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 4014 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4015 | __ jmp(&done); |
| 4016 | __ bind(&packed_case); |
| 4017 | } |
| 4018 | |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 4019 | ArraySingleArgumentConstructorStub stub(kind, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4020 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 4021 | __ bind(&done); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4022 | } else { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 4023 | ArrayNArgumentsConstructorStub stub(kind, override_mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4024 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4025 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4029 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 4030 | CallRuntime(instr->function(), instr->arity(), instr); |
| 4031 | } |
| 4032 | |
| 4033 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4034 | void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
| 4035 | Register function = ToRegister(instr->function()); |
| 4036 | Register code_object = ToRegister(instr->code_object()); |
| 4037 | __ Addu(code_object, code_object, |
| 4038 | Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4039 | __ sw(code_object, |
| 4040 | FieldMemOperand(function, JSFunction::kCodeEntryOffset)); |
| 4041 | } |
| 4042 | |
| 4043 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 4044 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 4045 | Register result = ToRegister(instr->result()); |
| 4046 | Register base = ToRegister(instr->base_object()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4047 | if (instr->offset()->IsConstantOperand()) { |
| 4048 | LConstantOperand* offset = LConstantOperand::cast(instr->offset()); |
| 4049 | __ Addu(result, base, Operand(ToInteger32(offset))); |
| 4050 | } else { |
| 4051 | Register offset = ToRegister(instr->offset()); |
| 4052 | __ Addu(result, base, offset); |
| 4053 | } |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4057 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4058 | Representation representation = instr->representation(); |
| 4059 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4060 | Register object = ToRegister(instr->object()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4061 | Register scratch = scratch0(); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4062 | HObjectAccess access = instr->hydrogen()->access(); |
| 4063 | int offset = access.offset(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4064 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4065 | if (access.IsExternalMemory()) { |
| 4066 | Register value = ToRegister(instr->value()); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4067 | MemOperand operand = MemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4068 | __ Store(value, operand, representation); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4069 | return; |
| 4070 | } |
| 4071 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4072 | Handle<Map> transition = instr->transition(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4073 | SmiCheck check_needed = |
| 4074 | instr->hydrogen()->value()->IsHeapObject() |
| 4075 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4076 | |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 4077 | ASSERT(!(representation.IsSmi() && |
| 4078 | instr->value()->IsConstantOperand() && |
| 4079 | !IsSmi(LConstantOperand::cast(instr->value())))); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4080 | if (representation.IsHeapObject()) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4081 | Register value = ToRegister(instr->value()); |
| 4082 | if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 4083 | __ SmiTst(value, scratch); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4084 | DeoptimizeIf(eq, instr->environment(), scratch, Operand(zero_reg)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4085 | |
| 4086 | // We know that value is a smi now, so we can omit the check below. |
| 4087 | check_needed = OMIT_SMI_CHECK; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 4088 | } |
machenbach@chromium.org | 09cae8d | 2014-01-30 01:05:27 +0000 | [diff] [blame] | 4089 | } else if (representation.IsDouble()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4090 | ASSERT(transition.is_null()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4091 | ASSERT(access.IsInobject()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4092 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4093 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 4094 | __ sdc1(value, FieldMemOperand(object, offset)); |
| 4095 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4096 | } |
| 4097 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4098 | if (!transition.is_null()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4099 | __ li(scratch, Operand(transition)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4100 | __ sw(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4101 | if (instr->hydrogen()->NeedsWriteBarrierForMap()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4102 | Register temp = ToRegister(instr->temp()); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4103 | // Update the write barrier for the map field. |
| 4104 | __ RecordWriteField(object, |
| 4105 | HeapObject::kMapOffset, |
| 4106 | scratch, |
| 4107 | temp, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4108 | GetRAState(), |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4109 | kSaveFPRegs, |
| 4110 | OMIT_REMEMBERED_SET, |
| 4111 | OMIT_SMI_CHECK); |
| 4112 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | // Do the store. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4116 | Register value = ToRegister(instr->value()); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4117 | if (access.IsInobject()) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4118 | MemOperand operand = FieldMemOperand(object, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4119 | __ Store(value, operand, representation); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4120 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 4121 | // Update the write barrier for the object for in-object properties. |
| 4122 | __ RecordWriteField(object, |
| 4123 | offset, |
| 4124 | value, |
| 4125 | scratch, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4126 | GetRAState(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4127 | kSaveFPRegs, |
| 4128 | EMIT_REMEMBERED_SET, |
| 4129 | check_needed); |
| 4130 | } |
| 4131 | } else { |
| 4132 | __ lw(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 4133 | MemOperand operand = FieldMemOperand(scratch, offset); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4134 | __ Store(value, operand, representation); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4135 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 4136 | // Update the write barrier for the properties array. |
| 4137 | // object is used as a scratch register. |
| 4138 | __ RecordWriteField(scratch, |
| 4139 | offset, |
| 4140 | value, |
| 4141 | object, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4142 | GetRAState(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4143 | kSaveFPRegs, |
| 4144 | EMIT_REMEMBERED_SET, |
| 4145 | check_needed); |
| 4146 | } |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | |
| 4151 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4152 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4153 | ASSERT(ToRegister(instr->object()).is(a1)); |
| 4154 | ASSERT(ToRegister(instr->value()).is(a0)); |
| 4155 | |
| 4156 | // Name is always in a2. |
| 4157 | __ li(a2, Operand(instr->name())); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4158 | Handle<Code> ic = StoreIC::initialize_stub(isolate(), instr->strict_mode()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4159 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4160 | } |
| 4161 | |
| 4162 | |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 4163 | void LCodeGen::ApplyCheckIf(Condition condition, |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4164 | LBoundsCheck* check, |
| 4165 | Register src1, |
| 4166 | const Operand& src2) { |
| 4167 | if (FLAG_debug_code && check->hydrogen()->skip_check()) { |
| 4168 | Label done; |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 4169 | __ Branch(&done, NegateCondition(condition), src1, src2); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4170 | __ stop("eliminated bounds check failed"); |
| 4171 | __ bind(&done); |
| 4172 | } else { |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 4173 | DeoptimizeIf(condition, check->environment(), src1, src2); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4174 | } |
| 4175 | } |
| 4176 | |
| 4177 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4178 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4179 | if (instr->hydrogen()->skip_check()) return; |
| 4180 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4181 | Condition condition = instr->hydrogen()->allow_equality() ? hi : hs; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4182 | if (instr->index()->IsConstantOperand()) { |
| 4183 | int constant_index = |
| 4184 | ToInteger32(LConstantOperand::cast(instr->index())); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4185 | if (instr->hydrogen()->length()->representation().IsSmi()) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4186 | __ li(at, Operand(Smi::FromInt(constant_index))); |
| 4187 | } else { |
| 4188 | __ li(at, Operand(constant_index)); |
| 4189 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4190 | ApplyCheckIf(condition, |
| 4191 | instr, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4192 | at, |
| 4193 | Operand(ToRegister(instr->length()))); |
| 4194 | } else { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4195 | ApplyCheckIf(condition, |
| 4196 | instr, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4197 | ToRegister(instr->index()), |
| 4198 | Operand(ToRegister(instr->length()))); |
| 4199 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4203 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
| 4204 | Register external_pointer = ToRegister(instr->elements()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4205 | Register key = no_reg; |
| 4206 | ElementsKind elements_kind = instr->elements_kind(); |
| 4207 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4208 | int constant_key = 0; |
| 4209 | if (key_is_constant) { |
| 4210 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4211 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4212 | Abort(kArrayIndexConstantValueTooBig); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4213 | } |
| 4214 | } else { |
| 4215 | key = ToRegister(instr->key()); |
| 4216 | } |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 4217 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4218 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 4219 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4220 | int additional_offset = IsFixedTypedArrayElementsKind(elements_kind) |
| 4221 | ? FixedTypedArrayBase::kDataOffset - kHeapObjectTag |
| 4222 | : 0; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4223 | |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4224 | if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4225 | elements_kind == FLOAT32_ELEMENTS || |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4226 | elements_kind == EXTERNAL_FLOAT64_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4227 | elements_kind == FLOAT64_ELEMENTS) { |
| 4228 | int base_offset = |
| 4229 | (instr->additional_index() << element_size_shift) + additional_offset; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4230 | Register address = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4231 | FPURegister value(ToDoubleRegister(instr->value())); |
| 4232 | if (key_is_constant) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4233 | if (constant_key != 0) { |
| 4234 | __ Addu(address, external_pointer, |
| 4235 | Operand(constant_key << element_size_shift)); |
| 4236 | } else { |
| 4237 | address = external_pointer; |
| 4238 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4239 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4240 | __ sll(address, key, shift_size); |
| 4241 | __ Addu(address, external_pointer, address); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4244 | if (elements_kind == EXTERNAL_FLOAT32_ELEMENTS || |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4245 | elements_kind == FLOAT32_ELEMENTS) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4246 | __ cvt_s_d(double_scratch0(), value); |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4247 | __ swc1(double_scratch0(), MemOperand(address, base_offset)); |
| 4248 | } else { // Storing doubles, not floats. |
| 4249 | __ sdc1(value, MemOperand(address, base_offset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4250 | } |
| 4251 | } else { |
| 4252 | Register value(ToRegister(instr->value())); |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 4253 | MemOperand mem_operand = PrepareKeyedOperand( |
| 4254 | key, external_pointer, key_is_constant, constant_key, |
| 4255 | element_size_shift, shift_size, |
| 4256 | instr->additional_index(), additional_offset); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4257 | switch (elements_kind) { |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4258 | case EXTERNAL_UINT8_CLAMPED_ELEMENTS: |
| 4259 | case EXTERNAL_INT8_ELEMENTS: |
| 4260 | case EXTERNAL_UINT8_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4261 | case UINT8_ELEMENTS: |
| 4262 | case UINT8_CLAMPED_ELEMENTS: |
| 4263 | case INT8_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4264 | __ sb(value, mem_operand); |
| 4265 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4266 | case EXTERNAL_INT16_ELEMENTS: |
| 4267 | case EXTERNAL_UINT16_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4268 | case INT16_ELEMENTS: |
| 4269 | case UINT16_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4270 | __ sh(value, mem_operand); |
| 4271 | break; |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4272 | case EXTERNAL_INT32_ELEMENTS: |
| 4273 | case EXTERNAL_UINT32_ELEMENTS: |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4274 | case INT32_ELEMENTS: |
| 4275 | case UINT32_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4276 | __ sw(value, mem_operand); |
| 4277 | break; |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4278 | case FLOAT32_ELEMENTS: |
| 4279 | case FLOAT64_ELEMENTS: |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame] | 4280 | case EXTERNAL_FLOAT32_ELEMENTS: |
| 4281 | case EXTERNAL_FLOAT64_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4282 | case FAST_DOUBLE_ELEMENTS: |
| 4283 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4284 | case FAST_SMI_ELEMENTS: |
| 4285 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 4286 | case FAST_HOLEY_ELEMENTS: |
| 4287 | case FAST_HOLEY_SMI_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4288 | case DICTIONARY_ELEMENTS: |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4289 | case SLOPPY_ARGUMENTS_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4290 | UNREACHABLE(); |
| 4291 | break; |
| 4292 | } |
| 4293 | } |
| 4294 | } |
| 4295 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4296 | |
| 4297 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
| 4298 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 4299 | Register elements = ToRegister(instr->elements()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4300 | Register scratch = scratch0(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4301 | DoubleRegister double_scratch = double_scratch0(); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4302 | bool key_is_constant = instr->key()->IsConstantOperand(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4303 | Label not_nan, done; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4304 | |
| 4305 | // Calculate the effective address of the slot in the array to store the |
| 4306 | // double value. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4307 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4308 | if (key_is_constant) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4309 | int constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4310 | if (constant_key & 0xF0000000) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4311 | Abort(kArrayIndexConstantValueTooBig); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4312 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4313 | __ Addu(scratch, elements, |
| 4314 | Operand((constant_key << element_size_shift) + |
| 4315 | FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4316 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4317 | int shift_size = (instr->hydrogen()->key()->representation().IsSmi()) |
| 4318 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 4319 | __ Addu(scratch, elements, |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4320 | Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4321 | __ sll(at, ToRegister(instr->key()), shift_size); |
| 4322 | __ Addu(scratch, scratch, at); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | if (instr->NeedsCanonicalization()) { |
| 4326 | Label is_nan; |
| 4327 | // Check for NaN. All NaNs must be canonicalized. |
| 4328 | __ BranchF(NULL, &is_nan, eq, value, value); |
| 4329 | __ Branch(¬_nan); |
| 4330 | |
| 4331 | // Only load canonical NaN if the comparison above set the overflow. |
| 4332 | __ bind(&is_nan); |
machenbach@chromium.org | 8297530 | 2014-02-06 01:06:18 +0000 | [diff] [blame] | 4333 | __ LoadRoot(at, Heap::kNanValueRootIndex); |
| 4334 | __ ldc1(double_scratch, FieldMemOperand(at, HeapNumber::kValueOffset)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4335 | __ sdc1(double_scratch, MemOperand(scratch, instr->additional_index() << |
| 4336 | element_size_shift)); |
| 4337 | __ Branch(&done); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | __ bind(¬_nan); |
| 4341 | __ sdc1(value, MemOperand(scratch, instr->additional_index() << |
| 4342 | element_size_shift)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4343 | __ bind(&done); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | |
| 4347 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| 4348 | Register value = ToRegister(instr->value()); |
| 4349 | Register elements = ToRegister(instr->elements()); |
| 4350 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) |
| 4351 | : no_reg; |
| 4352 | Register scratch = scratch0(); |
| 4353 | Register store_base = scratch; |
| 4354 | int offset = 0; |
| 4355 | |
| 4356 | // Do the store. |
| 4357 | if (instr->key()->IsConstantOperand()) { |
| 4358 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4359 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 4360 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 4361 | instr->additional_index()); |
| 4362 | store_base = elements; |
| 4363 | } else { |
| 4364 | // Even though the HLoadKeyed instruction forces the input |
| 4365 | // representation for the key to be an integer, the input gets replaced |
| 4366 | // during bound check elimination with the index argument to the bounds |
| 4367 | // check, which can be tagged, so that case must be handled here, too. |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 4368 | if (instr->hydrogen()->key()->representation().IsSmi()) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4369 | __ sll(scratch, key, kPointerSizeLog2 - kSmiTagSize); |
| 4370 | __ addu(scratch, elements, scratch); |
| 4371 | } else { |
| 4372 | __ sll(scratch, key, kPointerSizeLog2); |
| 4373 | __ addu(scratch, elements, scratch); |
| 4374 | } |
| 4375 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 4376 | } |
| 4377 | __ sw(value, FieldMemOperand(store_base, offset)); |
| 4378 | |
| 4379 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4380 | SmiCheck check_needed = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4381 | instr->hydrogen()->value()->IsHeapObject() |
| 4382 | ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4383 | // Compute address of modified element and store it into key register. |
| 4384 | __ Addu(key, store_base, Operand(offset - kHeapObjectTag)); |
| 4385 | __ RecordWrite(elements, |
| 4386 | key, |
| 4387 | value, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4388 | GetRAState(), |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4389 | kSaveFPRegs, |
| 4390 | EMIT_REMEMBERED_SET, |
| 4391 | check_needed); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | |
| 4396 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4397 | // By cases: external, fast double |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 4398 | if (instr->is_typed_elements()) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4399 | DoStoreKeyedExternalArray(instr); |
| 4400 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4401 | DoStoreKeyedFixedDoubleArray(instr); |
| 4402 | } else { |
| 4403 | DoStoreKeyedFixedArray(instr); |
| 4404 | } |
| 4405 | } |
| 4406 | |
| 4407 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4408 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4409 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4410 | ASSERT(ToRegister(instr->object()).is(a2)); |
| 4411 | ASSERT(ToRegister(instr->key()).is(a1)); |
| 4412 | ASSERT(ToRegister(instr->value()).is(a0)); |
| 4413 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4414 | Handle<Code> ic = (instr->strict_mode() == STRICT) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4415 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4416 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
| 4417 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4418 | } |
| 4419 | |
| 4420 | |
| 4421 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4422 | Register object_reg = ToRegister(instr->object()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4423 | Register scratch = scratch0(); |
| 4424 | |
| 4425 | Handle<Map> from_map = instr->original_map(); |
| 4426 | Handle<Map> to_map = instr->transitioned_map(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4427 | ElementsKind from_kind = instr->from_kind(); |
| 4428 | ElementsKind to_kind = instr->to_kind(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4429 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4430 | Label not_applicable; |
| 4431 | __ lw(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4432 | __ Branch(¬_applicable, ne, scratch, Operand(from_map)); |
| 4433 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4434 | if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4435 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
| 4436 | __ li(new_map_reg, Operand(to_map)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4437 | __ sw(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4438 | // Write barrier. |
| 4439 | __ RecordWriteField(object_reg, HeapObject::kMapOffset, new_map_reg, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4440 | scratch, GetRAState(), kDontSaveFPRegs); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4441 | } else { |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 4442 | ASSERT(object_reg.is(a0)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4443 | ASSERT(ToRegister(instr->context()).is(cp)); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4444 | PushSafepointRegistersScope scope( |
| 4445 | this, Safepoint::kWithRegistersAndDoubles); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4446 | __ li(a1, Operand(to_map)); |
machenbach@chromium.org | 9801e3c | 2014-03-19 01:04:51 +0000 | [diff] [blame] | 4447 | bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; |
| 4448 | TransitionElementsKindStub stub(from_kind, to_kind, is_js_array); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4449 | __ CallStub(&stub); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 4450 | RecordSafepointWithRegistersAndDoubles( |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 4451 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4452 | } |
| 4453 | __ bind(¬_applicable); |
| 4454 | } |
| 4455 | |
| 4456 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4457 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4458 | Register object = ToRegister(instr->object()); |
| 4459 | Register temp = ToRegister(instr->temp()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4460 | Label no_memento_found; |
| 4461 | __ TestJSArrayForAllocationMemento(object, temp, &no_memento_found, |
| 4462 | ne, &no_memento_found); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4463 | DeoptimizeIf(al, instr->environment()); |
mstarzinger@chromium.org | b4968be | 2013-10-16 09:00:56 +0000 | [diff] [blame] | 4464 | __ bind(&no_memento_found); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4468 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4469 | ASSERT(ToRegister(instr->context()).is(cp)); |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 4470 | ASSERT(ToRegister(instr->left()).is(a1)); |
| 4471 | ASSERT(ToRegister(instr->right()).is(a0)); |
| 4472 | StringAddStub stub(instr->hydrogen()->flags(), |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 4473 | instr->hydrogen()->pretenure_flag()); |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 4474 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | |
| 4478 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4479 | class DeferredStringCharCodeAt V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4480 | public: |
| 4481 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 4482 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4483 | virtual void Generate() V8_OVERRIDE { |
| 4484 | codegen()->DoDeferredStringCharCodeAt(instr_); |
| 4485 | } |
| 4486 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4487 | private: |
| 4488 | LStringCharCodeAt* instr_; |
| 4489 | }; |
| 4490 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4491 | DeferredStringCharCodeAt* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4492 | new(zone()) DeferredStringCharCodeAt(this, instr); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4493 | StringCharLoadGenerator::Generate(masm(), |
| 4494 | ToRegister(instr->string()), |
| 4495 | ToRegister(instr->index()), |
| 4496 | ToRegister(instr->result()), |
| 4497 | deferred->entry()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4498 | __ bind(deferred->exit()); |
| 4499 | } |
| 4500 | |
| 4501 | |
| 4502 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4503 | Register string = ToRegister(instr->string()); |
| 4504 | Register result = ToRegister(instr->result()); |
| 4505 | Register scratch = scratch0(); |
| 4506 | |
| 4507 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4508 | // result register contain a valid pointer because it is already |
| 4509 | // contained in the register pointer map. |
| 4510 | __ mov(result, zero_reg); |
| 4511 | |
| 4512 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4513 | __ push(string); |
| 4514 | // Push the index as a smi. This is safe because of the checks in |
| 4515 | // DoStringCharCodeAt above. |
| 4516 | if (instr->index()->IsConstantOperand()) { |
| 4517 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4518 | __ Addu(scratch, zero_reg, Operand(Smi::FromInt(const_index))); |
| 4519 | __ push(scratch); |
| 4520 | } else { |
| 4521 | Register index = ToRegister(instr->index()); |
| 4522 | __ SmiTag(index); |
| 4523 | __ push(index); |
| 4524 | } |
machenbach@chromium.org | 9b95fd7 | 2014-03-26 01:04:35 +0000 | [diff] [blame] | 4525 | CallRuntimeFromDeferred(Runtime::kHiddenStringCharCodeAt, 2, instr, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4526 | instr->context()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4527 | __ AssertSmi(v0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4528 | __ SmiUntag(v0); |
| 4529 | __ StoreToSafepointRegisterSlot(v0, result); |
| 4530 | } |
| 4531 | |
| 4532 | |
| 4533 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4534 | class DeferredStringCharFromCode V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4535 | public: |
| 4536 | DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 4537 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4538 | virtual void Generate() V8_OVERRIDE { |
| 4539 | codegen()->DoDeferredStringCharFromCode(instr_); |
| 4540 | } |
| 4541 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4542 | private: |
| 4543 | LStringCharFromCode* instr_; |
| 4544 | }; |
| 4545 | |
| 4546 | DeferredStringCharFromCode* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4547 | new(zone()) DeferredStringCharFromCode(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4548 | |
| 4549 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4550 | Register char_code = ToRegister(instr->char_code()); |
| 4551 | Register result = ToRegister(instr->result()); |
| 4552 | Register scratch = scratch0(); |
| 4553 | ASSERT(!char_code.is(result)); |
| 4554 | |
| 4555 | __ Branch(deferred->entry(), hi, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4556 | char_code, Operand(String::kMaxOneByteCharCode)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4557 | __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 4558 | __ sll(scratch, char_code, kPointerSizeLog2); |
| 4559 | __ Addu(result, result, scratch); |
| 4560 | __ lw(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 4561 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 4562 | __ Branch(deferred->entry(), eq, result, Operand(scratch)); |
| 4563 | __ bind(deferred->exit()); |
| 4564 | } |
| 4565 | |
| 4566 | |
| 4567 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4568 | Register char_code = ToRegister(instr->char_code()); |
| 4569 | Register result = ToRegister(instr->result()); |
| 4570 | |
| 4571 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4572 | // result register contain a valid pointer because it is already |
| 4573 | // contained in the register pointer map. |
| 4574 | __ mov(result, zero_reg); |
| 4575 | |
| 4576 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4577 | __ SmiTag(char_code); |
| 4578 | __ push(char_code); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4579 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4580 | __ StoreToSafepointRegisterSlot(v0, result); |
| 4581 | } |
| 4582 | |
| 4583 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4584 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4585 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4586 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 4587 | LOperand* output = instr->result(); |
| 4588 | ASSERT(output->IsDoubleRegister()); |
| 4589 | FPURegister single_scratch = double_scratch0().low(); |
| 4590 | if (input->IsStackSlot()) { |
| 4591 | Register scratch = scratch0(); |
| 4592 | __ lw(scratch, ToMemOperand(input)); |
| 4593 | __ mtc1(scratch, single_scratch); |
| 4594 | } else { |
| 4595 | __ mtc1(ToRegister(input), single_scratch); |
| 4596 | } |
| 4597 | __ cvt_d_w(ToDoubleRegister(output), single_scratch); |
| 4598 | } |
| 4599 | |
| 4600 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4601 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4602 | LOperand* input = instr->value(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4603 | LOperand* output = instr->result(); |
| 4604 | |
| 4605 | FPURegister dbl_scratch = double_scratch0(); |
| 4606 | __ mtc1(ToRegister(input), dbl_scratch); |
| 4607 | __ Cvt_d_uw(ToDoubleRegister(output), dbl_scratch, f22); |
| 4608 | } |
| 4609 | |
| 4610 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4611 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4612 | class DeferredNumberTagI V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4613 | public: |
| 4614 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 4615 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4616 | virtual void Generate() V8_OVERRIDE { |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4617 | codegen()->DoDeferredNumberTagIU(instr_, |
| 4618 | instr_->value(), |
| 4619 | instr_->temp1(), |
| 4620 | instr_->temp2(), |
| 4621 | SIGNED_INT32); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4622 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4623 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4624 | private: |
| 4625 | LNumberTagI* instr_; |
| 4626 | }; |
| 4627 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4628 | Register src = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4629 | Register dst = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4630 | Register overflow = scratch0(); |
| 4631 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4632 | DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4633 | __ SmiTagCheckOverflow(dst, src, overflow); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4634 | __ BranchOnOverflow(deferred->entry(), overflow); |
| 4635 | __ bind(deferred->exit()); |
| 4636 | } |
| 4637 | |
| 4638 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4639 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4640 | class DeferredNumberTagU V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4641 | public: |
| 4642 | DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4643 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4644 | virtual void Generate() V8_OVERRIDE { |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4645 | codegen()->DoDeferredNumberTagIU(instr_, |
| 4646 | instr_->value(), |
| 4647 | instr_->temp1(), |
| 4648 | instr_->temp2(), |
| 4649 | UNSIGNED_INT32); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4650 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4651 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4652 | private: |
| 4653 | LNumberTagU* instr_; |
| 4654 | }; |
| 4655 | |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4656 | Register input = ToRegister(instr->value()); |
| 4657 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4658 | |
| 4659 | DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4660 | __ Branch(deferred->entry(), hi, input, Operand(Smi::kMaxValue)); |
| 4661 | __ SmiTag(result, input); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4662 | __ bind(deferred->exit()); |
| 4663 | } |
| 4664 | |
| 4665 | |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4666 | void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr, |
| 4667 | LOperand* value, |
| 4668 | LOperand* temp1, |
| 4669 | LOperand* temp2, |
| 4670 | IntegerSignedness signedness) { |
| 4671 | Label done, slow; |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4672 | Register src = ToRegister(value); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4673 | Register dst = ToRegister(instr->result()); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4674 | Register tmp1 = scratch0(); |
| 4675 | Register tmp2 = ToRegister(temp1); |
| 4676 | Register tmp3 = ToRegister(temp2); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4677 | DoubleRegister dbl_scratch = double_scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4678 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4679 | if (signedness == SIGNED_INT32) { |
| 4680 | // There was overflow, so bits 30 and 31 of the original integer |
| 4681 | // disagree. Try to allocate a heap number in new space and store |
| 4682 | // the value in there. If that fails, call the runtime system. |
| 4683 | if (dst.is(src)) { |
| 4684 | __ SmiUntag(src, dst); |
| 4685 | __ Xor(src, src, Operand(0x80000000)); |
| 4686 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4687 | __ mtc1(src, dbl_scratch); |
| 4688 | __ cvt_d_w(dbl_scratch, dbl_scratch); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4689 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4690 | __ mtc1(src, dbl_scratch); |
| 4691 | __ Cvt_d_uw(dbl_scratch, dbl_scratch, f22); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4692 | } |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4693 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4694 | if (FLAG_inline_new) { |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4695 | __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex); |
| 4696 | __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow, DONT_TAG_RESULT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4697 | __ Branch(&done); |
| 4698 | } |
| 4699 | |
| 4700 | // Slow case: Call the runtime system to do the number allocation. |
| 4701 | __ bind(&slow); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4702 | { |
| 4703 | // TODO(3095996): Put a valid pointer value in the stack slot where the |
| 4704 | // result register is stored, as this register is in the pointer map, but |
| 4705 | // contains an integer value. |
| 4706 | __ mov(dst, zero_reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4707 | |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4708 | // Preserve the value of all registers. |
| 4709 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4710 | |
| 4711 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4712 | // the environment's HContext or HInlinedContext value. |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4713 | // They only call Runtime::kHiddenAllocateHeapNumber. |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4714 | // The corresponding HChange instructions are added in a phase that does |
| 4715 | // not have easy access to the local context. |
| 4716 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4717 | __ CallRuntimeSaveDoubles(Runtime::kHiddenAllocateHeapNumber); |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 4718 | RecordSafepointWithRegisters( |
| 4719 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
| 4720 | __ Subu(v0, v0, kHeapObjectTag); |
| 4721 | __ StoreToSafepointRegisterSlot(v0, dst); |
| 4722 | } |
| 4723 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4724 | |
| 4725 | // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 4726 | // number. |
| 4727 | __ bind(&done); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4728 | __ sdc1(dbl_scratch, MemOperand(dst, HeapNumber::kValueOffset)); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4729 | __ Addu(dst, dst, kHeapObjectTag); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | |
| 4733 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4734 | class DeferredNumberTagD V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4735 | public: |
| 4736 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 4737 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4738 | virtual void Generate() V8_OVERRIDE { |
| 4739 | codegen()->DoDeferredNumberTagD(instr_); |
| 4740 | } |
| 4741 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4742 | private: |
| 4743 | LNumberTagD* instr_; |
| 4744 | }; |
| 4745 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4746 | DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4747 | Register scratch = scratch0(); |
| 4748 | Register reg = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4749 | Register temp1 = ToRegister(instr->temp()); |
| 4750 | Register temp2 = ToRegister(instr->temp2()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4751 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4752 | DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4753 | if (FLAG_inline_new) { |
| 4754 | __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4755 | // We want the untagged address first for performance |
| 4756 | __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(), |
| 4757 | DONT_TAG_RESULT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4758 | } else { |
| 4759 | __ Branch(deferred->entry()); |
| 4760 | } |
| 4761 | __ bind(deferred->exit()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4762 | __ sdc1(input_reg, MemOperand(reg, HeapNumber::kValueOffset)); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4763 | // Now that we have finished with the object's real address tag it |
| 4764 | __ Addu(reg, reg, kHeapObjectTag); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | |
| 4768 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 4769 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4770 | // result register contain a valid pointer because it is already |
| 4771 | // contained in the register pointer map. |
| 4772 | Register reg = ToRegister(instr->result()); |
| 4773 | __ mov(reg, zero_reg); |
| 4774 | |
| 4775 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4776 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4777 | // the environment's HContext or HInlinedContext value. |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4778 | // They only call Runtime::kHiddenAllocateHeapNumber. |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4779 | // The corresponding HChange instructions are added in a phase that does |
| 4780 | // not have easy access to the local context. |
| 4781 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4782 | __ CallRuntimeSaveDoubles(Runtime::kHiddenAllocateHeapNumber); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 4783 | RecordSafepointWithRegisters( |
| 4784 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4785 | __ Subu(v0, v0, kHeapObjectTag); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4786 | __ StoreToSafepointRegisterSlot(v0, reg); |
| 4787 | } |
| 4788 | |
| 4789 | |
| 4790 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
machenbach@chromium.org | 381adef | 2014-03-14 03:04:56 +0000 | [diff] [blame] | 4791 | HChange* hchange = instr->hydrogen(); |
| 4792 | Register input = ToRegister(instr->value()); |
| 4793 | Register output = ToRegister(instr->result()); |
| 4794 | if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4795 | hchange->value()->CheckFlag(HValue::kUint32)) { |
| 4796 | __ And(at, input, Operand(0xc0000000)); |
| 4797 | DeoptimizeIf(ne, instr->environment(), at, Operand(zero_reg)); |
| 4798 | } |
| 4799 | if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4800 | !hchange->value()->CheckFlag(HValue::kUint32)) { |
| 4801 | __ SmiTagCheckOverflow(output, input, at); |
| 4802 | DeoptimizeIf(lt, instr->environment(), at, Operand(zero_reg)); |
| 4803 | } else { |
| 4804 | __ SmiTag(output, input); |
| 4805 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | |
| 4809 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
| 4810 | Register scratch = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4811 | Register input = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4812 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4813 | if (instr->needs_check()) { |
| 4814 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4815 | // If the input is a HeapObject, value of scratch won't be zero. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4816 | __ And(scratch, input, Operand(kHeapObjectTag)); |
| 4817 | __ SmiUntag(result, input); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4818 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg)); |
| 4819 | } else { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4820 | __ SmiUntag(result, input); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4821 | } |
| 4822 | } |
| 4823 | |
| 4824 | |
| 4825 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
| 4826 | DoubleRegister result_reg, |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 4827 | bool can_convert_undefined_to_nan, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4828 | bool deoptimize_on_minus_zero, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4829 | LEnvironment* env, |
| 4830 | NumberUntagDMode mode) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4831 | Register scratch = scratch0(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4832 | Label convert, load_smi, done; |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 4833 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4834 | // Smi check. |
| 4835 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4836 | // Heap number map check. |
| 4837 | __ lw(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4838 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4839 | if (can_convert_undefined_to_nan) { |
| 4840 | __ Branch(&convert, ne, scratch, Operand(at)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4841 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4842 | DeoptimizeIf(ne, env, scratch, Operand(at)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4843 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4844 | // Load heap number. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4845 | __ ldc1(result_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4846 | if (deoptimize_on_minus_zero) { |
| 4847 | __ mfc1(at, result_reg.low()); |
| 4848 | __ Branch(&done, ne, at, Operand(zero_reg)); |
| 4849 | __ mfc1(scratch, result_reg.high()); |
| 4850 | DeoptimizeIf(eq, env, scratch, Operand(HeapNumber::kSignMask)); |
| 4851 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4852 | __ Branch(&done); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4853 | if (can_convert_undefined_to_nan) { |
| 4854 | __ bind(&convert); |
| 4855 | // Convert undefined (and hole) to NaN. |
| 4856 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4857 | DeoptimizeIf(ne, env, input_reg, Operand(at)); |
| 4858 | __ LoadRoot(scratch, Heap::kNanValueRootIndex); |
| 4859 | __ ldc1(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset)); |
| 4860 | __ Branch(&done); |
| 4861 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4862 | } else { |
| 4863 | __ SmiUntag(scratch, input_reg); |
| 4864 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4865 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4866 | // Smi to double register conversion |
| 4867 | __ bind(&load_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4868 | // scratch: untagged value of input_reg |
| 4869 | __ mtc1(scratch, result_reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4870 | __ cvt_d_w(result_reg, result_reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4871 | __ bind(&done); |
| 4872 | } |
| 4873 | |
| 4874 | |
| 4875 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4876 | Register input_reg = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4877 | Register scratch1 = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4878 | Register scratch2 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4879 | DoubleRegister double_scratch = double_scratch0(); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4880 | DoubleRegister double_scratch2 = ToDoubleRegister(instr->temp2()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4881 | |
| 4882 | ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
| 4883 | ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
| 4884 | |
| 4885 | Label done; |
| 4886 | |
| 4887 | // The input is a tagged HeapObject. |
| 4888 | // Heap number map check. |
| 4889 | __ lw(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4890 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 4891 | // This 'at' value and scratch1 map value are used for tests in both clauses |
| 4892 | // of the if. |
| 4893 | |
| 4894 | if (instr->truncating()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4895 | // Performs a truncating conversion of a floating point number as used by |
| 4896 | // the JS bitwise operations. |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4897 | Label no_heap_number, check_bools, check_false; |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4898 | // Check HeapNumber map. |
| 4899 | __ Branch(USE_DELAY_SLOT, &no_heap_number, ne, scratch1, Operand(at)); |
| 4900 | __ mov(scratch2, input_reg); // In delay slot. |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 4901 | __ TruncateHeapNumberToI(input_reg, scratch2); |
mstarzinger@chromium.org | 2efc3e4 | 2013-10-14 08:45:38 +0000 | [diff] [blame] | 4902 | __ Branch(&done); |
| 4903 | |
| 4904 | // Check for Oddballs. Undefined/False is converted to zero and True to one |
| 4905 | // for truncating conversions. |
| 4906 | __ bind(&no_heap_number); |
| 4907 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4908 | __ Branch(&check_bools, ne, input_reg, Operand(at)); |
| 4909 | ASSERT(ToRegister(instr->result()).is(input_reg)); |
| 4910 | __ Branch(USE_DELAY_SLOT, &done); |
| 4911 | __ mov(input_reg, zero_reg); // In delay slot. |
| 4912 | |
| 4913 | __ bind(&check_bools); |
| 4914 | __ LoadRoot(at, Heap::kTrueValueRootIndex); |
| 4915 | __ Branch(&check_false, ne, scratch2, Operand(at)); |
| 4916 | __ Branch(USE_DELAY_SLOT, &done); |
| 4917 | __ li(input_reg, Operand(1)); // In delay slot. |
| 4918 | |
| 4919 | __ bind(&check_false); |
| 4920 | __ LoadRoot(at, Heap::kFalseValueRootIndex); |
| 4921 | DeoptimizeIf(ne, instr->environment(), scratch2, Operand(at)); |
| 4922 | __ Branch(USE_DELAY_SLOT, &done); |
| 4923 | __ mov(input_reg, zero_reg); // In delay slot. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4924 | } else { |
| 4925 | // Deoptimize if we don't have a heap number. |
| 4926 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(at)); |
| 4927 | |
| 4928 | // Load the double value. |
| 4929 | __ ldc1(double_scratch, |
| 4930 | FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4931 | |
| 4932 | Register except_flag = scratch2; |
| 4933 | __ EmitFPUTruncate(kRoundToZero, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4934 | input_reg, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4935 | double_scratch, |
| 4936 | scratch1, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4937 | double_scratch2, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4938 | except_flag, |
| 4939 | kCheckForInexactConversion); |
| 4940 | |
| 4941 | // Deopt if the operation did not succeed. |
| 4942 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
| 4943 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4944 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4945 | __ Branch(&done, ne, input_reg, Operand(zero_reg)); |
| 4946 | |
| 4947 | __ mfc1(scratch1, double_scratch.high()); |
| 4948 | __ And(scratch1, scratch1, Operand(HeapNumber::kSignMask)); |
| 4949 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(zero_reg)); |
| 4950 | } |
| 4951 | } |
| 4952 | __ bind(&done); |
| 4953 | } |
| 4954 | |
| 4955 | |
| 4956 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4957 | class DeferredTaggedToI V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4958 | public: |
| 4959 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 4960 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 4961 | virtual void Generate() V8_OVERRIDE { |
| 4962 | codegen()->DoDeferredTaggedToI(instr_); |
| 4963 | } |
| 4964 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4965 | private: |
| 4966 | LTaggedToI* instr_; |
| 4967 | }; |
| 4968 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4969 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4970 | ASSERT(input->IsRegister()); |
| 4971 | ASSERT(input->Equals(instr->result())); |
| 4972 | |
| 4973 | Register input_reg = ToRegister(input); |
| 4974 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4975 | if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 4976 | __ SmiUntag(input_reg); |
| 4977 | } else { |
| 4978 | DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4979 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4980 | // Let the deferred code handle the HeapObject case. |
| 4981 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4982 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4983 | // Smi to int32 conversion. |
| 4984 | __ SmiUntag(input_reg); |
| 4985 | __ bind(deferred->exit()); |
| 4986 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | |
| 4990 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4991 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4992 | ASSERT(input->IsRegister()); |
| 4993 | LOperand* result = instr->result(); |
| 4994 | ASSERT(result->IsDoubleRegister()); |
| 4995 | |
| 4996 | Register input_reg = ToRegister(input); |
| 4997 | DoubleRegister result_reg = ToDoubleRegister(result); |
| 4998 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4999 | HValue* value = instr->hydrogen()->value(); |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 5000 | NumberUntagDMode mode = value->representation().IsSmi() |
| 5001 | ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5002 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5003 | EmitNumberUntagD(input_reg, result_reg, |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 5004 | instr->hydrogen()->can_convert_undefined_to_nan(), |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5005 | instr->hydrogen()->deoptimize_on_minus_zero(), |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5006 | instr->environment(), |
| 5007 | mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | |
| 5011 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
| 5012 | Register result_reg = ToRegister(instr->result()); |
| 5013 | Register scratch1 = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5014 | DoubleRegister double_input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5015 | |
| 5016 | if (instr->truncating()) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5017 | __ TruncateDoubleToI(result_reg, double_input); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5018 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5019 | Register except_flag = LCodeGen::scratch1(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5020 | |
| 5021 | __ EmitFPUTruncate(kRoundToMinusInf, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 5022 | result_reg, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5023 | double_input, |
| 5024 | scratch1, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 5025 | double_scratch0(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5026 | except_flag, |
| 5027 | kCheckForInexactConversion); |
| 5028 | |
| 5029 | // Deopt if the operation did not succeed (except_flag != 0). |
| 5030 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5031 | |
| 5032 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5033 | Label done; |
| 5034 | __ Branch(&done, ne, result_reg, Operand(zero_reg)); |
| 5035 | __ mfc1(scratch1, double_input.high()); |
| 5036 | __ And(scratch1, scratch1, Operand(HeapNumber::kSignMask)); |
| 5037 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(zero_reg)); |
| 5038 | __ bind(&done); |
| 5039 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5044 | void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
| 5045 | Register result_reg = ToRegister(instr->result()); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5046 | Register scratch1 = LCodeGen::scratch0(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5047 | DoubleRegister double_input = ToDoubleRegister(instr->value()); |
| 5048 | |
| 5049 | if (instr->truncating()) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5050 | __ TruncateDoubleToI(result_reg, double_input); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5051 | } else { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 5052 | Register except_flag = LCodeGen::scratch1(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5053 | |
| 5054 | __ EmitFPUTruncate(kRoundToMinusInf, |
| 5055 | result_reg, |
| 5056 | double_input, |
| 5057 | scratch1, |
| 5058 | double_scratch0(), |
| 5059 | except_flag, |
| 5060 | kCheckForInexactConversion); |
| 5061 | |
| 5062 | // Deopt if the operation did not succeed (except_flag != 0). |
| 5063 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
| 5064 | |
| 5065 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 5066 | Label done; |
| 5067 | __ Branch(&done, ne, result_reg, Operand(zero_reg)); |
| 5068 | __ mfc1(scratch1, double_input.high()); |
| 5069 | __ And(scratch1, scratch1, Operand(HeapNumber::kSignMask)); |
| 5070 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(zero_reg)); |
| 5071 | __ bind(&done); |
| 5072 | } |
| 5073 | } |
| 5074 | __ SmiTagCheckOverflow(result_reg, result_reg, scratch1); |
| 5075 | DeoptimizeIf(lt, instr->environment(), scratch1, Operand(zero_reg)); |
| 5076 | } |
| 5077 | |
| 5078 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5079 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5080 | LOperand* input = instr->value(); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 5081 | __ SmiTst(ToRegister(input), at); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5082 | DeoptimizeIf(ne, instr->environment(), at, Operand(zero_reg)); |
| 5083 | } |
| 5084 | |
| 5085 | |
| 5086 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5087 | if (!instr->hydrogen()->value()->IsHeapObject()) { |
| 5088 | LOperand* input = instr->value(); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 5089 | __ SmiTst(ToRegister(input), at); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5090 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
| 5091 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
| 5094 | |
| 5095 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5096 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5097 | Register scratch = scratch0(); |
| 5098 | |
| 5099 | __ GetObjectType(input, scratch, scratch); |
| 5100 | |
| 5101 | if (instr->hydrogen()->is_interval_check()) { |
| 5102 | InstanceType first; |
| 5103 | InstanceType last; |
| 5104 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 5105 | |
| 5106 | // If there is only one type in the interval check for equality. |
| 5107 | if (first == last) { |
| 5108 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(first)); |
| 5109 | } else { |
| 5110 | DeoptimizeIf(lo, instr->environment(), scratch, Operand(first)); |
| 5111 | // Omit check for the last type. |
| 5112 | if (last != LAST_TYPE) { |
| 5113 | DeoptimizeIf(hi, instr->environment(), scratch, Operand(last)); |
| 5114 | } |
| 5115 | } |
| 5116 | } else { |
| 5117 | uint8_t mask; |
| 5118 | uint8_t tag; |
| 5119 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 5120 | |
| 5121 | if (IsPowerOf2(mask)) { |
| 5122 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 5123 | __ And(at, scratch, mask); |
| 5124 | DeoptimizeIf(tag == 0 ? ne : eq, instr->environment(), |
| 5125 | at, Operand(zero_reg)); |
| 5126 | } else { |
| 5127 | __ And(scratch, scratch, Operand(mask)); |
| 5128 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(tag)); |
| 5129 | } |
| 5130 | } |
| 5131 | } |
| 5132 | |
| 5133 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5134 | void LCodeGen::DoCheckValue(LCheckValue* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5135 | Register reg = ToRegister(instr->value()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5136 | Handle<HeapObject> object = instr->hydrogen()->object().handle(); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5137 | AllowDeferredHandleDereference smi_check; |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5138 | if (isolate()->heap()->InNewSpace(*object)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5139 | Register reg = ToRegister(instr->value()); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5140 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5141 | __ li(at, Operand(Handle<Object>(cell))); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 5142 | __ lw(at, FieldMemOperand(at, Cell::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5143 | DeoptimizeIf(ne, instr->environment(), reg, |
| 5144 | Operand(at)); |
| 5145 | } else { |
| 5146 | DeoptimizeIf(ne, instr->environment(), reg, |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 5147 | Operand(object)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5148 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5152 | void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
| 5153 | { |
| 5154 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 5155 | __ push(object); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 5156 | __ mov(cp, zero_reg); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 5157 | __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 5158 | RecordSafepointWithRegisters( |
| 5159 | instr->pointer_map(), 1, Safepoint::kNoLazyDeopt); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5160 | __ StoreToSafepointRegisterSlot(v0, scratch0()); |
| 5161 | } |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 5162 | __ SmiTst(scratch0(), at); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5163 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5167 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5168 | class DeferredCheckMaps V8_FINAL : public LDeferredCode { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5169 | public: |
| 5170 | DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) |
| 5171 | : LDeferredCode(codegen), instr_(instr), object_(object) { |
| 5172 | SetExit(check_maps()); |
| 5173 | } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5174 | virtual void Generate() V8_OVERRIDE { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5175 | codegen()->DoDeferredInstanceMigration(instr_, object_); |
| 5176 | } |
| 5177 | Label* check_maps() { return &check_maps_; } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5178 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5179 | private: |
| 5180 | LCheckMaps* instr_; |
| 5181 | Label check_maps_; |
| 5182 | Register object_; |
| 5183 | }; |
| 5184 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5185 | if (instr->hydrogen()->CanOmitMapChecks()) return; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5186 | Register map_reg = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5187 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5188 | ASSERT(input->IsRegister()); |
| 5189 | Register reg = ToRegister(input); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5190 | __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5191 | |
| 5192 | DeferredCheckMaps* deferred = NULL; |
| 5193 | if (instr->hydrogen()->has_migration_target()) { |
| 5194 | deferred = new(zone()) DeferredCheckMaps(this, instr, reg); |
| 5195 | __ bind(deferred->check_maps()); |
| 5196 | } |
| 5197 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5198 | UniqueSet<Map> map_set = instr->hydrogen()->map_set(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5199 | Label success; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5200 | for (int i = 0; i < map_set.size() - 1; i++) { |
| 5201 | Handle<Map> map = map_set.at(i).handle(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5202 | __ CompareMapAndBranch(map_reg, map, &success, eq, &success); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5203 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5204 | Handle<Map> map = map_set.at(map_set.size() - 1).handle(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5205 | // Do the CompareMap() directly within the Branch() and DeoptimizeIf(). |
| 5206 | if (instr->hydrogen()->has_migration_target()) { |
| 5207 | __ Branch(deferred->entry(), ne, map_reg, Operand(map)); |
| 5208 | } else { |
| 5209 | DeoptimizeIf(ne, instr->environment(), map_reg, Operand(map)); |
| 5210 | } |
| 5211 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5212 | __ bind(&success); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | |
| 5216 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
| 5217 | DoubleRegister value_reg = ToDoubleRegister(instr->unclamped()); |
| 5218 | Register result_reg = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5219 | DoubleRegister temp_reg = ToDoubleRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5220 | __ ClampDoubleToUint8(result_reg, value_reg, temp_reg); |
| 5221 | } |
| 5222 | |
| 5223 | |
| 5224 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5225 | Register unclamped_reg = ToRegister(instr->unclamped()); |
| 5226 | Register result_reg = ToRegister(instr->result()); |
| 5227 | __ ClampUint8(result_reg, unclamped_reg); |
| 5228 | } |
| 5229 | |
| 5230 | |
| 5231 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 5232 | Register scratch = scratch0(); |
| 5233 | Register input_reg = ToRegister(instr->unclamped()); |
| 5234 | Register result_reg = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5235 | DoubleRegister temp_reg = ToDoubleRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5236 | Label is_smi, done, heap_number; |
| 5237 | |
| 5238 | // Both smi and heap number cases are handled. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5239 | __ UntagAndJumpIfSmi(scratch, input_reg, &is_smi); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5240 | |
| 5241 | // Check for heap number |
| 5242 | __ lw(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 5243 | __ Branch(&heap_number, eq, scratch, Operand(factory()->heap_number_map())); |
| 5244 | |
| 5245 | // Check for undefined. Undefined is converted to zero for clamping |
| 5246 | // conversions. |
| 5247 | DeoptimizeIf(ne, instr->environment(), input_reg, |
| 5248 | Operand(factory()->undefined_value())); |
| 5249 | __ mov(result_reg, zero_reg); |
| 5250 | __ jmp(&done); |
| 5251 | |
| 5252 | // Heap number |
| 5253 | __ bind(&heap_number); |
| 5254 | __ ldc1(double_scratch0(), FieldMemOperand(input_reg, |
| 5255 | HeapNumber::kValueOffset)); |
| 5256 | __ ClampDoubleToUint8(result_reg, double_scratch0(), temp_reg); |
| 5257 | __ jmp(&done); |
| 5258 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5259 | __ bind(&is_smi); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5260 | __ ClampUint8(result_reg, scratch); |
| 5261 | |
| 5262 | __ bind(&done); |
| 5263 | } |
| 5264 | |
| 5265 | |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 5266 | void LCodeGen::DoDoubleBits(LDoubleBits* instr) { |
| 5267 | DoubleRegister value_reg = ToDoubleRegister(instr->value()); |
| 5268 | Register result_reg = ToRegister(instr->result()); |
| 5269 | if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { |
| 5270 | __ FmoveHigh(result_reg, value_reg); |
| 5271 | } else { |
| 5272 | __ FmoveLow(result_reg, value_reg); |
| 5273 | } |
| 5274 | } |
| 5275 | |
| 5276 | |
| 5277 | void LCodeGen::DoConstructDouble(LConstructDouble* instr) { |
| 5278 | Register hi_reg = ToRegister(instr->hi()); |
| 5279 | Register lo_reg = ToRegister(instr->lo()); |
| 5280 | DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
| 5281 | __ Move(result_reg, lo_reg, hi_reg); |
| 5282 | } |
| 5283 | |
| 5284 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5285 | void LCodeGen::DoAllocate(LAllocate* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5286 | class DeferredAllocate V8_FINAL : public LDeferredCode { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5287 | public: |
| 5288 | DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5289 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5290 | virtual void Generate() V8_OVERRIDE { |
| 5291 | codegen()->DoDeferredAllocate(instr_); |
| 5292 | } |
| 5293 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5294 | private: |
| 5295 | LAllocate* instr_; |
| 5296 | }; |
| 5297 | |
| 5298 | DeferredAllocate* deferred = |
| 5299 | new(zone()) DeferredAllocate(this, instr); |
| 5300 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5301 | Register result = ToRegister(instr->result()); |
| 5302 | Register scratch = ToRegister(instr->temp1()); |
| 5303 | Register scratch2 = ToRegister(instr->temp2()); |
| 5304 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5305 | // Allocate memory for the object. |
| 5306 | AllocationFlags flags = TAG_OBJECT; |
| 5307 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 5308 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 5309 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5310 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5311 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5312 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5313 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5314 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5315 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5316 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5317 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5318 | if (instr->size()->IsConstantOperand()) { |
| 5319 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
dslomov@chromium.org | 6b6df38 | 2014-03-14 16:14:53 +0000 | [diff] [blame] | 5320 | if (size <= Page::kMaxRegularHeapObjectSize) { |
| 5321 | __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
| 5322 | } else { |
| 5323 | __ jmp(deferred->entry()); |
| 5324 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5325 | } else { |
| 5326 | Register size = ToRegister(instr->size()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5327 | __ Allocate(size, |
| 5328 | result, |
| 5329 | scratch, |
| 5330 | scratch2, |
| 5331 | deferred->entry(), |
| 5332 | flags); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | __ bind(deferred->exit()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5336 | |
| 5337 | if (instr->hydrogen()->MustPrefillWithFiller()) { |
| 5338 | if (instr->size()->IsConstantOperand()) { |
| 5339 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5340 | __ li(scratch, Operand(size)); |
| 5341 | } else { |
| 5342 | scratch = ToRegister(instr->size()); |
| 5343 | } |
| 5344 | __ Subu(scratch, scratch, Operand(kPointerSize)); |
| 5345 | __ Subu(result, result, Operand(kHeapObjectTag)); |
| 5346 | Label loop; |
| 5347 | __ bind(&loop); |
| 5348 | __ li(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 5349 | __ Addu(at, result, Operand(scratch)); |
| 5350 | __ sw(scratch2, MemOperand(at)); |
| 5351 | __ Subu(scratch, scratch, Operand(kPointerSize)); |
| 5352 | __ Branch(&loop, ge, scratch, Operand(zero_reg)); |
| 5353 | __ Addu(result, result, Operand(kHeapObjectTag)); |
| 5354 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | |
| 5358 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5359 | Register result = ToRegister(instr->result()); |
| 5360 | |
| 5361 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5362 | // result register contain a valid pointer because it is already |
| 5363 | // contained in the register pointer map. |
| 5364 | __ mov(result, zero_reg); |
| 5365 | |
| 5366 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5367 | if (instr->size()->IsRegister()) { |
| 5368 | Register size = ToRegister(instr->size()); |
| 5369 | ASSERT(!size.is(result)); |
| 5370 | __ SmiTag(size); |
| 5371 | __ push(size); |
| 5372 | } else { |
| 5373 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
machenbach@chromium.org | eb3cc64 | 2014-04-04 08:28:47 +0000 | [diff] [blame] | 5374 | if (size >= 0 && size <= Smi::kMaxValue) { |
| 5375 | __ Push(Smi::FromInt(size)); |
| 5376 | } else { |
| 5377 | // We should never get here at runtime => abort |
| 5378 | __ stop("invalid allocation size"); |
| 5379 | return; |
| 5380 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5381 | } |
| 5382 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5383 | int flags = AllocateDoubleAlignFlag::encode( |
| 5384 | instr->hydrogen()->MustAllocateDoubleAligned()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5385 | if (instr->hydrogen()->IsOldPointerSpaceAllocation()) { |
| 5386 | ASSERT(!instr->hydrogen()->IsOldDataSpaceAllocation()); |
| 5387 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5388 | flags = AllocateTargetSpace::update(flags, OLD_POINTER_SPACE); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5389 | } else if (instr->hydrogen()->IsOldDataSpaceAllocation()) { |
| 5390 | ASSERT(!instr->hydrogen()->IsNewSpaceAllocation()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5391 | flags = AllocateTargetSpace::update(flags, OLD_DATA_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5392 | } else { |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5393 | flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5394 | } |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5395 | __ Push(Smi::FromInt(flags)); |
| 5396 | |
| 5397 | CallRuntimeFromDeferred( |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5398 | Runtime::kHiddenAllocateInTargetSpace, 2, instr, instr->context()); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5399 | __ StoreToSafepointRegisterSlot(v0, result); |
| 5400 | } |
| 5401 | |
| 5402 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5403 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5404 | ASSERT(ToRegister(instr->value()).is(a0)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5405 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 5406 | __ push(a0); |
| 5407 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
| 5408 | } |
| 5409 | |
| 5410 | |
| 5411 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 5412 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5413 | Label materialized; |
| 5414 | // Registers will be used as follows: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5415 | // t3 = literals array. |
| 5416 | // a1 = regexp literal. |
| 5417 | // a0 = regexp literal clone. |
| 5418 | // a2 and t0-t2 are used as temporaries. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5419 | int literal_offset = |
| 5420 | FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 5421 | __ li(t3, instr->hydrogen()->literals()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5422 | __ lw(a1, FieldMemOperand(t3, literal_offset)); |
| 5423 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5424 | __ Branch(&materialized, ne, a1, Operand(at)); |
| 5425 | |
| 5426 | // Create regexp literal using runtime function |
| 5427 | // Result will be in v0. |
| 5428 | __ li(t2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 5429 | __ li(t1, Operand(instr->hydrogen()->pattern())); |
| 5430 | __ li(t0, Operand(instr->hydrogen()->flags())); |
| 5431 | __ Push(t3, t2, t1, t0); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5432 | CallRuntime(Runtime::kHiddenMaterializeRegExpLiteral, 4, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5433 | __ mov(a1, v0); |
| 5434 | |
| 5435 | __ bind(&materialized); |
| 5436 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 5437 | Label allocated, runtime_allocate; |
| 5438 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 5439 | __ Allocate(size, v0, a2, a3, &runtime_allocate, TAG_OBJECT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5440 | __ jmp(&allocated); |
| 5441 | |
| 5442 | __ bind(&runtime_allocate); |
| 5443 | __ li(a0, Operand(Smi::FromInt(size))); |
| 5444 | __ Push(a1, a0); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5445 | CallRuntime(Runtime::kHiddenAllocateInNewSpace, 1, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5446 | __ pop(a1); |
| 5447 | |
| 5448 | __ bind(&allocated); |
| 5449 | // Copy the content into the newly allocated memory. |
| 5450 | // (Unroll copy loop once for better throughput). |
| 5451 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 5452 | __ lw(a3, FieldMemOperand(a1, i)); |
| 5453 | __ lw(a2, FieldMemOperand(a1, i + kPointerSize)); |
| 5454 | __ sw(a3, FieldMemOperand(v0, i)); |
| 5455 | __ sw(a2, FieldMemOperand(v0, i + kPointerSize)); |
| 5456 | } |
| 5457 | if ((size % (2 * kPointerSize)) != 0) { |
| 5458 | __ lw(a3, FieldMemOperand(a1, size - kPointerSize)); |
| 5459 | __ sw(a3, FieldMemOperand(v0, size - kPointerSize)); |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | |
| 5464 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 5465 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5466 | // Use the fast case closure allocation code that allocates in new |
| 5467 | // space for nested functions that don't need literals cloning. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5468 | bool pretenure = instr->hydrogen()->pretenure(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5469 | if (!pretenure && instr->hydrogen()->has_no_literals()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 5470 | FastNewClosureStub stub(instr->hydrogen()->strict_mode(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5471 | instr->hydrogen()->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 5472 | __ li(a2, Operand(instr->hydrogen()->shared_info())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5473 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5474 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5475 | __ li(a2, Operand(instr->hydrogen()->shared_info())); |
| 5476 | __ li(a1, Operand(pretenure ? factory()->true_value() |
| 5477 | : factory()->false_value())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5478 | __ Push(cp, a2, a1); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5479 | CallRuntime(Runtime::kHiddenNewClosure, 3, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | |
| 5484 | void LCodeGen::DoTypeof(LTypeof* instr) { |
| 5485 | ASSERT(ToRegister(instr->result()).is(v0)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5486 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5487 | __ push(input); |
| 5488 | CallRuntime(Runtime::kTypeof, 1, instr); |
| 5489 | } |
| 5490 | |
| 5491 | |
| 5492 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5493 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5494 | |
| 5495 | Register cmp1 = no_reg; |
| 5496 | Operand cmp2 = Operand(no_reg); |
| 5497 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5498 | Condition final_branch_condition = EmitTypeofIs(instr->TrueLabel(chunk_), |
| 5499 | instr->FalseLabel(chunk_), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5500 | input, |
| 5501 | instr->type_literal(), |
| 5502 | cmp1, |
| 5503 | cmp2); |
| 5504 | |
| 5505 | ASSERT(cmp1.is_valid()); |
| 5506 | ASSERT(!cmp2.is_reg() || cmp2.rm().is_valid()); |
| 5507 | |
| 5508 | if (final_branch_condition != kNoCondition) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5509 | EmitBranch(instr, final_branch_condition, cmp1, cmp2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5510 | } |
| 5511 | } |
| 5512 | |
| 5513 | |
| 5514 | Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 5515 | Label* false_label, |
| 5516 | Register input, |
| 5517 | Handle<String> type_name, |
| 5518 | Register& cmp1, |
| 5519 | Operand& cmp2) { |
| 5520 | // This function utilizes the delay slot heavily. This is used to load |
| 5521 | // values that are always usable without depending on the type of the input |
| 5522 | // register. |
| 5523 | Condition final_branch_condition = kNoCondition; |
| 5524 | Register scratch = scratch0(); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5525 | if (type_name->Equals(heap()->number_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5526 | __ JumpIfSmi(input, true_label); |
| 5527 | __ lw(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5528 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 5529 | cmp1 = input; |
| 5530 | cmp2 = Operand(at); |
| 5531 | final_branch_condition = eq; |
| 5532 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5533 | } else if (type_name->Equals(heap()->string_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5534 | __ JumpIfSmi(input, false_label); |
| 5535 | __ GetObjectType(input, input, scratch); |
| 5536 | __ Branch(USE_DELAY_SLOT, false_label, |
| 5537 | ge, scratch, Operand(FIRST_NONSTRING_TYPE)); |
| 5538 | // input is an object so we can load the BitFieldOffset even if we take the |
| 5539 | // other branch. |
| 5540 | __ lbu(at, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 5541 | __ And(at, at, 1 << Map::kIsUndetectable); |
| 5542 | cmp1 = at; |
| 5543 | cmp2 = Operand(zero_reg); |
| 5544 | final_branch_condition = eq; |
| 5545 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5546 | } else if (type_name->Equals(heap()->symbol_string())) { |
| 5547 | __ JumpIfSmi(input, false_label); |
| 5548 | __ GetObjectType(input, input, scratch); |
| 5549 | cmp1 = scratch; |
| 5550 | cmp2 = Operand(SYMBOL_TYPE); |
| 5551 | final_branch_condition = eq; |
| 5552 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5553 | } else if (type_name->Equals(heap()->boolean_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5554 | __ LoadRoot(at, Heap::kTrueValueRootIndex); |
| 5555 | __ Branch(USE_DELAY_SLOT, true_label, eq, at, Operand(input)); |
| 5556 | __ LoadRoot(at, Heap::kFalseValueRootIndex); |
| 5557 | cmp1 = at; |
| 5558 | cmp2 = Operand(input); |
| 5559 | final_branch_condition = eq; |
| 5560 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5561 | } else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5562 | __ LoadRoot(at, Heap::kNullValueRootIndex); |
| 5563 | cmp1 = at; |
| 5564 | cmp2 = Operand(input); |
| 5565 | final_branch_condition = eq; |
| 5566 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5567 | } else if (type_name->Equals(heap()->undefined_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5568 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5569 | __ Branch(USE_DELAY_SLOT, true_label, eq, at, Operand(input)); |
| 5570 | // The first instruction of JumpIfSmi is an And - it is safe in the delay |
| 5571 | // slot. |
| 5572 | __ JumpIfSmi(input, false_label); |
| 5573 | // Check for undetectable objects => true. |
| 5574 | __ lw(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5575 | __ lbu(at, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 5576 | __ And(at, at, 1 << Map::kIsUndetectable); |
| 5577 | cmp1 = at; |
| 5578 | cmp2 = Operand(zero_reg); |
| 5579 | final_branch_condition = ne; |
| 5580 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5581 | } else if (type_name->Equals(heap()->function_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5582 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 5583 | __ JumpIfSmi(input, false_label); |
| 5584 | __ GetObjectType(input, scratch, input); |
| 5585 | __ Branch(true_label, eq, input, Operand(JS_FUNCTION_TYPE)); |
| 5586 | cmp1 = input; |
| 5587 | cmp2 = Operand(JS_FUNCTION_PROXY_TYPE); |
| 5588 | final_branch_condition = eq; |
| 5589 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5590 | } else if (type_name->Equals(heap()->object_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5591 | __ JumpIfSmi(input, false_label); |
| 5592 | if (!FLAG_harmony_typeof) { |
| 5593 | __ LoadRoot(at, Heap::kNullValueRootIndex); |
| 5594 | __ Branch(USE_DELAY_SLOT, true_label, eq, at, Operand(input)); |
| 5595 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5596 | Register map = input; |
| 5597 | __ GetObjectType(input, map, scratch); |
| 5598 | __ Branch(false_label, |
| 5599 | lt, scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5600 | __ Branch(USE_DELAY_SLOT, false_label, |
| 5601 | gt, scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5602 | // map is still valid, so the BitField can be loaded in delay slot. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5603 | // Check for undetectable objects => false. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5604 | __ lbu(at, FieldMemOperand(map, Map::kBitFieldOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5605 | __ And(at, at, 1 << Map::kIsUndetectable); |
| 5606 | cmp1 = at; |
| 5607 | cmp2 = Operand(zero_reg); |
| 5608 | final_branch_condition = eq; |
| 5609 | |
| 5610 | } else { |
| 5611 | cmp1 = at; |
| 5612 | cmp2 = Operand(zero_reg); // Set to valid regs, to avoid caller assertion. |
| 5613 | __ Branch(false_label); |
| 5614 | } |
| 5615 | |
| 5616 | return final_branch_condition; |
| 5617 | } |
| 5618 | |
| 5619 | |
| 5620 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5621 | Register temp1 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5622 | |
| 5623 | EmitIsConstructCall(temp1, scratch0()); |
| 5624 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5625 | EmitBranch(instr, eq, temp1, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5626 | Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 5627 | } |
| 5628 | |
| 5629 | |
| 5630 | void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { |
| 5631 | ASSERT(!temp1.is(temp2)); |
| 5632 | // Get the frame pointer for the calling frame. |
| 5633 | __ lw(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5634 | |
| 5635 | // Skip the arguments adaptor frame if it exists. |
| 5636 | Label check_frame_marker; |
| 5637 | __ lw(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); |
| 5638 | __ Branch(&check_frame_marker, ne, temp2, |
| 5639 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5640 | __ lw(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset)); |
| 5641 | |
| 5642 | // Check the marker in the calling frame. |
| 5643 | __ bind(&check_frame_marker); |
| 5644 | __ lw(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); |
| 5645 | } |
| 5646 | |
| 5647 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5648 | void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 5649 | if (!info()->IsStub()) { |
| 5650 | // Ensure that we have enough space after the previous lazy-bailout |
| 5651 | // instruction for patching the code here. |
| 5652 | int current_pc = masm()->pc_offset(); |
| 5653 | if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
| 5654 | int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
| 5655 | ASSERT_EQ(0, padding_size % Assembler::kInstrSize); |
| 5656 | while (padding_size > 0) { |
| 5657 | __ nop(); |
| 5658 | padding_size -= Assembler::kInstrSize; |
| 5659 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5660 | } |
| 5661 | } |
machenbach@chromium.org | 5c88bc3 | 2014-01-17 08:10:36 +0000 | [diff] [blame] | 5662 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5666 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
machenbach@chromium.org | fa0c3c6 | 2014-03-24 08:11:09 +0000 | [diff] [blame] | 5667 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5668 | ASSERT(instr->HasEnvironment()); |
| 5669 | LEnvironment* env = instr->environment(); |
| 5670 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5671 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | |
| 5675 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5676 | Deoptimizer::BailoutType type = instr->hydrogen()->type(); |
| 5677 | // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the |
| 5678 | // needed return address), even though the implementation of LAZY and EAGER is |
| 5679 | // now identical. When LAZY is eventually completely folded into EAGER, remove |
| 5680 | // the special case below. |
| 5681 | if (info()->IsStub() && type == Deoptimizer::EAGER) { |
| 5682 | type = Deoptimizer::LAZY; |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 5683 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5684 | |
| 5685 | Comment(";;; deoptimize: %s", instr->hydrogen()->reason()); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5686 | DeoptimizeIf(al, instr->environment(), type, zero_reg, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 5690 | void LCodeGen::DoDummy(LDummy* instr) { |
| 5691 | // Nothing to see here, move on! |
| 5692 | } |
| 5693 | |
| 5694 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5695 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 5696 | // Nothing to see here, move on! |
| 5697 | } |
| 5698 | |
| 5699 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5700 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5701 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 5702 | LoadContextFromDeferred(instr->context()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 5703 | __ CallRuntimeSaveDoubles(Runtime::kHiddenStackGuard); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5704 | RecordSafepointWithLazyDeopt( |
| 5705 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 5706 | ASSERT(instr->HasEnvironment()); |
| 5707 | LEnvironment* env = instr->environment(); |
| 5708 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | |
| 5712 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5713 | class DeferredStackCheck V8_FINAL : public LDeferredCode { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5714 | public: |
| 5715 | DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
| 5716 | : LDeferredCode(codegen), instr_(instr) { } |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 5717 | virtual void Generate() V8_OVERRIDE { |
| 5718 | codegen()->DoDeferredStackCheck(instr_); |
| 5719 | } |
| 5720 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5721 | private: |
| 5722 | LStackCheck* instr_; |
| 5723 | }; |
| 5724 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5725 | ASSERT(instr->HasEnvironment()); |
| 5726 | LEnvironment* env = instr->environment(); |
| 5727 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 5728 | // prepare for lazy deoptimization explicitly here. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5729 | if (instr->hydrogen()->is_function_entry()) { |
| 5730 | // Perform stack overflow check. |
| 5731 | Label done; |
| 5732 | __ LoadRoot(at, Heap::kStackLimitRootIndex); |
| 5733 | __ Branch(&done, hs, sp, Operand(at)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 5734 | ASSERT(instr->context()->IsRegister()); |
| 5735 | ASSERT(ToRegister(instr->context()).is(cp)); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 5736 | CallCode(isolate()->builtins()->StackCheck(), |
| 5737 | RelocInfo::CODE_TARGET, |
| 5738 | instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5739 | __ bind(&done); |
| 5740 | } else { |
| 5741 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 5742 | // Perform stack overflow check if this goto needs it before jumping. |
| 5743 | DeferredStackCheck* deferred_stack_check = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5744 | new(zone()) DeferredStackCheck(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5745 | __ LoadRoot(at, Heap::kStackLimitRootIndex); |
| 5746 | __ Branch(deferred_stack_check->entry(), lo, sp, Operand(at)); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 5747 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5748 | __ bind(instr->done_label()); |
| 5749 | deferred_stack_check->SetExit(instr->done_label()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5750 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5751 | // Don't record a deoptimization index for the safepoint here. |
| 5752 | // This will be done explicitly when emitting call and the safepoint in |
| 5753 | // the deferred code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | |
| 5758 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 5759 | // This is a pseudo-instruction that ensures that the environment here is |
| 5760 | // properly registered for deoptimization and records the assembler's PC |
| 5761 | // offset. |
| 5762 | LEnvironment* environment = instr->environment(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5763 | |
| 5764 | // If the environment were already registered, we would have no way of |
| 5765 | // backpatching it with the spill slot operands. |
| 5766 | ASSERT(!environment->HasBeenRegistered()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5767 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5768 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 5769 | GenerateOsrPrologue(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5773 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
| 5774 | Register result = ToRegister(instr->result()); |
| 5775 | Register object = ToRegister(instr->object()); |
| 5776 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5777 | DeoptimizeIf(eq, instr->environment(), object, Operand(at)); |
| 5778 | |
| 5779 | Register null_value = t1; |
| 5780 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 5781 | DeoptimizeIf(eq, instr->environment(), object, Operand(null_value)); |
| 5782 | |
| 5783 | __ And(at, object, kSmiTagMask); |
| 5784 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
| 5785 | |
| 5786 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 5787 | __ GetObjectType(object, a1, a1); |
| 5788 | DeoptimizeIf(le, instr->environment(), a1, Operand(LAST_JS_PROXY_TYPE)); |
| 5789 | |
| 5790 | Label use_cache, call_runtime; |
| 5791 | ASSERT(object.is(a0)); |
| 5792 | __ CheckEnumCache(null_value, &call_runtime); |
| 5793 | |
| 5794 | __ lw(result, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5795 | __ Branch(&use_cache); |
| 5796 | |
| 5797 | // Get the set of properties to enumerate. |
| 5798 | __ bind(&call_runtime); |
| 5799 | __ push(object); |
| 5800 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 5801 | |
| 5802 | __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 5803 | ASSERT(result.is(v0)); |
| 5804 | __ LoadRoot(at, Heap::kMetaMapRootIndex); |
| 5805 | DeoptimizeIf(ne, instr->environment(), a1, Operand(at)); |
| 5806 | __ bind(&use_cache); |
| 5807 | } |
| 5808 | |
| 5809 | |
| 5810 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5811 | Register map = ToRegister(instr->map()); |
| 5812 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5813 | Label load_cache, done; |
| 5814 | __ EnumLength(result, map); |
| 5815 | __ Branch(&load_cache, ne, result, Operand(Smi::FromInt(0))); |
| 5816 | __ li(result, Operand(isolate()->factory()->empty_fixed_array())); |
| 5817 | __ jmp(&done); |
| 5818 | |
| 5819 | __ bind(&load_cache); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5820 | __ LoadInstanceDescriptors(map, result); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5821 | __ lw(result, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 5822 | FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5823 | __ lw(result, |
| 5824 | FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
| 5825 | DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5826 | |
| 5827 | __ bind(&done); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | |
| 5831 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5832 | Register object = ToRegister(instr->value()); |
| 5833 | Register map = ToRegister(instr->map()); |
| 5834 | __ lw(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5835 | DeoptimizeIf(ne, instr->environment(), map, Operand(scratch0())); |
| 5836 | } |
| 5837 | |
| 5838 | |
machenbach@chromium.org | ab43d2f | 2014-04-01 06:35:49 +0000 | [diff] [blame] | 5839 | void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, |
| 5840 | Register result, |
| 5841 | Register object, |
| 5842 | Register index) { |
| 5843 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 5844 | __ Push(object, index); |
| 5845 | __ mov(cp, zero_reg); |
| 5846 | __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); |
| 5847 | RecordSafepointWithRegisters( |
| 5848 | instr->pointer_map(), 2, Safepoint::kNoLazyDeopt); |
| 5849 | __ StoreToSafepointRegisterSlot(v0, result); |
| 5850 | } |
| 5851 | |
| 5852 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5853 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
machenbach@chromium.org | ab43d2f | 2014-04-01 06:35:49 +0000 | [diff] [blame] | 5854 | class DeferredLoadMutableDouble V8_FINAL : public LDeferredCode { |
| 5855 | public: |
| 5856 | DeferredLoadMutableDouble(LCodeGen* codegen, |
| 5857 | LLoadFieldByIndex* instr, |
| 5858 | Register result, |
| 5859 | Register object, |
| 5860 | Register index) |
| 5861 | : LDeferredCode(codegen), |
| 5862 | instr_(instr), |
| 5863 | result_(result), |
| 5864 | object_(object), |
| 5865 | index_(index) { |
| 5866 | } |
| 5867 | virtual void Generate() V8_OVERRIDE { |
| 5868 | codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_); |
| 5869 | } |
| 5870 | virtual LInstruction* instr() V8_OVERRIDE { return instr_; } |
| 5871 | private: |
| 5872 | LLoadFieldByIndex* instr_; |
| 5873 | Register result_; |
| 5874 | Register object_; |
| 5875 | Register index_; |
| 5876 | }; |
| 5877 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5878 | Register object = ToRegister(instr->object()); |
| 5879 | Register index = ToRegister(instr->index()); |
| 5880 | Register result = ToRegister(instr->result()); |
| 5881 | Register scratch = scratch0(); |
| 5882 | |
machenbach@chromium.org | ab43d2f | 2014-04-01 06:35:49 +0000 | [diff] [blame] | 5883 | DeferredLoadMutableDouble* deferred; |
| 5884 | deferred = new(zone()) DeferredLoadMutableDouble( |
| 5885 | this, instr, result, object, index); |
| 5886 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5887 | Label out_of_object, done; |
machenbach@chromium.org | ab43d2f | 2014-04-01 06:35:49 +0000 | [diff] [blame] | 5888 | |
| 5889 | __ And(scratch, index, Operand(Smi::FromInt(1))); |
| 5890 | __ Branch(deferred->entry(), ne, scratch, Operand(zero_reg)); |
| 5891 | __ sra(index, index, 1); |
| 5892 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5893 | __ Branch(USE_DELAY_SLOT, &out_of_object, lt, index, Operand(zero_reg)); |
| 5894 | __ sll(scratch, index, kPointerSizeLog2 - kSmiTagSize); // In delay slot. |
| 5895 | |
| 5896 | STATIC_ASSERT(kPointerSizeLog2 > kSmiTagSize); |
| 5897 | __ Addu(scratch, object, scratch); |
| 5898 | __ lw(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
| 5899 | |
| 5900 | __ Branch(&done); |
| 5901 | |
| 5902 | __ bind(&out_of_object); |
| 5903 | __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 5904 | // Index is equal to negated out of object property index plus 1. |
| 5905 | __ Subu(scratch, result, scratch); |
| 5906 | __ lw(result, FieldMemOperand(scratch, |
| 5907 | FixedArray::kHeaderSize - kPointerSize)); |
machenbach@chromium.org | ab43d2f | 2014-04-01 06:35:49 +0000 | [diff] [blame] | 5908 | __ bind(deferred->exit()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5909 | __ bind(&done); |
| 5910 | } |
| 5911 | |
| 5912 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5913 | #undef __ |
| 5914 | |
| 5915 | } } // namespace v8::internal |