erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
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" |
| 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | |
| 39 | class SafepointGenerator : public CallWrapper { |
| 40 | public: |
| 41 | SafepointGenerator(LCodeGen* codegen, |
| 42 | LPointerMap* pointers, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 43 | Safepoint::DeoptMode mode) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 44 | : codegen_(codegen), |
| 45 | pointers_(pointers), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 46 | deopt_mode_(mode) { } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 47 | virtual ~SafepointGenerator() { } |
| 48 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 49 | virtual void BeforeCall(int call_size) const { } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 50 | |
| 51 | virtual void AfterCall() const { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 52 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | private: |
| 56 | LCodeGen* codegen_; |
| 57 | LPointerMap* pointers_; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 58 | Safepoint::DeoptMode deopt_mode_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | |
| 62 | #define __ masm()-> |
| 63 | |
| 64 | bool LCodeGen::GenerateCode() { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 65 | HPhase phase("Z_Code generation", chunk()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 66 | ASSERT(is_unused()); |
| 67 | status_ = GENERATING; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 68 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 69 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 70 | // NONE indicates that the scope shouldn't actually generate code to set up |
| 71 | // the frame (that is done in GeneratePrologue). |
| 72 | FrameScope frame_scope(masm_, StackFrame::NONE); |
| 73 | |
| 74 | return GeneratePrologue() && |
| 75 | GenerateBody() && |
| 76 | GenerateDeferredCode() && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 77 | GenerateDeoptJumpTable() && |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 78 | GenerateSafepointTable(); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 83 | ASSERT(is_done()); |
| 84 | code->set_stack_slots(GetStackSlotCount()); |
| 85 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 86 | if (FLAG_weak_embedded_maps_in_optimized_code) { |
| 87 | RegisterDependentCodeForEmbeddedMaps(code); |
| 88 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 89 | PopulateDeoptimizationData(code); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 90 | for (int i = 0 ; i < prototype_maps_.length(); i++) { |
| 91 | prototype_maps_.at(i)->AddDependentCode( |
| 92 | DependentCode::kPrototypeCheckGroup, code); |
| 93 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 94 | for (int i = 0 ; i < transition_maps_.length(); i++) { |
| 95 | transition_maps_.at(i)->AddDependentCode( |
| 96 | DependentCode::kTransitionGroup, code); |
| 97 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 101 | void LChunkBuilder::Abort(const char* reason) { |
| 102 | info()->set_bailout_reason(reason); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 103 | status_ = ABORTED; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | void LCodeGen::Comment(const char* format, ...) { |
| 108 | if (!FLAG_code_comments) return; |
| 109 | char buffer[4 * KB]; |
| 110 | StringBuilder builder(buffer, ARRAY_SIZE(buffer)); |
| 111 | va_list arguments; |
| 112 | va_start(arguments, format); |
| 113 | builder.AddFormattedList(format, arguments); |
| 114 | va_end(arguments); |
| 115 | |
| 116 | // Copy the string before recording it in the assembler to avoid |
| 117 | // issues when the stack allocated buffer goes out of scope. |
| 118 | size_t length = builder.position(); |
| 119 | Vector<char> copy = Vector<char>::New(length + 1); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 120 | OS::MemCopy(copy.start(), builder.Finalize(), copy.length()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 121 | masm()->RecordComment(copy.start()); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | bool LCodeGen::GeneratePrologue() { |
| 126 | ASSERT(is_generating()); |
| 127 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 128 | if (info()->IsOptimizing()) { |
| 129 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 130 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 131 | #ifdef DEBUG |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 132 | if (strlen(FLAG_stop_at) > 0 && |
| 133 | info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
| 134 | __ stop("stop_at"); |
| 135 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 136 | #endif |
| 137 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 138 | // a1: Callee's JS function. |
| 139 | // cp: Callee's context. |
| 140 | // fp: Caller's frame pointer. |
| 141 | // lr: Caller's pc. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 142 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 143 | // Strict mode functions and builtins need to replace the receiver |
| 144 | // with undefined when called as functions (without an explicit |
| 145 | // receiver object). r5 is zero for method calls and non-zero for |
| 146 | // function calls. |
| 147 | if (!info_->is_classic_mode() || info_->is_native()) { |
| 148 | Label ok; |
| 149 | __ Branch(&ok, eq, t1, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 150 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 151 | int receiver_offset = scope()->num_parameters() * kPointerSize; |
| 152 | __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
| 153 | __ sw(a2, MemOperand(sp, receiver_offset)); |
| 154 | __ bind(&ok); |
| 155 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 156 | } |
| 157 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 158 | info()->set_prologue_offset(masm_->pc_offset()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 159 | if (NeedsEagerFrame()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 160 | if (info()->IsStub()) { |
| 161 | __ Push(ra, fp, cp); |
| 162 | __ Push(Smi::FromInt(StackFrame::STUB)); |
| 163 | // Adjust FP to point to saved FP. |
| 164 | __ Addu(fp, sp, Operand(2 * kPointerSize)); |
| 165 | } else { |
| 166 | // The following three instructions must remain together and unmodified |
| 167 | // for code aging to work properly. |
| 168 | __ Push(ra, fp, cp, a1); |
| 169 | // Add unused load of ip to ensure prologue sequence is identical for |
| 170 | // full-codegen and lithium-codegen. |
| 171 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 172 | // Adj. FP to point to saved FP. |
| 173 | __ Addu(fp, sp, Operand(2 * kPointerSize)); |
| 174 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 175 | frame_is_built_ = true; |
| 176 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 177 | |
| 178 | // Reserve space for the stack slots needed by the code. |
| 179 | int slots = GetStackSlotCount(); |
| 180 | if (slots > 0) { |
| 181 | if (FLAG_debug_code) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 182 | __ Subu(sp, sp, Operand(slots * kPointerSize)); |
| 183 | __ push(a0); |
| 184 | __ push(a1); |
| 185 | __ Addu(a0, sp, Operand(slots * kPointerSize)); |
| 186 | __ li(a1, Operand(kSlotsZapValue)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 187 | Label loop; |
| 188 | __ bind(&loop); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 189 | __ Subu(a0, a0, Operand(kPointerSize)); |
| 190 | __ sw(a1, MemOperand(a0, 2 * kPointerSize)); |
| 191 | __ Branch(&loop, ne, a0, Operand(sp)); |
| 192 | __ pop(a1); |
| 193 | __ pop(a0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 194 | } else { |
| 195 | __ Subu(sp, sp, Operand(slots * kPointerSize)); |
| 196 | } |
| 197 | } |
| 198 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 199 | if (info()->saves_caller_doubles()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 200 | Comment(";;; Save clobbered callee double registers"); |
| 201 | int count = 0; |
| 202 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 203 | BitVector::Iterator save_iterator(doubles); |
| 204 | while (!save_iterator.Done()) { |
| 205 | __ sdc1(DoubleRegister::FromAllocationIndex(save_iterator.Current()), |
| 206 | MemOperand(sp, count * kDoubleSize)); |
| 207 | save_iterator.Advance(); |
| 208 | count++; |
| 209 | } |
| 210 | } |
| 211 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 212 | // Possibly allocate a local context. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 213 | int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 214 | if (heap_slots > 0) { |
| 215 | Comment(";;; Allocate local context"); |
| 216 | // Argument to NewContext is the function, which is in a1. |
| 217 | __ push(a1); |
| 218 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 219 | FastNewContextStub stub(heap_slots); |
| 220 | __ CallStub(&stub); |
| 221 | } else { |
| 222 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
| 223 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 224 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 225 | // Context is returned in both v0 and cp. It replaces the context |
| 226 | // passed to us. It's saved in the stack and kept live in cp. |
| 227 | __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 228 | // Copy any necessary parameters into the context. |
| 229 | int num_parameters = scope()->num_parameters(); |
| 230 | for (int i = 0; i < num_parameters; i++) { |
| 231 | Variable* var = scope()->parameter(i); |
| 232 | if (var->IsContextSlot()) { |
| 233 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 234 | (num_parameters - 1 - i) * kPointerSize; |
| 235 | // Load parameter from stack. |
| 236 | __ lw(a0, MemOperand(fp, parameter_offset)); |
| 237 | // Store it in the context. |
| 238 | MemOperand target = ContextOperand(cp, var->index()); |
| 239 | __ sw(a0, target); |
| 240 | // Update the write barrier. This clobbers a3 and a0. |
| 241 | __ RecordWriteContextSlot( |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 242 | cp, target.offset(), a0, a3, GetRAState(), kSaveFPRegs); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | Comment(";;; End allocate local context"); |
| 246 | } |
| 247 | |
| 248 | // Trace the call. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 249 | if (FLAG_trace && info()->IsOptimizing()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 250 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 251 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 252 | EnsureSpaceForLazyDeopt(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 253 | return !is_aborted(); |
| 254 | } |
| 255 | |
| 256 | |
| 257 | bool LCodeGen::GenerateBody() { |
| 258 | ASSERT(is_generating()); |
| 259 | bool emit_instructions = true; |
| 260 | for (current_instruction_ = 0; |
| 261 | !is_aborted() && current_instruction_ < instructions_->length(); |
| 262 | current_instruction_++) { |
| 263 | LInstruction* instr = instructions_->at(current_instruction_); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 264 | |
| 265 | // Don't emit code for basic blocks with a replacement. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 266 | if (instr->IsLabel()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 267 | emit_instructions = !LLabel::cast(instr)->HasReplacement(); |
| 268 | } |
| 269 | if (!emit_instructions) continue; |
| 270 | |
| 271 | if (FLAG_code_comments && instr->HasInterestingComment(this)) { |
| 272 | Comment(";;; <@%d,#%d> %s", |
| 273 | current_instruction_, |
| 274 | instr->hydrogen_value()->id(), |
| 275 | instr->Mnemonic()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 276 | } |
| 277 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 278 | instr->CompileToNative(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 279 | } |
| 280 | return !is_aborted(); |
| 281 | } |
| 282 | |
| 283 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 284 | bool LCodeGen::GenerateDeferredCode() { |
| 285 | ASSERT(is_generating()); |
| 286 | if (deferred_.length() > 0) { |
| 287 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 288 | LDeferredCode* code = deferred_[i]; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 289 | Comment(";;; <@%d,#%d> " |
| 290 | "-------------------- Deferred %s --------------------", |
| 291 | code->instruction_index(), |
| 292 | code->instr()->hydrogen_value()->id(), |
| 293 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 294 | __ bind(code->entry()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 295 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 296 | Comment(";;; Build frame"); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 297 | ASSERT(!frame_is_built_); |
| 298 | ASSERT(info()->IsStub()); |
| 299 | frame_is_built_ = true; |
| 300 | __ MultiPush(cp.bit() | fp.bit() | ra.bit()); |
| 301 | __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 302 | __ push(scratch0()); |
| 303 | __ Addu(fp, sp, Operand(2 * kPointerSize)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 304 | Comment(";;; Deferred code"); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 305 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 306 | code->Generate(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 307 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 308 | Comment(";;; Destroy frame"); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 309 | ASSERT(frame_is_built_); |
| 310 | __ pop(at); |
| 311 | __ MultiPop(cp.bit() | fp.bit() | ra.bit()); |
| 312 | frame_is_built_ = false; |
| 313 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 314 | __ jmp(code->exit()); |
| 315 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 316 | } |
| 317 | // Deferred code is the last part of the instruction sequence. Mark |
| 318 | // the generated code as done unless we bailed out. |
| 319 | if (!is_aborted()) status_ = DONE; |
| 320 | return !is_aborted(); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | bool LCodeGen::GenerateDeoptJumpTable() { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 325 | // Check that the jump table is accessible from everywhere in the function |
| 326 | // code, i.e. that offsets to the table can be encoded in the 16bit signed |
| 327 | // immediate of a branch instruction. |
| 328 | // To simplify we consider the code size from the first instruction to the |
| 329 | // end of the jump table. |
| 330 | if (!is_int16((masm()->pc_offset() / Assembler::kInstrSize) + |
| 331 | deopt_jump_table_.length() * 12)) { |
| 332 | Abort("Generated code is too large"); |
| 333 | } |
| 334 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 335 | if (deopt_jump_table_.length() > 0) { |
| 336 | Comment(";;; -------------------- Jump table --------------------"); |
| 337 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 338 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 339 | Label table_start; |
| 340 | __ bind(&table_start); |
| 341 | Label needs_frame_not_call; |
| 342 | Label needs_frame_is_call; |
| 343 | for (int i = 0; i < deopt_jump_table_.length(); i++) { |
| 344 | __ bind(&deopt_jump_table_[i].label); |
| 345 | Address entry = deopt_jump_table_[i].address; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 346 | bool is_lazy_deopt = deopt_jump_table_[i].is_lazy_deopt; |
| 347 | Deoptimizer::BailoutType type = |
| 348 | is_lazy_deopt ? Deoptimizer::LAZY : Deoptimizer::EAGER; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 349 | int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 350 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 351 | Comment(";;; jump table entry %d.", i); |
| 352 | } else { |
| 353 | Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 354 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 355 | __ li(t9, Operand(ExternalReference::ForDeoptEntry(entry))); |
| 356 | if (deopt_jump_table_[i].needs_frame) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 357 | if (is_lazy_deopt) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 358 | if (needs_frame_is_call.is_bound()) { |
| 359 | __ Branch(&needs_frame_is_call); |
| 360 | } else { |
| 361 | __ bind(&needs_frame_is_call); |
| 362 | __ MultiPush(cp.bit() | fp.bit() | ra.bit()); |
| 363 | // This variant of deopt can only be used with stubs. Since we don't |
| 364 | // have a function pointer to install in the stack frame that we're |
| 365 | // building, install a special marker there instead. |
| 366 | ASSERT(info()->IsStub()); |
| 367 | __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 368 | __ push(scratch0()); |
| 369 | __ Addu(fp, sp, Operand(2 * kPointerSize)); |
| 370 | __ Call(t9); |
| 371 | } |
| 372 | } else { |
| 373 | if (needs_frame_not_call.is_bound()) { |
| 374 | __ Branch(&needs_frame_not_call); |
| 375 | } else { |
| 376 | __ bind(&needs_frame_not_call); |
| 377 | __ MultiPush(cp.bit() | fp.bit() | ra.bit()); |
| 378 | // This variant of deopt can only be used with stubs. Since we don't |
| 379 | // have a function pointer to install in the stack frame that we're |
| 380 | // building, install a special marker there instead. |
| 381 | ASSERT(info()->IsStub()); |
| 382 | __ li(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 383 | __ push(scratch0()); |
| 384 | __ Addu(fp, sp, Operand(2 * kPointerSize)); |
| 385 | __ Jump(t9); |
| 386 | } |
| 387 | } |
| 388 | } else { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 389 | if (is_lazy_deopt) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 390 | __ Call(t9); |
| 391 | } else { |
| 392 | __ Jump(t9); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | __ RecordComment("]"); |
| 397 | |
| 398 | // The deoptimization jump table is the last part of the instruction |
| 399 | // sequence. Mark the generated code as done unless we bailed out. |
| 400 | if (!is_aborted()) status_ = DONE; |
| 401 | return !is_aborted(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | |
| 405 | bool LCodeGen::GenerateSafepointTable() { |
| 406 | ASSERT(is_done()); |
| 407 | safepoints_.Emit(masm(), GetStackSlotCount()); |
| 408 | return !is_aborted(); |
| 409 | } |
| 410 | |
| 411 | |
| 412 | Register LCodeGen::ToRegister(int index) const { |
| 413 | return Register::FromAllocationIndex(index); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | DoubleRegister LCodeGen::ToDoubleRegister(int index) const { |
| 418 | return DoubleRegister::FromAllocationIndex(index); |
| 419 | } |
| 420 | |
| 421 | |
| 422 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 423 | ASSERT(op->IsRegister()); |
| 424 | return ToRegister(op->index()); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 429 | if (op->IsRegister()) { |
| 430 | return ToRegister(op->index()); |
| 431 | } else if (op->IsConstantOperand()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 432 | LConstantOperand* const_op = LConstantOperand::cast(op); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 433 | HConstant* constant = chunk_->LookupConstant(const_op); |
| 434 | Handle<Object> literal = constant->handle(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 435 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 436 | if (r.IsInteger32()) { |
| 437 | ASSERT(literal->IsNumber()); |
| 438 | __ li(scratch, Operand(static_cast<int32_t>(literal->Number()))); |
| 439 | } else if (r.IsDouble()) { |
| 440 | Abort("EmitLoadRegister: Unsupported double immediate."); |
| 441 | } else { |
| 442 | ASSERT(r.IsTagged()); |
| 443 | if (literal->IsSmi()) { |
| 444 | __ li(scratch, Operand(literal)); |
| 445 | } else { |
| 446 | __ LoadHeapObject(scratch, Handle<HeapObject>::cast(literal)); |
| 447 | } |
| 448 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 449 | return scratch; |
| 450 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 451 | __ lw(scratch, ToMemOperand(op)); |
| 452 | return scratch; |
| 453 | } |
| 454 | UNREACHABLE(); |
| 455 | return scratch; |
| 456 | } |
| 457 | |
| 458 | |
| 459 | DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 460 | ASSERT(op->IsDoubleRegister()); |
| 461 | return ToDoubleRegister(op->index()); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | DoubleRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, |
| 466 | FloatRegister flt_scratch, |
| 467 | DoubleRegister dbl_scratch) { |
| 468 | if (op->IsDoubleRegister()) { |
| 469 | return ToDoubleRegister(op->index()); |
| 470 | } else if (op->IsConstantOperand()) { |
| 471 | LConstantOperand* const_op = LConstantOperand::cast(op); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 472 | HConstant* constant = chunk_->LookupConstant(const_op); |
| 473 | Handle<Object> literal = constant->handle(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 474 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 475 | if (r.IsInteger32()) { |
| 476 | ASSERT(literal->IsNumber()); |
| 477 | __ li(at, Operand(static_cast<int32_t>(literal->Number()))); |
| 478 | __ mtc1(at, flt_scratch); |
| 479 | __ cvt_d_w(dbl_scratch, flt_scratch); |
| 480 | return dbl_scratch; |
| 481 | } else if (r.IsDouble()) { |
| 482 | Abort("unsupported double immediate"); |
| 483 | } else if (r.IsTagged()) { |
| 484 | Abort("unsupported tagged immediate"); |
| 485 | } |
| 486 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 487 | MemOperand mem_op = ToMemOperand(op); |
| 488 | __ ldc1(dbl_scratch, mem_op); |
| 489 | return dbl_scratch; |
| 490 | } |
| 491 | UNREACHABLE(); |
| 492 | return dbl_scratch; |
| 493 | } |
| 494 | |
| 495 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 496 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 497 | HConstant* constant = chunk_->LookupConstant(op); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 498 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged()); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 499 | return constant->handle(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | |
| 503 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
| 504 | return chunk_->LookupLiteralRepresentation(op).IsInteger32(); |
| 505 | } |
| 506 | |
| 507 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 508 | int LCodeGen::ToInteger32(LConstantOperand* op) const { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 509 | HConstant* constant = chunk_->LookupConstant(op); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 510 | return constant->Integer32Value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | |
| 514 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 515 | HConstant* constant = chunk_->LookupConstant(op); |
| 516 | ASSERT(constant->HasDoubleValue()); |
| 517 | return constant->DoubleValue(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
| 521 | Operand LCodeGen::ToOperand(LOperand* op) { |
| 522 | if (op->IsConstantOperand()) { |
| 523 | LConstantOperand* const_op = LConstantOperand::cast(op); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 524 | HConstant* constant = chunk()->LookupConstant(const_op); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 525 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 526 | if (r.IsInteger32()) { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 527 | ASSERT(constant->HasInteger32Value()); |
| 528 | return Operand(constant->Integer32Value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 529 | } else if (r.IsDouble()) { |
| 530 | Abort("ToOperand Unsupported double immediate."); |
| 531 | } |
| 532 | ASSERT(r.IsTagged()); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 533 | return Operand(constant->handle()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 534 | } else if (op->IsRegister()) { |
| 535 | return Operand(ToRegister(op)); |
| 536 | } else if (op->IsDoubleRegister()) { |
| 537 | Abort("ToOperand IsDoubleRegister unimplemented"); |
| 538 | return Operand(0); |
| 539 | } |
| 540 | // Stack slots not implemented, use ToMemOperand instead. |
| 541 | UNREACHABLE(); |
| 542 | return Operand(0); |
| 543 | } |
| 544 | |
| 545 | |
| 546 | MemOperand LCodeGen::ToMemOperand(LOperand* op) const { |
| 547 | ASSERT(!op->IsRegister()); |
| 548 | ASSERT(!op->IsDoubleRegister()); |
| 549 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
jkummerow@chromium.org | ac36071 | 2013-02-11 09:00:07 +0000 | [diff] [blame] | 550 | return MemOperand(fp, StackSlotOffset(op->index())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
| 554 | MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { |
| 555 | ASSERT(op->IsDoubleStackSlot()); |
jkummerow@chromium.org | ac36071 | 2013-02-11 09:00:07 +0000 | [diff] [blame] | 556 | return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | |
| 560 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 561 | Translation* translation, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 562 | int* pushed_arguments_index, |
| 563 | int* pushed_arguments_count) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 564 | if (environment == NULL) return; |
| 565 | |
| 566 | // The translation includes one command per value in the environment. |
| 567 | int translation_size = environment->values()->length(); |
| 568 | // The output frame height does not include the parameters. |
| 569 | int height = translation_size - environment->parameter_count(); |
| 570 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 571 | // Function parameters are arguments to the outermost environment. The |
| 572 | // arguments index points to the first element of a sequence of tagged |
| 573 | // values on the stack that represent the arguments. This needs to be |
| 574 | // kept in sync with the LArgumentsElements implementation. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 575 | *pushed_arguments_index = -environment->parameter_count(); |
| 576 | *pushed_arguments_count = environment->parameter_count(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 577 | |
| 578 | WriteTranslation(environment->outer(), |
| 579 | translation, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 580 | pushed_arguments_index, |
| 581 | pushed_arguments_count); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 582 | bool has_closure_id = !info()->closure().is_null() && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 583 | !info()->closure().is_identical_to(environment->closure()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 584 | int closure_id = has_closure_id |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 585 | ? DefineDeoptimizationLiteral(environment->closure()) |
| 586 | : Translation::kSelfLiteralId; |
| 587 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 588 | switch (environment->frame_type()) { |
| 589 | case JS_FUNCTION: |
| 590 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 591 | break; |
| 592 | case JS_CONSTRUCT: |
| 593 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 594 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 595 | case JS_GETTER: |
| 596 | ASSERT(translation_size == 1); |
| 597 | ASSERT(height == 0); |
| 598 | translation->BeginGetterStubFrame(closure_id); |
| 599 | break; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 600 | case JS_SETTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 601 | ASSERT(translation_size == 2); |
| 602 | ASSERT(height == 0); |
| 603 | translation->BeginSetterStubFrame(closure_id); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 604 | break; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 605 | case STUB: |
| 606 | translation->BeginCompiledStubFrame(); |
| 607 | break; |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 608 | case ARGUMENTS_ADAPTOR: |
| 609 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 610 | break; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 611 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 612 | |
| 613 | // Inlined frames which push their arguments cause the index to be |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 614 | // bumped and another stack area to be used for materialization, |
| 615 | // otherwise actual argument values are unknown for inlined frames. |
| 616 | bool arguments_known = true; |
| 617 | int arguments_index = *pushed_arguments_index; |
| 618 | int arguments_count = *pushed_arguments_count; |
| 619 | if (environment->entry() != NULL) { |
| 620 | arguments_known = environment->entry()->arguments_pushed(); |
| 621 | arguments_index = arguments_index < 0 |
| 622 | ? GetStackSlotCount() : arguments_index + arguments_count; |
| 623 | arguments_count = environment->entry()->arguments_count() + 1; |
| 624 | if (environment->entry()->arguments_pushed()) { |
| 625 | *pushed_arguments_index = arguments_index; |
| 626 | *pushed_arguments_count = arguments_count; |
| 627 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 628 | } |
| 629 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 630 | for (int i = 0; i < translation_size; ++i) { |
| 631 | LOperand* value = environment->values()->at(i); |
| 632 | // spilled_registers_ and spilled_double_registers_ are either |
| 633 | // both NULL or both set. |
| 634 | if (environment->spilled_registers() != NULL && value != NULL) { |
| 635 | if (value->IsRegister() && |
| 636 | environment->spilled_registers()[value->index()] != NULL) { |
| 637 | translation->MarkDuplicate(); |
| 638 | AddToTranslation(translation, |
| 639 | environment->spilled_registers()[value->index()], |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 640 | environment->HasTaggedValueAt(i), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 641 | environment->HasUint32ValueAt(i), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 642 | arguments_known, |
| 643 | arguments_index, |
| 644 | arguments_count); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 645 | } else if ( |
| 646 | value->IsDoubleRegister() && |
| 647 | environment->spilled_double_registers()[value->index()] != NULL) { |
| 648 | translation->MarkDuplicate(); |
| 649 | AddToTranslation( |
| 650 | translation, |
| 651 | environment->spilled_double_registers()[value->index()], |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 652 | false, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 653 | false, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 654 | arguments_known, |
| 655 | arguments_index, |
| 656 | arguments_count); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 660 | AddToTranslation(translation, |
| 661 | value, |
| 662 | environment->HasTaggedValueAt(i), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 663 | environment->HasUint32ValueAt(i), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 664 | arguments_known, |
| 665 | arguments_index, |
| 666 | arguments_count); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
| 670 | |
| 671 | void LCodeGen::AddToTranslation(Translation* translation, |
| 672 | LOperand* op, |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 673 | bool is_tagged, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 674 | bool is_uint32, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 675 | bool arguments_known, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 676 | int arguments_index, |
| 677 | int arguments_count) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 678 | if (op == NULL) { |
| 679 | // TODO(twuerthinger): Introduce marker operands to indicate that this value |
| 680 | // is not present and must be reconstructed from the deoptimizer. Currently |
| 681 | // this is only used for the arguments object. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 682 | translation->StoreArgumentsObject( |
| 683 | arguments_known, arguments_index, arguments_count); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 684 | } else if (op->IsStackSlot()) { |
| 685 | if (is_tagged) { |
| 686 | translation->StoreStackSlot(op->index()); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 687 | } else if (is_uint32) { |
| 688 | translation->StoreUint32StackSlot(op->index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 689 | } else { |
| 690 | translation->StoreInt32StackSlot(op->index()); |
| 691 | } |
| 692 | } else if (op->IsDoubleStackSlot()) { |
| 693 | translation->StoreDoubleStackSlot(op->index()); |
| 694 | } else if (op->IsArgument()) { |
| 695 | ASSERT(is_tagged); |
| 696 | int src_index = GetStackSlotCount() + op->index(); |
| 697 | translation->StoreStackSlot(src_index); |
| 698 | } else if (op->IsRegister()) { |
| 699 | Register reg = ToRegister(op); |
| 700 | if (is_tagged) { |
| 701 | translation->StoreRegister(reg); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 702 | } else if (is_uint32) { |
| 703 | translation->StoreUint32Register(reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 704 | } else { |
| 705 | translation->StoreInt32Register(reg); |
| 706 | } |
| 707 | } else if (op->IsDoubleRegister()) { |
| 708 | DoubleRegister reg = ToDoubleRegister(op); |
| 709 | translation->StoreDoubleRegister(reg); |
| 710 | } else if (op->IsConstantOperand()) { |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 711 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
| 712 | int src_index = DefineDeoptimizationLiteral(constant->handle()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 713 | translation->StoreLiteral(src_index); |
| 714 | } else { |
| 715 | UNREACHABLE(); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | |
| 720 | void LCodeGen::CallCode(Handle<Code> code, |
| 721 | RelocInfo::Mode mode, |
| 722 | LInstruction* instr) { |
| 723 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
| 724 | } |
| 725 | |
| 726 | |
| 727 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 728 | RelocInfo::Mode mode, |
| 729 | LInstruction* instr, |
| 730 | SafepointMode safepoint_mode) { |
| 731 | ASSERT(instr != NULL); |
| 732 | LPointerMap* pointers = instr->pointer_map(); |
| 733 | RecordPosition(pointers->position()); |
| 734 | __ Call(code, mode); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 735 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
| 739 | void LCodeGen::CallRuntime(const Runtime::Function* function, |
| 740 | int num_arguments, |
| 741 | LInstruction* instr) { |
| 742 | ASSERT(instr != NULL); |
| 743 | LPointerMap* pointers = instr->pointer_map(); |
| 744 | ASSERT(pointers != NULL); |
| 745 | RecordPosition(pointers->position()); |
| 746 | |
| 747 | __ CallRuntime(function, num_arguments); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 748 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | |
| 752 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 753 | int argc, |
| 754 | LInstruction* instr) { |
| 755 | __ CallRuntimeSaveDoubles(id); |
| 756 | RecordSafepointWithRegisters( |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 757 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 761 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 762 | Safepoint::DeoptMode mode) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 763 | if (!environment->HasBeenRegistered()) { |
| 764 | // Physical stack frame layout: |
| 765 | // -x ............. -4 0 ..................................... y |
| 766 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 767 | |
| 768 | // Layout of the environment: |
| 769 | // 0 ..................................................... size-1 |
| 770 | // [parameters] [locals] [expression stack including arguments] |
| 771 | |
| 772 | // Layout of the translation: |
| 773 | // 0 ........................................................ size - 1 + 4 |
| 774 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 775 | // |>------------ translation_size ------------<| |
| 776 | |
| 777 | int frame_count = 0; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 778 | int jsframe_count = 0; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 779 | int args_index = 0; |
| 780 | int args_count = 0; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 781 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 782 | ++frame_count; |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 783 | if (e->frame_type() == JS_FUNCTION) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 784 | ++jsframe_count; |
| 785 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 786 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 787 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 788 | WriteTranslation(environment, &translation, &args_index, &args_count); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 789 | int deoptimization_index = deoptimizations_.length(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 790 | int pc_offset = masm()->pc_offset(); |
| 791 | environment->Register(deoptimization_index, |
| 792 | translation.index(), |
| 793 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 794 | deoptimizations_.Add(environment, zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
| 798 | |
| 799 | void LCodeGen::DeoptimizeIf(Condition cc, |
| 800 | LEnvironment* environment, |
| 801 | Register src1, |
| 802 | const Operand& src2) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 803 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 804 | ASSERT(environment->HasBeenRegistered()); |
| 805 | int id = environment->deoptimization_index(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 806 | ASSERT(info()->IsOptimizing() || info()->IsStub()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 807 | Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 808 | ? Deoptimizer::LAZY |
| 809 | : Deoptimizer::EAGER; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 810 | Address entry = |
| 811 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 812 | if (entry == NULL) { |
| 813 | Abort("bailout was not prepared"); |
| 814 | return; |
| 815 | } |
| 816 | |
| 817 | ASSERT(FLAG_deopt_every_n_times < 2); // Other values not supported on MIPS. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 818 | if (FLAG_deopt_every_n_times == 1 && |
| 819 | !info()->IsStub() && |
| 820 | info()->opt_count() == id) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 821 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 822 | return; |
| 823 | } |
| 824 | |
| 825 | if (FLAG_trap_on_deopt) { |
| 826 | Label skip; |
| 827 | if (cc != al) { |
| 828 | __ Branch(&skip, NegateCondition(cc), src1, src2); |
| 829 | } |
| 830 | __ stop("trap_on_deopt"); |
| 831 | __ bind(&skip); |
| 832 | } |
| 833 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 834 | ASSERT(info()->IsStub() || frame_is_built_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 835 | bool needs_lazy_deopt = info()->IsStub(); |
| 836 | if (cc == al && frame_is_built_) { |
| 837 | if (needs_lazy_deopt) { |
| 838 | __ Call(entry, RelocInfo::RUNTIME_ENTRY, cc, src1, src2); |
| 839 | } else { |
| 840 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY, cc, src1, src2); |
| 841 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 842 | } else { |
| 843 | // We often have several deopts to the same entry, reuse the last |
| 844 | // jump entry if this is the case. |
| 845 | if (deopt_jump_table_.is_empty() || |
| 846 | (deopt_jump_table_.last().address != entry) || |
| 847 | (deopt_jump_table_.last().is_lazy_deopt != needs_lazy_deopt) || |
| 848 | (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { |
| 849 | JumpTableEntry table_entry(entry, !frame_is_built_, needs_lazy_deopt); |
| 850 | deopt_jump_table_.Add(table_entry, zone()); |
| 851 | } |
| 852 | __ Branch(&deopt_jump_table_.last().label, cc, src1, src2); |
| 853 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 857 | void LCodeGen::RegisterDependentCodeForEmbeddedMaps(Handle<Code> code) { |
| 858 | ZoneList<Handle<Map> > maps(1, zone()); |
| 859 | int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 860 | for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 861 | RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 862 | if (mode == RelocInfo::EMBEDDED_OBJECT && |
| 863 | it.rinfo()->target_object()->IsMap()) { |
| 864 | Handle<Map> map(Map::cast(it.rinfo()->target_object())); |
| 865 | if (map->CanTransition()) { |
| 866 | maps.Add(map, zone()); |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | #ifdef VERIFY_HEAP |
| 871 | // This disables verification of weak embedded maps after full GC. |
| 872 | // AddDependentCode can cause a GC, which would observe the state where |
| 873 | // this code is not yet in the depended code lists of the embedded maps. |
| 874 | NoWeakEmbeddedMapsVerificationScope disable_verification_of_embedded_maps; |
| 875 | #endif |
| 876 | for (int i = 0; i < maps.length(); i++) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 877 | maps.at(i)->AddDependentCode(DependentCode::kWeaklyEmbeddedGroup, code); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | |
| 881 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 882 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 883 | int length = deoptimizations_.length(); |
| 884 | if (length == 0) return; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 885 | Handle<DeoptimizationInputData> data = |
| 886 | factory()->NewDeoptimizationInputData(length, TENURED); |
| 887 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 888 | Handle<ByteArray> translations = |
| 889 | translations_.CreateByteArray(isolate()->factory()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 890 | data->SetTranslationByteArray(*translations); |
| 891 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 892 | |
| 893 | Handle<FixedArray> literals = |
| 894 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 895 | { ALLOW_HANDLE_DEREF(isolate(), |
| 896 | "copying a ZoneList of handles into a FixedArray"); |
| 897 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 898 | literals->set(i, *deoptimization_literals_[i]); |
| 899 | } |
| 900 | data->SetLiteralArray(*literals); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 901 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 902 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 903 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 904 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 905 | |
| 906 | // Populate the deoptimization entries. |
| 907 | for (int i = 0; i < length; i++) { |
| 908 | LEnvironment* env = deoptimizations_[i]; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 909 | data->SetAstId(i, env->ast_id()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 910 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 911 | data->SetArgumentsStackHeight(i, |
| 912 | Smi::FromInt(env->arguments_stack_height())); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 913 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 914 | } |
| 915 | code->set_deoptimization_data(*data); |
| 916 | } |
| 917 | |
| 918 | |
| 919 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 920 | int result = deoptimization_literals_.length(); |
| 921 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 922 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 923 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 924 | deoptimization_literals_.Add(literal, zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 925 | return result; |
| 926 | } |
| 927 | |
| 928 | |
| 929 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 930 | ASSERT(deoptimization_literals_.length() == 0); |
| 931 | |
| 932 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 933 | chunk()->inlined_closures(); |
| 934 | |
| 935 | for (int i = 0, length = inlined_closures->length(); |
| 936 | i < length; |
| 937 | i++) { |
| 938 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 939 | } |
| 940 | |
| 941 | inlined_function_count_ = deoptimization_literals_.length(); |
| 942 | } |
| 943 | |
| 944 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 945 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 946 | LInstruction* instr, SafepointMode safepoint_mode) { |
| 947 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 948 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 949 | } else { |
| 950 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 951 | RecordSafepointWithRegisters( |
| 952 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 957 | void LCodeGen::RecordSafepoint( |
| 958 | LPointerMap* pointers, |
| 959 | Safepoint::Kind kind, |
| 960 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 961 | Safepoint::DeoptMode deopt_mode) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 962 | ASSERT(expected_safepoint_kind_ == kind); |
| 963 | |
| 964 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
| 965 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 966 | kind, arguments, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 967 | for (int i = 0; i < operands->length(); i++) { |
| 968 | LOperand* pointer = operands->at(i); |
| 969 | if (pointer->IsStackSlot()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 970 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 971 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 972 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | if (kind & Safepoint::kWithRegisters) { |
| 976 | // Register cp always contains a pointer to the context. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 977 | safepoint.DefinePointerRegister(cp, zone()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | |
| 981 | |
| 982 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 983 | Safepoint::DeoptMode deopt_mode) { |
| 984 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 988 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 989 | LPointerMap empty_pointers(RelocInfo::kNoPosition, zone()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 990 | RecordSafepoint(&empty_pointers, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | |
| 994 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 995 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 996 | Safepoint::DeoptMode deopt_mode) { |
| 997 | RecordSafepoint( |
| 998 | pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | |
| 1002 | void LCodeGen::RecordSafepointWithRegistersAndDoubles( |
| 1003 | LPointerMap* pointers, |
| 1004 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1005 | Safepoint::DeoptMode deopt_mode) { |
| 1006 | RecordSafepoint( |
| 1007 | pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | void LCodeGen::RecordPosition(int position) { |
| 1012 | if (position == RelocInfo::kNoPosition) return; |
| 1013 | masm()->positions_recorder()->RecordPosition(position); |
| 1014 | } |
| 1015 | |
| 1016 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1017 | static const char* LabelType(LLabel* label) { |
| 1018 | if (label->is_loop_header()) return " (loop header)"; |
| 1019 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 1020 | return ""; |
| 1021 | } |
| 1022 | |
| 1023 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1024 | void LCodeGen::DoLabel(LLabel* label) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1025 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1026 | current_instruction_, |
| 1027 | label->hydrogen_value()->id(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1028 | label->block_id(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1029 | LabelType(label)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1030 | __ bind(label->label()); |
| 1031 | current_block_ = label->block_id(); |
| 1032 | DoGap(label); |
| 1033 | } |
| 1034 | |
| 1035 | |
| 1036 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
| 1037 | resolver_.Resolve(move); |
| 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | void LCodeGen::DoGap(LGap* gap) { |
| 1042 | for (int i = LGap::FIRST_INNER_POSITION; |
| 1043 | i <= LGap::LAST_INNER_POSITION; |
| 1044 | i++) { |
| 1045 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 1046 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 1047 | if (move != NULL) DoParallelMove(move); |
| 1048 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 1053 | DoGap(instr); |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | void LCodeGen::DoParameter(LParameter* instr) { |
| 1058 | // Nothing to do. |
| 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | void LCodeGen::DoCallStub(LCallStub* instr) { |
| 1063 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 1064 | switch (instr->hydrogen()->major_key()) { |
| 1065 | case CodeStub::RegExpConstructResult: { |
| 1066 | RegExpConstructResultStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1067 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1068 | break; |
| 1069 | } |
| 1070 | case CodeStub::RegExpExec: { |
| 1071 | RegExpExecStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1072 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1073 | break; |
| 1074 | } |
| 1075 | case CodeStub::SubString: { |
| 1076 | SubStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1077 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1078 | break; |
| 1079 | } |
| 1080 | case CodeStub::NumberToString: { |
| 1081 | NumberToStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1082 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1083 | break; |
| 1084 | } |
| 1085 | case CodeStub::StringAdd: { |
| 1086 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1087 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1088 | break; |
| 1089 | } |
| 1090 | case CodeStub::StringCompare: { |
| 1091 | StringCompareStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1092 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1093 | break; |
| 1094 | } |
| 1095 | case CodeStub::TranscendentalCache: { |
| 1096 | __ lw(a0, MemOperand(sp, 0)); |
| 1097 | TranscendentalCacheStub stub(instr->transcendental_type(), |
| 1098 | TranscendentalCacheStub::TAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1099 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1100 | break; |
| 1101 | } |
| 1102 | default: |
| 1103 | UNREACHABLE(); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | |
| 1108 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 1109 | // Nothing to do. |
| 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | void LCodeGen::DoModI(LModI* instr) { |
| 1114 | Register scratch = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1115 | const Register left = ToRegister(instr->left()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1116 | const Register result = ToRegister(instr->result()); |
| 1117 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1118 | Label done; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1119 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1120 | if (instr->hydrogen()->HasPowerOf2Divisor()) { |
| 1121 | Register scratch = scratch0(); |
| 1122 | ASSERT(!left.is(scratch)); |
| 1123 | __ mov(scratch, left); |
| 1124 | int32_t p2constant = HConstant::cast( |
| 1125 | instr->hydrogen()->right())->Integer32Value(); |
| 1126 | ASSERT(p2constant != 0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1127 | // Result always takes the sign of the dividend (left). |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1128 | p2constant = abs(p2constant); |
| 1129 | |
| 1130 | Label positive_dividend; |
| 1131 | __ Branch(USE_DELAY_SLOT, &positive_dividend, ge, left, Operand(zero_reg)); |
| 1132 | __ subu(result, zero_reg, left); |
| 1133 | __ And(result, result, p2constant - 1); |
| 1134 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1135 | DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); |
| 1136 | } |
| 1137 | __ Branch(USE_DELAY_SLOT, &done); |
| 1138 | __ subu(result, zero_reg, result); |
| 1139 | __ bind(&positive_dividend); |
| 1140 | __ And(result, scratch, p2constant - 1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1141 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1142 | // div runs in the background while we check for special cases. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1143 | Register right = EmitLoadRegister(instr->right(), scratch); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1144 | __ div(left, right); |
| 1145 | |
| 1146 | // Check for x % 0. |
| 1147 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1148 | DeoptimizeIf(eq, instr->environment(), right, Operand(zero_reg)); |
| 1149 | } |
| 1150 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1151 | // Check for (kMinInt % -1). |
| 1152 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1153 | Label left_not_min_int; |
| 1154 | __ Branch(&left_not_min_int, ne, left, Operand(kMinInt)); |
| 1155 | DeoptimizeIf(eq, instr->environment(), right, Operand(-1)); |
| 1156 | __ bind(&left_not_min_int); |
| 1157 | } |
| 1158 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1159 | __ Branch(USE_DELAY_SLOT, &done, ge, left, Operand(zero_reg)); |
| 1160 | __ mfhi(result); |
| 1161 | |
| 1162 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1163 | DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); |
| 1164 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1165 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1166 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | |
| 1170 | void LCodeGen::DoDivI(LDivI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1171 | const Register left = ToRegister(instr->left()); |
| 1172 | const Register right = ToRegister(instr->right()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1173 | const Register result = ToRegister(instr->result()); |
| 1174 | |
| 1175 | // On MIPS div is asynchronous - it will run in the background while we |
| 1176 | // check for special cases. |
| 1177 | __ div(left, right); |
| 1178 | |
| 1179 | // Check for x / 0. |
| 1180 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1181 | DeoptimizeIf(eq, instr->environment(), right, Operand(zero_reg)); |
| 1182 | } |
| 1183 | |
| 1184 | // Check for (0 / -x) that will produce negative zero. |
| 1185 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1186 | Label left_not_zero; |
| 1187 | __ Branch(&left_not_zero, ne, left, Operand(zero_reg)); |
| 1188 | DeoptimizeIf(lt, instr->environment(), right, Operand(zero_reg)); |
| 1189 | __ bind(&left_not_zero); |
| 1190 | } |
| 1191 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1192 | // Check for (kMinInt / -1). |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1193 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1194 | Label left_not_min_int; |
| 1195 | __ Branch(&left_not_min_int, ne, left, Operand(kMinInt)); |
| 1196 | DeoptimizeIf(eq, instr->environment(), right, Operand(-1)); |
| 1197 | __ bind(&left_not_min_int); |
| 1198 | } |
| 1199 | |
| 1200 | __ mfhi(result); |
| 1201 | DeoptimizeIf(ne, instr->environment(), result, Operand(zero_reg)); |
| 1202 | __ mflo(result); |
| 1203 | } |
| 1204 | |
| 1205 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1206 | void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
| 1207 | DoubleRegister addend = ToDoubleRegister(instr->addend()); |
| 1208 | DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1209 | DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1210 | |
| 1211 | // This is computed in-place. |
| 1212 | ASSERT(addend.is(ToDoubleRegister(instr->result()))); |
| 1213 | |
| 1214 | __ madd_d(addend, addend, multiplier, multiplicand); |
| 1215 | } |
| 1216 | |
| 1217 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1218 | void LCodeGen::DoMulI(LMulI* instr) { |
| 1219 | Register scratch = scratch0(); |
| 1220 | Register result = ToRegister(instr->result()); |
| 1221 | // Note that result may alias left. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1222 | Register left = ToRegister(instr->left()); |
| 1223 | LOperand* right_op = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1224 | |
| 1225 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1226 | bool bailout_on_minus_zero = |
| 1227 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
| 1228 | |
| 1229 | if (right_op->IsConstantOperand() && !can_overflow) { |
| 1230 | // Use optimized code for specific constants. |
| 1231 | int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
| 1232 | |
| 1233 | if (bailout_on_minus_zero && (constant < 0)) { |
| 1234 | // The case of a null constant will be handled separately. |
| 1235 | // If constant is negative and left is null, the result should be -0. |
| 1236 | DeoptimizeIf(eq, instr->environment(), left, Operand(zero_reg)); |
| 1237 | } |
| 1238 | |
| 1239 | switch (constant) { |
| 1240 | case -1: |
| 1241 | __ Subu(result, zero_reg, left); |
| 1242 | break; |
| 1243 | case 0: |
| 1244 | if (bailout_on_minus_zero) { |
| 1245 | // If left is strictly negative and the constant is null, the |
| 1246 | // result is -0. Deoptimize if required, otherwise return 0. |
| 1247 | DeoptimizeIf(lt, instr->environment(), left, Operand(zero_reg)); |
| 1248 | } |
| 1249 | __ mov(result, zero_reg); |
| 1250 | break; |
| 1251 | case 1: |
| 1252 | // Nothing to do. |
| 1253 | __ Move(result, left); |
| 1254 | break; |
| 1255 | default: |
| 1256 | // Multiplying by powers of two and powers of two plus or minus |
| 1257 | // one can be done faster with shifted operands. |
| 1258 | // For other constants we emit standard code. |
| 1259 | int32_t mask = constant >> 31; |
| 1260 | uint32_t constant_abs = (constant + mask) ^ mask; |
| 1261 | |
| 1262 | if (IsPowerOf2(constant_abs) || |
| 1263 | IsPowerOf2(constant_abs - 1) || |
| 1264 | IsPowerOf2(constant_abs + 1)) { |
| 1265 | if (IsPowerOf2(constant_abs)) { |
| 1266 | int32_t shift = WhichPowerOf2(constant_abs); |
| 1267 | __ sll(result, left, shift); |
| 1268 | } else if (IsPowerOf2(constant_abs - 1)) { |
| 1269 | int32_t shift = WhichPowerOf2(constant_abs - 1); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1270 | __ sll(scratch, left, shift); |
| 1271 | __ Addu(result, scratch, left); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1272 | } else if (IsPowerOf2(constant_abs + 1)) { |
| 1273 | int32_t shift = WhichPowerOf2(constant_abs + 1); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1274 | __ sll(scratch, left, shift); |
| 1275 | __ Subu(result, scratch, left); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | // Correct the sign of the result is the constant is negative. |
| 1279 | if (constant < 0) { |
| 1280 | __ Subu(result, zero_reg, result); |
| 1281 | } |
| 1282 | |
| 1283 | } else { |
| 1284 | // Generate standard code. |
| 1285 | __ li(at, constant); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1286 | __ Mul(result, left, at); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | } else { |
| 1291 | Register right = EmitLoadRegister(right_op, scratch); |
| 1292 | if (bailout_on_minus_zero) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1293 | __ Or(ToRegister(instr->temp()), left, right); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | if (can_overflow) { |
| 1297 | // hi:lo = left * right. |
| 1298 | __ mult(left, right); |
| 1299 | __ mfhi(scratch); |
| 1300 | __ mflo(result); |
| 1301 | __ sra(at, result, 31); |
| 1302 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(at)); |
| 1303 | } else { |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1304 | __ Mul(result, left, right); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | if (bailout_on_minus_zero) { |
| 1308 | // Bail out if the result is supposed to be negative zero. |
| 1309 | Label done; |
| 1310 | __ Branch(&done, ne, result, Operand(zero_reg)); |
| 1311 | DeoptimizeIf(lt, |
| 1312 | instr->environment(), |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1313 | ToRegister(instr->temp()), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1314 | Operand(zero_reg)); |
| 1315 | __ bind(&done); |
| 1316 | } |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | void LCodeGen::DoBitI(LBitI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1322 | LOperand* left_op = instr->left(); |
| 1323 | LOperand* right_op = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1324 | ASSERT(left_op->IsRegister()); |
| 1325 | Register left = ToRegister(left_op); |
| 1326 | Register result = ToRegister(instr->result()); |
| 1327 | Operand right(no_reg); |
| 1328 | |
| 1329 | if (right_op->IsStackSlot() || right_op->IsArgument()) { |
| 1330 | right = Operand(EmitLoadRegister(right_op, at)); |
| 1331 | } else { |
| 1332 | ASSERT(right_op->IsRegister() || right_op->IsConstantOperand()); |
| 1333 | right = ToOperand(right_op); |
| 1334 | } |
| 1335 | |
| 1336 | switch (instr->op()) { |
| 1337 | case Token::BIT_AND: |
| 1338 | __ And(result, left, right); |
| 1339 | break; |
| 1340 | case Token::BIT_OR: |
| 1341 | __ Or(result, left, right); |
| 1342 | break; |
| 1343 | case Token::BIT_XOR: |
| 1344 | __ Xor(result, left, right); |
| 1345 | break; |
| 1346 | default: |
| 1347 | UNREACHABLE(); |
| 1348 | break; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | void LCodeGen::DoShiftI(LShiftI* instr) { |
| 1354 | // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
| 1355 | // result may alias either of them. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1356 | LOperand* right_op = instr->right(); |
| 1357 | Register left = ToRegister(instr->left()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1358 | Register result = ToRegister(instr->result()); |
| 1359 | |
| 1360 | if (right_op->IsRegister()) { |
| 1361 | // No need to mask the right operand on MIPS, it is built into the variable |
| 1362 | // shift instructions. |
| 1363 | switch (instr->op()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1364 | case Token::ROR: |
| 1365 | __ Ror(result, left, Operand(ToRegister(right_op))); |
| 1366 | break; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1367 | case Token::SAR: |
| 1368 | __ srav(result, left, ToRegister(right_op)); |
| 1369 | break; |
| 1370 | case Token::SHR: |
| 1371 | __ srlv(result, left, ToRegister(right_op)); |
| 1372 | if (instr->can_deopt()) { |
| 1373 | DeoptimizeIf(lt, instr->environment(), result, Operand(zero_reg)); |
| 1374 | } |
| 1375 | break; |
| 1376 | case Token::SHL: |
| 1377 | __ sllv(result, left, ToRegister(right_op)); |
| 1378 | break; |
| 1379 | default: |
| 1380 | UNREACHABLE(); |
| 1381 | break; |
| 1382 | } |
| 1383 | } else { |
| 1384 | // Mask the right_op operand. |
| 1385 | int value = ToInteger32(LConstantOperand::cast(right_op)); |
| 1386 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1387 | switch (instr->op()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1388 | case Token::ROR: |
| 1389 | if (shift_count != 0) { |
| 1390 | __ Ror(result, left, Operand(shift_count)); |
| 1391 | } else { |
| 1392 | __ Move(result, left); |
| 1393 | } |
| 1394 | break; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1395 | case Token::SAR: |
| 1396 | if (shift_count != 0) { |
| 1397 | __ sra(result, left, shift_count); |
| 1398 | } else { |
| 1399 | __ Move(result, left); |
| 1400 | } |
| 1401 | break; |
| 1402 | case Token::SHR: |
| 1403 | if (shift_count != 0) { |
| 1404 | __ srl(result, left, shift_count); |
| 1405 | } else { |
| 1406 | if (instr->can_deopt()) { |
| 1407 | __ And(at, left, Operand(0x80000000)); |
| 1408 | DeoptimizeIf(ne, instr->environment(), at, Operand(zero_reg)); |
| 1409 | } |
| 1410 | __ Move(result, left); |
| 1411 | } |
| 1412 | break; |
| 1413 | case Token::SHL: |
| 1414 | if (shift_count != 0) { |
| 1415 | __ sll(result, left, shift_count); |
| 1416 | } else { |
| 1417 | __ Move(result, left); |
| 1418 | } |
| 1419 | break; |
| 1420 | default: |
| 1421 | UNREACHABLE(); |
| 1422 | break; |
| 1423 | } |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | |
| 1428 | void LCodeGen::DoSubI(LSubI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1429 | LOperand* left = instr->left(); |
| 1430 | LOperand* right = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1431 | LOperand* result = instr->result(); |
| 1432 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1433 | |
| 1434 | if (!can_overflow) { |
| 1435 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1436 | Register right_reg = EmitLoadRegister(right, at); |
| 1437 | __ Subu(ToRegister(result), ToRegister(left), Operand(right_reg)); |
| 1438 | } else { |
| 1439 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
| 1440 | __ Subu(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1441 | } |
| 1442 | } else { // can_overflow. |
| 1443 | Register overflow = scratch0(); |
| 1444 | Register scratch = scratch1(); |
| 1445 | if (right->IsStackSlot() || |
| 1446 | right->IsArgument() || |
| 1447 | right->IsConstantOperand()) { |
| 1448 | Register right_reg = EmitLoadRegister(right, scratch); |
| 1449 | __ SubuAndCheckForOverflow(ToRegister(result), |
| 1450 | ToRegister(left), |
| 1451 | right_reg, |
| 1452 | overflow); // Reg at also used as scratch. |
| 1453 | } else { |
| 1454 | ASSERT(right->IsRegister()); |
| 1455 | // Due to overflow check macros not supporting constant operands, |
| 1456 | // handling the IsConstantOperand case was moved to prev if clause. |
| 1457 | __ SubuAndCheckForOverflow(ToRegister(result), |
| 1458 | ToRegister(left), |
| 1459 | ToRegister(right), |
| 1460 | overflow); // Reg at also used as scratch. |
| 1461 | } |
| 1462 | DeoptimizeIf(lt, instr->environment(), overflow, Operand(zero_reg)); |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | |
| 1467 | void LCodeGen::DoConstantI(LConstantI* instr) { |
| 1468 | ASSERT(instr->result()->IsRegister()); |
| 1469 | __ li(ToRegister(instr->result()), Operand(instr->value())); |
| 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | void LCodeGen::DoConstantD(LConstantD* instr) { |
| 1474 | ASSERT(instr->result()->IsDoubleRegister()); |
| 1475 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1476 | double v = instr->value(); |
| 1477 | __ Move(result, v); |
| 1478 | } |
| 1479 | |
| 1480 | |
| 1481 | void LCodeGen::DoConstantT(LConstantT* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1482 | Handle<Object> value = instr->value(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1483 | ALLOW_HANDLE_DEREF(isolate(), "smi check"); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1484 | if (value->IsSmi()) { |
| 1485 | __ li(ToRegister(instr->result()), Operand(value)); |
| 1486 | } else { |
| 1487 | __ LoadHeapObject(ToRegister(instr->result()), |
| 1488 | Handle<HeapObject>::cast(value)); |
| 1489 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1493 | void LCodeGen::DoFixedArrayBaseLength(LFixedArrayBaseLength* instr) { |
| 1494 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1495 | Register array = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1496 | __ lw(result, FieldMemOperand(array, FixedArrayBase::kLengthOffset)); |
| 1497 | } |
| 1498 | |
| 1499 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1500 | void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 1501 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1502 | Register map = ToRegister(instr->value()); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1503 | __ EnumLength(result, map); |
| 1504 | } |
| 1505 | |
| 1506 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1507 | void LCodeGen::DoElementsKind(LElementsKind* instr) { |
| 1508 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1509 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1510 | |
| 1511 | // Load map into |result|. |
| 1512 | __ lw(result, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 1513 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 1514 | // but the following bit field extraction takes care of that anyway. |
| 1515 | __ lbu(result, FieldMemOperand(result, Map::kBitField2Offset)); |
| 1516 | // Retrieve elements_kind from bit field 2. |
| 1517 | __ Ext(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount); |
| 1518 | } |
| 1519 | |
| 1520 | |
| 1521 | void LCodeGen::DoValueOf(LValueOf* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1522 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1523 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1524 | Register map = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1525 | Label done; |
| 1526 | |
| 1527 | // If the object is a smi return the object. |
| 1528 | __ Move(result, input); |
| 1529 | __ JumpIfSmi(input, &done); |
| 1530 | |
| 1531 | // If the object is not a value type, return the object. |
| 1532 | __ GetObjectType(input, map, map); |
| 1533 | __ Branch(&done, ne, map, Operand(JS_VALUE_TYPE)); |
| 1534 | __ lw(result, FieldMemOperand(input, JSValue::kValueOffset)); |
| 1535 | |
| 1536 | __ bind(&done); |
| 1537 | } |
| 1538 | |
| 1539 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1540 | void LCodeGen::DoDateField(LDateField* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1541 | Register object = ToRegister(instr->date()); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1542 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1543 | Register scratch = ToRegister(instr->temp()); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1544 | Smi* index = instr->index(); |
| 1545 | Label runtime, done; |
| 1546 | ASSERT(object.is(a0)); |
| 1547 | ASSERT(result.is(v0)); |
| 1548 | ASSERT(!scratch.is(scratch0())); |
| 1549 | ASSERT(!scratch.is(object)); |
| 1550 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1551 | __ And(at, object, Operand(kSmiTagMask)); |
| 1552 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1553 | __ GetObjectType(object, scratch, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1554 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(JS_DATE_TYPE)); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1555 | |
| 1556 | if (index->value() == 0) { |
| 1557 | __ lw(result, FieldMemOperand(object, JSDate::kValueOffset)); |
| 1558 | } else { |
| 1559 | if (index->value() < JSDate::kFirstUncachedField) { |
| 1560 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 1561 | __ li(scratch, Operand(stamp)); |
| 1562 | __ lw(scratch, MemOperand(scratch)); |
| 1563 | __ lw(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); |
| 1564 | __ Branch(&runtime, ne, scratch, Operand(scratch0())); |
| 1565 | __ lw(result, FieldMemOperand(object, JSDate::kValueOffset + |
| 1566 | kPointerSize * index->value())); |
| 1567 | __ jmp(&done); |
| 1568 | } |
| 1569 | __ bind(&runtime); |
| 1570 | __ PrepareCallCFunction(2, scratch); |
| 1571 | __ li(a1, Operand(index)); |
| 1572 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 1573 | __ bind(&done); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1578 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 1579 | SeqStringSetCharGenerator::Generate(masm(), |
| 1580 | instr->encoding(), |
| 1581 | ToRegister(instr->string()), |
| 1582 | ToRegister(instr->index()), |
| 1583 | ToRegister(instr->value())); |
| 1584 | } |
| 1585 | |
| 1586 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1587 | void LCodeGen::DoBitNotI(LBitNotI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1588 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1589 | Register result = ToRegister(instr->result()); |
| 1590 | __ Nor(result, zero_reg, Operand(input)); |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | void LCodeGen::DoThrow(LThrow* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1595 | Register input_reg = EmitLoadRegister(instr->value(), at); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1596 | __ push(input_reg); |
| 1597 | CallRuntime(Runtime::kThrow, 1, instr); |
| 1598 | |
| 1599 | if (FLAG_debug_code) { |
| 1600 | __ stop("Unreachable code."); |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | |
| 1605 | void LCodeGen::DoAddI(LAddI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1606 | LOperand* left = instr->left(); |
| 1607 | LOperand* right = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1608 | LOperand* result = instr->result(); |
| 1609 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1610 | |
| 1611 | if (!can_overflow) { |
| 1612 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1613 | Register right_reg = EmitLoadRegister(right, at); |
| 1614 | __ Addu(ToRegister(result), ToRegister(left), Operand(right_reg)); |
| 1615 | } else { |
| 1616 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
| 1617 | __ Addu(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1618 | } |
| 1619 | } else { // can_overflow. |
| 1620 | Register overflow = scratch0(); |
| 1621 | Register scratch = scratch1(); |
| 1622 | if (right->IsStackSlot() || |
| 1623 | right->IsArgument() || |
| 1624 | right->IsConstantOperand()) { |
| 1625 | Register right_reg = EmitLoadRegister(right, scratch); |
| 1626 | __ AdduAndCheckForOverflow(ToRegister(result), |
| 1627 | ToRegister(left), |
| 1628 | right_reg, |
| 1629 | overflow); // Reg at also used as scratch. |
| 1630 | } else { |
| 1631 | ASSERT(right->IsRegister()); |
| 1632 | // Due to overflow check macros not supporting constant operands, |
| 1633 | // handling the IsConstantOperand case was moved to prev if clause. |
| 1634 | __ AdduAndCheckForOverflow(ToRegister(result), |
| 1635 | ToRegister(left), |
| 1636 | ToRegister(right), |
| 1637 | overflow); // Reg at also used as scratch. |
| 1638 | } |
| 1639 | DeoptimizeIf(lt, instr->environment(), overflow, Operand(zero_reg)); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1644 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1645 | LOperand* left = instr->left(); |
| 1646 | LOperand* right = instr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1647 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
| 1648 | Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; |
| 1649 | if (instr->hydrogen()->representation().IsInteger32()) { |
| 1650 | Register left_reg = ToRegister(left); |
| 1651 | Operand right_op = (right->IsRegister() || right->IsConstantOperand()) |
| 1652 | ? ToOperand(right) |
| 1653 | : Operand(EmitLoadRegister(right, at)); |
| 1654 | Register result_reg = ToRegister(instr->result()); |
| 1655 | Label return_right, done; |
| 1656 | if (!result_reg.is(left_reg)) { |
| 1657 | __ Branch(&return_right, NegateCondition(condition), left_reg, right_op); |
| 1658 | __ mov(result_reg, left_reg); |
| 1659 | __ Branch(&done); |
| 1660 | } |
| 1661 | __ Branch(&done, condition, left_reg, right_op); |
| 1662 | __ bind(&return_right); |
| 1663 | __ Addu(result_reg, zero_reg, right_op); |
| 1664 | __ bind(&done); |
| 1665 | } else { |
| 1666 | ASSERT(instr->hydrogen()->representation().IsDouble()); |
| 1667 | FPURegister left_reg = ToDoubleRegister(left); |
| 1668 | FPURegister right_reg = ToDoubleRegister(right); |
| 1669 | FPURegister result_reg = ToDoubleRegister(instr->result()); |
| 1670 | Label check_nan_left, check_zero, return_left, return_right, done; |
| 1671 | __ BranchF(&check_zero, &check_nan_left, eq, left_reg, right_reg); |
| 1672 | __ BranchF(&return_left, NULL, condition, left_reg, right_reg); |
| 1673 | __ Branch(&return_right); |
| 1674 | |
| 1675 | __ bind(&check_zero); |
| 1676 | // left == right != 0. |
| 1677 | __ BranchF(&return_left, NULL, ne, left_reg, kDoubleRegZero); |
| 1678 | // At this point, both left and right are either 0 or -0. |
| 1679 | if (operation == HMathMinMax::kMathMin) { |
| 1680 | __ neg_d(left_reg, left_reg); |
| 1681 | __ sub_d(result_reg, left_reg, right_reg); |
| 1682 | __ neg_d(result_reg, result_reg); |
| 1683 | } else { |
| 1684 | __ add_d(result_reg, left_reg, right_reg); |
| 1685 | } |
| 1686 | __ Branch(&done); |
| 1687 | |
| 1688 | __ bind(&check_nan_left); |
| 1689 | // left == NaN. |
| 1690 | __ BranchF(NULL, &return_left, eq, left_reg, left_reg); |
| 1691 | __ bind(&return_right); |
| 1692 | if (!right_reg.is(result_reg)) { |
| 1693 | __ mov_d(result_reg, right_reg); |
| 1694 | } |
| 1695 | __ Branch(&done); |
| 1696 | |
| 1697 | __ bind(&return_left); |
| 1698 | if (!left_reg.is(result_reg)) { |
| 1699 | __ mov_d(result_reg, left_reg); |
| 1700 | } |
| 1701 | __ bind(&done); |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1706 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1707 | DoubleRegister left = ToDoubleRegister(instr->left()); |
| 1708 | DoubleRegister right = ToDoubleRegister(instr->right()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1709 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1710 | switch (instr->op()) { |
| 1711 | case Token::ADD: |
| 1712 | __ add_d(result, left, right); |
| 1713 | break; |
| 1714 | case Token::SUB: |
| 1715 | __ sub_d(result, left, right); |
| 1716 | break; |
| 1717 | case Token::MUL: |
| 1718 | __ mul_d(result, left, right); |
| 1719 | break; |
| 1720 | case Token::DIV: |
| 1721 | __ div_d(result, left, right); |
| 1722 | break; |
| 1723 | case Token::MOD: { |
| 1724 | // Save a0-a3 on the stack. |
| 1725 | RegList saved_regs = a0.bit() | a1.bit() | a2.bit() | a3.bit(); |
| 1726 | __ MultiPush(saved_regs); |
| 1727 | |
| 1728 | __ PrepareCallCFunction(0, 2, scratch0()); |
| 1729 | __ SetCallCDoubleArguments(left, right); |
| 1730 | __ CallCFunction( |
| 1731 | ExternalReference::double_fp_operation(Token::MOD, isolate()), |
| 1732 | 0, 2); |
| 1733 | // Move the result in the double result register. |
| 1734 | __ GetCFunctionDoubleResult(result); |
| 1735 | |
| 1736 | // Restore saved register. |
| 1737 | __ MultiPop(saved_regs); |
| 1738 | break; |
| 1739 | } |
| 1740 | default: |
| 1741 | UNREACHABLE(); |
| 1742 | break; |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | |
| 1747 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1748 | ASSERT(ToRegister(instr->left()).is(a1)); |
| 1749 | ASSERT(ToRegister(instr->right()).is(a0)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1750 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 1751 | |
| 1752 | BinaryOpStub stub(instr->op(), NO_OVERWRITE); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1753 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1754 | // Other arch use a nop here, to signal that there is no inlined |
| 1755 | // patchable code. Mips does not need the nop, since our marker |
| 1756 | // instruction (andi zero_reg) will never be used in normal code. |
| 1757 | } |
| 1758 | |
| 1759 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1760 | int LCodeGen::GetNextEmittedBlock() const { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1761 | for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { |
| 1762 | if (!chunk_->GetLabel(i)->HasReplacement()) return i; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1763 | } |
| 1764 | return -1; |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | void LCodeGen::EmitBranch(int left_block, int right_block, |
| 1769 | Condition cc, Register src1, const Operand& src2) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1770 | int next_block = GetNextEmittedBlock(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1771 | right_block = chunk_->LookupDestination(right_block); |
| 1772 | left_block = chunk_->LookupDestination(left_block); |
| 1773 | if (right_block == left_block) { |
| 1774 | EmitGoto(left_block); |
| 1775 | } else if (left_block == next_block) { |
| 1776 | __ Branch(chunk_->GetAssemblyLabel(right_block), |
| 1777 | NegateCondition(cc), src1, src2); |
| 1778 | } else if (right_block == next_block) { |
| 1779 | __ Branch(chunk_->GetAssemblyLabel(left_block), cc, src1, src2); |
| 1780 | } else { |
| 1781 | __ Branch(chunk_->GetAssemblyLabel(left_block), cc, src1, src2); |
| 1782 | __ Branch(chunk_->GetAssemblyLabel(right_block)); |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | |
| 1787 | void LCodeGen::EmitBranchF(int left_block, int right_block, |
| 1788 | Condition cc, FPURegister src1, FPURegister src2) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1789 | int next_block = GetNextEmittedBlock(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1790 | right_block = chunk_->LookupDestination(right_block); |
| 1791 | left_block = chunk_->LookupDestination(left_block); |
| 1792 | if (right_block == left_block) { |
| 1793 | EmitGoto(left_block); |
| 1794 | } else if (left_block == next_block) { |
| 1795 | __ BranchF(chunk_->GetAssemblyLabel(right_block), NULL, |
| 1796 | NegateCondition(cc), src1, src2); |
| 1797 | } else if (right_block == next_block) { |
| 1798 | __ BranchF(chunk_->GetAssemblyLabel(left_block), NULL, cc, src1, src2); |
| 1799 | } else { |
| 1800 | __ BranchF(chunk_->GetAssemblyLabel(left_block), NULL, cc, src1, src2); |
| 1801 | __ Branch(chunk_->GetAssemblyLabel(right_block)); |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | |
| 1806 | void LCodeGen::DoBranch(LBranch* instr) { |
| 1807 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1808 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1809 | |
| 1810 | Representation r = instr->hydrogen()->value()->representation(); |
| 1811 | if (r.IsInteger32()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1812 | Register reg = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1813 | EmitBranch(true_block, false_block, ne, reg, Operand(zero_reg)); |
| 1814 | } else if (r.IsDouble()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1815 | DoubleRegister reg = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1816 | // Test the double value. Zero and NaN are false. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1817 | EmitBranchF(true_block, false_block, nue, reg, kDoubleRegZero); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1818 | } else { |
| 1819 | ASSERT(r.IsTagged()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1820 | Register reg = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1821 | HType type = instr->hydrogen()->value()->type(); |
| 1822 | if (type.IsBoolean()) { |
| 1823 | __ LoadRoot(at, Heap::kTrueValueRootIndex); |
| 1824 | EmitBranch(true_block, false_block, eq, reg, Operand(at)); |
| 1825 | } else if (type.IsSmi()) { |
| 1826 | EmitBranch(true_block, false_block, ne, reg, Operand(zero_reg)); |
| 1827 | } else { |
| 1828 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1829 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1830 | |
| 1831 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 1832 | // Avoid deopts in the case where we've never executed this path before. |
| 1833 | if (expected.IsEmpty()) expected = ToBooleanStub::all_types(); |
| 1834 | |
| 1835 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 1836 | // undefined -> false. |
| 1837 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 1838 | __ Branch(false_label, eq, reg, Operand(at)); |
| 1839 | } |
| 1840 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 1841 | // Boolean -> its value. |
| 1842 | __ LoadRoot(at, Heap::kTrueValueRootIndex); |
| 1843 | __ Branch(true_label, eq, reg, Operand(at)); |
| 1844 | __ LoadRoot(at, Heap::kFalseValueRootIndex); |
| 1845 | __ Branch(false_label, eq, reg, Operand(at)); |
| 1846 | } |
| 1847 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 1848 | // 'null' -> false. |
| 1849 | __ LoadRoot(at, Heap::kNullValueRootIndex); |
| 1850 | __ Branch(false_label, eq, reg, Operand(at)); |
| 1851 | } |
| 1852 | |
| 1853 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 1854 | // Smis: 0 -> false, all other -> true. |
| 1855 | __ Branch(false_label, eq, reg, Operand(zero_reg)); |
| 1856 | __ JumpIfSmi(reg, true_label); |
| 1857 | } else if (expected.NeedsMap()) { |
| 1858 | // If we need a map later and have a Smi -> deopt. |
| 1859 | __ And(at, reg, Operand(kSmiTagMask)); |
| 1860 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
| 1861 | } |
| 1862 | |
| 1863 | const Register map = scratch0(); |
| 1864 | if (expected.NeedsMap()) { |
| 1865 | __ lw(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 1866 | if (expected.CanBeUndetectable()) { |
| 1867 | // Undetectable -> false. |
| 1868 | __ lbu(at, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1869 | __ And(at, at, Operand(1 << Map::kIsUndetectable)); |
| 1870 | __ Branch(false_label, ne, at, Operand(zero_reg)); |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 1875 | // spec object -> true. |
| 1876 | __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1877 | __ Branch(true_label, ge, at, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 1878 | } |
| 1879 | |
| 1880 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 1881 | // String value -> false iff empty. |
| 1882 | Label not_string; |
| 1883 | __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1884 | __ Branch(¬_string, ge , at, Operand(FIRST_NONSTRING_TYPE)); |
| 1885 | __ lw(at, FieldMemOperand(reg, String::kLengthOffset)); |
| 1886 | __ Branch(true_label, ne, at, Operand(zero_reg)); |
| 1887 | __ Branch(false_label); |
| 1888 | __ bind(¬_string); |
| 1889 | } |
| 1890 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1891 | if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 1892 | // Symbol value -> true. |
| 1893 | const Register scratch = scratch1(); |
| 1894 | __ lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1895 | __ Branch(true_label, eq, scratch, Operand(SYMBOL_TYPE)); |
| 1896 | } |
| 1897 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1898 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 1899 | // heap number -> false iff +0, -0, or NaN. |
| 1900 | DoubleRegister dbl_scratch = double_scratch0(); |
| 1901 | Label not_heap_number; |
| 1902 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 1903 | __ Branch(¬_heap_number, ne, map, Operand(at)); |
| 1904 | __ ldc1(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 1905 | __ BranchF(true_label, false_label, ne, dbl_scratch, kDoubleRegZero); |
| 1906 | // Falls through if dbl_scratch == 0. |
| 1907 | __ Branch(false_label); |
| 1908 | __ bind(¬_heap_number); |
| 1909 | } |
| 1910 | |
| 1911 | // We've seen something for the first time -> deopt. |
| 1912 | DeoptimizeIf(al, instr->environment(), zero_reg, Operand(zero_reg)); |
| 1913 | } |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | |
| 1918 | void LCodeGen::EmitGoto(int block) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1919 | if (!IsNextEmittedBlock(block)) { |
| 1920 | __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | void LCodeGen::DoGoto(LGoto* instr) { |
| 1926 | EmitGoto(instr->block_id()); |
| 1927 | } |
| 1928 | |
| 1929 | |
| 1930 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
| 1931 | Condition cond = kNoCondition; |
| 1932 | switch (op) { |
| 1933 | case Token::EQ: |
| 1934 | case Token::EQ_STRICT: |
| 1935 | cond = eq; |
| 1936 | break; |
| 1937 | case Token::LT: |
| 1938 | cond = is_unsigned ? lo : lt; |
| 1939 | break; |
| 1940 | case Token::GT: |
| 1941 | cond = is_unsigned ? hi : gt; |
| 1942 | break; |
| 1943 | case Token::LTE: |
| 1944 | cond = is_unsigned ? ls : le; |
| 1945 | break; |
| 1946 | case Token::GTE: |
| 1947 | cond = is_unsigned ? hs : ge; |
| 1948 | break; |
| 1949 | case Token::IN: |
| 1950 | case Token::INSTANCEOF: |
| 1951 | default: |
| 1952 | UNREACHABLE(); |
| 1953 | } |
| 1954 | return cond; |
| 1955 | } |
| 1956 | |
| 1957 | |
| 1958 | void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1959 | LOperand* left = instr->left(); |
| 1960 | LOperand* right = instr->right(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1961 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1962 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1963 | |
| 1964 | Condition cond = TokenToCondition(instr->op(), false); |
| 1965 | |
| 1966 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 1967 | // We can statically evaluate the comparison. |
| 1968 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 1969 | double right_val = ToDouble(LConstantOperand::cast(right)); |
| 1970 | int next_block = |
| 1971 | EvalComparison(instr->op(), left_val, right_val) ? true_block |
| 1972 | : false_block; |
| 1973 | EmitGoto(next_block); |
| 1974 | } else { |
| 1975 | if (instr->is_double()) { |
| 1976 | // Compare left and right as doubles and load the |
| 1977 | // resulting flags into the normal status register. |
| 1978 | FPURegister left_reg = ToDoubleRegister(left); |
| 1979 | FPURegister right_reg = ToDoubleRegister(right); |
| 1980 | |
| 1981 | // If a NaN is involved, i.e. the result is unordered, |
| 1982 | // jump to false block label. |
| 1983 | __ BranchF(NULL, chunk_->GetAssemblyLabel(false_block), eq, |
| 1984 | left_reg, right_reg); |
| 1985 | |
| 1986 | EmitBranchF(true_block, false_block, cond, left_reg, right_reg); |
| 1987 | } else { |
| 1988 | Register cmp_left; |
| 1989 | Operand cmp_right = Operand(0); |
| 1990 | |
| 1991 | if (right->IsConstantOperand()) { |
| 1992 | cmp_left = ToRegister(left); |
| 1993 | cmp_right = Operand(ToInteger32(LConstantOperand::cast(right))); |
| 1994 | } else if (left->IsConstantOperand()) { |
| 1995 | cmp_left = ToRegister(right); |
| 1996 | cmp_right = Operand(ToInteger32(LConstantOperand::cast(left))); |
| 1997 | // We transposed the operands. Reverse the condition. |
| 1998 | cond = ReverseCondition(cond); |
| 1999 | } else { |
| 2000 | cmp_left = ToRegister(left); |
| 2001 | cmp_right = Operand(ToRegister(right)); |
| 2002 | } |
| 2003 | |
| 2004 | EmitBranch(true_block, false_block, cond, cmp_left, cmp_right); |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | |
| 2010 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2011 | Register left = ToRegister(instr->left()); |
| 2012 | Register right = ToRegister(instr->right()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2013 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2014 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2015 | |
| 2016 | EmitBranch(true_block, false_block, eq, left, Operand(right)); |
| 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | void LCodeGen::DoCmpConstantEqAndBranch(LCmpConstantEqAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2021 | Register left = ToRegister(instr->left()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2022 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2023 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2024 | |
| 2025 | EmitBranch(true_block, false_block, eq, left, |
| 2026 | Operand(instr->hydrogen()->right())); |
| 2027 | } |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | void LCodeGen::DoIsNilAndBranch(LIsNilAndBranch* instr) { |
| 2032 | Register scratch = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2033 | Register reg = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2034 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2035 | |
| 2036 | // If the expression is known to be untagged or a smi, then it's definitely |
| 2037 | // not null, and it can't be a an undetectable object. |
| 2038 | if (instr->hydrogen()->representation().IsSpecialization() || |
| 2039 | instr->hydrogen()->type().IsSmi()) { |
| 2040 | EmitGoto(false_block); |
| 2041 | return; |
| 2042 | } |
| 2043 | |
| 2044 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2045 | |
| 2046 | Heap::RootListIndex nil_value = instr->nil() == kNullValue ? |
| 2047 | Heap::kNullValueRootIndex : |
| 2048 | Heap::kUndefinedValueRootIndex; |
| 2049 | __ LoadRoot(at, nil_value); |
| 2050 | if (instr->kind() == kStrictEquality) { |
| 2051 | EmitBranch(true_block, false_block, eq, reg, Operand(at)); |
| 2052 | } else { |
| 2053 | Heap::RootListIndex other_nil_value = instr->nil() == kNullValue ? |
| 2054 | Heap::kUndefinedValueRootIndex : |
| 2055 | Heap::kNullValueRootIndex; |
| 2056 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2057 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2058 | __ Branch(USE_DELAY_SLOT, true_label, eq, reg, Operand(at)); |
| 2059 | __ LoadRoot(at, other_nil_value); // In the delay slot. |
| 2060 | __ Branch(USE_DELAY_SLOT, true_label, eq, reg, Operand(at)); |
| 2061 | __ JumpIfSmi(reg, false_label); // In the delay slot. |
| 2062 | // Check for undetectable objects by looking in the bit field in |
| 2063 | // the map. The object has already been smi checked. |
| 2064 | __ lw(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2065 | __ lbu(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 2066 | __ And(scratch, scratch, 1 << Map::kIsUndetectable); |
| 2067 | EmitBranch(true_block, false_block, ne, scratch, Operand(zero_reg)); |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | |
| 2072 | Condition LCodeGen::EmitIsObject(Register input, |
| 2073 | Register temp1, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2074 | Register temp2, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2075 | Label* is_not_object, |
| 2076 | Label* is_object) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2077 | __ JumpIfSmi(input, is_not_object); |
| 2078 | |
| 2079 | __ LoadRoot(temp2, Heap::kNullValueRootIndex); |
| 2080 | __ Branch(is_object, eq, input, Operand(temp2)); |
| 2081 | |
| 2082 | // Load map. |
| 2083 | __ lw(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2084 | // Undetectable objects behave like undefined. |
| 2085 | __ lbu(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
| 2086 | __ And(temp2, temp2, Operand(1 << Map::kIsUndetectable)); |
| 2087 | __ Branch(is_not_object, ne, temp2, Operand(zero_reg)); |
| 2088 | |
| 2089 | // Load instance type and check that it is in object type range. |
| 2090 | __ lbu(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
| 2091 | __ Branch(is_not_object, |
| 2092 | lt, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2093 | |
| 2094 | return le; |
| 2095 | } |
| 2096 | |
| 2097 | |
| 2098 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2099 | Register reg = ToRegister(instr->value()); |
| 2100 | Register temp1 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2101 | Register temp2 = scratch0(); |
| 2102 | |
| 2103 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2104 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2105 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2106 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2107 | |
| 2108 | Condition true_cond = |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2109 | EmitIsObject(reg, temp1, temp2, false_label, true_label); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2110 | |
| 2111 | EmitBranch(true_block, false_block, true_cond, temp2, |
| 2112 | Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2113 | } |
| 2114 | |
| 2115 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2116 | Condition LCodeGen::EmitIsString(Register input, |
| 2117 | Register temp1, |
| 2118 | Label* is_not_string) { |
| 2119 | __ JumpIfSmi(input, is_not_string); |
| 2120 | __ GetObjectType(input, temp1, temp1); |
| 2121 | |
| 2122 | return lt; |
| 2123 | } |
| 2124 | |
| 2125 | |
| 2126 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2127 | Register reg = ToRegister(instr->value()); |
| 2128 | Register temp1 = ToRegister(instr->temp()); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2129 | |
| 2130 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2131 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2132 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2133 | |
| 2134 | Condition true_cond = |
| 2135 | EmitIsString(reg, temp1, false_label); |
| 2136 | |
| 2137 | EmitBranch(true_block, false_block, true_cond, temp1, |
| 2138 | Operand(FIRST_NONSTRING_TYPE)); |
| 2139 | } |
| 2140 | |
| 2141 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2142 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
| 2143 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2144 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2145 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2146 | Register input_reg = EmitLoadRegister(instr->value(), at); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2147 | __ And(at, input_reg, kSmiTagMask); |
| 2148 | EmitBranch(true_block, false_block, eq, at, Operand(zero_reg)); |
| 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2153 | Register input = ToRegister(instr->value()); |
| 2154 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2155 | |
| 2156 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2157 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2158 | |
| 2159 | __ JumpIfSmi(input, chunk_->GetAssemblyLabel(false_block)); |
| 2160 | __ lw(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2161 | __ lbu(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); |
| 2162 | __ And(at, temp, Operand(1 << Map::kIsUndetectable)); |
| 2163 | EmitBranch(true_block, false_block, ne, at, Operand(zero_reg)); |
| 2164 | } |
| 2165 | |
| 2166 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2167 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2168 | switch (op) { |
| 2169 | case Token::EQ_STRICT: |
| 2170 | case Token::EQ: |
| 2171 | return eq; |
| 2172 | case Token::LT: |
| 2173 | return lt; |
| 2174 | case Token::GT: |
| 2175 | return gt; |
| 2176 | case Token::LTE: |
| 2177 | return le; |
| 2178 | case Token::GTE: |
| 2179 | return ge; |
| 2180 | default: |
| 2181 | UNREACHABLE(); |
| 2182 | return kNoCondition; |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | |
| 2187 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
| 2188 | Token::Value op = instr->op(); |
| 2189 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2190 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2191 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2192 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2193 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2194 | |
| 2195 | Condition condition = ComputeCompareCondition(op); |
| 2196 | |
| 2197 | EmitBranch(true_block, false_block, condition, v0, Operand(zero_reg)); |
| 2198 | } |
| 2199 | |
| 2200 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2201 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
| 2202 | InstanceType from = instr->from(); |
| 2203 | InstanceType to = instr->to(); |
| 2204 | if (from == FIRST_TYPE) return to; |
| 2205 | ASSERT(from == to || to == LAST_TYPE); |
| 2206 | return from; |
| 2207 | } |
| 2208 | |
| 2209 | |
| 2210 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
| 2211 | InstanceType from = instr->from(); |
| 2212 | InstanceType to = instr->to(); |
| 2213 | if (from == to) return eq; |
| 2214 | if (to == LAST_TYPE) return hs; |
| 2215 | if (from == FIRST_TYPE) return ls; |
| 2216 | UNREACHABLE(); |
| 2217 | return eq; |
| 2218 | } |
| 2219 | |
| 2220 | |
| 2221 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
| 2222 | Register scratch = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2223 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2224 | |
| 2225 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2226 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2227 | |
| 2228 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2229 | |
| 2230 | __ JumpIfSmi(input, false_label); |
| 2231 | |
| 2232 | __ GetObjectType(input, scratch, scratch); |
| 2233 | EmitBranch(true_block, |
| 2234 | false_block, |
| 2235 | BranchCondition(instr->hydrogen()), |
| 2236 | scratch, |
| 2237 | Operand(TestType(instr->hydrogen()))); |
| 2238 | } |
| 2239 | |
| 2240 | |
| 2241 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2242 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2243 | Register result = ToRegister(instr->result()); |
| 2244 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2245 | __ AssertString(input); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2246 | |
| 2247 | __ lw(result, FieldMemOperand(input, String::kHashFieldOffset)); |
| 2248 | __ IndexFromHash(result, result); |
| 2249 | } |
| 2250 | |
| 2251 | |
| 2252 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2253 | LHasCachedArrayIndexAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2254 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2255 | Register scratch = scratch0(); |
| 2256 | |
| 2257 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2258 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2259 | |
| 2260 | __ lw(scratch, |
| 2261 | FieldMemOperand(input, String::kHashFieldOffset)); |
| 2262 | __ And(at, scratch, Operand(String::kContainsCachedArrayIndexMask)); |
| 2263 | EmitBranch(true_block, false_block, eq, at, Operand(zero_reg)); |
| 2264 | } |
| 2265 | |
| 2266 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2267 | // Branches to a label or falls through with the answer in flags. Trashes |
| 2268 | // the temp registers, but not the input. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2269 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2270 | Label* is_false, |
| 2271 | Handle<String>class_name, |
| 2272 | Register input, |
| 2273 | Register temp, |
| 2274 | Register temp2) { |
| 2275 | ASSERT(!input.is(temp)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2276 | ASSERT(!input.is(temp2)); |
| 2277 | ASSERT(!temp.is(temp2)); |
| 2278 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2279 | __ JumpIfSmi(input, is_false); |
| 2280 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2281 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2282 | // Assuming the following assertions, we can use the same compares to test |
| 2283 | // for both being a function type and being in the object type range. |
| 2284 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2285 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2286 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2287 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2288 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2289 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2290 | |
| 2291 | __ GetObjectType(input, temp, temp2); |
| 2292 | __ Branch(is_false, lt, temp2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 2293 | __ Branch(is_true, eq, temp2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 2294 | __ Branch(is_true, eq, temp2, Operand(LAST_SPEC_OBJECT_TYPE)); |
| 2295 | } else { |
| 2296 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2297 | // actual type and do a signed compare with the width of the type range. |
| 2298 | __ GetObjectType(input, temp, temp2); |
| 2299 | __ Subu(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2300 | __ Branch(is_false, gt, temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2301 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2302 | } |
| 2303 | |
| 2304 | // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
| 2305 | // Check if the constructor in the map is a function. |
| 2306 | __ lw(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
| 2307 | |
| 2308 | // Objects with a non-function constructor have class 'Object'. |
| 2309 | __ GetObjectType(temp, temp2, temp2); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2310 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2311 | __ Branch(is_true, ne, temp2, Operand(JS_FUNCTION_TYPE)); |
| 2312 | } else { |
| 2313 | __ Branch(is_false, ne, temp2, Operand(JS_FUNCTION_TYPE)); |
| 2314 | } |
| 2315 | |
| 2316 | // temp now contains the constructor function. Grab the |
| 2317 | // instance class name from there. |
| 2318 | __ lw(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2319 | __ lw(temp, FieldMemOperand(temp, |
| 2320 | SharedFunctionInfo::kInstanceClassNameOffset)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2321 | // The class name we are testing against is internalized since it's a literal. |
| 2322 | // The name in the constructor is internalized because of the way the context |
| 2323 | // 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] | 2324 | // 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] | 2325 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2326 | // identity comparison. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2327 | |
| 2328 | // End with the address of this class_name instance in temp register. |
| 2329 | // On MIPS, the caller must do the comparison with Handle<String>class_name. |
| 2330 | } |
| 2331 | |
| 2332 | |
| 2333 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2334 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2335 | Register temp = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2336 | Register temp2 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2337 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2338 | |
| 2339 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2340 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2341 | |
| 2342 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2343 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2344 | |
| 2345 | EmitClassOfTest(true_label, false_label, class_name, input, temp, temp2); |
| 2346 | |
| 2347 | EmitBranch(true_block, false_block, eq, temp, Operand(class_name)); |
| 2348 | } |
| 2349 | |
| 2350 | |
| 2351 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2352 | Register reg = ToRegister(instr->value()); |
| 2353 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2354 | int true_block = instr->true_block_id(); |
| 2355 | int false_block = instr->false_block_id(); |
| 2356 | |
| 2357 | __ lw(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2358 | EmitBranch(true_block, false_block, eq, temp, Operand(instr->map())); |
| 2359 | } |
| 2360 | |
| 2361 | |
| 2362 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
| 2363 | Label true_label, done; |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2364 | ASSERT(ToRegister(instr->left()).is(a0)); // Object is in a0. |
| 2365 | ASSERT(ToRegister(instr->right()).is(a1)); // Function is in a1. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2366 | Register result = ToRegister(instr->result()); |
| 2367 | ASSERT(result.is(v0)); |
| 2368 | |
| 2369 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2370 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2371 | |
| 2372 | __ Branch(&true_label, eq, result, Operand(zero_reg)); |
| 2373 | __ li(result, Operand(factory()->false_value())); |
| 2374 | __ Branch(&done); |
| 2375 | __ bind(&true_label); |
| 2376 | __ li(result, Operand(factory()->true_value())); |
| 2377 | __ bind(&done); |
| 2378 | } |
| 2379 | |
| 2380 | |
| 2381 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
| 2382 | class DeferredInstanceOfKnownGlobal: public LDeferredCode { |
| 2383 | public: |
| 2384 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2385 | LInstanceOfKnownGlobal* instr) |
| 2386 | : LDeferredCode(codegen), instr_(instr) { } |
| 2387 | virtual void Generate() { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2388 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2389 | } |
| 2390 | virtual LInstruction* instr() { return instr_; } |
| 2391 | Label* map_check() { return &map_check_; } |
| 2392 | |
| 2393 | private: |
| 2394 | LInstanceOfKnownGlobal* instr_; |
| 2395 | Label map_check_; |
| 2396 | }; |
| 2397 | |
| 2398 | DeferredInstanceOfKnownGlobal* deferred; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2399 | deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2400 | |
| 2401 | Label done, false_result; |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2402 | Register object = ToRegister(instr->value()); |
| 2403 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2404 | Register result = ToRegister(instr->result()); |
| 2405 | |
| 2406 | ASSERT(object.is(a0)); |
| 2407 | ASSERT(result.is(v0)); |
| 2408 | |
| 2409 | // A Smi is not instance of anything. |
| 2410 | __ JumpIfSmi(object, &false_result); |
| 2411 | |
| 2412 | // This is the inlined call site instanceof cache. The two occurences of the |
| 2413 | // hole value will be patched to the last map/result pair generated by the |
| 2414 | // instanceof stub. |
| 2415 | Label cache_miss; |
| 2416 | Register map = temp; |
| 2417 | __ lw(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2418 | |
| 2419 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 2420 | __ bind(deferred->map_check()); // Label for calculating code patching. |
| 2421 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2422 | // root array to force relocation to be able to later patch with |
| 2423 | // the cached map. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 2424 | Handle<JSGlobalPropertyCell> cell = |
| 2425 | factory()->NewJSGlobalPropertyCell(factory()->the_hole_value()); |
| 2426 | __ li(at, Operand(Handle<Object>(cell))); |
| 2427 | __ lw(at, FieldMemOperand(at, JSGlobalPropertyCell::kValueOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2428 | __ Branch(&cache_miss, ne, map, Operand(at)); |
| 2429 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2430 | // root array to force relocation to be able to later patch |
| 2431 | // with true or false. |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2432 | __ li(result, Operand(factory()->the_hole_value()), CONSTANT_SIZE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2433 | __ Branch(&done); |
| 2434 | |
| 2435 | // The inlined call site cache did not match. Check null and string before |
| 2436 | // calling the deferred code. |
| 2437 | __ bind(&cache_miss); |
| 2438 | // Null is not instance of anything. |
| 2439 | __ LoadRoot(temp, Heap::kNullValueRootIndex); |
| 2440 | __ Branch(&false_result, eq, object, Operand(temp)); |
| 2441 | |
| 2442 | // String values is not instance of anything. |
| 2443 | Condition cc = __ IsObjectStringType(object, temp, temp); |
| 2444 | __ Branch(&false_result, cc, temp, Operand(zero_reg)); |
| 2445 | |
| 2446 | // Go to the deferred code. |
| 2447 | __ Branch(deferred->entry()); |
| 2448 | |
| 2449 | __ bind(&false_result); |
| 2450 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 2451 | |
| 2452 | // Here result has either true or false. Deferred code also produces true or |
| 2453 | // false object. |
| 2454 | __ bind(deferred->exit()); |
| 2455 | __ bind(&done); |
| 2456 | } |
| 2457 | |
| 2458 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2459 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2460 | Label* map_check) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2461 | Register result = ToRegister(instr->result()); |
| 2462 | ASSERT(result.is(v0)); |
| 2463 | |
| 2464 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 2465 | flags = static_cast<InstanceofStub::Flags>( |
| 2466 | flags | InstanceofStub::kArgsInRegisters); |
| 2467 | flags = static_cast<InstanceofStub::Flags>( |
| 2468 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 2469 | flags = static_cast<InstanceofStub::Flags>( |
| 2470 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 2471 | InstanceofStub stub(flags); |
| 2472 | |
| 2473 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 2474 | |
| 2475 | // Get the temp register reserved by the instruction. This needs to be t0 as |
| 2476 | // its slot of the pushing of safepoint registers is used to communicate the |
| 2477 | // offset to the location of the map check. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2478 | Register temp = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2479 | ASSERT(temp.is(t0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2480 | __ LoadHeapObject(InstanceofStub::right(), instr->function()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2481 | static const int kAdditionalDelta = 7; |
| 2482 | int delta = masm_->InstructionsGeneratedSince(map_check) + kAdditionalDelta; |
| 2483 | Label before_push_delta; |
| 2484 | __ bind(&before_push_delta); |
| 2485 | { |
| 2486 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2487 | __ li(temp, Operand(delta * kPointerSize), CONSTANT_SIZE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2488 | __ StoreToSafepointRegisterSlot(temp, temp); |
| 2489 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2490 | CallCodeGeneric(stub.GetCode(isolate()), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2491 | RelocInfo::CODE_TARGET, |
| 2492 | instr, |
| 2493 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
danno@chromium.org | e4bfb26 | 2012-05-04 10:50:07 +0000 | [diff] [blame] | 2494 | LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2495 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2496 | // Put the result value into the result register slot and |
| 2497 | // restore all registers. |
| 2498 | __ StoreToSafepointRegisterSlot(result, result); |
| 2499 | } |
| 2500 | |
| 2501 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2502 | void LCodeGen::DoInstanceSize(LInstanceSize* instr) { |
| 2503 | Register object = ToRegister(instr->object()); |
| 2504 | Register result = ToRegister(instr->result()); |
| 2505 | __ lw(result, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2506 | __ lbu(result, FieldMemOperand(result, Map::kInstanceSizeOffset)); |
| 2507 | } |
| 2508 | |
| 2509 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2510 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 2511 | Token::Value op = instr->op(); |
| 2512 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2513 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2514 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2515 | // On MIPS there is no need for a "no inlined smi code" marker (nop). |
| 2516 | |
| 2517 | Condition condition = ComputeCompareCondition(op); |
| 2518 | // A minor optimization that relies on LoadRoot always emitting one |
| 2519 | // instruction. |
| 2520 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2521 | Label done, check; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2522 | __ Branch(USE_DELAY_SLOT, &done, condition, v0, Operand(zero_reg)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2523 | __ bind(&check); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2524 | __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2525 | ASSERT_EQ(1, masm()->InstructionsGeneratedSince(&check)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2526 | __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2527 | __ bind(&done); |
| 2528 | } |
| 2529 | |
| 2530 | |
| 2531 | void LCodeGen::DoReturn(LReturn* instr) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2532 | if (FLAG_trace && info()->IsOptimizing()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2533 | // Push the return value on the stack as the parameter. |
| 2534 | // Runtime::TraceExit returns its parameter in v0. |
| 2535 | __ push(v0); |
| 2536 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 2537 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2538 | if (info()->saves_caller_doubles()) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2539 | ASSERT(NeedsEagerFrame()); |
| 2540 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 2541 | BitVector::Iterator save_iterator(doubles); |
| 2542 | int count = 0; |
| 2543 | while (!save_iterator.Done()) { |
| 2544 | __ ldc1(DoubleRegister::FromAllocationIndex(save_iterator.Current()), |
| 2545 | MemOperand(sp, count * kDoubleSize)); |
| 2546 | save_iterator.Advance(); |
| 2547 | count++; |
| 2548 | } |
| 2549 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2550 | if (NeedsEagerFrame()) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2551 | __ mov(sp, fp); |
| 2552 | __ Pop(ra, fp); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2553 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2554 | if (instr->has_constant_parameter_count()) { |
| 2555 | int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 2556 | int32_t sp_delta = (parameter_count + 1) * kPointerSize; |
| 2557 | if (sp_delta != 0) { |
| 2558 | __ Addu(sp, sp, Operand(sp_delta)); |
| 2559 | } |
| 2560 | } else { |
| 2561 | Register reg = ToRegister(instr->parameter_count()); |
| 2562 | // The argument count parameter is a smi |
| 2563 | __ SmiUntag(reg); |
| 2564 | __ sll(at, reg, kPointerSizeLog2); |
| 2565 | __ Addu(sp, sp, at); |
| 2566 | } |
| 2567 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2568 | __ Jump(ra); |
| 2569 | } |
| 2570 | |
| 2571 | |
| 2572 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
| 2573 | Register result = ToRegister(instr->result()); |
| 2574 | __ li(at, Operand(Handle<Object>(instr->hydrogen()->cell()))); |
| 2575 | __ lw(result, FieldMemOperand(at, JSGlobalPropertyCell::kValueOffset)); |
| 2576 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2577 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 2578 | DeoptimizeIf(eq, instr->environment(), result, Operand(at)); |
| 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | |
| 2583 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
| 2584 | ASSERT(ToRegister(instr->global_object()).is(a0)); |
| 2585 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 2586 | |
| 2587 | __ li(a2, Operand(instr->name())); |
| 2588 | RelocInfo::Mode mode = instr->for_typeof() ? RelocInfo::CODE_TARGET |
| 2589 | : RelocInfo::CODE_TARGET_CONTEXT; |
| 2590 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2591 | CallCode(ic, mode, instr); |
| 2592 | } |
| 2593 | |
| 2594 | |
| 2595 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2596 | Register value = ToRegister(instr->value()); |
| 2597 | Register cell = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2598 | |
| 2599 | // Load the cell. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2600 | __ li(cell, Operand(instr->hydrogen()->cell())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2601 | |
| 2602 | // If the cell we are storing to contains the hole it could have |
| 2603 | // been deleted from the property dictionary. In that case, we need |
| 2604 | // to update the property details in the property dictionary to mark |
| 2605 | // it as no longer deleted. |
| 2606 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2607 | // We use a temp to check the payload. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2608 | Register payload = ToRegister(instr->temp()); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2609 | __ lw(payload, FieldMemOperand(cell, JSGlobalPropertyCell::kValueOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2610 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2611 | DeoptimizeIf(eq, instr->environment(), payload, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | // Store the value. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2615 | __ sw(value, FieldMemOperand(cell, JSGlobalPropertyCell::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2616 | // Cells are always rescanned, so no write barrier here. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | |
| 2620 | void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { |
| 2621 | ASSERT(ToRegister(instr->global_object()).is(a1)); |
| 2622 | ASSERT(ToRegister(instr->value()).is(a0)); |
| 2623 | |
| 2624 | __ li(a2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2625 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2626 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 2627 | : isolate()->builtins()->StoreIC_Initialize(); |
| 2628 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
| 2629 | } |
| 2630 | |
| 2631 | |
| 2632 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
| 2633 | Register context = ToRegister(instr->context()); |
| 2634 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2635 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2636 | __ lw(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2637 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2638 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2639 | |
| 2640 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2641 | DeoptimizeIf(eq, instr->environment(), result, Operand(at)); |
| 2642 | } else { |
| 2643 | Label is_not_hole; |
| 2644 | __ Branch(&is_not_hole, ne, result, Operand(at)); |
| 2645 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 2646 | __ bind(&is_not_hole); |
| 2647 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2648 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | |
| 2652 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 2653 | Register context = ToRegister(instr->context()); |
| 2654 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2655 | Register scratch = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2656 | MemOperand target = ContextOperand(context, instr->slot_index()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2657 | |
| 2658 | Label skip_assignment; |
| 2659 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2660 | if (instr->hydrogen()->RequiresHoleCheck()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2661 | __ lw(scratch, target); |
| 2662 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2663 | |
| 2664 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2665 | DeoptimizeIf(eq, instr->environment(), scratch, Operand(at)); |
| 2666 | } else { |
| 2667 | __ Branch(&skip_assignment, ne, scratch, Operand(at)); |
| 2668 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2669 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2670 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2671 | __ sw(value, target); |
| 2672 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 2673 | HType type = instr->hydrogen()->value()->type(); |
| 2674 | SmiCheck check_needed = |
| 2675 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
| 2676 | __ RecordWriteContextSlot(context, |
| 2677 | target.offset(), |
| 2678 | value, |
| 2679 | scratch0(), |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 2680 | GetRAState(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2681 | kSaveFPRegs, |
| 2682 | EMIT_REMEMBERED_SET, |
| 2683 | check_needed); |
| 2684 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 2685 | |
| 2686 | __ bind(&skip_assignment); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | |
| 2690 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 2691 | int offset = instr->hydrogen()->offset(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2692 | Register object = ToRegister(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 2693 | if (instr->hydrogen()->representation().IsDouble()) { |
| 2694 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 2695 | __ ldc1(result, FieldMemOperand(object, offset)); |
| 2696 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 2699 | Register result = ToRegister(instr->result()); |
| 2700 | if (instr->hydrogen()->is_in_object()) { |
| 2701 | __ lw(result, FieldMemOperand(object, offset)); |
| 2702 | } else { |
| 2703 | __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 2704 | __ lw(result, FieldMemOperand(result, offset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | |
| 2709 | void LCodeGen::EmitLoadFieldOrConstantFunction(Register result, |
| 2710 | Register object, |
| 2711 | Handle<Map> type, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2712 | Handle<String> name, |
| 2713 | LEnvironment* env) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2714 | LookupResult lookup(isolate()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2715 | type->LookupDescriptor(NULL, *name, &lookup); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2716 | ASSERT(lookup.IsFound() || lookup.IsCacheable()); |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 2717 | if (lookup.IsField()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2718 | int index = lookup.GetLocalFieldIndexFromMap(*type); |
| 2719 | int offset = index * kPointerSize; |
| 2720 | if (index < 0) { |
| 2721 | // Negative property indices are in-object properties, indexed |
| 2722 | // from the end of the fixed part of the object. |
| 2723 | __ lw(result, FieldMemOperand(object, offset + type->instance_size())); |
| 2724 | } else { |
| 2725 | // Non-negative property indices are in the properties array. |
| 2726 | __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 2727 | __ lw(result, FieldMemOperand(result, offset + FixedArray::kHeaderSize)); |
| 2728 | } |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 2729 | } else if (lookup.IsConstantFunction()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2730 | Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*type)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2731 | __ LoadHeapObject(result, function); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2732 | } else { |
| 2733 | // Negative lookup. |
| 2734 | // Check prototypes. |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 2735 | Handle<HeapObject> current(HeapObject::cast((*type)->prototype())); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2736 | Heap* heap = type->GetHeap(); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 2737 | while (*current != heap->null_value()) { |
| 2738 | __ LoadHeapObject(result, current); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2739 | __ lw(result, FieldMemOperand(result, HeapObject::kMapOffset)); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 2740 | DeoptimizeIf(ne, env, result, Operand(Handle<Map>(current->map()))); |
| 2741 | current = |
| 2742 | Handle<HeapObject>(HeapObject::cast(current->map()->prototype())); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2743 | } |
| 2744 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | |
| 2749 | void LCodeGen::DoLoadNamedFieldPolymorphic(LLoadNamedFieldPolymorphic* instr) { |
| 2750 | Register object = ToRegister(instr->object()); |
| 2751 | Register result = ToRegister(instr->result()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2752 | Register object_map = scratch0(); |
yangguo@chromium.org | 5f0b8ea | 2012-05-16 12:37:04 +0000 | [diff] [blame] | 2753 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2754 | int map_count = instr->hydrogen()->types()->length(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2755 | bool need_generic = instr->hydrogen()->need_generic(); |
| 2756 | |
| 2757 | if (map_count == 0 && !need_generic) { |
| 2758 | DeoptimizeIf(al, instr->environment()); |
| 2759 | return; |
| 2760 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2761 | Handle<String> name = instr->hydrogen()->name(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2762 | Label done; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2763 | __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2764 | for (int i = 0; i < map_count; ++i) { |
| 2765 | bool last = (i == map_count - 1); |
| 2766 | Handle<Map> map = instr->hydrogen()->types()->at(i); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2767 | Label check_passed; |
| 2768 | __ CompareMapAndBranch( |
| 2769 | object_map, map, &check_passed, |
| 2770 | eq, &check_passed, ALLOW_ELEMENT_TRANSITION_MAPS); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2771 | if (last && !need_generic) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2772 | DeoptimizeIf(al, instr->environment()); |
| 2773 | __ bind(&check_passed); |
| 2774 | EmitLoadFieldOrConstantFunction( |
| 2775 | result, object, map, name, instr->environment()); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2776 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2777 | Label next; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2778 | __ Branch(&next); |
| 2779 | __ bind(&check_passed); |
| 2780 | EmitLoadFieldOrConstantFunction( |
| 2781 | result, object, map, name, instr->environment()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2782 | __ Branch(&done); |
| 2783 | __ bind(&next); |
| 2784 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2785 | } |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2786 | if (need_generic) { |
| 2787 | __ li(a2, Operand(name)); |
| 2788 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2789 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2790 | } |
| 2791 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | |
| 2795 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
| 2796 | ASSERT(ToRegister(instr->object()).is(a0)); |
| 2797 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 2798 | |
| 2799 | // Name is always in a2. |
| 2800 | __ li(a2, Operand(instr->name())); |
| 2801 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2802 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2803 | } |
| 2804 | |
| 2805 | |
| 2806 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
| 2807 | Register scratch = scratch0(); |
| 2808 | Register function = ToRegister(instr->function()); |
| 2809 | Register result = ToRegister(instr->result()); |
| 2810 | |
| 2811 | // Check that the function really is a function. Load map into the |
| 2812 | // result register. |
| 2813 | __ GetObjectType(function, result, scratch); |
| 2814 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(JS_FUNCTION_TYPE)); |
| 2815 | |
| 2816 | // Make sure that the function has an instance prototype. |
| 2817 | Label non_instance; |
| 2818 | __ lbu(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 2819 | __ And(scratch, scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 2820 | __ Branch(&non_instance, ne, scratch, Operand(zero_reg)); |
| 2821 | |
| 2822 | // Get the prototype or initial map from the function. |
| 2823 | __ lw(result, |
| 2824 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2825 | |
| 2826 | // Check that the function has a prototype or an initial map. |
| 2827 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 2828 | DeoptimizeIf(eq, instr->environment(), result, Operand(at)); |
| 2829 | |
| 2830 | // If the function does not have an initial map, we're done. |
| 2831 | Label done; |
| 2832 | __ GetObjectType(result, scratch, scratch); |
| 2833 | __ Branch(&done, ne, scratch, Operand(MAP_TYPE)); |
| 2834 | |
| 2835 | // Get the prototype from the initial map. |
| 2836 | __ lw(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 2837 | __ Branch(&done); |
| 2838 | |
| 2839 | // Non-instance prototype: Fetch prototype from constructor field |
| 2840 | // in initial map. |
| 2841 | __ bind(&non_instance); |
| 2842 | __ lw(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 2843 | |
| 2844 | // All done. |
| 2845 | __ bind(&done); |
| 2846 | } |
| 2847 | |
| 2848 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2849 | void LCodeGen::DoLoadExternalArrayPointer( |
| 2850 | LLoadExternalArrayPointer* instr) { |
| 2851 | Register to_reg = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2852 | Register from_reg = ToRegister(instr->object()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2853 | __ lw(to_reg, FieldMemOperand(from_reg, |
| 2854 | ExternalArray::kExternalPointerOffset)); |
| 2855 | } |
| 2856 | |
| 2857 | |
| 2858 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
| 2859 | Register arguments = ToRegister(instr->arguments()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2860 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2861 | if (instr->length()->IsConstantOperand() && |
| 2862 | instr->index()->IsConstantOperand()) { |
| 2863 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 2864 | int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 2865 | int index = (const_length - const_index) + 1; |
| 2866 | __ lw(result, MemOperand(arguments, index * kPointerSize)); |
| 2867 | } else { |
| 2868 | Register length = ToRegister(instr->length()); |
| 2869 | Register index = ToRegister(instr->index()); |
| 2870 | // There are two words between the frame pointer and the last argument. |
| 2871 | // Subtracting from length accounts for one of them, add one more. |
| 2872 | __ subu(length, length, index); |
| 2873 | __ Addu(length, length, Operand(1)); |
| 2874 | __ sll(length, length, kPointerSizeLog2); |
| 2875 | __ Addu(at, arguments, Operand(length)); |
| 2876 | __ lw(result, MemOperand(at, 0)); |
| 2877 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2881 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
| 2882 | Register external_pointer = ToRegister(instr->elements()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2883 | Register key = no_reg; |
| 2884 | ElementsKind elements_kind = instr->elements_kind(); |
| 2885 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 2886 | int constant_key = 0; |
| 2887 | if (key_is_constant) { |
| 2888 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 2889 | if (constant_key & 0xF0000000) { |
| 2890 | Abort("array index constant value too big."); |
| 2891 | } |
| 2892 | } else { |
| 2893 | key = ToRegister(instr->key()); |
| 2894 | } |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 2895 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 2896 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 2897 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 2898 | int additional_offset = instr->additional_index() << element_size_shift; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2899 | |
| 2900 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 2901 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
| 2902 | FPURegister result = ToDoubleRegister(instr->result()); |
| 2903 | if (key_is_constant) { |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 2904 | __ Addu(scratch0(), external_pointer, constant_key << element_size_shift); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2905 | } else { |
| 2906 | __ sll(scratch0(), key, shift_size); |
| 2907 | __ Addu(scratch0(), scratch0(), external_pointer); |
| 2908 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2909 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
| 2910 | __ lwc1(result, MemOperand(scratch0(), additional_offset)); |
| 2911 | __ cvt_d_s(result, result); |
| 2912 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
| 2913 | __ ldc1(result, MemOperand(scratch0(), additional_offset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2914 | } |
| 2915 | } else { |
| 2916 | Register result = ToRegister(instr->result()); |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 2917 | MemOperand mem_operand = PrepareKeyedOperand( |
| 2918 | key, external_pointer, key_is_constant, constant_key, |
| 2919 | element_size_shift, shift_size, |
| 2920 | instr->additional_index(), additional_offset); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2921 | switch (elements_kind) { |
| 2922 | case EXTERNAL_BYTE_ELEMENTS: |
| 2923 | __ lb(result, mem_operand); |
| 2924 | break; |
| 2925 | case EXTERNAL_PIXEL_ELEMENTS: |
| 2926 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 2927 | __ lbu(result, mem_operand); |
| 2928 | break; |
| 2929 | case EXTERNAL_SHORT_ELEMENTS: |
| 2930 | __ lh(result, mem_operand); |
| 2931 | break; |
| 2932 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 2933 | __ lhu(result, mem_operand); |
| 2934 | break; |
| 2935 | case EXTERNAL_INT_ELEMENTS: |
| 2936 | __ lw(result, mem_operand); |
| 2937 | break; |
| 2938 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 2939 | __ lw(result, mem_operand); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 2940 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 2941 | DeoptimizeIf(Ugreater_equal, instr->environment(), |
| 2942 | result, Operand(0x80000000)); |
| 2943 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2944 | break; |
| 2945 | case EXTERNAL_FLOAT_ELEMENTS: |
| 2946 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 2947 | case FAST_DOUBLE_ELEMENTS: |
| 2948 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2949 | case FAST_SMI_ELEMENTS: |
| 2950 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 2951 | case FAST_HOLEY_ELEMENTS: |
| 2952 | case FAST_HOLEY_SMI_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2953 | case DICTIONARY_ELEMENTS: |
| 2954 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
| 2955 | UNREACHABLE(); |
| 2956 | break; |
| 2957 | } |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2962 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
| 2963 | Register elements = ToRegister(instr->elements()); |
| 2964 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 2965 | Register key = no_reg; |
| 2966 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 2967 | Register scratch = scratch0(); |
| 2968 | |
| 2969 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 2970 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 2971 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 2972 | int constant_key = 0; |
| 2973 | if (key_is_constant) { |
| 2974 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 2975 | if (constant_key & 0xF0000000) { |
| 2976 | Abort("array index constant value too big."); |
| 2977 | } |
| 2978 | } else { |
| 2979 | key = ToRegister(instr->key()); |
| 2980 | } |
| 2981 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2982 | int base_offset = (FixedDoubleArray::kHeaderSize - kHeapObjectTag) + |
| 2983 | ((constant_key + instr->additional_index()) << element_size_shift); |
| 2984 | if (!key_is_constant) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2985 | __ sll(scratch, key, shift_size); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2986 | __ Addu(elements, elements, scratch); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2987 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2988 | __ Addu(elements, elements, Operand(base_offset)); |
| 2989 | __ ldc1(result, MemOperand(elements)); |
| 2990 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2991 | __ lw(scratch, MemOperand(elements, sizeof(kHoleNanLower32))); |
| 2992 | DeoptimizeIf(eq, instr->environment(), scratch, Operand(kHoleNanUpper32)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2993 | } |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | |
| 2997 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 2998 | Register elements = ToRegister(instr->elements()); |
| 2999 | Register result = ToRegister(instr->result()); |
| 3000 | Register scratch = scratch0(); |
| 3001 | Register store_base = scratch; |
| 3002 | int offset = 0; |
| 3003 | |
| 3004 | if (instr->key()->IsConstantOperand()) { |
| 3005 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 3006 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 3007 | instr->additional_index()); |
| 3008 | store_base = elements; |
| 3009 | } else { |
| 3010 | Register key = EmitLoadRegister(instr->key(), scratch0()); |
| 3011 | // Even though the HLoadKeyed instruction forces the input |
| 3012 | // representation for the key to be an integer, the input gets replaced |
| 3013 | // during bound check elimination with the index argument to the bounds |
| 3014 | // check, which can be tagged, so that case must be handled here, too. |
| 3015 | if (instr->hydrogen()->key()->representation().IsTagged()) { |
| 3016 | __ sll(scratch, key, kPointerSizeLog2 - kSmiTagSize); |
| 3017 | __ addu(scratch, elements, scratch); |
| 3018 | } else { |
| 3019 | __ sll(scratch, key, kPointerSizeLog2); |
| 3020 | __ addu(scratch, elements, scratch); |
| 3021 | } |
| 3022 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 3023 | } |
| 3024 | __ lw(result, FieldMemOperand(store_base, offset)); |
| 3025 | |
| 3026 | // Check for the hole value. |
| 3027 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3028 | if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { |
| 3029 | __ And(scratch, result, Operand(kSmiTagMask)); |
| 3030 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg)); |
| 3031 | } else { |
| 3032 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 3033 | DeoptimizeIf(eq, instr->environment(), result, Operand(scratch)); |
| 3034 | } |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | |
| 3039 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
| 3040 | if (instr->is_external()) { |
| 3041 | DoLoadKeyedExternalArray(instr); |
| 3042 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3043 | DoLoadKeyedFixedDoubleArray(instr); |
| 3044 | } else { |
| 3045 | DoLoadKeyedFixedArray(instr); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | |
| 3050 | MemOperand LCodeGen::PrepareKeyedOperand(Register key, |
| 3051 | Register base, |
| 3052 | bool key_is_constant, |
| 3053 | int constant_key, |
| 3054 | int element_size, |
| 3055 | int shift_size, |
| 3056 | int additional_index, |
| 3057 | int additional_offset) { |
| 3058 | if (additional_index != 0 && !key_is_constant) { |
| 3059 | additional_index *= 1 << (element_size - shift_size); |
| 3060 | __ Addu(scratch0(), key, Operand(additional_index)); |
| 3061 | } |
| 3062 | |
| 3063 | if (key_is_constant) { |
| 3064 | return MemOperand(base, |
| 3065 | (constant_key << element_size) + additional_offset); |
| 3066 | } |
| 3067 | |
| 3068 | if (additional_index == 0) { |
| 3069 | if (shift_size >= 0) { |
| 3070 | __ sll(scratch0(), key, shift_size); |
| 3071 | __ Addu(scratch0(), base, scratch0()); |
| 3072 | return MemOperand(scratch0()); |
| 3073 | } else { |
| 3074 | ASSERT_EQ(-1, shift_size); |
| 3075 | __ srl(scratch0(), key, 1); |
| 3076 | __ Addu(scratch0(), base, scratch0()); |
| 3077 | return MemOperand(scratch0()); |
| 3078 | } |
| 3079 | } |
| 3080 | |
| 3081 | if (shift_size >= 0) { |
| 3082 | __ sll(scratch0(), scratch0(), shift_size); |
| 3083 | __ Addu(scratch0(), base, scratch0()); |
| 3084 | return MemOperand(scratch0()); |
| 3085 | } else { |
| 3086 | ASSERT_EQ(-1, shift_size); |
| 3087 | __ srl(scratch0(), scratch0(), 1); |
| 3088 | __ Addu(scratch0(), base, scratch0()); |
| 3089 | return MemOperand(scratch0()); |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3094 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
| 3095 | ASSERT(ToRegister(instr->object()).is(a1)); |
| 3096 | ASSERT(ToRegister(instr->key()).is(a0)); |
| 3097 | |
| 3098 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
| 3099 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3100 | } |
| 3101 | |
| 3102 | |
| 3103 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
| 3104 | Register scratch = scratch0(); |
| 3105 | Register temp = scratch1(); |
| 3106 | Register result = ToRegister(instr->result()); |
| 3107 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3108 | if (instr->hydrogen()->from_inlined()) { |
| 3109 | __ Subu(result, sp, 2 * kPointerSize); |
| 3110 | } else { |
| 3111 | // Check if the calling frame is an arguments adaptor frame. |
| 3112 | Label done, adapted; |
| 3113 | __ lw(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3114 | __ lw(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 3115 | __ Xor(temp, result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3116 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3117 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3118 | // frame below the adaptor frame if adapted. |
| 3119 | __ Movn(result, fp, temp); // Move only if temp is not equal to zero (ne). |
| 3120 | __ Movz(result, scratch, temp); // Move only if temp is equal to zero (eq). |
| 3121 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | |
| 3125 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3126 | Register elem = ToRegister(instr->elements()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3127 | Register result = ToRegister(instr->result()); |
| 3128 | |
| 3129 | Label done; |
| 3130 | |
| 3131 | // If no arguments adaptor frame the number of arguments is fixed. |
| 3132 | __ Addu(result, zero_reg, Operand(scope()->num_parameters())); |
| 3133 | __ Branch(&done, eq, fp, Operand(elem)); |
| 3134 | |
| 3135 | // Arguments adaptor frame present. Get argument length from there. |
| 3136 | __ lw(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3137 | __ lw(result, |
| 3138 | MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3139 | __ SmiUntag(result); |
| 3140 | |
| 3141 | // Argument length is in result register. |
| 3142 | __ bind(&done); |
| 3143 | } |
| 3144 | |
| 3145 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3146 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3147 | Register receiver = ToRegister(instr->receiver()); |
| 3148 | Register function = ToRegister(instr->function()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3149 | Register scratch = scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3150 | |
| 3151 | // If the receiver is null or undefined, we have to pass the global |
| 3152 | // object as a receiver to normal functions. Values have to be |
| 3153 | // passed unchanged to builtins and strict-mode functions. |
| 3154 | Label global_object, receiver_ok; |
| 3155 | |
| 3156 | // Do not transform the receiver to object for strict mode |
| 3157 | // functions. |
| 3158 | __ lw(scratch, |
| 3159 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3160 | __ lw(scratch, |
| 3161 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 3162 | |
| 3163 | // Do not transform the receiver to object for builtins. |
| 3164 | int32_t strict_mode_function_mask = |
| 3165 | 1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize); |
| 3166 | int32_t native_mask = 1 << (SharedFunctionInfo::kNative + kSmiTagSize); |
| 3167 | __ And(scratch, scratch, Operand(strict_mode_function_mask | native_mask)); |
| 3168 | __ Branch(&receiver_ok, ne, scratch, Operand(zero_reg)); |
| 3169 | |
| 3170 | // Normal function. Replace undefined or null with global receiver. |
| 3171 | __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
| 3172 | __ Branch(&global_object, eq, receiver, Operand(scratch)); |
| 3173 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 3174 | __ Branch(&global_object, eq, receiver, Operand(scratch)); |
| 3175 | |
| 3176 | // Deoptimize if the receiver is not a JS object. |
| 3177 | __ And(scratch, receiver, Operand(kSmiTagMask)); |
| 3178 | DeoptimizeIf(eq, instr->environment(), scratch, Operand(zero_reg)); |
| 3179 | |
| 3180 | __ GetObjectType(receiver, scratch, scratch); |
| 3181 | DeoptimizeIf(lt, instr->environment(), |
| 3182 | scratch, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 3183 | __ Branch(&receiver_ok); |
| 3184 | |
| 3185 | __ bind(&global_object); |
| 3186 | __ lw(receiver, GlobalObjectOperand()); |
| 3187 | __ lw(receiver, |
| 3188 | FieldMemOperand(receiver, JSGlobalObject::kGlobalReceiverOffset)); |
| 3189 | __ bind(&receiver_ok); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3193 | Register receiver = ToRegister(instr->receiver()); |
| 3194 | Register function = ToRegister(instr->function()); |
| 3195 | Register length = ToRegister(instr->length()); |
| 3196 | Register elements = ToRegister(instr->elements()); |
| 3197 | Register scratch = scratch0(); |
| 3198 | ASSERT(receiver.is(a0)); // Used for parameter count. |
| 3199 | ASSERT(function.is(a1)); // Required by InvokeFunction. |
| 3200 | ASSERT(ToRegister(instr->result()).is(v0)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3201 | |
| 3202 | // Copy the arguments to this function possibly from the |
| 3203 | // adaptor frame below it. |
| 3204 | const uint32_t kArgumentsLimit = 1 * KB; |
| 3205 | DeoptimizeIf(hi, instr->environment(), length, Operand(kArgumentsLimit)); |
| 3206 | |
| 3207 | // Push the receiver and use the register to keep the original |
| 3208 | // number of arguments. |
| 3209 | __ push(receiver); |
| 3210 | __ Move(receiver, length); |
| 3211 | // The arguments are at a one pointer size offset from elements. |
| 3212 | __ Addu(elements, elements, Operand(1 * kPointerSize)); |
| 3213 | |
| 3214 | // Loop through the arguments pushing them onto the execution |
| 3215 | // stack. |
| 3216 | Label invoke, loop; |
| 3217 | // length is a small non-negative integer, due to the test above. |
| 3218 | __ Branch(USE_DELAY_SLOT, &invoke, eq, length, Operand(zero_reg)); |
| 3219 | __ sll(scratch, length, 2); |
| 3220 | __ bind(&loop); |
| 3221 | __ Addu(scratch, elements, scratch); |
| 3222 | __ lw(scratch, MemOperand(scratch)); |
| 3223 | __ push(scratch); |
| 3224 | __ Subu(length, length, Operand(1)); |
| 3225 | __ Branch(USE_DELAY_SLOT, &loop, ne, length, Operand(zero_reg)); |
| 3226 | __ sll(scratch, length, 2); |
| 3227 | |
| 3228 | __ bind(&invoke); |
danno@chromium.org | e4bfb26 | 2012-05-04 10:50:07 +0000 | [diff] [blame] | 3229 | ASSERT(instr->HasPointerMap()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3230 | LPointerMap* pointers = instr->pointer_map(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3231 | RecordPosition(pointers->position()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3232 | SafepointGenerator safepoint_generator( |
| 3233 | this, pointers, Safepoint::kLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3234 | // The number of arguments is stored in receiver which is a0, as expected |
| 3235 | // by InvokeFunction. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3236 | ParameterCount actual(receiver); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3237 | __ InvokeFunction(function, actual, CALL_FUNCTION, |
| 3238 | safepoint_generator, CALL_AS_METHOD); |
| 3239 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3240 | } |
| 3241 | |
| 3242 | |
| 3243 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3244 | LOperand* argument = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3245 | if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
| 3246 | Abort("DoPushArgument not implemented for double type."); |
| 3247 | } else { |
| 3248 | Register argument_reg = EmitLoadRegister(argument, at); |
| 3249 | __ push(argument_reg); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3254 | void LCodeGen::DoDrop(LDrop* instr) { |
| 3255 | __ Drop(instr->count()); |
| 3256 | } |
| 3257 | |
| 3258 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3259 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3260 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3261 | __ lw(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | |
| 3265 | void LCodeGen::DoContext(LContext* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3266 | // 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] | 3267 | Register result = ToRegister(instr->result()); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3268 | for (HUseIterator it(instr->hydrogen()->uses()); !it.Done(); it.Advance()) { |
| 3269 | if (!it.value()->IsReturn()) { |
| 3270 | __ mov(result, cp); |
| 3271 | return; |
| 3272 | } |
| 3273 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | |
| 3277 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 3278 | Register context = ToRegister(instr->context()); |
| 3279 | Register result = ToRegister(instr->result()); |
| 3280 | __ lw(result, |
| 3281 | MemOperand(context, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
| 3282 | } |
| 3283 | |
| 3284 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3285 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
| 3286 | __ LoadHeapObject(scratch0(), instr->hydrogen()->pairs()); |
| 3287 | __ li(scratch1(), Operand(Smi::FromInt(instr->hydrogen()->flags()))); |
| 3288 | // The context is the first argument. |
| 3289 | __ Push(cp, scratch0(), scratch1()); |
| 3290 | CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
| 3291 | } |
| 3292 | |
| 3293 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3294 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3295 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3296 | __ lw(result, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | |
| 3300 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3301 | Register global = ToRegister(instr->global_object()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3302 | Register result = ToRegister(instr->result()); |
| 3303 | __ lw(result, FieldMemOperand(global, GlobalObject::kGlobalReceiverOffset)); |
| 3304 | } |
| 3305 | |
| 3306 | |
| 3307 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3308 | int formal_parameter_count, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3309 | int arity, |
| 3310 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3311 | CallKind call_kind, |
| 3312 | A1State a1_state) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3313 | bool dont_adapt_arguments = |
| 3314 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3315 | bool can_invoke_directly = |
| 3316 | dont_adapt_arguments || formal_parameter_count == arity; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3317 | |
| 3318 | LPointerMap* pointers = instr->pointer_map(); |
| 3319 | RecordPosition(pointers->position()); |
| 3320 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3321 | if (can_invoke_directly) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3322 | if (a1_state == A1_UNINITIALIZED) { |
| 3323 | __ LoadHeapObject(a1, function); |
| 3324 | } |
| 3325 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3326 | // Change context. |
| 3327 | __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3328 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3329 | // Set r0 to arguments count if adaption is not needed. Assumes that r0 |
| 3330 | // is available to write to at this point. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3331 | if (dont_adapt_arguments) { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3332 | __ li(a0, Operand(arity)); |
| 3333 | } |
| 3334 | |
| 3335 | // Invoke function. |
| 3336 | __ SetCallKind(t1, call_kind); |
| 3337 | __ lw(at, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
| 3338 | __ Call(at); |
| 3339 | |
| 3340 | // Set up deoptimization. |
| 3341 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3342 | } else { |
| 3343 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3344 | ParameterCount count(arity); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3345 | ParameterCount expected(formal_parameter_count); |
| 3346 | __ InvokeFunction( |
| 3347 | function, expected, count, CALL_FUNCTION, generator, call_kind); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3348 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3349 | |
| 3350 | // Restore context. |
| 3351 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3352 | } |
| 3353 | |
| 3354 | |
| 3355 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
| 3356 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3357 | __ mov(a0, v0); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3358 | CallKnownFunction(instr->hydrogen()->function(), |
| 3359 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3360 | instr->arity(), |
| 3361 | instr, |
| 3362 | CALL_AS_METHOD, |
| 3363 | A1_UNINITIALIZED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3367 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3368 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3369 | Register result = ToRegister(instr->result()); |
| 3370 | Register scratch = scratch0(); |
| 3371 | |
| 3372 | // Deoptimize if not a heap number. |
| 3373 | __ lw(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3374 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 3375 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(at)); |
| 3376 | |
| 3377 | Label done; |
| 3378 | Register exponent = scratch0(); |
| 3379 | scratch = no_reg; |
| 3380 | __ lw(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3381 | // Check the sign of the argument. If the argument is positive, just |
| 3382 | // return it. |
| 3383 | __ Move(result, input); |
| 3384 | __ And(at, exponent, Operand(HeapNumber::kSignMask)); |
| 3385 | __ Branch(&done, eq, at, Operand(zero_reg)); |
| 3386 | |
| 3387 | // Input is negative. Reverse its sign. |
| 3388 | // Preserve the value of all registers. |
| 3389 | { |
| 3390 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 3391 | |
| 3392 | // Registers were saved at the safepoint, so we can use |
| 3393 | // many scratch registers. |
| 3394 | Register tmp1 = input.is(a1) ? a0 : a1; |
| 3395 | Register tmp2 = input.is(a2) ? a0 : a2; |
| 3396 | Register tmp3 = input.is(a3) ? a0 : a3; |
| 3397 | Register tmp4 = input.is(t0) ? a0 : t0; |
| 3398 | |
| 3399 | // exponent: floating point exponent value. |
| 3400 | |
| 3401 | Label allocated, slow; |
| 3402 | __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 3403 | __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
| 3404 | __ Branch(&allocated); |
| 3405 | |
| 3406 | // Slow case: Call the runtime system to do the number allocation. |
| 3407 | __ bind(&slow); |
| 3408 | |
| 3409 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
| 3410 | // Set the pointer to the new heap number in tmp. |
| 3411 | if (!tmp1.is(v0)) |
| 3412 | __ mov(tmp1, v0); |
| 3413 | // Restore input_reg after call to runtime. |
| 3414 | __ LoadFromSafepointRegisterSlot(input, input); |
| 3415 | __ lw(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3416 | |
| 3417 | __ bind(&allocated); |
| 3418 | // exponent: floating point exponent value. |
| 3419 | // tmp1: allocated heap number. |
| 3420 | __ And(exponent, exponent, Operand(~HeapNumber::kSignMask)); |
| 3421 | __ sw(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
| 3422 | __ lw(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3423 | __ sw(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
| 3424 | |
| 3425 | __ StoreToSafepointRegisterSlot(tmp1, result); |
| 3426 | } |
| 3427 | |
| 3428 | __ bind(&done); |
| 3429 | } |
| 3430 | |
| 3431 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3432 | void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3433 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3434 | Register result = ToRegister(instr->result()); |
| 3435 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); |
| 3436 | Label done; |
| 3437 | __ Branch(USE_DELAY_SLOT, &done, ge, input, Operand(zero_reg)); |
| 3438 | __ mov(result, input); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3439 | // Overflow if result is still negative, i.e. 0x80000000. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3440 | DeoptimizeIf(lt, instr->environment(), result, Operand(zero_reg)); |
| 3441 | __ bind(&done); |
| 3442 | } |
| 3443 | |
| 3444 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3445 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3446 | // Class for deferred case. |
| 3447 | class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { |
| 3448 | public: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3449 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3450 | : LDeferredCode(codegen), instr_(instr) { } |
| 3451 | virtual void Generate() { |
| 3452 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3453 | } |
| 3454 | virtual LInstruction* instr() { return instr_; } |
| 3455 | private: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3456 | LMathAbs* instr_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3457 | }; |
| 3458 | |
| 3459 | Representation r = instr->hydrogen()->value()->representation(); |
| 3460 | if (r.IsDouble()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3461 | FPURegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3462 | FPURegister result = ToDoubleRegister(instr->result()); |
| 3463 | __ abs_d(result, input); |
| 3464 | } else if (r.IsInteger32()) { |
| 3465 | EmitIntegerMathAbs(instr); |
| 3466 | } else { |
| 3467 | // Representation is tagged. |
| 3468 | DeferredMathAbsTaggedHeapNumber* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3469 | new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3470 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3471 | // Smi check. |
| 3472 | __ JumpIfNotSmi(input, deferred->entry()); |
| 3473 | // If smi, handle it directly. |
| 3474 | EmitIntegerMathAbs(instr); |
| 3475 | __ bind(deferred->exit()); |
| 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3480 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3481 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3482 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3483 | Register scratch1 = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3484 | Register except_flag = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3485 | |
| 3486 | __ EmitFPUTruncate(kRoundToMinusInf, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3487 | result, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3488 | input, |
| 3489 | scratch1, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3490 | double_scratch0(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3491 | except_flag); |
| 3492 | |
| 3493 | // Deopt if the operation did not succeed. |
| 3494 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
| 3495 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3496 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3497 | // Test for -0. |
| 3498 | Label done; |
| 3499 | __ Branch(&done, ne, result, Operand(zero_reg)); |
| 3500 | __ mfc1(scratch1, input.high()); |
| 3501 | __ And(scratch1, scratch1, Operand(HeapNumber::kSignMask)); |
| 3502 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(zero_reg)); |
| 3503 | __ bind(&done); |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3508 | void LCodeGen::DoMathRound(LMathRound* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3509 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3510 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3511 | DoubleRegister double_scratch1 = ToDoubleRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3512 | Register scratch = scratch0(); |
| 3513 | Label done, check_sign_on_zero; |
| 3514 | |
| 3515 | // Extract exponent bits. |
| 3516 | __ mfc1(result, input.high()); |
| 3517 | __ Ext(scratch, |
| 3518 | result, |
| 3519 | HeapNumber::kExponentShift, |
| 3520 | HeapNumber::kExponentBits); |
| 3521 | |
| 3522 | // If the number is in ]-0.5, +0.5[, the result is +/- 0. |
| 3523 | Label skip1; |
| 3524 | __ Branch(&skip1, gt, scratch, Operand(HeapNumber::kExponentBias - 2)); |
| 3525 | __ mov(result, zero_reg); |
| 3526 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3527 | __ Branch(&check_sign_on_zero); |
| 3528 | } else { |
| 3529 | __ Branch(&done); |
| 3530 | } |
| 3531 | __ bind(&skip1); |
| 3532 | |
| 3533 | // The following conversion will not work with numbers |
| 3534 | // outside of ]-2^32, 2^32[. |
| 3535 | DeoptimizeIf(ge, instr->environment(), scratch, |
| 3536 | Operand(HeapNumber::kExponentBias + 32)); |
| 3537 | |
| 3538 | // Save the original sign for later comparison. |
| 3539 | __ And(scratch, result, Operand(HeapNumber::kSignMask)); |
| 3540 | |
| 3541 | __ Move(double_scratch0(), 0.5); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3542 | __ add_d(double_scratch0(), input, double_scratch0()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3543 | |
| 3544 | // Check sign of the result: if the sign changed, the input |
| 3545 | // 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] | 3546 | __ mfc1(result, double_scratch0().high()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3547 | __ Xor(result, result, Operand(scratch)); |
| 3548 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3549 | // ARM uses 'mi' here, which is 'lt' |
| 3550 | DeoptimizeIf(lt, instr->environment(), result, |
| 3551 | Operand(zero_reg)); |
| 3552 | } else { |
| 3553 | Label skip2; |
| 3554 | // ARM uses 'mi' here, which is 'lt' |
| 3555 | // Negating it results in 'ge' |
| 3556 | __ Branch(&skip2, ge, result, Operand(zero_reg)); |
| 3557 | __ mov(result, zero_reg); |
| 3558 | __ Branch(&done); |
| 3559 | __ bind(&skip2); |
| 3560 | } |
| 3561 | |
| 3562 | Register except_flag = scratch; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3563 | __ EmitFPUTruncate(kRoundToMinusInf, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3564 | result, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3565 | double_scratch0(), |
| 3566 | at, |
| 3567 | double_scratch1, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3568 | except_flag); |
| 3569 | |
| 3570 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
| 3571 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3572 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3573 | // Test for -0. |
| 3574 | __ Branch(&done, ne, result, Operand(zero_reg)); |
| 3575 | __ bind(&check_sign_on_zero); |
| 3576 | __ mfc1(scratch, input.high()); |
| 3577 | __ And(scratch, scratch, Operand(HeapNumber::kSignMask)); |
| 3578 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg)); |
| 3579 | } |
| 3580 | __ bind(&done); |
| 3581 | } |
| 3582 | |
| 3583 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3584 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3585 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3586 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3587 | __ sqrt_d(result, input); |
| 3588 | } |
| 3589 | |
| 3590 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3591 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3592 | DoubleRegister input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3593 | DoubleRegister result = ToDoubleRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3594 | DoubleRegister temp = ToDoubleRegister(instr->temp()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3595 | |
| 3596 | ASSERT(!input.is(result)); |
| 3597 | |
| 3598 | // Note that according to ECMA-262 15.8.2.13: |
| 3599 | // Math.pow(-Infinity, 0.5) == Infinity |
| 3600 | // Math.sqrt(-Infinity) == NaN |
| 3601 | Label done; |
| 3602 | __ Move(temp, -V8_INFINITY); |
| 3603 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, temp, input); |
| 3604 | // Set up Infinity in the delay slot. |
| 3605 | // result is overwritten if the branch is not taken. |
| 3606 | __ neg_d(result, temp); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3607 | |
| 3608 | // Add +0 to convert -0 to +0. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3609 | __ add_d(result, input, kDoubleRegZero); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3610 | __ sqrt_d(result, result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3611 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | |
| 3615 | void LCodeGen::DoPower(LPower* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3616 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3617 | // Having marked this as a call, we can use any registers. |
| 3618 | // 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] | 3619 | ASSERT(!instr->right()->IsDoubleRegister() || |
| 3620 | ToDoubleRegister(instr->right()).is(f4)); |
| 3621 | ASSERT(!instr->right()->IsRegister() || |
| 3622 | ToRegister(instr->right()).is(a2)); |
| 3623 | ASSERT(ToDoubleRegister(instr->left()).is(f2)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3624 | ASSERT(ToDoubleRegister(instr->result()).is(f0)); |
| 3625 | |
| 3626 | if (exponent_type.IsTagged()) { |
| 3627 | Label no_deopt; |
| 3628 | __ JumpIfSmi(a2, &no_deopt); |
| 3629 | __ lw(t3, FieldMemOperand(a2, HeapObject::kMapOffset)); |
| 3630 | DeoptimizeIf(ne, instr->environment(), t3, Operand(at)); |
| 3631 | __ bind(&no_deopt); |
| 3632 | MathPowStub stub(MathPowStub::TAGGED); |
| 3633 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3634 | } else if (exponent_type.IsInteger32()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3635 | MathPowStub stub(MathPowStub::INTEGER); |
| 3636 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3637 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3638 | ASSERT(exponent_type.IsDouble()); |
| 3639 | MathPowStub stub(MathPowStub::DOUBLE); |
| 3640 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3641 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3645 | void LCodeGen::DoRandom(LRandom* instr) { |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3646 | class DeferredDoRandom: public LDeferredCode { |
| 3647 | public: |
| 3648 | DeferredDoRandom(LCodeGen* codegen, LRandom* instr) |
| 3649 | : LDeferredCode(codegen), instr_(instr) { } |
| 3650 | virtual void Generate() { codegen()->DoDeferredRandom(instr_); } |
| 3651 | virtual LInstruction* instr() { return instr_; } |
| 3652 | private: |
| 3653 | LRandom* instr_; |
| 3654 | }; |
| 3655 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3656 | DeferredDoRandom* deferred = new(zone()) DeferredDoRandom(this, instr); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3657 | // Having marked this instruction as a call we can use any |
| 3658 | // registers. |
| 3659 | ASSERT(ToDoubleRegister(instr->result()).is(f0)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3660 | ASSERT(ToRegister(instr->global_object()).is(a0)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3661 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3662 | static const int kSeedSize = sizeof(uint32_t); |
| 3663 | STATIC_ASSERT(kPointerSize == kSeedSize); |
| 3664 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3665 | __ lw(a0, FieldMemOperand(a0, GlobalObject::kNativeContextOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3666 | static const int kRandomSeedOffset = |
| 3667 | FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3668 | __ lw(a2, FieldMemOperand(a0, kRandomSeedOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3669 | // a2: FixedArray of the native context's random seeds |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3670 | |
| 3671 | // Load state[0]. |
| 3672 | __ lw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize)); |
| 3673 | __ Branch(deferred->entry(), eq, a1, Operand(zero_reg)); |
| 3674 | // Load state[1]. |
| 3675 | __ lw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize)); |
| 3676 | // a1: state[0]. |
| 3677 | // a0: state[1]. |
| 3678 | |
| 3679 | // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3680 | __ And(a3, a1, Operand(0xFFFF)); |
| 3681 | __ li(t0, Operand(18273)); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3682 | __ Mul(a3, a3, t0); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3683 | __ srl(a1, a1, 16); |
| 3684 | __ Addu(a1, a3, a1); |
| 3685 | // Save state[0]. |
| 3686 | __ sw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize)); |
| 3687 | |
| 3688 | // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 3689 | __ And(a3, a0, Operand(0xFFFF)); |
| 3690 | __ li(t0, Operand(36969)); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3691 | __ Mul(a3, a3, t0); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3692 | __ srl(a0, a0, 16), |
| 3693 | __ Addu(a0, a3, a0); |
| 3694 | // Save state[1]. |
| 3695 | __ sw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize)); |
| 3696 | |
| 3697 | // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 3698 | __ And(a0, a0, Operand(0x3FFFF)); |
| 3699 | __ sll(a1, a1, 14); |
| 3700 | __ Addu(v0, a0, a1); |
| 3701 | |
| 3702 | __ bind(deferred->exit()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3703 | |
| 3704 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 3705 | __ li(a2, Operand(0x41300000)); |
| 3706 | // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU. |
| 3707 | __ Move(f12, v0, a2); |
| 3708 | // Move 0x4130000000000000 to FPU. |
| 3709 | __ Move(f14, zero_reg, a2); |
| 3710 | // Subtract to get the result. |
| 3711 | __ sub_d(f0, f12, f14); |
| 3712 | } |
| 3713 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3714 | void LCodeGen::DoDeferredRandom(LRandom* instr) { |
| 3715 | __ PrepareCallCFunction(1, scratch0()); |
| 3716 | __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
| 3717 | // Return value is in v0. |
| 3718 | } |
| 3719 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3720 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3721 | void LCodeGen::DoMathExp(LMathExp* instr) { |
| 3722 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3723 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3724 | DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 3725 | DoubleRegister double_scratch2 = double_scratch0(); |
| 3726 | Register temp1 = ToRegister(instr->temp1()); |
| 3727 | Register temp2 = ToRegister(instr->temp2()); |
| 3728 | |
| 3729 | MathExpGenerator::EmitMathExp( |
| 3730 | masm(), input, result, double_scratch1, double_scratch2, |
| 3731 | temp1, temp2, scratch0()); |
| 3732 | } |
| 3733 | |
| 3734 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3735 | void LCodeGen::DoMathLog(LMathLog* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3736 | ASSERT(ToDoubleRegister(instr->result()).is(f4)); |
| 3737 | TranscendentalCacheStub stub(TranscendentalCache::LOG, |
| 3738 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3739 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3743 | void LCodeGen::DoMathTan(LMathTan* instr) { |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3744 | ASSERT(ToDoubleRegister(instr->result()).is(f4)); |
| 3745 | TranscendentalCacheStub stub(TranscendentalCache::TAN, |
| 3746 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3747 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3751 | void LCodeGen::DoMathCos(LMathCos* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3752 | ASSERT(ToDoubleRegister(instr->result()).is(f4)); |
| 3753 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 3754 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3755 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3759 | void LCodeGen::DoMathSin(LMathSin* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3760 | ASSERT(ToDoubleRegister(instr->result()).is(f4)); |
| 3761 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 3762 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3763 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3767 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
| 3768 | ASSERT(ToRegister(instr->function()).is(a1)); |
| 3769 | ASSERT(instr->HasPointerMap()); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3770 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3771 | Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 3772 | if (known_function.is_null()) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3773 | LPointerMap* pointers = instr->pointer_map(); |
| 3774 | RecordPosition(pointers->position()); |
| 3775 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3776 | ParameterCount count(instr->arity()); |
| 3777 | __ InvokeFunction(a1, count, CALL_FUNCTION, generator, CALL_AS_METHOD); |
| 3778 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3779 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3780 | CallKnownFunction(known_function, |
| 3781 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3782 | instr->arity(), |
| 3783 | instr, |
| 3784 | CALL_AS_METHOD, |
| 3785 | A1_CONTAINS_TARGET); |
| 3786 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | |
| 3790 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
| 3791 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3792 | |
| 3793 | int arity = instr->arity(); |
| 3794 | Handle<Code> ic = |
| 3795 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arity); |
| 3796 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3797 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3798 | } |
| 3799 | |
| 3800 | |
| 3801 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
| 3802 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3803 | |
| 3804 | int arity = instr->arity(); |
| 3805 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
| 3806 | Handle<Code> ic = |
| 3807 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
| 3808 | __ li(a2, Operand(instr->name())); |
| 3809 | CallCode(ic, mode, instr); |
| 3810 | // Restore context register. |
| 3811 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3812 | } |
| 3813 | |
| 3814 | |
| 3815 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3816 | ASSERT(ToRegister(instr->function()).is(a1)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3817 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3818 | |
| 3819 | int arity = instr->arity(); |
| 3820 | CallFunctionStub stub(arity, NO_CALL_FUNCTION_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3821 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3822 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3823 | } |
| 3824 | |
| 3825 | |
| 3826 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
| 3827 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3828 | |
| 3829 | int arity = instr->arity(); |
| 3830 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET_CONTEXT; |
| 3831 | Handle<Code> ic = |
| 3832 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
| 3833 | __ li(a2, Operand(instr->name())); |
| 3834 | CallCode(ic, mode, instr); |
| 3835 | __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3836 | } |
| 3837 | |
| 3838 | |
| 3839 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 3840 | ASSERT(ToRegister(instr->result()).is(v0)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3841 | CallKnownFunction(instr->hydrogen()->target(), |
| 3842 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3843 | instr->arity(), |
| 3844 | instr, |
| 3845 | CALL_AS_FUNCTION, |
| 3846 | A1_UNINITIALIZED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | |
| 3850 | void LCodeGen::DoCallNew(LCallNew* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3851 | ASSERT(ToRegister(instr->constructor()).is(a1)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3852 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3853 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3854 | __ li(a0, Operand(instr->arity())); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3855 | if (FLAG_optimize_constructed_arrays) { |
| 3856 | // No cell in a2 for construct type feedback in optimized code |
| 3857 | Handle<Object> undefined_value(isolate()->heap()->undefined_value(), |
| 3858 | isolate()); |
| 3859 | __ li(a2, Operand(undefined_value)); |
| 3860 | } |
| 3861 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3862 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3866 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
| 3867 | ASSERT(ToRegister(instr->constructor()).is(a1)); |
| 3868 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 3869 | ASSERT(FLAG_optimize_constructed_arrays); |
| 3870 | |
| 3871 | __ li(a0, Operand(instr->arity())); |
| 3872 | __ li(a2, Operand(instr->hydrogen()->property_cell())); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3873 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3874 | if (instr->arity() == 0) { |
| 3875 | ArrayNoArgumentConstructorStub stub(kind); |
| 3876 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 3877 | } else if (instr->arity() == 1) { |
| 3878 | ArraySingleArgumentConstructorStub stub(kind); |
| 3879 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 3880 | } else { |
| 3881 | ArrayNArgumentsConstructorStub stub(kind); |
| 3882 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 3883 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3887 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 3888 | CallRuntime(instr->function(), instr->arity(), instr); |
| 3889 | } |
| 3890 | |
| 3891 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 3892 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 3893 | Register result = ToRegister(instr->result()); |
| 3894 | Register base = ToRegister(instr->base_object()); |
| 3895 | __ Addu(result, base, Operand(instr->offset())); |
| 3896 | } |
| 3897 | |
| 3898 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3899 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3900 | Representation representation = instr->representation(); |
| 3901 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3902 | Register object = ToRegister(instr->object()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3903 | Register scratch = scratch0(); |
| 3904 | int offset = instr->offset(); |
| 3905 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3906 | Handle<Map> transition = instr->transition(); |
| 3907 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3908 | if (FLAG_track_fields && representation.IsSmi()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3909 | Register value = ToRegister(instr->value()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3910 | __ SmiTagCheckOverflow(value, value, scratch); |
| 3911 | if (!instr->hydrogen()->value()->range()->IsInSmiRange()) { |
| 3912 | DeoptimizeIf(lt, instr->environment(), scratch, Operand(zero_reg)); |
| 3913 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3914 | } else if (FLAG_track_double_fields && representation.IsDouble()) { |
| 3915 | ASSERT(transition.is_null()); |
| 3916 | ASSERT(instr->is_in_object()); |
| 3917 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 3918 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 3919 | __ sdc1(value, FieldMemOperand(object, offset)); |
| 3920 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3923 | if (!transition.is_null()) { |
| 3924 | if (transition->CanBeDeprecated()) { |
| 3925 | transition_maps_.Add(transition, info()->zone()); |
| 3926 | } |
| 3927 | __ li(scratch, Operand(transition)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3928 | __ sw(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 3929 | if (instr->hydrogen()->NeedsWriteBarrierForMap()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3930 | Register temp = ToRegister(instr->temp()); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 3931 | // Update the write barrier for the map field. |
| 3932 | __ RecordWriteField(object, |
| 3933 | HeapObject::kMapOffset, |
| 3934 | scratch, |
| 3935 | temp, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 3936 | GetRAState(), |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 3937 | kSaveFPRegs, |
| 3938 | OMIT_REMEMBERED_SET, |
| 3939 | OMIT_SMI_CHECK); |
| 3940 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | // Do the store. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3944 | Register value = ToRegister(instr->value()); |
| 3945 | ASSERT(!object.is(value)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3946 | HType type = instr->hydrogen()->value()->type(); |
| 3947 | SmiCheck check_needed = |
| 3948 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
| 3949 | if (instr->is_in_object()) { |
| 3950 | __ sw(value, FieldMemOperand(object, offset)); |
| 3951 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 3952 | // Update the write barrier for the object for in-object properties. |
| 3953 | __ RecordWriteField(object, |
| 3954 | offset, |
| 3955 | value, |
| 3956 | scratch, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 3957 | GetRAState(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3958 | kSaveFPRegs, |
| 3959 | EMIT_REMEMBERED_SET, |
| 3960 | check_needed); |
| 3961 | } |
| 3962 | } else { |
| 3963 | __ lw(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 3964 | __ sw(value, FieldMemOperand(scratch, offset)); |
| 3965 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 3966 | // Update the write barrier for the properties array. |
| 3967 | // object is used as a scratch register. |
| 3968 | __ RecordWriteField(scratch, |
| 3969 | offset, |
| 3970 | value, |
| 3971 | object, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 3972 | GetRAState(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3973 | kSaveFPRegs, |
| 3974 | EMIT_REMEMBERED_SET, |
| 3975 | check_needed); |
| 3976 | } |
| 3977 | } |
| 3978 | } |
| 3979 | |
| 3980 | |
| 3981 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
| 3982 | ASSERT(ToRegister(instr->object()).is(a1)); |
| 3983 | ASSERT(ToRegister(instr->value()).is(a0)); |
| 3984 | |
| 3985 | // Name is always in a2. |
| 3986 | __ li(a2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3987 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3988 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 3989 | : isolate()->builtins()->StoreIC_Initialize(); |
| 3990 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3991 | } |
| 3992 | |
| 3993 | |
| 3994 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 3995 | if (instr->hydrogen()->skip_check()) return; |
| 3996 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 3997 | if (instr->index()->IsConstantOperand()) { |
| 3998 | int constant_index = |
| 3999 | ToInteger32(LConstantOperand::cast(instr->index())); |
| 4000 | if (instr->hydrogen()->length()->representation().IsTagged()) { |
| 4001 | __ li(at, Operand(Smi::FromInt(constant_index))); |
| 4002 | } else { |
| 4003 | __ li(at, Operand(constant_index)); |
| 4004 | } |
| 4005 | DeoptimizeIf(hs, |
| 4006 | instr->environment(), |
| 4007 | at, |
| 4008 | Operand(ToRegister(instr->length()))); |
| 4009 | } else { |
| 4010 | DeoptimizeIf(hs, |
| 4011 | instr->environment(), |
| 4012 | ToRegister(instr->index()), |
| 4013 | Operand(ToRegister(instr->length()))); |
| 4014 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4018 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
| 4019 | Register external_pointer = ToRegister(instr->elements()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4020 | Register key = no_reg; |
| 4021 | ElementsKind elements_kind = instr->elements_kind(); |
| 4022 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4023 | int constant_key = 0; |
| 4024 | if (key_is_constant) { |
| 4025 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4026 | if (constant_key & 0xF0000000) { |
| 4027 | Abort("array index constant value too big."); |
| 4028 | } |
| 4029 | } else { |
| 4030 | key = ToRegister(instr->key()); |
| 4031 | } |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 4032 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 4033 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 4034 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 4035 | int additional_offset = instr->additional_index() << element_size_shift; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4036 | |
| 4037 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 4038 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
| 4039 | FPURegister value(ToDoubleRegister(instr->value())); |
| 4040 | if (key_is_constant) { |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 4041 | __ Addu(scratch0(), external_pointer, constant_key << |
| 4042 | element_size_shift); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4043 | } else { |
| 4044 | __ sll(scratch0(), key, shift_size); |
| 4045 | __ Addu(scratch0(), scratch0(), external_pointer); |
| 4046 | } |
| 4047 | |
| 4048 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
| 4049 | __ cvt_s_d(double_scratch0(), value); |
jkummerow@chromium.org | 777db6f | 2012-05-24 09:33:09 +0000 | [diff] [blame] | 4050 | __ swc1(double_scratch0(), MemOperand(scratch0(), additional_offset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4051 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
jkummerow@chromium.org | 777db6f | 2012-05-24 09:33:09 +0000 | [diff] [blame] | 4052 | __ sdc1(value, MemOperand(scratch0(), additional_offset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4053 | } |
| 4054 | } else { |
| 4055 | Register value(ToRegister(instr->value())); |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 4056 | MemOperand mem_operand = PrepareKeyedOperand( |
| 4057 | key, external_pointer, key_is_constant, constant_key, |
| 4058 | element_size_shift, shift_size, |
| 4059 | instr->additional_index(), additional_offset); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4060 | switch (elements_kind) { |
| 4061 | case EXTERNAL_PIXEL_ELEMENTS: |
| 4062 | case EXTERNAL_BYTE_ELEMENTS: |
| 4063 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 4064 | __ sb(value, mem_operand); |
| 4065 | break; |
| 4066 | case EXTERNAL_SHORT_ELEMENTS: |
| 4067 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 4068 | __ sh(value, mem_operand); |
| 4069 | break; |
| 4070 | case EXTERNAL_INT_ELEMENTS: |
| 4071 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 4072 | __ sw(value, mem_operand); |
| 4073 | break; |
| 4074 | case EXTERNAL_FLOAT_ELEMENTS: |
| 4075 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 4076 | case FAST_DOUBLE_ELEMENTS: |
| 4077 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4078 | case FAST_SMI_ELEMENTS: |
| 4079 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 4080 | case FAST_HOLEY_ELEMENTS: |
| 4081 | case FAST_HOLEY_SMI_ELEMENTS: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4082 | case DICTIONARY_ELEMENTS: |
| 4083 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
| 4084 | UNREACHABLE(); |
| 4085 | break; |
| 4086 | } |
| 4087 | } |
| 4088 | } |
| 4089 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4090 | |
| 4091 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
| 4092 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 4093 | Register elements = ToRegister(instr->elements()); |
| 4094 | Register key = no_reg; |
| 4095 | Register scratch = scratch0(); |
| 4096 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4097 | int constant_key = 0; |
| 4098 | Label not_nan; |
| 4099 | |
| 4100 | // Calculate the effective address of the slot in the array to store the |
| 4101 | // double value. |
| 4102 | if (key_is_constant) { |
| 4103 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4104 | if (constant_key & 0xF0000000) { |
| 4105 | Abort("array index constant value too big."); |
| 4106 | } |
| 4107 | } else { |
| 4108 | key = ToRegister(instr->key()); |
| 4109 | } |
| 4110 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 4111 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 4112 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 4113 | if (key_is_constant) { |
| 4114 | __ Addu(scratch, elements, Operand((constant_key << element_size_shift) + |
| 4115 | FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
| 4116 | } else { |
| 4117 | __ sll(scratch, key, shift_size); |
| 4118 | __ Addu(scratch, elements, Operand(scratch)); |
| 4119 | __ Addu(scratch, scratch, |
| 4120 | Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
| 4121 | } |
| 4122 | |
| 4123 | if (instr->NeedsCanonicalization()) { |
| 4124 | Label is_nan; |
| 4125 | // Check for NaN. All NaNs must be canonicalized. |
| 4126 | __ BranchF(NULL, &is_nan, eq, value, value); |
| 4127 | __ Branch(¬_nan); |
| 4128 | |
| 4129 | // Only load canonical NaN if the comparison above set the overflow. |
| 4130 | __ bind(&is_nan); |
| 4131 | __ Move(value, FixedDoubleArray::canonical_not_the_hole_nan_as_double()); |
| 4132 | } |
| 4133 | |
| 4134 | __ bind(¬_nan); |
| 4135 | __ sdc1(value, MemOperand(scratch, instr->additional_index() << |
| 4136 | element_size_shift)); |
| 4137 | } |
| 4138 | |
| 4139 | |
| 4140 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| 4141 | Register value = ToRegister(instr->value()); |
| 4142 | Register elements = ToRegister(instr->elements()); |
| 4143 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) |
| 4144 | : no_reg; |
| 4145 | Register scratch = scratch0(); |
| 4146 | Register store_base = scratch; |
| 4147 | int offset = 0; |
| 4148 | |
| 4149 | // Do the store. |
| 4150 | if (instr->key()->IsConstantOperand()) { |
| 4151 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4152 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 4153 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 4154 | instr->additional_index()); |
| 4155 | store_base = elements; |
| 4156 | } else { |
| 4157 | // Even though the HLoadKeyed instruction forces the input |
| 4158 | // representation for the key to be an integer, the input gets replaced |
| 4159 | // during bound check elimination with the index argument to the bounds |
| 4160 | // check, which can be tagged, so that case must be handled here, too. |
| 4161 | if (instr->hydrogen()->key()->representation().IsTagged()) { |
| 4162 | __ sll(scratch, key, kPointerSizeLog2 - kSmiTagSize); |
| 4163 | __ addu(scratch, elements, scratch); |
| 4164 | } else { |
| 4165 | __ sll(scratch, key, kPointerSizeLog2); |
| 4166 | __ addu(scratch, elements, scratch); |
| 4167 | } |
| 4168 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 4169 | } |
| 4170 | __ sw(value, FieldMemOperand(store_base, offset)); |
| 4171 | |
| 4172 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 4173 | HType type = instr->hydrogen()->value()->type(); |
| 4174 | SmiCheck check_needed = |
| 4175 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
| 4176 | // Compute address of modified element and store it into key register. |
| 4177 | __ Addu(key, store_base, Operand(offset - kHeapObjectTag)); |
| 4178 | __ RecordWrite(elements, |
| 4179 | key, |
| 4180 | value, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4181 | GetRAState(), |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4182 | kSaveFPRegs, |
| 4183 | EMIT_REMEMBERED_SET, |
| 4184 | check_needed); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | |
| 4189 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4190 | // By cases: external, fast double |
| 4191 | if (instr->is_external()) { |
| 4192 | DoStoreKeyedExternalArray(instr); |
| 4193 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4194 | DoStoreKeyedFixedDoubleArray(instr); |
| 4195 | } else { |
| 4196 | DoStoreKeyedFixedArray(instr); |
| 4197 | } |
| 4198 | } |
| 4199 | |
| 4200 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4201 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
| 4202 | ASSERT(ToRegister(instr->object()).is(a2)); |
| 4203 | ASSERT(ToRegister(instr->key()).is(a1)); |
| 4204 | ASSERT(ToRegister(instr->value()).is(a0)); |
| 4205 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4206 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4207 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4208 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
| 4209 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4210 | } |
| 4211 | |
| 4212 | |
| 4213 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4214 | Register object_reg = ToRegister(instr->object()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4215 | Register scratch = scratch0(); |
| 4216 | |
| 4217 | Handle<Map> from_map = instr->original_map(); |
| 4218 | Handle<Map> to_map = instr->transitioned_map(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4219 | ElementsKind from_kind = instr->from_kind(); |
| 4220 | ElementsKind to_kind = instr->to_kind(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4221 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4222 | Label not_applicable; |
| 4223 | __ lw(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4224 | __ Branch(¬_applicable, ne, scratch, Operand(from_map)); |
| 4225 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4226 | if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4227 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
| 4228 | __ li(new_map_reg, Operand(to_map)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4229 | __ sw(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4230 | // Write barrier. |
| 4231 | __ RecordWriteField(object_reg, HeapObject::kMapOffset, new_map_reg, |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4232 | scratch, GetRAState(), kDontSaveFPRegs); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4233 | } else if (FLAG_compiled_transitions) { |
| 4234 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4235 | __ mov(a0, object_reg); |
| 4236 | __ li(a1, Operand(to_map)); |
| 4237 | TransitionElementsKindStub stub(from_kind, to_kind); |
| 4238 | __ CallStub(&stub); |
| 4239 | RecordSafepointWithRegisters( |
| 4240 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4241 | } else if (IsFastSmiElementsKind(from_kind) && |
| 4242 | IsFastDoubleElementsKind(to_kind)) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4243 | Register fixed_object_reg = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4244 | ASSERT(fixed_object_reg.is(a2)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4245 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4246 | ASSERT(new_map_reg.is(a3)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4247 | __ li(new_map_reg, Operand(to_map)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4248 | __ mov(fixed_object_reg, object_reg); |
| 4249 | CallCode(isolate()->builtins()->TransitionElementsSmiToDouble(), |
| 4250 | RelocInfo::CODE_TARGET, instr); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4251 | } else if (IsFastDoubleElementsKind(from_kind) && |
| 4252 | IsFastObjectElementsKind(to_kind)) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4253 | Register fixed_object_reg = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4254 | ASSERT(fixed_object_reg.is(a2)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4255 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4256 | ASSERT(new_map_reg.is(a3)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4257 | __ li(new_map_reg, Operand(to_map)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4258 | __ mov(fixed_object_reg, object_reg); |
| 4259 | CallCode(isolate()->builtins()->TransitionElementsDoubleToObject(), |
| 4260 | RelocInfo::CODE_TARGET, instr); |
| 4261 | } else { |
| 4262 | UNREACHABLE(); |
| 4263 | } |
| 4264 | __ bind(¬_applicable); |
| 4265 | } |
| 4266 | |
| 4267 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4268 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4269 | Register object = ToRegister(instr->object()); |
| 4270 | Register temp = ToRegister(instr->temp()); |
| 4271 | Label fail; |
| 4272 | __ TestJSArrayForAllocationSiteInfo(object, temp, ne, &fail); |
| 4273 | DeoptimizeIf(al, instr->environment()); |
| 4274 | __ bind(&fail); |
| 4275 | } |
| 4276 | |
| 4277 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4278 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
| 4279 | __ push(ToRegister(instr->left())); |
| 4280 | __ push(ToRegister(instr->right())); |
| 4281 | StringAddStub stub(NO_STRING_CHECK_IN_STUB); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4282 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | |
| 4286 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4287 | class DeferredStringCharCodeAt: public LDeferredCode { |
| 4288 | public: |
| 4289 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 4290 | : LDeferredCode(codegen), instr_(instr) { } |
| 4291 | virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
| 4292 | virtual LInstruction* instr() { return instr_; } |
| 4293 | private: |
| 4294 | LStringCharCodeAt* instr_; |
| 4295 | }; |
| 4296 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4297 | DeferredStringCharCodeAt* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4298 | new(zone()) DeferredStringCharCodeAt(this, instr); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4299 | StringCharLoadGenerator::Generate(masm(), |
| 4300 | ToRegister(instr->string()), |
| 4301 | ToRegister(instr->index()), |
| 4302 | ToRegister(instr->result()), |
| 4303 | deferred->entry()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4304 | __ bind(deferred->exit()); |
| 4305 | } |
| 4306 | |
| 4307 | |
| 4308 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4309 | Register string = ToRegister(instr->string()); |
| 4310 | Register result = ToRegister(instr->result()); |
| 4311 | Register scratch = scratch0(); |
| 4312 | |
| 4313 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4314 | // result register contain a valid pointer because it is already |
| 4315 | // contained in the register pointer map. |
| 4316 | __ mov(result, zero_reg); |
| 4317 | |
| 4318 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4319 | __ push(string); |
| 4320 | // Push the index as a smi. This is safe because of the checks in |
| 4321 | // DoStringCharCodeAt above. |
| 4322 | if (instr->index()->IsConstantOperand()) { |
| 4323 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4324 | __ Addu(scratch, zero_reg, Operand(Smi::FromInt(const_index))); |
| 4325 | __ push(scratch); |
| 4326 | } else { |
| 4327 | Register index = ToRegister(instr->index()); |
| 4328 | __ SmiTag(index); |
| 4329 | __ push(index); |
| 4330 | } |
| 4331 | CallRuntimeFromDeferred(Runtime::kStringCharCodeAt, 2, instr); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4332 | __ AssertSmi(v0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4333 | __ SmiUntag(v0); |
| 4334 | __ StoreToSafepointRegisterSlot(v0, result); |
| 4335 | } |
| 4336 | |
| 4337 | |
| 4338 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
| 4339 | class DeferredStringCharFromCode: public LDeferredCode { |
| 4340 | public: |
| 4341 | DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 4342 | : LDeferredCode(codegen), instr_(instr) { } |
| 4343 | virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); } |
| 4344 | virtual LInstruction* instr() { return instr_; } |
| 4345 | private: |
| 4346 | LStringCharFromCode* instr_; |
| 4347 | }; |
| 4348 | |
| 4349 | DeferredStringCharFromCode* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4350 | new(zone()) DeferredStringCharFromCode(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4351 | |
| 4352 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4353 | Register char_code = ToRegister(instr->char_code()); |
| 4354 | Register result = ToRegister(instr->result()); |
| 4355 | Register scratch = scratch0(); |
| 4356 | ASSERT(!char_code.is(result)); |
| 4357 | |
| 4358 | __ Branch(deferred->entry(), hi, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4359 | char_code, Operand(String::kMaxOneByteCharCode)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4360 | __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 4361 | __ sll(scratch, char_code, kPointerSizeLog2); |
| 4362 | __ Addu(result, result, scratch); |
| 4363 | __ lw(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 4364 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 4365 | __ Branch(deferred->entry(), eq, result, Operand(scratch)); |
| 4366 | __ bind(deferred->exit()); |
| 4367 | } |
| 4368 | |
| 4369 | |
| 4370 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4371 | Register char_code = ToRegister(instr->char_code()); |
| 4372 | Register result = ToRegister(instr->result()); |
| 4373 | |
| 4374 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4375 | // result register contain a valid pointer because it is already |
| 4376 | // contained in the register pointer map. |
| 4377 | __ mov(result, zero_reg); |
| 4378 | |
| 4379 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4380 | __ SmiTag(char_code); |
| 4381 | __ push(char_code); |
| 4382 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr); |
| 4383 | __ StoreToSafepointRegisterSlot(v0, result); |
| 4384 | } |
| 4385 | |
| 4386 | |
| 4387 | void LCodeGen::DoStringLength(LStringLength* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4388 | Register string = ToRegister(instr->string()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4389 | Register result = ToRegister(instr->result()); |
| 4390 | __ lw(result, FieldMemOperand(string, String::kLengthOffset)); |
| 4391 | } |
| 4392 | |
| 4393 | |
| 4394 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4395 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4396 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 4397 | LOperand* output = instr->result(); |
| 4398 | ASSERT(output->IsDoubleRegister()); |
| 4399 | FPURegister single_scratch = double_scratch0().low(); |
| 4400 | if (input->IsStackSlot()) { |
| 4401 | Register scratch = scratch0(); |
| 4402 | __ lw(scratch, ToMemOperand(input)); |
| 4403 | __ mtc1(scratch, single_scratch); |
| 4404 | } else { |
| 4405 | __ mtc1(ToRegister(input), single_scratch); |
| 4406 | } |
| 4407 | __ cvt_d_w(ToDoubleRegister(output), single_scratch); |
| 4408 | } |
| 4409 | |
| 4410 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4411 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4412 | LOperand* input = instr->value(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4413 | LOperand* output = instr->result(); |
| 4414 | |
| 4415 | FPURegister dbl_scratch = double_scratch0(); |
| 4416 | __ mtc1(ToRegister(input), dbl_scratch); |
| 4417 | __ Cvt_d_uw(ToDoubleRegister(output), dbl_scratch, f22); |
| 4418 | } |
| 4419 | |
| 4420 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4421 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 4422 | class DeferredNumberTagI: public LDeferredCode { |
| 4423 | public: |
| 4424 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 4425 | : LDeferredCode(codegen), instr_(instr) { } |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4426 | virtual void Generate() { |
| 4427 | codegen()->DoDeferredNumberTagI(instr_, |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4428 | instr_->value(), |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4429 | SIGNED_INT32); |
| 4430 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4431 | virtual LInstruction* instr() { return instr_; } |
| 4432 | private: |
| 4433 | LNumberTagI* instr_; |
| 4434 | }; |
| 4435 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4436 | Register src = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4437 | Register dst = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4438 | Register overflow = scratch0(); |
| 4439 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4440 | DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4441 | __ SmiTagCheckOverflow(dst, src, overflow); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4442 | __ BranchOnOverflow(deferred->entry(), overflow); |
| 4443 | __ bind(deferred->exit()); |
| 4444 | } |
| 4445 | |
| 4446 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4447 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
| 4448 | class DeferredNumberTagU: public LDeferredCode { |
| 4449 | public: |
| 4450 | DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4451 | : LDeferredCode(codegen), instr_(instr) { } |
| 4452 | virtual void Generate() { |
| 4453 | codegen()->DoDeferredNumberTagI(instr_, |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4454 | instr_->value(), |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4455 | UNSIGNED_INT32); |
| 4456 | } |
| 4457 | virtual LInstruction* instr() { return instr_; } |
| 4458 | private: |
| 4459 | LNumberTagU* instr_; |
| 4460 | }; |
| 4461 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4462 | LOperand* input = instr->value(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4463 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 4464 | Register reg = ToRegister(input); |
| 4465 | |
| 4466 | DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); |
| 4467 | __ Branch(deferred->entry(), hi, reg, Operand(Smi::kMaxValue)); |
| 4468 | __ SmiTag(reg, reg); |
| 4469 | __ bind(deferred->exit()); |
| 4470 | } |
| 4471 | |
| 4472 | |
| 4473 | void LCodeGen::DoDeferredNumberTagI(LInstruction* instr, |
| 4474 | LOperand* value, |
| 4475 | IntegerSignedness signedness) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4476 | Label slow; |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4477 | Register src = ToRegister(value); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4478 | Register dst = ToRegister(instr->result()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4479 | DoubleRegister dbl_scratch = double_scratch0(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4480 | |
| 4481 | // Preserve the value of all registers. |
| 4482 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4483 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4484 | Label done; |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4485 | if (signedness == SIGNED_INT32) { |
| 4486 | // There was overflow, so bits 30 and 31 of the original integer |
| 4487 | // disagree. Try to allocate a heap number in new space and store |
| 4488 | // the value in there. If that fails, call the runtime system. |
| 4489 | if (dst.is(src)) { |
| 4490 | __ SmiUntag(src, dst); |
| 4491 | __ Xor(src, src, Operand(0x80000000)); |
| 4492 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4493 | __ mtc1(src, dbl_scratch); |
| 4494 | __ cvt_d_w(dbl_scratch, dbl_scratch); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4495 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4496 | __ mtc1(src, dbl_scratch); |
| 4497 | __ Cvt_d_uw(dbl_scratch, dbl_scratch, f22); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4498 | } |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 4499 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4500 | if (FLAG_inline_new) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4501 | __ LoadRoot(scratch0(), Heap::kHeapNumberMapRootIndex); |
| 4502 | __ AllocateHeapNumber(t1, a3, t0, scratch0(), &slow, DONT_TAG_RESULT); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4503 | __ Move(dst, t1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4504 | __ Branch(&done); |
| 4505 | } |
| 4506 | |
| 4507 | // Slow case: Call the runtime system to do the number allocation. |
| 4508 | __ bind(&slow); |
| 4509 | |
| 4510 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 4511 | // register is stored, as this register is in the pointer map, but contains an |
| 4512 | // integer value. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4513 | __ StoreToSafepointRegisterSlot(zero_reg, dst); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4514 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4515 | __ Move(dst, v0); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4516 | __ Subu(dst, dst, kHeapObjectTag); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4517 | |
| 4518 | // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 4519 | // number. |
| 4520 | __ bind(&done); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4521 | __ sdc1(dbl_scratch, MemOperand(dst, HeapNumber::kValueOffset)); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4522 | __ Addu(dst, dst, kHeapObjectTag); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4523 | __ StoreToSafepointRegisterSlot(dst, dst); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | |
| 4527 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
| 4528 | class DeferredNumberTagD: public LDeferredCode { |
| 4529 | public: |
| 4530 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 4531 | : LDeferredCode(codegen), instr_(instr) { } |
| 4532 | virtual void Generate() { codegen()->DoDeferredNumberTagD(instr_); } |
| 4533 | virtual LInstruction* instr() { return instr_; } |
| 4534 | private: |
| 4535 | LNumberTagD* instr_; |
| 4536 | }; |
| 4537 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4538 | DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4539 | Register scratch = scratch0(); |
| 4540 | Register reg = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4541 | Register temp1 = ToRegister(instr->temp()); |
| 4542 | Register temp2 = ToRegister(instr->temp2()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4543 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4544 | bool convert_hole = false; |
| 4545 | HValue* change_input = instr->hydrogen()->value(); |
| 4546 | if (change_input->IsLoadKeyed()) { |
| 4547 | HLoadKeyed* load = HLoadKeyed::cast(change_input); |
| 4548 | convert_hole = load->UsesMustHandleHole(); |
| 4549 | } |
| 4550 | |
| 4551 | Label no_special_nan_handling; |
| 4552 | Label done; |
| 4553 | if (convert_hole) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4554 | DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
| 4555 | __ BranchF(&no_special_nan_handling, NULL, eq, input_reg, input_reg); |
| 4556 | __ Move(reg, scratch0(), input_reg); |
| 4557 | Label canonicalize; |
| 4558 | __ Branch(&canonicalize, ne, scratch0(), Operand(kHoleNanUpper32)); |
| 4559 | __ li(reg, factory()->the_hole_value()); |
| 4560 | __ Branch(&done); |
| 4561 | __ bind(&canonicalize); |
| 4562 | __ Move(input_reg, |
| 4563 | FixedDoubleArray::canonical_not_the_hole_nan_as_double()); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | __ bind(&no_special_nan_handling); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4567 | DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4568 | if (FLAG_inline_new) { |
| 4569 | __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4570 | // We want the untagged address first for performance |
| 4571 | __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(), |
| 4572 | DONT_TAG_RESULT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4573 | } else { |
| 4574 | __ Branch(deferred->entry()); |
| 4575 | } |
| 4576 | __ bind(deferred->exit()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4577 | __ sdc1(input_reg, MemOperand(reg, HeapNumber::kValueOffset)); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4578 | // Now that we have finished with the object's real address tag it |
| 4579 | __ Addu(reg, reg, kHeapObjectTag); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4580 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | |
| 4584 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 4585 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4586 | // result register contain a valid pointer because it is already |
| 4587 | // contained in the register pointer map. |
| 4588 | Register reg = ToRegister(instr->result()); |
| 4589 | __ mov(reg, zero_reg); |
| 4590 | |
| 4591 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4592 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4593 | __ Subu(v0, v0, kHeapObjectTag); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4594 | __ StoreToSafepointRegisterSlot(v0, reg); |
| 4595 | } |
| 4596 | |
| 4597 | |
| 4598 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4599 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4600 | __ SmiTag(ToRegister(instr->result()), ToRegister(instr->value())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | |
| 4604 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
| 4605 | Register scratch = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4606 | Register input = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4607 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4608 | if (instr->needs_check()) { |
| 4609 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4610 | // 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] | 4611 | __ And(scratch, input, Operand(kHeapObjectTag)); |
| 4612 | __ SmiUntag(result, input); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4613 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(zero_reg)); |
| 4614 | } else { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4615 | __ SmiUntag(result, input); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | |
| 4620 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
| 4621 | DoubleRegister result_reg, |
| 4622 | bool deoptimize_on_undefined, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4623 | bool deoptimize_on_minus_zero, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4624 | LEnvironment* env, |
| 4625 | NumberUntagDMode mode) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4626 | Register scratch = scratch0(); |
| 4627 | |
| 4628 | Label load_smi, heap_number, done; |
| 4629 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4630 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
| 4631 | // Smi check. |
| 4632 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4633 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4634 | // Heap number map check. |
| 4635 | __ lw(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4636 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 4637 | if (deoptimize_on_undefined) { |
| 4638 | DeoptimizeIf(ne, env, scratch, Operand(at)); |
| 4639 | } else { |
| 4640 | Label heap_number; |
| 4641 | __ Branch(&heap_number, eq, scratch, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4642 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4643 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4644 | DeoptimizeIf(ne, env, input_reg, Operand(at)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4645 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4646 | // Convert undefined to NaN. |
| 4647 | __ LoadRoot(at, Heap::kNanValueRootIndex); |
| 4648 | __ ldc1(result_reg, FieldMemOperand(at, HeapNumber::kValueOffset)); |
| 4649 | __ Branch(&done); |
| 4650 | |
| 4651 | __ bind(&heap_number); |
| 4652 | } |
| 4653 | // Heap number to double register conversion. |
| 4654 | __ ldc1(result_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4655 | if (deoptimize_on_minus_zero) { |
| 4656 | __ mfc1(at, result_reg.low()); |
| 4657 | __ Branch(&done, ne, at, Operand(zero_reg)); |
| 4658 | __ mfc1(scratch, result_reg.high()); |
| 4659 | DeoptimizeIf(eq, env, scratch, Operand(HeapNumber::kSignMask)); |
| 4660 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4661 | __ Branch(&done); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4662 | } else if (mode == NUMBER_CANDIDATE_IS_SMI_OR_HOLE) { |
| 4663 | __ SmiUntag(scratch, input_reg); |
| 4664 | DeoptimizeIf(Ugreater_equal, env, scratch, Operand(zero_reg)); |
| 4665 | } else if (mode == NUMBER_CANDIDATE_IS_SMI_CONVERT_HOLE) { |
| 4666 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
| 4667 | __ Move(result_reg, |
| 4668 | FixedDoubleArray::hole_nan_as_double()); |
| 4669 | __ Branch(&done); |
| 4670 | } else { |
| 4671 | __ SmiUntag(scratch, input_reg); |
| 4672 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4673 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4674 | |
| 4675 | // Smi to double register conversion |
| 4676 | __ bind(&load_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4677 | // scratch: untagged value of input_reg |
| 4678 | __ mtc1(scratch, result_reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4679 | __ cvt_d_w(result_reg, result_reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4680 | __ bind(&done); |
| 4681 | } |
| 4682 | |
| 4683 | |
| 4684 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4685 | Register input_reg = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4686 | Register scratch1 = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4687 | Register scratch2 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4688 | DoubleRegister double_scratch = double_scratch0(); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4689 | DoubleRegister double_scratch2 = ToDoubleRegister(instr->temp3()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4690 | |
| 4691 | ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
| 4692 | ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
| 4693 | |
| 4694 | Label done; |
| 4695 | |
| 4696 | // The input is a tagged HeapObject. |
| 4697 | // Heap number map check. |
| 4698 | __ lw(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4699 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 4700 | // This 'at' value and scratch1 map value are used for tests in both clauses |
| 4701 | // of the if. |
| 4702 | |
| 4703 | if (instr->truncating()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4704 | Register scratch3 = ToRegister(instr->temp2()); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4705 | FPURegister single_scratch = double_scratch.low(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4706 | ASSERT(!scratch3.is(input_reg) && |
| 4707 | !scratch3.is(scratch1) && |
| 4708 | !scratch3.is(scratch2)); |
| 4709 | // Performs a truncating conversion of a floating point number as used by |
| 4710 | // the JS bitwise operations. |
| 4711 | Label heap_number; |
| 4712 | __ Branch(&heap_number, eq, scratch1, Operand(at)); // HeapNumber map? |
| 4713 | // Check for undefined. Undefined is converted to zero for truncating |
| 4714 | // conversions. |
| 4715 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4716 | DeoptimizeIf(ne, instr->environment(), input_reg, Operand(at)); |
| 4717 | ASSERT(ToRegister(instr->result()).is(input_reg)); |
| 4718 | __ mov(input_reg, zero_reg); |
| 4719 | __ Branch(&done); |
| 4720 | |
| 4721 | __ bind(&heap_number); |
| 4722 | __ ldc1(double_scratch2, |
| 4723 | FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4724 | __ EmitECMATruncate(input_reg, |
| 4725 | double_scratch2, |
| 4726 | single_scratch, |
| 4727 | scratch1, |
| 4728 | scratch2, |
| 4729 | scratch3); |
| 4730 | } else { |
| 4731 | // Deoptimize if we don't have a heap number. |
| 4732 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(at)); |
| 4733 | |
| 4734 | // Load the double value. |
| 4735 | __ ldc1(double_scratch, |
| 4736 | FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4737 | |
| 4738 | Register except_flag = scratch2; |
| 4739 | __ EmitFPUTruncate(kRoundToZero, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4740 | input_reg, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4741 | double_scratch, |
| 4742 | scratch1, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4743 | double_scratch2, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4744 | except_flag, |
| 4745 | kCheckForInexactConversion); |
| 4746 | |
| 4747 | // Deopt if the operation did not succeed. |
| 4748 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
| 4749 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4750 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4751 | __ Branch(&done, ne, input_reg, Operand(zero_reg)); |
| 4752 | |
| 4753 | __ mfc1(scratch1, double_scratch.high()); |
| 4754 | __ And(scratch1, scratch1, Operand(HeapNumber::kSignMask)); |
| 4755 | DeoptimizeIf(ne, instr->environment(), scratch1, Operand(zero_reg)); |
| 4756 | } |
| 4757 | } |
| 4758 | __ bind(&done); |
| 4759 | } |
| 4760 | |
| 4761 | |
| 4762 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
| 4763 | class DeferredTaggedToI: public LDeferredCode { |
| 4764 | public: |
| 4765 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 4766 | : LDeferredCode(codegen), instr_(instr) { } |
| 4767 | virtual void Generate() { codegen()->DoDeferredTaggedToI(instr_); } |
| 4768 | virtual LInstruction* instr() { return instr_; } |
| 4769 | private: |
| 4770 | LTaggedToI* instr_; |
| 4771 | }; |
| 4772 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4773 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4774 | ASSERT(input->IsRegister()); |
| 4775 | ASSERT(input->Equals(instr->result())); |
| 4776 | |
| 4777 | Register input_reg = ToRegister(input); |
| 4778 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4779 | DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4780 | |
| 4781 | // Let the deferred code handle the HeapObject case. |
| 4782 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
| 4783 | |
| 4784 | // Smi to int32 conversion. |
| 4785 | __ SmiUntag(input_reg); |
| 4786 | __ bind(deferred->exit()); |
| 4787 | } |
| 4788 | |
| 4789 | |
| 4790 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4791 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4792 | ASSERT(input->IsRegister()); |
| 4793 | LOperand* result = instr->result(); |
| 4794 | ASSERT(result->IsDoubleRegister()); |
| 4795 | |
| 4796 | Register input_reg = ToRegister(input); |
| 4797 | DoubleRegister result_reg = ToDoubleRegister(result); |
| 4798 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4799 | NumberUntagDMode mode = NUMBER_CANDIDATE_IS_ANY_TAGGED; |
| 4800 | HValue* value = instr->hydrogen()->value(); |
| 4801 | if (value->type().IsSmi()) { |
| 4802 | if (value->IsLoadKeyed()) { |
| 4803 | HLoadKeyed* load = HLoadKeyed::cast(value); |
| 4804 | if (load->UsesMustHandleHole()) { |
| 4805 | if (load->hole_mode() == ALLOW_RETURN_HOLE) { |
| 4806 | mode = NUMBER_CANDIDATE_IS_SMI_CONVERT_HOLE; |
| 4807 | } else { |
| 4808 | mode = NUMBER_CANDIDATE_IS_SMI_OR_HOLE; |
| 4809 | } |
| 4810 | } else { |
| 4811 | mode = NUMBER_CANDIDATE_IS_SMI; |
| 4812 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4813 | } else { |
| 4814 | mode = NUMBER_CANDIDATE_IS_SMI; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4815 | } |
| 4816 | } |
| 4817 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4818 | EmitNumberUntagD(input_reg, result_reg, |
| 4819 | instr->hydrogen()->deoptimize_on_undefined(), |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4820 | instr->hydrogen()->deoptimize_on_minus_zero(), |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4821 | instr->environment(), |
| 4822 | mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | |
| 4826 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
| 4827 | Register result_reg = ToRegister(instr->result()); |
| 4828 | Register scratch1 = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4829 | Register scratch2 = ToRegister(instr->temp()); |
| 4830 | DoubleRegister double_input = ToDoubleRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4831 | |
| 4832 | if (instr->truncating()) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4833 | Register scratch3 = ToRegister(instr->temp2()); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4834 | FPURegister single_scratch = double_scratch0().low(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4835 | __ EmitECMATruncate(result_reg, |
| 4836 | double_input, |
| 4837 | single_scratch, |
| 4838 | scratch1, |
| 4839 | scratch2, |
| 4840 | scratch3); |
| 4841 | } else { |
| 4842 | Register except_flag = scratch2; |
| 4843 | |
| 4844 | __ EmitFPUTruncate(kRoundToMinusInf, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4845 | result_reg, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4846 | double_input, |
| 4847 | scratch1, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 4848 | double_scratch0(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4849 | except_flag, |
| 4850 | kCheckForInexactConversion); |
| 4851 | |
| 4852 | // Deopt if the operation did not succeed (except_flag != 0). |
| 4853 | DeoptimizeIf(ne, instr->environment(), except_flag, Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | |
| 4857 | |
| 4858 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4859 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4860 | __ And(at, ToRegister(input), Operand(kSmiTagMask)); |
| 4861 | DeoptimizeIf(ne, instr->environment(), at, Operand(zero_reg)); |
| 4862 | } |
| 4863 | |
| 4864 | |
| 4865 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4866 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4867 | __ And(at, ToRegister(input), Operand(kSmiTagMask)); |
| 4868 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
| 4869 | } |
| 4870 | |
| 4871 | |
| 4872 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4873 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4874 | Register scratch = scratch0(); |
| 4875 | |
| 4876 | __ GetObjectType(input, scratch, scratch); |
| 4877 | |
| 4878 | if (instr->hydrogen()->is_interval_check()) { |
| 4879 | InstanceType first; |
| 4880 | InstanceType last; |
| 4881 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 4882 | |
| 4883 | // If there is only one type in the interval check for equality. |
| 4884 | if (first == last) { |
| 4885 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(first)); |
| 4886 | } else { |
| 4887 | DeoptimizeIf(lo, instr->environment(), scratch, Operand(first)); |
| 4888 | // Omit check for the last type. |
| 4889 | if (last != LAST_TYPE) { |
| 4890 | DeoptimizeIf(hi, instr->environment(), scratch, Operand(last)); |
| 4891 | } |
| 4892 | } |
| 4893 | } else { |
| 4894 | uint8_t mask; |
| 4895 | uint8_t tag; |
| 4896 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 4897 | |
| 4898 | if (IsPowerOf2(mask)) { |
| 4899 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 4900 | __ And(at, scratch, mask); |
| 4901 | DeoptimizeIf(tag == 0 ? ne : eq, instr->environment(), |
| 4902 | at, Operand(zero_reg)); |
| 4903 | } else { |
| 4904 | __ And(scratch, scratch, Operand(mask)); |
| 4905 | DeoptimizeIf(ne, instr->environment(), scratch, Operand(tag)); |
| 4906 | } |
| 4907 | } |
| 4908 | } |
| 4909 | |
| 4910 | |
| 4911 | void LCodeGen::DoCheckFunction(LCheckFunction* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4912 | Register reg = ToRegister(instr->value()); |
| 4913 | Handle<JSFunction> target = instr->hydrogen()->target(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4914 | ALLOW_HANDLE_DEREF(isolate(), "smi check"); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4915 | if (isolate()->heap()->InNewSpace(*target)) { |
| 4916 | Register reg = ToRegister(instr->value()); |
| 4917 | Handle<JSGlobalPropertyCell> cell = |
| 4918 | isolate()->factory()->NewJSGlobalPropertyCell(target); |
| 4919 | __ li(at, Operand(Handle<Object>(cell))); |
| 4920 | __ lw(at, FieldMemOperand(at, JSGlobalPropertyCell::kValueOffset)); |
| 4921 | DeoptimizeIf(ne, instr->environment(), reg, |
| 4922 | Operand(at)); |
| 4923 | } else { |
| 4924 | DeoptimizeIf(ne, instr->environment(), reg, |
| 4925 | Operand(target)); |
| 4926 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4930 | void LCodeGen::DoCheckMapCommon(Register map_reg, |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 4931 | Handle<Map> map, |
| 4932 | CompareMapMode mode, |
| 4933 | LEnvironment* env) { |
| 4934 | Label success; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4935 | __ CompareMapAndBranch(map_reg, map, &success, eq, &success, mode); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 4936 | DeoptimizeIf(al, env); |
| 4937 | __ bind(&success); |
| 4938 | } |
| 4939 | |
| 4940 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4941 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4942 | Register map_reg = scratch0(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4943 | LOperand* input = instr->value(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4944 | ASSERT(input->IsRegister()); |
| 4945 | Register reg = ToRegister(input); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4946 | Label success; |
| 4947 | SmallMapList* map_set = instr->hydrogen()->map_set(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4948 | __ lw(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4949 | for (int i = 0; i < map_set->length() - 1; i++) { |
| 4950 | Handle<Map> map = map_set->at(i); |
| 4951 | __ CompareMapAndBranch( |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4952 | map_reg, map, &success, eq, &success, REQUIRE_EXACT_MAP); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4953 | } |
| 4954 | Handle<Map> map = map_set->last(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4955 | DoCheckMapCommon(map_reg, map, REQUIRE_EXACT_MAP, instr->environment()); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4956 | __ bind(&success); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | |
| 4960 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
| 4961 | DoubleRegister value_reg = ToDoubleRegister(instr->unclamped()); |
| 4962 | Register result_reg = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4963 | DoubleRegister temp_reg = ToDoubleRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4964 | __ ClampDoubleToUint8(result_reg, value_reg, temp_reg); |
| 4965 | } |
| 4966 | |
| 4967 | |
| 4968 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 4969 | Register unclamped_reg = ToRegister(instr->unclamped()); |
| 4970 | Register result_reg = ToRegister(instr->result()); |
| 4971 | __ ClampUint8(result_reg, unclamped_reg); |
| 4972 | } |
| 4973 | |
| 4974 | |
| 4975 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 4976 | Register scratch = scratch0(); |
| 4977 | Register input_reg = ToRegister(instr->unclamped()); |
| 4978 | Register result_reg = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4979 | DoubleRegister temp_reg = ToDoubleRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4980 | Label is_smi, done, heap_number; |
| 4981 | |
| 4982 | // Both smi and heap number cases are handled. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4983 | __ UntagAndJumpIfSmi(scratch, input_reg, &is_smi); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4984 | |
| 4985 | // Check for heap number |
| 4986 | __ lw(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4987 | __ Branch(&heap_number, eq, scratch, Operand(factory()->heap_number_map())); |
| 4988 | |
| 4989 | // Check for undefined. Undefined is converted to zero for clamping |
| 4990 | // conversions. |
| 4991 | DeoptimizeIf(ne, instr->environment(), input_reg, |
| 4992 | Operand(factory()->undefined_value())); |
| 4993 | __ mov(result_reg, zero_reg); |
| 4994 | __ jmp(&done); |
| 4995 | |
| 4996 | // Heap number |
| 4997 | __ bind(&heap_number); |
| 4998 | __ ldc1(double_scratch0(), FieldMemOperand(input_reg, |
| 4999 | HeapNumber::kValueOffset)); |
| 5000 | __ ClampDoubleToUint8(result_reg, double_scratch0(), temp_reg); |
| 5001 | __ jmp(&done); |
| 5002 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5003 | __ bind(&is_smi); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5004 | __ ClampUint8(result_reg, scratch); |
| 5005 | |
| 5006 | __ bind(&done); |
| 5007 | } |
| 5008 | |
| 5009 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5010 | void LCodeGen::DoCheckPrototypeMaps(LCheckPrototypeMaps* instr) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5011 | Register prototype_reg = ToRegister(instr->temp()); |
| 5012 | Register map_reg = ToRegister(instr->temp2()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5013 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5014 | ZoneList<Handle<JSObject> >* prototypes = instr->prototypes(); |
| 5015 | ZoneList<Handle<Map> >* maps = instr->maps(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5016 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5017 | ASSERT(prototypes->length() == maps->length()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5018 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 5019 | if (instr->hydrogen()->CanOmitPrototypeChecks()) { |
| 5020 | for (int i = 0; i < maps->length(); i++) { |
| 5021 | prototype_maps_.Add(maps->at(i), info()->zone()); |
| 5022 | } |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 5023 | } else { |
| 5024 | for (int i = 0; i < prototypes->length(); i++) { |
| 5025 | __ LoadHeapObject(prototype_reg, prototypes->at(i)); |
| 5026 | __ lw(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); |
| 5027 | DoCheckMapCommon(map_reg, |
| 5028 | maps->at(i), |
| 5029 | ALLOW_ELEMENT_TRANSITION_MAPS, |
| 5030 | instr->environment()); |
| 5031 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5032 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5036 | void LCodeGen::DoAllocateObject(LAllocateObject* instr) { |
| 5037 | class DeferredAllocateObject: public LDeferredCode { |
| 5038 | public: |
| 5039 | DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
| 5040 | : LDeferredCode(codegen), instr_(instr) { } |
| 5041 | virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
| 5042 | virtual LInstruction* instr() { return instr_; } |
| 5043 | private: |
| 5044 | LAllocateObject* instr_; |
| 5045 | }; |
| 5046 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5047 | DeferredAllocateObject* deferred = |
| 5048 | new(zone()) DeferredAllocateObject(this, instr); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5049 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5050 | Register result = ToRegister(instr->result()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5051 | Register scratch = ToRegister(instr->temp()); |
| 5052 | Register scratch2 = ToRegister(instr->temp2()); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5053 | Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5054 | Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5055 | int instance_size = initial_map->instance_size(); |
| 5056 | ASSERT(initial_map->pre_allocated_property_fields() + |
| 5057 | initial_map->unused_property_fields() - |
| 5058 | initial_map->inobject_properties() == 0); |
| 5059 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 5060 | __ Allocate(instance_size, result, scratch, scratch2, deferred->entry(), |
| 5061 | TAG_OBJECT); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5062 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5063 | __ bind(deferred->exit()); |
| 5064 | if (FLAG_debug_code) { |
| 5065 | Label is_in_new_space; |
| 5066 | __ JumpIfInNewSpace(result, scratch, &is_in_new_space); |
| 5067 | __ Abort("Allocated object is not in new-space"); |
| 5068 | __ bind(&is_in_new_space); |
| 5069 | } |
| 5070 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5071 | // Load the initial map. |
| 5072 | Register map = scratch; |
| 5073 | __ LoadHeapObject(map, constructor); |
| 5074 | __ lw(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5075 | |
| 5076 | // Initialize map and fields of the newly allocated object. |
| 5077 | ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); |
| 5078 | __ sw(map, FieldMemOperand(result, JSObject::kMapOffset)); |
| 5079 | __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); |
| 5080 | __ sw(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); |
| 5081 | __ sw(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); |
| 5082 | if (initial_map->inobject_properties() != 0) { |
| 5083 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5084 | for (int i = 0; i < initial_map->inobject_properties(); i++) { |
| 5085 | int property_offset = JSObject::kHeaderSize + i * kPointerSize; |
| 5086 | __ sw(scratch, FieldMemOperand(result, property_offset)); |
| 5087 | } |
| 5088 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | |
| 5092 | void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
| 5093 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5094 | Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5095 | int instance_size = initial_map->instance_size(); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5096 | |
| 5097 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5098 | // result register contain a valid pointer because it is already |
| 5099 | // contained in the register pointer map. |
| 5100 | __ mov(result, zero_reg); |
| 5101 | |
| 5102 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5103 | __ li(a0, Operand(Smi::FromInt(instance_size))); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5104 | __ push(a0); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5105 | CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5106 | __ StoreToSafepointRegisterSlot(v0, result); |
| 5107 | } |
| 5108 | |
| 5109 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5110 | void LCodeGen::DoAllocate(LAllocate* instr) { |
| 5111 | class DeferredAllocate: public LDeferredCode { |
| 5112 | public: |
| 5113 | DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5114 | : LDeferredCode(codegen), instr_(instr) { } |
| 5115 | virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
| 5116 | virtual LInstruction* instr() { return instr_; } |
| 5117 | private: |
| 5118 | LAllocate* instr_; |
| 5119 | }; |
| 5120 | |
| 5121 | DeferredAllocate* deferred = |
| 5122 | new(zone()) DeferredAllocate(this, instr); |
| 5123 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5124 | Register result = ToRegister(instr->result()); |
| 5125 | Register scratch = ToRegister(instr->temp1()); |
| 5126 | Register scratch2 = ToRegister(instr->temp2()); |
| 5127 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5128 | // Allocate memory for the object. |
| 5129 | AllocationFlags flags = TAG_OBJECT; |
| 5130 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 5131 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 5132 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5133 | if (instr->hydrogen()->CanAllocateInOldPointerSpace()) { |
| 5134 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
| 5135 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5136 | if (instr->size()->IsConstantOperand()) { |
| 5137 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 5138 | __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5139 | } else { |
| 5140 | Register size = ToRegister(instr->size()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5141 | __ Allocate(size, |
| 5142 | result, |
| 5143 | scratch, |
| 5144 | scratch2, |
| 5145 | deferred->entry(), |
| 5146 | flags); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | __ bind(deferred->exit()); |
| 5150 | } |
| 5151 | |
| 5152 | |
| 5153 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5154 | Register result = ToRegister(instr->result()); |
| 5155 | |
| 5156 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5157 | // result register contain a valid pointer because it is already |
| 5158 | // contained in the register pointer map. |
| 5159 | __ mov(result, zero_reg); |
| 5160 | |
| 5161 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5162 | if (instr->size()->IsRegister()) { |
| 5163 | Register size = ToRegister(instr->size()); |
| 5164 | ASSERT(!size.is(result)); |
| 5165 | __ SmiTag(size); |
| 5166 | __ push(size); |
| 5167 | } else { |
| 5168 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5169 | __ Push(Smi::FromInt(size)); |
| 5170 | } |
| 5171 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5172 | if (instr->hydrogen()->CanAllocateInOldPointerSpace()) { |
| 5173 | CallRuntimeFromDeferred( |
| 5174 | Runtime::kAllocateInOldPointerSpace, 1, instr); |
| 5175 | } else { |
| 5176 | CallRuntimeFromDeferred( |
| 5177 | Runtime::kAllocateInNewSpace, 1, instr); |
| 5178 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5179 | __ StoreToSafepointRegisterSlot(v0, result); |
| 5180 | } |
| 5181 | |
| 5182 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5183 | void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5184 | Handle<FixedArray> literals = instr->hydrogen()->literals(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5185 | ElementsKind boilerplate_elements_kind = |
| 5186 | instr->hydrogen()->boilerplate_elements_kind(); |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 5187 | AllocationSiteMode allocation_site_mode = |
| 5188 | instr->hydrogen()->allocation_site_mode(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5189 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5190 | // Deopt if the array literal boilerplate ElementsKind is of a type different |
| 5191 | // than the expected one. The check isn't necessary if the boilerplate has |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5192 | // already been converted to TERMINAL_FAST_ELEMENTS_KIND. |
| 5193 | if (CanTransitionToMoreGeneralFastElementsKind( |
| 5194 | boilerplate_elements_kind, true)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5195 | __ LoadHeapObject(a1, instr->hydrogen()->boilerplate_object()); |
| 5196 | // Load map into a2. |
| 5197 | __ lw(a2, FieldMemOperand(a1, HeapObject::kMapOffset)); |
| 5198 | // Load the map's "bit field 2". |
| 5199 | __ lbu(a2, FieldMemOperand(a2, Map::kBitField2Offset)); |
| 5200 | // Retrieve elements_kind from bit field 2. |
| 5201 | __ Ext(a2, a2, Map::kElementsKindShift, Map::kElementsKindBitCount); |
| 5202 | DeoptimizeIf(ne, |
| 5203 | instr->environment(), |
| 5204 | a2, |
| 5205 | Operand(boilerplate_elements_kind)); |
| 5206 | } |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5207 | |
| 5208 | // Set up the parameters to the stub/runtime call. |
| 5209 | __ LoadHeapObject(a3, literals); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5210 | __ li(a2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5211 | // Boilerplate already exists, constant elements are never accessed. |
| 5212 | // Pass an empty fixed array. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5213 | __ li(a1, Operand(isolate()->factory()->empty_fixed_array())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5214 | |
| 5215 | // Pick the right runtime function or stub to call. |
| 5216 | int length = instr->hydrogen()->length(); |
| 5217 | if (instr->hydrogen()->IsCopyOnWrite()) { |
| 5218 | ASSERT(instr->hydrogen()->depth() == 1); |
| 5219 | FastCloneShallowArrayStub::Mode mode = |
| 5220 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 5221 | FastCloneShallowArrayStub stub(mode, DONT_TRACK_ALLOCATION_SITE, length); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5222 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5223 | } else if (instr->hydrogen()->depth() > 1) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5224 | __ Push(a3, a2, a1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5225 | CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); |
| 5226 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5227 | __ Push(a3, a2, a1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5228 | CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); |
| 5229 | } else { |
| 5230 | FastCloneShallowArrayStub::Mode mode = |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5231 | boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 5232 | ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 5233 | : FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 5234 | FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5235 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 5240 | void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5241 | ASSERT(ToRegister(instr->result()).is(v0)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5242 | Handle<FixedArray> literals = instr->hydrogen()->literals(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5243 | Handle<FixedArray> constant_properties = |
| 5244 | instr->hydrogen()->constant_properties(); |
| 5245 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5246 | // Set up the parameters to the stub/runtime call. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5247 | __ LoadHeapObject(a3, literals); |
| 5248 | __ li(a2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 5249 | __ li(a1, Operand(constant_properties)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5250 | int flags = instr->hydrogen()->fast_elements() |
| 5251 | ? ObjectLiteral::kFastElements |
| 5252 | : ObjectLiteral::kNoFlags; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5253 | __ li(a0, Operand(Smi::FromInt(flags))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5254 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5255 | // Pick the right runtime function or stub to call. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5256 | int properties_count = instr->hydrogen()->constant_properties_length() / 2; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5257 | if ((FLAG_track_double_fields && instr->hydrogen()->may_store_doubles()) || |
| 5258 | instr->hydrogen()->depth() > 1) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5259 | __ Push(a3, a2, a1, a0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5260 | CallRuntime(Runtime::kCreateObjectLiteral, 4, instr); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5261 | } else if (flags != ObjectLiteral::kFastElements || |
| 5262 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5263 | __ Push(a3, a2, a1, a0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5264 | CallRuntime(Runtime::kCreateObjectLiteralShallow, 4, instr); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5265 | } else { |
| 5266 | FastCloneShallowObjectStub stub(properties_count); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5267 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5268 | } |
| 5269 | } |
| 5270 | |
| 5271 | |
| 5272 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5273 | ASSERT(ToRegister(instr->value()).is(a0)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5274 | ASSERT(ToRegister(instr->result()).is(v0)); |
| 5275 | __ push(a0); |
| 5276 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
| 5277 | } |
| 5278 | |
| 5279 | |
| 5280 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
| 5281 | Label materialized; |
| 5282 | // Registers will be used as follows: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5283 | // t3 = literals array. |
| 5284 | // a1 = regexp literal. |
| 5285 | // a0 = regexp literal clone. |
| 5286 | // a2 and t0-t2 are used as temporaries. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5287 | int literal_offset = |
| 5288 | FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
| 5289 | __ LoadHeapObject(t3, instr->hydrogen()->literals()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5290 | __ lw(a1, FieldMemOperand(t3, literal_offset)); |
| 5291 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5292 | __ Branch(&materialized, ne, a1, Operand(at)); |
| 5293 | |
| 5294 | // Create regexp literal using runtime function |
| 5295 | // Result will be in v0. |
| 5296 | __ li(t2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 5297 | __ li(t1, Operand(instr->hydrogen()->pattern())); |
| 5298 | __ li(t0, Operand(instr->hydrogen()->flags())); |
| 5299 | __ Push(t3, t2, t1, t0); |
| 5300 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
| 5301 | __ mov(a1, v0); |
| 5302 | |
| 5303 | __ bind(&materialized); |
| 5304 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 5305 | Label allocated, runtime_allocate; |
| 5306 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 5307 | __ Allocate(size, v0, a2, a3, &runtime_allocate, TAG_OBJECT); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5308 | __ jmp(&allocated); |
| 5309 | |
| 5310 | __ bind(&runtime_allocate); |
| 5311 | __ li(a0, Operand(Smi::FromInt(size))); |
| 5312 | __ Push(a1, a0); |
| 5313 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 5314 | __ pop(a1); |
| 5315 | |
| 5316 | __ bind(&allocated); |
| 5317 | // Copy the content into the newly allocated memory. |
| 5318 | // (Unroll copy loop once for better throughput). |
| 5319 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 5320 | __ lw(a3, FieldMemOperand(a1, i)); |
| 5321 | __ lw(a2, FieldMemOperand(a1, i + kPointerSize)); |
| 5322 | __ sw(a3, FieldMemOperand(v0, i)); |
| 5323 | __ sw(a2, FieldMemOperand(v0, i + kPointerSize)); |
| 5324 | } |
| 5325 | if ((size % (2 * kPointerSize)) != 0) { |
| 5326 | __ lw(a3, FieldMemOperand(a1, size - kPointerSize)); |
| 5327 | __ sw(a3, FieldMemOperand(v0, size - kPointerSize)); |
| 5328 | } |
| 5329 | } |
| 5330 | |
| 5331 | |
| 5332 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
| 5333 | // Use the fast case closure allocation code that allocates in new |
| 5334 | // space for nested functions that don't need literals cloning. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5335 | bool pretenure = instr->hydrogen()->pretenure(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5336 | if (!pretenure && instr->hydrogen()->has_no_literals()) { |
| 5337 | FastNewClosureStub stub(instr->hydrogen()->language_mode(), |
| 5338 | instr->hydrogen()->is_generator()); |
| 5339 | __ li(a1, Operand(instr->hydrogen()->shared_info())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5340 | __ push(a1); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5341 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5342 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5343 | __ li(a2, Operand(instr->hydrogen()->shared_info())); |
| 5344 | __ li(a1, Operand(pretenure ? factory()->true_value() |
| 5345 | : factory()->false_value())); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5346 | __ Push(cp, a2, a1); |
| 5347 | CallRuntime(Runtime::kNewClosure, 3, instr); |
| 5348 | } |
| 5349 | } |
| 5350 | |
| 5351 | |
| 5352 | void LCodeGen::DoTypeof(LTypeof* instr) { |
| 5353 | ASSERT(ToRegister(instr->result()).is(v0)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5354 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5355 | __ push(input); |
| 5356 | CallRuntime(Runtime::kTypeof, 1, instr); |
| 5357 | } |
| 5358 | |
| 5359 | |
| 5360 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5361 | Register input = ToRegister(instr->value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5362 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 5363 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 5364 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 5365 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 5366 | |
| 5367 | Register cmp1 = no_reg; |
| 5368 | Operand cmp2 = Operand(no_reg); |
| 5369 | |
| 5370 | Condition final_branch_condition = EmitTypeofIs(true_label, |
| 5371 | false_label, |
| 5372 | input, |
| 5373 | instr->type_literal(), |
| 5374 | cmp1, |
| 5375 | cmp2); |
| 5376 | |
| 5377 | ASSERT(cmp1.is_valid()); |
| 5378 | ASSERT(!cmp2.is_reg() || cmp2.rm().is_valid()); |
| 5379 | |
| 5380 | if (final_branch_condition != kNoCondition) { |
| 5381 | EmitBranch(true_block, false_block, final_branch_condition, cmp1, cmp2); |
| 5382 | } |
| 5383 | } |
| 5384 | |
| 5385 | |
| 5386 | Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 5387 | Label* false_label, |
| 5388 | Register input, |
| 5389 | Handle<String> type_name, |
| 5390 | Register& cmp1, |
| 5391 | Operand& cmp2) { |
| 5392 | // This function utilizes the delay slot heavily. This is used to load |
| 5393 | // values that are always usable without depending on the type of the input |
| 5394 | // register. |
| 5395 | Condition final_branch_condition = kNoCondition; |
| 5396 | Register scratch = scratch0(); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5397 | if (type_name->Equals(heap()->number_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5398 | __ JumpIfSmi(input, true_label); |
| 5399 | __ lw(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5400 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 5401 | cmp1 = input; |
| 5402 | cmp2 = Operand(at); |
| 5403 | final_branch_condition = eq; |
| 5404 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5405 | } else if (type_name->Equals(heap()->string_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5406 | __ JumpIfSmi(input, false_label); |
| 5407 | __ GetObjectType(input, input, scratch); |
| 5408 | __ Branch(USE_DELAY_SLOT, false_label, |
| 5409 | ge, scratch, Operand(FIRST_NONSTRING_TYPE)); |
| 5410 | // input is an object so we can load the BitFieldOffset even if we take the |
| 5411 | // other branch. |
| 5412 | __ lbu(at, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 5413 | __ And(at, at, 1 << Map::kIsUndetectable); |
| 5414 | cmp1 = at; |
| 5415 | cmp2 = Operand(zero_reg); |
| 5416 | final_branch_condition = eq; |
| 5417 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5418 | } else if (type_name->Equals(heap()->symbol_string())) { |
| 5419 | __ JumpIfSmi(input, false_label); |
| 5420 | __ GetObjectType(input, input, scratch); |
| 5421 | cmp1 = scratch; |
| 5422 | cmp2 = Operand(SYMBOL_TYPE); |
| 5423 | final_branch_condition = eq; |
| 5424 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5425 | } else if (type_name->Equals(heap()->boolean_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5426 | __ LoadRoot(at, Heap::kTrueValueRootIndex); |
| 5427 | __ Branch(USE_DELAY_SLOT, true_label, eq, at, Operand(input)); |
| 5428 | __ LoadRoot(at, Heap::kFalseValueRootIndex); |
| 5429 | cmp1 = at; |
| 5430 | cmp2 = Operand(input); |
| 5431 | final_branch_condition = eq; |
| 5432 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5433 | } else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5434 | __ LoadRoot(at, Heap::kNullValueRootIndex); |
| 5435 | cmp1 = at; |
| 5436 | cmp2 = Operand(input); |
| 5437 | final_branch_condition = eq; |
| 5438 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5439 | } else if (type_name->Equals(heap()->undefined_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5440 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5441 | __ Branch(USE_DELAY_SLOT, true_label, eq, at, Operand(input)); |
| 5442 | // The first instruction of JumpIfSmi is an And - it is safe in the delay |
| 5443 | // slot. |
| 5444 | __ JumpIfSmi(input, false_label); |
| 5445 | // Check for undetectable objects => true. |
| 5446 | __ lw(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5447 | __ lbu(at, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 5448 | __ And(at, at, 1 << Map::kIsUndetectable); |
| 5449 | cmp1 = at; |
| 5450 | cmp2 = Operand(zero_reg); |
| 5451 | final_branch_condition = ne; |
| 5452 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5453 | } else if (type_name->Equals(heap()->function_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5454 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 5455 | __ JumpIfSmi(input, false_label); |
| 5456 | __ GetObjectType(input, scratch, input); |
| 5457 | __ Branch(true_label, eq, input, Operand(JS_FUNCTION_TYPE)); |
| 5458 | cmp1 = input; |
| 5459 | cmp2 = Operand(JS_FUNCTION_PROXY_TYPE); |
| 5460 | final_branch_condition = eq; |
| 5461 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5462 | } else if (type_name->Equals(heap()->object_string())) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5463 | __ JumpIfSmi(input, false_label); |
| 5464 | if (!FLAG_harmony_typeof) { |
| 5465 | __ LoadRoot(at, Heap::kNullValueRootIndex); |
| 5466 | __ Branch(USE_DELAY_SLOT, true_label, eq, at, Operand(input)); |
| 5467 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5468 | Register map = input; |
| 5469 | __ GetObjectType(input, map, scratch); |
| 5470 | __ Branch(false_label, |
| 5471 | lt, scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5472 | __ Branch(USE_DELAY_SLOT, false_label, |
| 5473 | gt, scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5474 | // 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] | 5475 | // Check for undetectable objects => false. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5476 | __ lbu(at, FieldMemOperand(map, Map::kBitFieldOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5477 | __ And(at, at, 1 << Map::kIsUndetectable); |
| 5478 | cmp1 = at; |
| 5479 | cmp2 = Operand(zero_reg); |
| 5480 | final_branch_condition = eq; |
| 5481 | |
| 5482 | } else { |
| 5483 | cmp1 = at; |
| 5484 | cmp2 = Operand(zero_reg); // Set to valid regs, to avoid caller assertion. |
| 5485 | __ Branch(false_label); |
| 5486 | } |
| 5487 | |
| 5488 | return final_branch_condition; |
| 5489 | } |
| 5490 | |
| 5491 | |
| 5492 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5493 | Register temp1 = ToRegister(instr->temp()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5494 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 5495 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 5496 | |
| 5497 | EmitIsConstructCall(temp1, scratch0()); |
| 5498 | |
| 5499 | EmitBranch(true_block, false_block, eq, temp1, |
| 5500 | Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 5501 | } |
| 5502 | |
| 5503 | |
| 5504 | void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { |
| 5505 | ASSERT(!temp1.is(temp2)); |
| 5506 | // Get the frame pointer for the calling frame. |
| 5507 | __ lw(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5508 | |
| 5509 | // Skip the arguments adaptor frame if it exists. |
| 5510 | Label check_frame_marker; |
| 5511 | __ lw(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); |
| 5512 | __ Branch(&check_frame_marker, ne, temp2, |
| 5513 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5514 | __ lw(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset)); |
| 5515 | |
| 5516 | // Check the marker in the calling frame. |
| 5517 | __ bind(&check_frame_marker); |
| 5518 | __ lw(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); |
| 5519 | } |
| 5520 | |
| 5521 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5522 | void LCodeGen::EnsureSpaceForLazyDeopt() { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5523 | if (info()->IsStub()) return; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5524 | // Ensure that we have enough space after the previous lazy-bailout |
| 5525 | // instruction for patching the code here. |
| 5526 | int current_pc = masm()->pc_offset(); |
| 5527 | int patch_size = Deoptimizer::patch_size(); |
| 5528 | if (current_pc < last_lazy_deopt_pc_ + patch_size) { |
| 5529 | int padding_size = last_lazy_deopt_pc_ + patch_size - current_pc; |
| 5530 | ASSERT_EQ(0, padding_size % Assembler::kInstrSize); |
| 5531 | while (padding_size > 0) { |
| 5532 | __ nop(); |
| 5533 | padding_size -= Assembler::kInstrSize; |
| 5534 | } |
| 5535 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5536 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5540 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5541 | EnsureSpaceForLazyDeopt(); |
| 5542 | ASSERT(instr->HasEnvironment()); |
| 5543 | LEnvironment* env = instr->environment(); |
| 5544 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5545 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5546 | } |
| 5547 | |
| 5548 | |
| 5549 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
| 5550 | DeoptimizeIf(al, instr->environment(), zero_reg, Operand(zero_reg)); |
| 5551 | } |
| 5552 | |
| 5553 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5554 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 5555 | // Nothing to see here, move on! |
| 5556 | } |
| 5557 | |
| 5558 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5559 | void LCodeGen::DoDeleteProperty(LDeleteProperty* instr) { |
| 5560 | Register object = ToRegister(instr->object()); |
| 5561 | Register key = ToRegister(instr->key()); |
| 5562 | Register strict = scratch0(); |
| 5563 | __ li(strict, Operand(Smi::FromInt(strict_mode_flag()))); |
| 5564 | __ Push(object, key, strict); |
danno@chromium.org | e4bfb26 | 2012-05-04 10:50:07 +0000 | [diff] [blame] | 5565 | ASSERT(instr->HasPointerMap()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5566 | LPointerMap* pointers = instr->pointer_map(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5567 | RecordPosition(pointers->position()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5568 | SafepointGenerator safepoint_generator( |
| 5569 | this, pointers, Safepoint::kLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5570 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, safepoint_generator); |
| 5571 | } |
| 5572 | |
| 5573 | |
| 5574 | void LCodeGen::DoIn(LIn* instr) { |
| 5575 | Register obj = ToRegister(instr->object()); |
| 5576 | Register key = ToRegister(instr->key()); |
| 5577 | __ Push(key, obj); |
danno@chromium.org | e4bfb26 | 2012-05-04 10:50:07 +0000 | [diff] [blame] | 5578 | ASSERT(instr->HasPointerMap()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5579 | LPointerMap* pointers = instr->pointer_map(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5580 | RecordPosition(pointers->position()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5581 | SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5582 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); |
| 5583 | } |
| 5584 | |
| 5585 | |
| 5586 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5587 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 5588 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 5589 | RecordSafepointWithLazyDeopt( |
| 5590 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 5591 | ASSERT(instr->HasEnvironment()); |
| 5592 | LEnvironment* env = instr->environment(); |
| 5593 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | |
| 5597 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
| 5598 | class DeferredStackCheck: public LDeferredCode { |
| 5599 | public: |
| 5600 | DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
| 5601 | : LDeferredCode(codegen), instr_(instr) { } |
| 5602 | virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } |
| 5603 | virtual LInstruction* instr() { return instr_; } |
| 5604 | private: |
| 5605 | LStackCheck* instr_; |
| 5606 | }; |
| 5607 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5608 | ASSERT(instr->HasEnvironment()); |
| 5609 | LEnvironment* env = instr->environment(); |
| 5610 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 5611 | // prepare for lazy deoptimization explicitly here. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5612 | if (instr->hydrogen()->is_function_entry()) { |
| 5613 | // Perform stack overflow check. |
| 5614 | Label done; |
| 5615 | __ LoadRoot(at, Heap::kStackLimitRootIndex); |
| 5616 | __ Branch(&done, hs, sp, Operand(at)); |
| 5617 | StackCheckStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5618 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5619 | EnsureSpaceForLazyDeopt(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5620 | __ bind(&done); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5621 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5622 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5623 | } else { |
| 5624 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 5625 | // Perform stack overflow check if this goto needs it before jumping. |
| 5626 | DeferredStackCheck* deferred_stack_check = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5627 | new(zone()) DeferredStackCheck(this, instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5628 | __ LoadRoot(at, Heap::kStackLimitRootIndex); |
| 5629 | __ Branch(deferred_stack_check->entry(), lo, sp, Operand(at)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5630 | EnsureSpaceForLazyDeopt(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5631 | __ bind(instr->done_label()); |
| 5632 | deferred_stack_check->SetExit(instr->done_label()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5633 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5634 | // Don't record a deoptimization index for the safepoint here. |
| 5635 | // This will be done explicitly when emitting call and the safepoint in |
| 5636 | // the deferred code. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5637 | } |
| 5638 | } |
| 5639 | |
| 5640 | |
| 5641 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 5642 | // This is a pseudo-instruction that ensures that the environment here is |
| 5643 | // properly registered for deoptimization and records the assembler's PC |
| 5644 | // offset. |
| 5645 | LEnvironment* environment = instr->environment(); |
| 5646 | environment->SetSpilledRegisters(instr->SpilledRegisterArray(), |
| 5647 | instr->SpilledDoubleRegisterArray()); |
| 5648 | |
| 5649 | // If the environment were already registered, we would have no way of |
| 5650 | // backpatching it with the spill slot operands. |
| 5651 | ASSERT(!environment->HasBeenRegistered()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5652 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5653 | ASSERT(osr_pc_offset_ == -1); |
| 5654 | osr_pc_offset_ = masm()->pc_offset(); |
| 5655 | } |
| 5656 | |
| 5657 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5658 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
| 5659 | Register result = ToRegister(instr->result()); |
| 5660 | Register object = ToRegister(instr->object()); |
| 5661 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5662 | DeoptimizeIf(eq, instr->environment(), object, Operand(at)); |
| 5663 | |
| 5664 | Register null_value = t1; |
| 5665 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 5666 | DeoptimizeIf(eq, instr->environment(), object, Operand(null_value)); |
| 5667 | |
| 5668 | __ And(at, object, kSmiTagMask); |
| 5669 | DeoptimizeIf(eq, instr->environment(), at, Operand(zero_reg)); |
| 5670 | |
| 5671 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 5672 | __ GetObjectType(object, a1, a1); |
| 5673 | DeoptimizeIf(le, instr->environment(), a1, Operand(LAST_JS_PROXY_TYPE)); |
| 5674 | |
| 5675 | Label use_cache, call_runtime; |
| 5676 | ASSERT(object.is(a0)); |
| 5677 | __ CheckEnumCache(null_value, &call_runtime); |
| 5678 | |
| 5679 | __ lw(result, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5680 | __ Branch(&use_cache); |
| 5681 | |
| 5682 | // Get the set of properties to enumerate. |
| 5683 | __ bind(&call_runtime); |
| 5684 | __ push(object); |
| 5685 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 5686 | |
| 5687 | __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 5688 | ASSERT(result.is(v0)); |
| 5689 | __ LoadRoot(at, Heap::kMetaMapRootIndex); |
| 5690 | DeoptimizeIf(ne, instr->environment(), a1, Operand(at)); |
| 5691 | __ bind(&use_cache); |
| 5692 | } |
| 5693 | |
| 5694 | |
| 5695 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5696 | Register map = ToRegister(instr->map()); |
| 5697 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5698 | Label load_cache, done; |
| 5699 | __ EnumLength(result, map); |
| 5700 | __ Branch(&load_cache, ne, result, Operand(Smi::FromInt(0))); |
| 5701 | __ li(result, Operand(isolate()->factory()->empty_fixed_array())); |
| 5702 | __ jmp(&done); |
| 5703 | |
| 5704 | __ bind(&load_cache); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5705 | __ LoadInstanceDescriptors(map, result); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5706 | __ lw(result, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 5707 | FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5708 | __ lw(result, |
| 5709 | FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
| 5710 | DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg)); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5711 | |
| 5712 | __ bind(&done); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | |
| 5716 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5717 | Register object = ToRegister(instr->value()); |
| 5718 | Register map = ToRegister(instr->map()); |
| 5719 | __ lw(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5720 | DeoptimizeIf(ne, instr->environment(), map, Operand(scratch0())); |
| 5721 | } |
| 5722 | |
| 5723 | |
| 5724 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 5725 | Register object = ToRegister(instr->object()); |
| 5726 | Register index = ToRegister(instr->index()); |
| 5727 | Register result = ToRegister(instr->result()); |
| 5728 | Register scratch = scratch0(); |
| 5729 | |
| 5730 | Label out_of_object, done; |
| 5731 | __ Branch(USE_DELAY_SLOT, &out_of_object, lt, index, Operand(zero_reg)); |
| 5732 | __ sll(scratch, index, kPointerSizeLog2 - kSmiTagSize); // In delay slot. |
| 5733 | |
| 5734 | STATIC_ASSERT(kPointerSizeLog2 > kSmiTagSize); |
| 5735 | __ Addu(scratch, object, scratch); |
| 5736 | __ lw(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
| 5737 | |
| 5738 | __ Branch(&done); |
| 5739 | |
| 5740 | __ bind(&out_of_object); |
| 5741 | __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 5742 | // Index is equal to negated out of object property index plus 1. |
| 5743 | __ Subu(scratch, result, scratch); |
| 5744 | __ lw(result, FieldMemOperand(scratch, |
| 5745 | FixedArray::kHeaderSize - kPointerSize)); |
| 5746 | __ bind(&done); |
| 5747 | } |
| 5748 | |
| 5749 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5750 | #undef __ |
| 5751 | |
| 5752 | } } // namespace v8::internal |