erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 30 | #include "arm/lithium-codegen-arm.h" |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 31 | #include "arm/lithium-gap-resolver-arm.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 32 | #include "code-stubs.h" |
| 33 | #include "stub-cache.h" |
| 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 39 | class SafepointGenerator : public CallWrapper { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 40 | public: |
| 41 | SafepointGenerator(LCodeGen* codegen, |
| 42 | LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 43 | Safepoint::DeoptMode mode) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 44 | : codegen_(codegen), |
| 45 | pointers_(pointers), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 46 | deopt_mode_(mode) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 47 | virtual ~SafepointGenerator() { } |
| 48 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 49 | virtual void BeforeCall(int call_size) const { } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 50 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 51 | virtual void AfterCall() const { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 52 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | private: |
| 56 | LCodeGen* codegen_; |
| 57 | LPointerMap* pointers_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 58 | Safepoint::DeoptMode deopt_mode_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 66 | ASSERT(is_unused()); |
| 67 | status_ = GENERATING; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 68 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +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 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 74 | return GeneratePrologue() && |
| 75 | GenerateBody() && |
| 76 | GenerateDeferredCode() && |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 77 | GenerateDeoptJumpTable() && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 78 | GenerateSafepointTable(); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 83 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 84 | code->set_stack_slots(GetStackSlotCount()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 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 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 101 | void LCodeGen::Abort(const char* reason) { |
| 102 | info()->set_bailout_reason(reason); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 121 | masm()->RecordComment(copy.start()); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | bool LCodeGen::GeneratePrologue() { |
| 126 | ASSERT(is_generating()); |
| 127 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 128 | if (info()->IsOptimizing()) { |
| 129 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 130 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 131 | #ifdef DEBUG |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 132 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 133 | info_->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 134 | __ stop("stop_at"); |
| 135 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 136 | #endif |
| 137 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 138 | // r1: Callee's JS function. |
| 139 | // cp: Callee's context. |
| 140 | // fp: Caller's frame pointer. |
| 141 | // lr: Caller's pc. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 142 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +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; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 149 | __ cmp(r5, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 150 | __ b(eq, &ok); |
| 151 | int receiver_offset = scope()->num_parameters() * kPointerSize; |
| 152 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 153 | __ str(r2, MemOperand(sp, receiver_offset)); |
| 154 | __ bind(&ok); |
| 155 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +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()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 159 | if (NeedsEagerFrame()) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 160 | if (info()->IsStub()) { |
| 161 | __ stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 162 | __ Push(Smi::FromInt(StackFrame::STUB)); |
| 163 | // Adjust FP to point to saved FP. |
| 164 | __ add(fp, sp, Operand(2 * kPointerSize)); |
| 165 | } else { |
| 166 | PredictableCodeSizeScope predictible_code_size_scope( |
| 167 | masm_, kNoCodeAgeSequenceLength * Assembler::kInstrSize); |
| 168 | // The following three instructions must remain together and unmodified |
| 169 | // for code aging to work properly. |
| 170 | __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
| 171 | // Load undefined value here, so the value is ready for the loop |
| 172 | // below. |
| 173 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 174 | // Adjust FP to point to saved FP. |
| 175 | __ add(fp, sp, Operand(2 * kPointerSize)); |
| 176 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 177 | frame_is_built_ = true; |
ulan@chromium.org | fae3da5 | 2012-12-03 15:37:23 +0000 | [diff] [blame] | 178 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 179 | |
| 180 | // Reserve space for the stack slots needed by the code. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 181 | int slots = GetStackSlotCount(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 182 | if (slots > 0) { |
| 183 | if (FLAG_debug_code) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 184 | __ sub(sp, sp, Operand(slots * kPointerSize)); |
| 185 | __ push(r0); |
| 186 | __ push(r1); |
| 187 | __ add(r0, sp, Operand(slots * kPointerSize)); |
| 188 | __ mov(r1, Operand(kSlotsZapValue)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 189 | Label loop; |
| 190 | __ bind(&loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 191 | __ sub(r0, r0, Operand(kPointerSize)); |
| 192 | __ str(r1, MemOperand(r0, 2 * kPointerSize)); |
| 193 | __ cmp(r0, sp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 194 | __ b(ne, &loop); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 195 | __ pop(r1); |
| 196 | __ pop(r0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 197 | } else { |
| 198 | __ sub(sp, sp, Operand(slots * kPointerSize)); |
| 199 | } |
| 200 | } |
| 201 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 202 | if (info()->saves_caller_doubles()) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 203 | Comment(";;; Save clobbered callee double registers"); |
| 204 | int count = 0; |
| 205 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 206 | BitVector::Iterator save_iterator(doubles); |
| 207 | while (!save_iterator.Done()) { |
| 208 | __ vstr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), |
| 209 | MemOperand(sp, count * kDoubleSize)); |
| 210 | save_iterator.Advance(); |
| 211 | count++; |
| 212 | } |
| 213 | } |
| 214 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 215 | // Possibly allocate a local context. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 216 | int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 217 | if (heap_slots > 0) { |
| 218 | Comment(";;; Allocate local context"); |
| 219 | // Argument to NewContext is the function, which is in r1. |
| 220 | __ push(r1); |
| 221 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 222 | FastNewContextStub stub(heap_slots); |
| 223 | __ CallStub(&stub); |
| 224 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 225 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 226 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 227 | RecordSafepoint(Safepoint::kNoLazyDeopt); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 228 | // Context is returned in both r0 and cp. It replaces the context |
| 229 | // passed to us. It's saved in the stack and kept live in cp. |
| 230 | __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 231 | // Copy any necessary parameters into the context. |
| 232 | int num_parameters = scope()->num_parameters(); |
| 233 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 234 | Variable* var = scope()->parameter(i); |
| 235 | if (var->IsContextSlot()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 236 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 237 | (num_parameters - 1 - i) * kPointerSize; |
| 238 | // Load parameter from stack. |
| 239 | __ ldr(r0, MemOperand(fp, parameter_offset)); |
| 240 | // Store it in the context. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 241 | MemOperand target = ContextOperand(cp, var->index()); |
| 242 | __ str(r0, target); |
| 243 | // Update the write barrier. This clobbers r3 and r0. |
| 244 | __ RecordWriteContextSlot( |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 245 | cp, |
| 246 | target.offset(), |
| 247 | r0, |
| 248 | r3, |
| 249 | GetLinkRegisterState(), |
| 250 | kSaveFPRegs); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | Comment(";;; End allocate local context"); |
| 254 | } |
| 255 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 256 | // Trace the call. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 257 | if (FLAG_trace && info()->IsOptimizing()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 258 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 259 | } |
| 260 | return !is_aborted(); |
| 261 | } |
| 262 | |
| 263 | |
| 264 | bool LCodeGen::GenerateBody() { |
| 265 | ASSERT(is_generating()); |
| 266 | bool emit_instructions = true; |
| 267 | for (current_instruction_ = 0; |
| 268 | !is_aborted() && current_instruction_ < instructions_->length(); |
| 269 | current_instruction_++) { |
| 270 | LInstruction* instr = instructions_->at(current_instruction_); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 271 | |
| 272 | // Don't emit code for basic blocks with a replacement. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 273 | if (instr->IsLabel()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 274 | emit_instructions = !LLabel::cast(instr)->HasReplacement(); |
| 275 | } |
| 276 | if (!emit_instructions) continue; |
| 277 | |
| 278 | if (FLAG_code_comments && instr->HasInterestingComment(this)) { |
| 279 | Comment(";;; <@%d,#%d> %s", |
| 280 | current_instruction_, |
| 281 | instr->hydrogen_value()->id(), |
| 282 | instr->Mnemonic()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 283 | } |
| 284 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 285 | instr->CompileToNative(this); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 286 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 287 | EnsureSpaceForLazyDeopt(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 288 | return !is_aborted(); |
| 289 | } |
| 290 | |
| 291 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 292 | bool LCodeGen::GenerateDeferredCode() { |
| 293 | ASSERT(is_generating()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 294 | if (deferred_.length() > 0) { |
| 295 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 296 | LDeferredCode* code = deferred_[i]; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 297 | Comment(";;; <@%d,#%d> " |
| 298 | "-------------------- Deferred %s --------------------", |
| 299 | code->instruction_index(), |
| 300 | code->instr()->hydrogen_value()->id(), |
| 301 | code->instr()->Mnemonic()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 302 | __ bind(code->entry()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 303 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 304 | Comment(";;; Build frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 305 | ASSERT(!frame_is_built_); |
| 306 | ASSERT(info()->IsStub()); |
| 307 | frame_is_built_ = true; |
| 308 | __ stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 309 | __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 310 | __ push(scratch0()); |
| 311 | __ add(fp, sp, Operand(2 * kPointerSize)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 312 | Comment(";;; Deferred code"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 313 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 314 | code->Generate(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 315 | if (NeedsDeferredFrame()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 316 | Comment(";;; Destroy frame"); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 317 | ASSERT(frame_is_built_); |
| 318 | __ pop(ip); |
| 319 | __ ldm(ia_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 320 | frame_is_built_ = false; |
| 321 | } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 322 | __ jmp(code->exit()); |
| 323 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 324 | } |
| 325 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 326 | // Force constant pool emission at the end of the deferred code to make |
| 327 | // sure that no constant pools are emitted after. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 328 | masm()->CheckConstPool(true, false); |
| 329 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 330 | return !is_aborted(); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | bool LCodeGen::GenerateDeoptJumpTable() { |
| 335 | // Check that the jump table is accessible from everywhere in the function |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 336 | // code, i.e. that offsets to the table can be encoded in the 24bit signed |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 337 | // immediate of a branch instruction. |
| 338 | // To simplify we consider the code size from the first instruction to the |
| 339 | // end of the jump table. We also don't consider the pc load delta. |
| 340 | // Each entry in the jump table generates one instruction and inlines one |
| 341 | // 32bit data after it. |
| 342 | if (!is_int24((masm()->pc_offset() / Assembler::kInstrSize) + |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 343 | deopt_jump_table_.length() * 7)) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 344 | Abort("Generated code is too large"); |
| 345 | } |
| 346 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 347 | if (deopt_jump_table_.length() > 0) { |
| 348 | Comment(";;; -------------------- Jump table --------------------"); |
| 349 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 350 | Label table_start; |
| 351 | __ bind(&table_start); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 352 | Label needs_frame_not_call; |
| 353 | Label needs_frame_is_call; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 354 | for (int i = 0; i < deopt_jump_table_.length(); i++) { |
| 355 | __ bind(&deopt_jump_table_[i].label); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 356 | Address entry = deopt_jump_table_[i].address; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 357 | bool is_lazy_deopt = deopt_jump_table_[i].is_lazy_deopt; |
| 358 | Deoptimizer::BailoutType type = |
| 359 | is_lazy_deopt ? Deoptimizer::LAZY : Deoptimizer::EAGER; |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 360 | int id = Deoptimizer::GetDeoptimizationId(isolate(), entry, type); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 361 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 362 | Comment(";;; jump table entry %d.", i); |
| 363 | } else { |
| 364 | Comment(";;; jump table entry %d: deoptimization bailout %d.", i, id); |
| 365 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 366 | if (deopt_jump_table_[i].needs_frame) { |
| 367 | __ mov(ip, Operand(ExternalReference::ForDeoptEntry(entry))); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 368 | if (is_lazy_deopt) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 369 | if (needs_frame_is_call.is_bound()) { |
| 370 | __ b(&needs_frame_is_call); |
| 371 | } else { |
| 372 | __ bind(&needs_frame_is_call); |
| 373 | __ stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 374 | // This variant of deopt can only be used with stubs. Since we don't |
| 375 | // have a function pointer to install in the stack frame that we're |
| 376 | // building, install a special marker there instead. |
| 377 | ASSERT(info()->IsStub()); |
| 378 | __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 379 | __ push(scratch0()); |
| 380 | __ add(fp, sp, Operand(2 * kPointerSize)); |
| 381 | __ mov(lr, Operand(pc), LeaveCC, al); |
| 382 | __ mov(pc, ip); |
| 383 | } |
| 384 | } else { |
| 385 | if (needs_frame_not_call.is_bound()) { |
| 386 | __ b(&needs_frame_not_call); |
| 387 | } else { |
| 388 | __ bind(&needs_frame_not_call); |
| 389 | __ stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 390 | // This variant of deopt can only be used with stubs. Since we don't |
| 391 | // have a function pointer to install in the stack frame that we're |
| 392 | // building, install a special marker there instead. |
| 393 | ASSERT(info()->IsStub()); |
| 394 | __ mov(scratch0(), Operand(Smi::FromInt(StackFrame::STUB))); |
| 395 | __ push(scratch0()); |
| 396 | __ add(fp, sp, Operand(2 * kPointerSize)); |
| 397 | __ mov(pc, ip); |
| 398 | } |
| 399 | } |
| 400 | } else { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 401 | if (is_lazy_deopt) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 402 | __ mov(lr, Operand(pc), LeaveCC, al); |
| 403 | __ mov(pc, Operand(ExternalReference::ForDeoptEntry(entry))); |
| 404 | } else { |
| 405 | __ mov(pc, Operand(ExternalReference::ForDeoptEntry(entry))); |
| 406 | } |
| 407 | } |
| 408 | masm()->CheckConstPool(false, false); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 409 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 410 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 411 | // Force constant pool emission at the end of the deopt jump table to make |
| 412 | // sure that no constant pools are emitted after. |
| 413 | masm()->CheckConstPool(true, false); |
| 414 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 415 | // The deoptimization jump table is the last part of the instruction |
| 416 | // sequence. Mark the generated code as done unless we bailed out. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 417 | if (!is_aborted()) status_ = DONE; |
| 418 | return !is_aborted(); |
| 419 | } |
| 420 | |
| 421 | |
| 422 | bool LCodeGen::GenerateSafepointTable() { |
| 423 | ASSERT(is_done()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 424 | safepoints_.Emit(masm(), GetStackSlotCount()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 425 | return !is_aborted(); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | Register LCodeGen::ToRegister(int index) const { |
| 430 | return Register::FromAllocationIndex(index); |
| 431 | } |
| 432 | |
| 433 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 434 | DwVfpRegister LCodeGen::ToDoubleRegister(int index) const { |
| 435 | return DwVfpRegister::FromAllocationIndex(index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
| 439 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 440 | ASSERT(op->IsRegister()); |
| 441 | return ToRegister(op->index()); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 446 | if (op->IsRegister()) { |
| 447 | return ToRegister(op->index()); |
| 448 | } else if (op->IsConstantOperand()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 449 | LConstantOperand* const_op = LConstantOperand::cast(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 450 | HConstant* constant = chunk_->LookupConstant(const_op); |
| 451 | Handle<Object> literal = constant->handle(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 452 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 453 | if (r.IsInteger32()) { |
| 454 | ASSERT(literal->IsNumber()); |
| 455 | __ mov(scratch, Operand(static_cast<int32_t>(literal->Number()))); |
| 456 | } else if (r.IsDouble()) { |
| 457 | Abort("EmitLoadRegister: Unsupported double immediate."); |
| 458 | } else { |
| 459 | ASSERT(r.IsTagged()); |
| 460 | if (literal->IsSmi()) { |
| 461 | __ mov(scratch, Operand(literal)); |
| 462 | } else { |
| 463 | __ LoadHeapObject(scratch, Handle<HeapObject>::cast(literal)); |
| 464 | } |
| 465 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 466 | return scratch; |
| 467 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 468 | __ ldr(scratch, ToMemOperand(op)); |
| 469 | return scratch; |
| 470 | } |
| 471 | UNREACHABLE(); |
| 472 | return scratch; |
| 473 | } |
| 474 | |
| 475 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 476 | DwVfpRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 477 | ASSERT(op->IsDoubleRegister()); |
| 478 | return ToDoubleRegister(op->index()); |
| 479 | } |
| 480 | |
| 481 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 482 | DwVfpRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, |
| 483 | SwVfpRegister flt_scratch, |
| 484 | DwVfpRegister dbl_scratch) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 485 | if (op->IsDoubleRegister()) { |
| 486 | return ToDoubleRegister(op->index()); |
| 487 | } else if (op->IsConstantOperand()) { |
| 488 | LConstantOperand* const_op = LConstantOperand::cast(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 489 | HConstant* constant = chunk_->LookupConstant(const_op); |
| 490 | Handle<Object> literal = constant->handle(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 491 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 492 | if (r.IsInteger32()) { |
| 493 | ASSERT(literal->IsNumber()); |
| 494 | __ mov(ip, Operand(static_cast<int32_t>(literal->Number()))); |
| 495 | __ vmov(flt_scratch, ip); |
| 496 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
| 497 | return dbl_scratch; |
| 498 | } else if (r.IsDouble()) { |
| 499 | Abort("unsupported double immediate"); |
| 500 | } else if (r.IsTagged()) { |
| 501 | Abort("unsupported tagged immediate"); |
| 502 | } |
| 503 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 504 | // TODO(regis): Why is vldr not taking a MemOperand? |
| 505 | // __ vldr(dbl_scratch, ToMemOperand(op)); |
| 506 | MemOperand mem_op = ToMemOperand(op); |
| 507 | __ vldr(dbl_scratch, mem_op.rn(), mem_op.offset()); |
| 508 | return dbl_scratch; |
| 509 | } |
| 510 | UNREACHABLE(); |
| 511 | return dbl_scratch; |
| 512 | } |
| 513 | |
| 514 | |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 515 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 516 | HConstant* constant = chunk_->LookupConstant(op); |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 517 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsTagged()); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 518 | return constant->handle(); |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
| 522 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
| 523 | return chunk_->LookupLiteralRepresentation(op).IsInteger32(); |
| 524 | } |
| 525 | |
| 526 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 527 | int LCodeGen::ToInteger32(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 528 | HConstant* constant = chunk_->LookupConstant(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 529 | return constant->Integer32Value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 533 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 534 | HConstant* constant = chunk_->LookupConstant(op); |
| 535 | ASSERT(constant->HasDoubleValue()); |
| 536 | return constant->DoubleValue(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 540 | Operand LCodeGen::ToOperand(LOperand* op) { |
| 541 | if (op->IsConstantOperand()) { |
| 542 | LConstantOperand* const_op = LConstantOperand::cast(op); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 543 | HConstant* constant = chunk()->LookupConstant(const_op); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 544 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 545 | if (r.IsInteger32()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 546 | ASSERT(constant->HasInteger32Value()); |
| 547 | return Operand(constant->Integer32Value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 548 | } else if (r.IsDouble()) { |
| 549 | Abort("ToOperand Unsupported double immediate."); |
| 550 | } |
| 551 | ASSERT(r.IsTagged()); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 552 | return Operand(constant->handle()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 553 | } else if (op->IsRegister()) { |
| 554 | return Operand(ToRegister(op)); |
| 555 | } else if (op->IsDoubleRegister()) { |
| 556 | Abort("ToOperand IsDoubleRegister unimplemented"); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 557 | return Operand::Zero(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 558 | } |
| 559 | // Stack slots not implemented, use ToMemOperand instead. |
| 560 | UNREACHABLE(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 561 | return Operand::Zero(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
| 565 | MemOperand LCodeGen::ToMemOperand(LOperand* op) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 566 | ASSERT(!op->IsRegister()); |
| 567 | ASSERT(!op->IsDoubleRegister()); |
| 568 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
jkummerow@chromium.org | ac36071 | 2013-02-11 09:00:07 +0000 | [diff] [blame] | 569 | return MemOperand(fp, StackSlotOffset(op->index())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 573 | MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { |
| 574 | ASSERT(op->IsDoubleStackSlot()); |
jkummerow@chromium.org | ac36071 | 2013-02-11 09:00:07 +0000 | [diff] [blame] | 575 | return MemOperand(fp, StackSlotOffset(op->index()) + kPointerSize); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 579 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 580 | Translation* translation, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 581 | int* pushed_arguments_index, |
| 582 | int* pushed_arguments_count) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 583 | if (environment == NULL) return; |
| 584 | |
| 585 | // The translation includes one command per value in the environment. |
| 586 | int translation_size = environment->values()->length(); |
| 587 | // The output frame height does not include the parameters. |
| 588 | int height = translation_size - environment->parameter_count(); |
| 589 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 590 | // Function parameters are arguments to the outermost environment. The |
| 591 | // arguments index points to the first element of a sequence of tagged |
| 592 | // values on the stack that represent the arguments. This needs to be |
| 593 | // kept in sync with the LArgumentsElements implementation. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 594 | *pushed_arguments_index = -environment->parameter_count(); |
| 595 | *pushed_arguments_count = environment->parameter_count(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 596 | |
| 597 | WriteTranslation(environment->outer(), |
| 598 | translation, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 599 | pushed_arguments_index, |
| 600 | pushed_arguments_count); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 601 | bool has_closure_id = !info()->closure().is_null() && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 602 | !info()->closure().is_identical_to(environment->closure()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 603 | int closure_id = has_closure_id |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 604 | ? DefineDeoptimizationLiteral(environment->closure()) |
| 605 | : Translation::kSelfLiteralId; |
| 606 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 607 | switch (environment->frame_type()) { |
| 608 | case JS_FUNCTION: |
| 609 | translation->BeginJSFrame(environment->ast_id(), closure_id, height); |
| 610 | break; |
| 611 | case JS_CONSTRUCT: |
| 612 | translation->BeginConstructStubFrame(closure_id, translation_size); |
| 613 | break; |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 614 | case JS_GETTER: |
| 615 | ASSERT(translation_size == 1); |
| 616 | ASSERT(height == 0); |
| 617 | translation->BeginGetterStubFrame(closure_id); |
| 618 | break; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 619 | case JS_SETTER: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 620 | ASSERT(translation_size == 2); |
| 621 | ASSERT(height == 0); |
| 622 | translation->BeginSetterStubFrame(closure_id); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 623 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 624 | case STUB: |
| 625 | translation->BeginCompiledStubFrame(); |
| 626 | break; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 627 | case ARGUMENTS_ADAPTOR: |
| 628 | translation->BeginArgumentsAdaptorFrame(closure_id, translation_size); |
| 629 | break; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 630 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 631 | |
| 632 | // Inlined frames which push their arguments cause the index to be |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 633 | // bumped and another stack area to be used for materialization, |
| 634 | // otherwise actual argument values are unknown for inlined frames. |
| 635 | bool arguments_known = true; |
| 636 | int arguments_index = *pushed_arguments_index; |
| 637 | int arguments_count = *pushed_arguments_count; |
| 638 | if (environment->entry() != NULL) { |
| 639 | arguments_known = environment->entry()->arguments_pushed(); |
| 640 | arguments_index = arguments_index < 0 |
| 641 | ? GetStackSlotCount() : arguments_index + arguments_count; |
| 642 | arguments_count = environment->entry()->arguments_count() + 1; |
| 643 | if (environment->entry()->arguments_pushed()) { |
| 644 | *pushed_arguments_index = arguments_index; |
| 645 | *pushed_arguments_count = arguments_count; |
| 646 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 647 | } |
| 648 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 649 | for (int i = 0; i < translation_size; ++i) { |
| 650 | LOperand* value = environment->values()->at(i); |
| 651 | // spilled_registers_ and spilled_double_registers_ are either |
| 652 | // both NULL or both set. |
| 653 | if (environment->spilled_registers() != NULL && value != NULL) { |
| 654 | if (value->IsRegister() && |
| 655 | environment->spilled_registers()[value->index()] != NULL) { |
| 656 | translation->MarkDuplicate(); |
| 657 | AddToTranslation(translation, |
| 658 | environment->spilled_registers()[value->index()], |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 659 | environment->HasTaggedValueAt(i), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 660 | environment->HasUint32ValueAt(i), |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 661 | arguments_known, |
| 662 | arguments_index, |
| 663 | arguments_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 664 | } else if ( |
| 665 | value->IsDoubleRegister() && |
| 666 | environment->spilled_double_registers()[value->index()] != NULL) { |
| 667 | translation->MarkDuplicate(); |
| 668 | AddToTranslation( |
| 669 | translation, |
| 670 | environment->spilled_double_registers()[value->index()], |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 671 | false, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 672 | false, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 673 | arguments_known, |
| 674 | arguments_index, |
| 675 | arguments_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 679 | AddToTranslation(translation, |
| 680 | value, |
| 681 | environment->HasTaggedValueAt(i), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 682 | environment->HasUint32ValueAt(i), |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 683 | arguments_known, |
| 684 | arguments_index, |
| 685 | arguments_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
| 689 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 690 | void LCodeGen::AddToTranslation(Translation* translation, |
| 691 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 692 | bool is_tagged, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 693 | bool is_uint32, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 694 | bool arguments_known, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 695 | int arguments_index, |
| 696 | int arguments_count) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 697 | if (op == NULL) { |
| 698 | // TODO(twuerthinger): Introduce marker operands to indicate that this value |
| 699 | // is not present and must be reconstructed from the deoptimizer. Currently |
| 700 | // this is only used for the arguments object. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 701 | translation->StoreArgumentsObject( |
| 702 | arguments_known, arguments_index, arguments_count); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 703 | } else if (op->IsStackSlot()) { |
| 704 | if (is_tagged) { |
| 705 | translation->StoreStackSlot(op->index()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 706 | } else if (is_uint32) { |
| 707 | translation->StoreUint32StackSlot(op->index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 708 | } else { |
| 709 | translation->StoreInt32StackSlot(op->index()); |
| 710 | } |
| 711 | } else if (op->IsDoubleStackSlot()) { |
| 712 | translation->StoreDoubleStackSlot(op->index()); |
| 713 | } else if (op->IsArgument()) { |
| 714 | ASSERT(is_tagged); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 715 | int src_index = GetStackSlotCount() + op->index(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 716 | translation->StoreStackSlot(src_index); |
| 717 | } else if (op->IsRegister()) { |
| 718 | Register reg = ToRegister(op); |
| 719 | if (is_tagged) { |
| 720 | translation->StoreRegister(reg); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 721 | } else if (is_uint32) { |
| 722 | translation->StoreUint32Register(reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 723 | } else { |
| 724 | translation->StoreInt32Register(reg); |
| 725 | } |
| 726 | } else if (op->IsDoubleRegister()) { |
| 727 | DoubleRegister reg = ToDoubleRegister(op); |
| 728 | translation->StoreDoubleRegister(reg); |
| 729 | } else if (op->IsConstantOperand()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 730 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
| 731 | int src_index = DefineDeoptimizationLiteral(constant->handle()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | translation->StoreLiteral(src_index); |
| 733 | } else { |
| 734 | UNREACHABLE(); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | |
| 739 | void LCodeGen::CallCode(Handle<Code> code, |
| 740 | RelocInfo::Mode mode, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 741 | LInstruction* instr, |
| 742 | TargetAddressStorageMode storage_mode) { |
| 743 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT, storage_mode); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | |
| 747 | void LCodeGen::CallCodeGeneric(Handle<Code> code, |
| 748 | RelocInfo::Mode mode, |
| 749 | LInstruction* instr, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 750 | SafepointMode safepoint_mode, |
| 751 | TargetAddressStorageMode storage_mode) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 752 | ASSERT(instr != NULL); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 753 | // Block literal pool emission to ensure nop indicating no inlined smi code |
| 754 | // is in the correct position. |
| 755 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 756 | LPointerMap* pointers = instr->pointer_map(); |
| 757 | RecordPosition(pointers->position()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 758 | __ Call(code, mode, TypeFeedbackId::None(), al, storage_mode); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 759 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 760 | |
| 761 | // Signal that we don't inline smi code before these stubs in the |
| 762 | // optimizing code generator. |
| 763 | if (code->kind() == Code::BINARY_OP_IC || |
| 764 | code->kind() == Code::COMPARE_IC) { |
| 765 | __ nop(); |
| 766 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 770 | void LCodeGen::CallRuntime(const Runtime::Function* function, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 771 | int num_arguments, |
| 772 | LInstruction* instr) { |
| 773 | ASSERT(instr != NULL); |
| 774 | LPointerMap* pointers = instr->pointer_map(); |
| 775 | ASSERT(pointers != NULL); |
| 776 | RecordPosition(pointers->position()); |
| 777 | |
| 778 | __ CallRuntime(function, num_arguments); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 779 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 783 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 784 | int argc, |
| 785 | LInstruction* instr) { |
| 786 | __ CallRuntimeSaveDoubles(id); |
| 787 | RecordSafepointWithRegisters( |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 788 | instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 792 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 793 | Safepoint::DeoptMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 794 | if (!environment->HasBeenRegistered()) { |
| 795 | // Physical stack frame layout: |
| 796 | // -x ............. -4 0 ..................................... y |
| 797 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 798 | |
| 799 | // Layout of the environment: |
| 800 | // 0 ..................................................... size-1 |
| 801 | // [parameters] [locals] [expression stack including arguments] |
| 802 | |
| 803 | // Layout of the translation: |
| 804 | // 0 ........................................................ size - 1 + 4 |
| 805 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 806 | // |>------------ translation_size ------------<| |
| 807 | |
| 808 | int frame_count = 0; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 809 | int jsframe_count = 0; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 810 | int args_index = 0; |
| 811 | int args_count = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 812 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 813 | ++frame_count; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 814 | if (e->frame_type() == JS_FUNCTION) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 815 | ++jsframe_count; |
| 816 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 817 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 818 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
| 819 | WriteTranslation(environment, &translation, &args_index, &args_count); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 820 | int deoptimization_index = deoptimizations_.length(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 821 | int pc_offset = masm()->pc_offset(); |
| 822 | environment->Register(deoptimization_index, |
| 823 | translation.index(), |
| 824 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 825 | deoptimizations_.Add(environment, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | |
| 830 | void LCodeGen::DeoptimizeIf(Condition cc, LEnvironment* environment) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 831 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 832 | ASSERT(environment->HasBeenRegistered()); |
| 833 | int id = environment->deoptimization_index(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 834 | ASSERT(info()->IsOptimizing() || info()->IsStub()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 835 | Deoptimizer::BailoutType bailout_type = info()->IsStub() |
| 836 | ? Deoptimizer::LAZY |
| 837 | : Deoptimizer::EAGER; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 838 | Address entry = |
| 839 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 840 | if (entry == NULL) { |
| 841 | Abort("bailout was not prepared"); |
| 842 | return; |
| 843 | } |
| 844 | |
| 845 | ASSERT(FLAG_deopt_every_n_times < 2); // Other values not supported on ARM. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 846 | if (FLAG_deopt_every_n_times == 1 && |
| 847 | !info()->IsStub() && |
| 848 | info()->opt_count() == id) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 849 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 850 | return; |
| 851 | } |
| 852 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 853 | if (FLAG_trap_on_deopt) { |
| 854 | __ stop("trap_on_deopt", cc); |
| 855 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 856 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 857 | ASSERT(info()->IsStub() || frame_is_built_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 858 | bool needs_lazy_deopt = info()->IsStub(); |
| 859 | if (cc == al && frame_is_built_) { |
| 860 | if (needs_lazy_deopt) { |
| 861 | __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
| 862 | } else { |
| 863 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 864 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 865 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 866 | // We often have several deopts to the same entry, reuse the last |
| 867 | // jump entry if this is the case. |
| 868 | if (deopt_jump_table_.is_empty() || |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 869 | (deopt_jump_table_.last().address != entry) || |
| 870 | (deopt_jump_table_.last().is_lazy_deopt != needs_lazy_deopt) || |
| 871 | (deopt_jump_table_.last().needs_frame != !frame_is_built_)) { |
| 872 | JumpTableEntry table_entry(entry, !frame_is_built_, needs_lazy_deopt); |
| 873 | deopt_jump_table_.Add(table_entry, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 874 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 875 | __ b(cc, &deopt_jump_table_.last().label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 876 | } |
| 877 | } |
| 878 | |
| 879 | |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 880 | void LCodeGen::RegisterDependentCodeForEmbeddedMaps(Handle<Code> code) { |
| 881 | ZoneList<Handle<Map> > maps(1, zone()); |
| 882 | int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 883 | for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 884 | RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 885 | if (mode == RelocInfo::EMBEDDED_OBJECT && |
| 886 | it.rinfo()->target_object()->IsMap()) { |
| 887 | Handle<Map> map(Map::cast(it.rinfo()->target_object())); |
| 888 | if (map->CanTransition()) { |
| 889 | maps.Add(map, zone()); |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | #ifdef VERIFY_HEAP |
| 894 | // This disables verification of weak embedded maps after full GC. |
| 895 | // AddDependentCode can cause a GC, which would observe the state where |
| 896 | // this code is not yet in the depended code lists of the embedded maps. |
| 897 | NoWeakEmbeddedMapsVerificationScope disable_verification_of_embedded_maps; |
| 898 | #endif |
| 899 | for (int i = 0; i < maps.length(); i++) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 900 | maps.at(i)->AddDependentCode(DependentCode::kWeaklyEmbeddedGroup, code); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
| 904 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 905 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 906 | int length = deoptimizations_.length(); |
| 907 | if (length == 0) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 908 | Handle<DeoptimizationInputData> data = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 909 | factory()->NewDeoptimizationInputData(length, TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 910 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 911 | Handle<ByteArray> translations = |
| 912 | translations_.CreateByteArray(isolate()->factory()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 913 | data->SetTranslationByteArray(*translations); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 914 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 915 | |
| 916 | Handle<FixedArray> literals = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 917 | factory()->NewFixedArray(deoptimization_literals_.length(), TENURED); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 918 | { ALLOW_HANDLE_DEREF(isolate(), |
| 919 | "copying a ZoneList of handles into a FixedArray"); |
| 920 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 921 | literals->set(i, *deoptimization_literals_[i]); |
| 922 | } |
| 923 | data->SetLiteralArray(*literals); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 924 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 925 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 926 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 927 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 928 | |
| 929 | // Populate the deoptimization entries. |
| 930 | for (int i = 0; i < length; i++) { |
| 931 | LEnvironment* env = deoptimizations_[i]; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 932 | data->SetAstId(i, env->ast_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 933 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 934 | data->SetArgumentsStackHeight(i, |
| 935 | Smi::FromInt(env->arguments_stack_height())); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 936 | data->SetPc(i, Smi::FromInt(env->pc_offset())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 937 | } |
| 938 | code->set_deoptimization_data(*data); |
| 939 | } |
| 940 | |
| 941 | |
| 942 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 943 | int result = deoptimization_literals_.length(); |
| 944 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 945 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 946 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 947 | deoptimization_literals_.Add(literal, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 948 | return result; |
| 949 | } |
| 950 | |
| 951 | |
| 952 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 953 | ASSERT(deoptimization_literals_.length() == 0); |
| 954 | |
| 955 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 956 | chunk()->inlined_closures(); |
| 957 | |
| 958 | for (int i = 0, length = inlined_closures->length(); |
| 959 | i < length; |
| 960 | i++) { |
| 961 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 962 | } |
| 963 | |
| 964 | inlined_function_count_ = deoptimization_literals_.length(); |
| 965 | } |
| 966 | |
| 967 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 968 | void LCodeGen::RecordSafepointWithLazyDeopt( |
| 969 | LInstruction* instr, SafepointMode safepoint_mode) { |
| 970 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 971 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 972 | } else { |
| 973 | ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 974 | RecordSafepointWithRegisters( |
| 975 | instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 980 | void LCodeGen::RecordSafepoint( |
| 981 | LPointerMap* pointers, |
| 982 | Safepoint::Kind kind, |
| 983 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 984 | Safepoint::DeoptMode deopt_mode) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 985 | ASSERT(expected_safepoint_kind_ == kind); |
| 986 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 987 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 988 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 989 | kind, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 990 | for (int i = 0; i < operands->length(); i++) { |
| 991 | LOperand* pointer = operands->at(i); |
| 992 | if (pointer->IsStackSlot()) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 993 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 994 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 995 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 996 | } |
| 997 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 998 | if (kind & Safepoint::kWithRegisters) { |
| 999 | // Register cp always contains a pointer to the context. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1000 | safepoint.DefinePointerRegister(cp, zone()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1006 | Safepoint::DeoptMode deopt_mode) { |
| 1007 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1011 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1012 | LPointerMap empty_pointers(RelocInfo::kNoPosition, zone()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1013 | RecordSafepoint(&empty_pointers, deopt_mode); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1017 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 1018 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1019 | Safepoint::DeoptMode deopt_mode) { |
| 1020 | RecordSafepoint( |
| 1021 | pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1025 | void LCodeGen::RecordSafepointWithRegistersAndDoubles( |
| 1026 | LPointerMap* pointers, |
| 1027 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1028 | Safepoint::DeoptMode deopt_mode) { |
| 1029 | RecordSafepoint( |
| 1030 | pointers, Safepoint::kWithRegistersAndDoubles, arguments, deopt_mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1034 | void LCodeGen::RecordPosition(int position) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1035 | if (position == RelocInfo::kNoPosition) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1036 | masm()->positions_recorder()->RecordPosition(position); |
| 1037 | } |
| 1038 | |
| 1039 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1040 | static const char* LabelType(LLabel* label) { |
| 1041 | if (label->is_loop_header()) return " (loop header)"; |
| 1042 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 1043 | return ""; |
| 1044 | } |
| 1045 | |
| 1046 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1047 | void LCodeGen::DoLabel(LLabel* label) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1048 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 1049 | current_instruction_, |
| 1050 | label->hydrogen_value()->id(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1051 | label->block_id(), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1052 | LabelType(label)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1053 | __ bind(label->label()); |
| 1054 | current_block_ = label->block_id(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1055 | DoGap(label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1060 | resolver_.Resolve(move); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | void LCodeGen::DoGap(LGap* gap) { |
| 1065 | for (int i = LGap::FIRST_INNER_POSITION; |
| 1066 | i <= LGap::LAST_INNER_POSITION; |
| 1067 | i++) { |
| 1068 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 1069 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 1070 | if (move != NULL) DoParallelMove(move); |
| 1071 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1075 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
| 1076 | DoGap(instr); |
| 1077 | } |
| 1078 | |
| 1079 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1080 | void LCodeGen::DoParameter(LParameter* instr) { |
| 1081 | // Nothing to do. |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | void LCodeGen::DoCallStub(LCallStub* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1086 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 1087 | switch (instr->hydrogen()->major_key()) { |
| 1088 | case CodeStub::RegExpConstructResult: { |
| 1089 | RegExpConstructResultStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1090 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1091 | break; |
| 1092 | } |
| 1093 | case CodeStub::RegExpExec: { |
| 1094 | RegExpExecStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1095 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1096 | break; |
| 1097 | } |
| 1098 | case CodeStub::SubString: { |
| 1099 | SubStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1100 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1101 | break; |
| 1102 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1103 | case CodeStub::NumberToString: { |
| 1104 | NumberToStringStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1105 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1106 | break; |
| 1107 | } |
| 1108 | case CodeStub::StringAdd: { |
| 1109 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1110 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1111 | break; |
| 1112 | } |
| 1113 | case CodeStub::StringCompare: { |
| 1114 | StringCompareStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1115 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1116 | break; |
| 1117 | } |
| 1118 | case CodeStub::TranscendentalCache: { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1119 | __ ldr(r0, MemOperand(sp, 0)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1120 | TranscendentalCacheStub stub(instr->transcendental_type(), |
| 1121 | TranscendentalCacheStub::TAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1122 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1123 | break; |
| 1124 | } |
| 1125 | default: |
| 1126 | UNREACHABLE(); |
| 1127 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 1132 | // Nothing to do. |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | void LCodeGen::DoModI(LModI* instr) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1137 | if (instr->hydrogen()->HasPowerOf2Divisor()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1138 | Register dividend = ToRegister(instr->left()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1139 | Register result = ToRegister(instr->result()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1140 | |
| 1141 | int32_t divisor = |
| 1142 | HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
| 1143 | |
| 1144 | if (divisor < 0) divisor = -divisor; |
| 1145 | |
| 1146 | Label positive_dividend, done; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1147 | __ cmp(dividend, Operand::Zero()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1148 | __ b(pl, &positive_dividend); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1149 | __ rsb(result, dividend, Operand::Zero()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1150 | __ and_(result, result, Operand(divisor - 1), SetCC); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1151 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1152 | DeoptimizeIf(eq, instr->environment()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1153 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1154 | __ rsb(result, result, Operand::Zero()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1155 | __ b(&done); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1156 | __ bind(&positive_dividend); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1157 | __ and_(result, dividend, Operand(divisor - 1)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1158 | __ bind(&done); |
| 1159 | return; |
| 1160 | } |
| 1161 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1162 | // These registers hold untagged 32 bit values. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1163 | Register left = ToRegister(instr->left()); |
| 1164 | Register right = ToRegister(instr->right()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1165 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1166 | Label done; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1167 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1168 | // Check for x % 0. |
| 1169 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1170 | __ cmp(right, Operand::Zero()); |
| 1171 | DeoptimizeIf(eq, instr->environment()); |
| 1172 | } |
| 1173 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1174 | if (CpuFeatures::IsSupported(SUDIV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1175 | CpuFeatureScope scope(masm(), SUDIV); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1176 | // Check for (kMinInt % -1). |
| 1177 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1178 | Label left_not_min_int; |
| 1179 | __ cmp(left, Operand(kMinInt)); |
| 1180 | __ b(ne, &left_not_min_int); |
| 1181 | __ cmp(right, Operand(-1)); |
| 1182 | DeoptimizeIf(eq, instr->environment()); |
| 1183 | __ bind(&left_not_min_int); |
| 1184 | } |
| 1185 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1186 | // For r3 = r1 % r2; we can have the following ARM code |
| 1187 | // sdiv r3, r1, r2 |
| 1188 | // mls r3, r3, r2, r1 |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1189 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1190 | __ sdiv(result, left, right); |
| 1191 | __ mls(result, result, right, left); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1192 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1193 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1194 | __ cmp(result, Operand::Zero()); |
| 1195 | __ b(ne, &done); |
| 1196 | __ cmp(left, Operand::Zero()); |
| 1197 | DeoptimizeIf(lt, instr->environment()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1198 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1199 | } else { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1200 | Register scratch = scratch0(); |
| 1201 | Register scratch2 = ToRegister(instr->temp()); |
| 1202 | DwVfpRegister dividend = ToDoubleRegister(instr->temp2()); |
| 1203 | DwVfpRegister divisor = ToDoubleRegister(instr->temp3()); |
| 1204 | DwVfpRegister quotient = double_scratch0(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1205 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1206 | ASSERT(!dividend.is(divisor)); |
| 1207 | ASSERT(!dividend.is(quotient)); |
| 1208 | ASSERT(!divisor.is(quotient)); |
| 1209 | ASSERT(!scratch.is(left)); |
| 1210 | ASSERT(!scratch.is(right)); |
| 1211 | ASSERT(!scratch.is(result)); |
| 1212 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1213 | Label vfp_modulo, right_negative; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1214 | |
| 1215 | __ Move(result, left); |
| 1216 | |
| 1217 | // (0 % x) must yield 0 (if x is finite, which is the case here). |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1218 | __ cmp(left, Operand::Zero()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1219 | __ b(eq, &done); |
| 1220 | // Preload right in a vfp register. |
| 1221 | __ vmov(divisor.low(), right); |
| 1222 | __ b(lt, &vfp_modulo); |
| 1223 | |
| 1224 | __ cmp(left, Operand(right)); |
| 1225 | __ b(lt, &done); |
| 1226 | |
| 1227 | // Check for (positive) power of two on the right hand side. |
| 1228 | __ JumpIfNotPowerOfTwoOrZeroAndNeg(right, |
| 1229 | scratch, |
| 1230 | &right_negative, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 1231 | &vfp_modulo); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1232 | // Perform modulo operation (scratch contains right - 1). |
| 1233 | __ and_(result, scratch, Operand(left)); |
| 1234 | __ b(&done); |
| 1235 | |
| 1236 | __ bind(&right_negative); |
| 1237 | // Negate right. The sign of the divisor does not matter. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1238 | __ rsb(right, right, Operand::Zero()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1239 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1240 | __ bind(&vfp_modulo); |
| 1241 | // Load the arguments in VFP registers. |
| 1242 | // The divisor value is preloaded before. Be careful that 'right' |
| 1243 | // is only live on entry. |
| 1244 | __ vmov(dividend.low(), left); |
| 1245 | // From here on don't use right as it may have been reallocated |
| 1246 | // (for example to scratch2). |
| 1247 | right = no_reg; |
| 1248 | |
| 1249 | __ vcvt_f64_s32(dividend, dividend.low()); |
| 1250 | __ vcvt_f64_s32(divisor, divisor.low()); |
| 1251 | |
| 1252 | // We do not care about the sign of the divisor. |
| 1253 | __ vabs(divisor, divisor); |
| 1254 | // Compute the quotient and round it to a 32bit integer. |
| 1255 | __ vdiv(quotient, dividend, divisor); |
| 1256 | __ vcvt_s32_f64(quotient.low(), quotient); |
| 1257 | __ vcvt_f64_s32(quotient, quotient.low()); |
| 1258 | |
| 1259 | // Compute the remainder in result. |
| 1260 | DwVfpRegister double_scratch = dividend; |
| 1261 | __ vmul(double_scratch, divisor, quotient); |
| 1262 | __ vcvt_s32_f64(double_scratch.low(), double_scratch); |
| 1263 | __ vmov(scratch, double_scratch.low()); |
| 1264 | |
| 1265 | if (!instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1266 | __ sub(result, left, scratch); |
| 1267 | } else { |
| 1268 | Label ok; |
| 1269 | // Check for -0. |
| 1270 | __ sub(scratch2, left, scratch, SetCC); |
| 1271 | __ b(ne, &ok); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1272 | __ cmp(left, Operand::Zero()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1273 | DeoptimizeIf(mi, instr->environment()); |
| 1274 | __ bind(&ok); |
| 1275 | // Load the result and we are done. |
| 1276 | __ mov(result, scratch2); |
| 1277 | } |
| 1278 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1279 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1283 | void LCodeGen::EmitSignedIntegerDivisionByConstant( |
| 1284 | Register result, |
| 1285 | Register dividend, |
| 1286 | int32_t divisor, |
| 1287 | Register remainder, |
| 1288 | Register scratch, |
| 1289 | LEnvironment* environment) { |
| 1290 | ASSERT(!AreAliased(dividend, scratch, ip)); |
| 1291 | ASSERT(LChunkBuilder::HasMagicNumberForDivisor(divisor)); |
| 1292 | |
| 1293 | uint32_t divisor_abs = abs(divisor); |
| 1294 | |
| 1295 | int32_t power_of_2_factor = |
| 1296 | CompilerIntrinsics::CountTrailingZeros(divisor_abs); |
| 1297 | |
| 1298 | switch (divisor_abs) { |
| 1299 | case 0: |
| 1300 | DeoptimizeIf(al, environment); |
| 1301 | return; |
| 1302 | |
| 1303 | case 1: |
| 1304 | if (divisor > 0) { |
| 1305 | __ Move(result, dividend); |
| 1306 | } else { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1307 | __ rsb(result, dividend, Operand::Zero(), SetCC); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1308 | DeoptimizeIf(vs, environment); |
| 1309 | } |
| 1310 | // Compute the remainder. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1311 | __ mov(remainder, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1312 | return; |
| 1313 | |
| 1314 | default: |
| 1315 | if (IsPowerOf2(divisor_abs)) { |
| 1316 | // Branch and condition free code for integer division by a power |
| 1317 | // of two. |
| 1318 | int32_t power = WhichPowerOf2(divisor_abs); |
| 1319 | if (power > 1) { |
| 1320 | __ mov(scratch, Operand(dividend, ASR, power - 1)); |
| 1321 | } |
| 1322 | __ add(scratch, dividend, Operand(scratch, LSR, 32 - power)); |
| 1323 | __ mov(result, Operand(scratch, ASR, power)); |
| 1324 | // Negate if necessary. |
| 1325 | // We don't need to check for overflow because the case '-1' is |
| 1326 | // handled separately. |
| 1327 | if (divisor < 0) { |
| 1328 | ASSERT(divisor != -1); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1329 | __ rsb(result, result, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1330 | } |
| 1331 | // Compute the remainder. |
| 1332 | if (divisor > 0) { |
| 1333 | __ sub(remainder, dividend, Operand(result, LSL, power)); |
| 1334 | } else { |
| 1335 | __ add(remainder, dividend, Operand(result, LSL, power)); |
| 1336 | } |
| 1337 | return; |
| 1338 | } else { |
| 1339 | // Use magic numbers for a few specific divisors. |
| 1340 | // Details and proofs can be found in: |
| 1341 | // - Hacker's Delight, Henry S. Warren, Jr. |
| 1342 | // - The PowerPC Compiler Writer’s Guide |
| 1343 | // and probably many others. |
| 1344 | // |
| 1345 | // We handle |
| 1346 | // <divisor with magic numbers> * <power of 2> |
| 1347 | // but not |
| 1348 | // <divisor with magic numbers> * <other divisor with magic numbers> |
| 1349 | DivMagicNumbers magic_numbers = |
| 1350 | DivMagicNumberFor(divisor_abs >> power_of_2_factor); |
| 1351 | // Branch and condition free code for integer division by a power |
| 1352 | // of two. |
| 1353 | const int32_t M = magic_numbers.M; |
| 1354 | const int32_t s = magic_numbers.s + power_of_2_factor; |
| 1355 | |
| 1356 | __ mov(ip, Operand(M)); |
| 1357 | __ smull(ip, scratch, dividend, ip); |
| 1358 | if (M < 0) { |
| 1359 | __ add(scratch, scratch, Operand(dividend)); |
| 1360 | } |
| 1361 | if (s > 0) { |
| 1362 | __ mov(scratch, Operand(scratch, ASR, s)); |
| 1363 | } |
| 1364 | __ add(result, scratch, Operand(dividend, LSR, 31)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1365 | if (divisor < 0) __ rsb(result, result, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1366 | // Compute the remainder. |
| 1367 | __ mov(ip, Operand(divisor)); |
| 1368 | // This sequence could be replaced with 'mls' when |
| 1369 | // it gets implemented. |
| 1370 | __ mul(scratch, result, ip); |
| 1371 | __ sub(remainder, dividend, scratch); |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1377 | void LCodeGen::DoDivI(LDivI* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1378 | class DeferredDivI: public LDeferredCode { |
| 1379 | public: |
| 1380 | DeferredDivI(LCodeGen* codegen, LDivI* instr) |
| 1381 | : LDeferredCode(codegen), instr_(instr) { } |
| 1382 | virtual void Generate() { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1383 | codegen()->DoDeferredBinaryOpStub(instr_->pointer_map(), |
| 1384 | instr_->left(), |
| 1385 | instr_->right(), |
| 1386 | Token::DIV); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1387 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1388 | virtual LInstruction* instr() { return instr_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1389 | private: |
| 1390 | LDivI* instr_; |
| 1391 | }; |
| 1392 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1393 | if (instr->hydrogen()->HasPowerOf2Divisor()) { |
| 1394 | Register dividend = ToRegister(instr->left()); |
| 1395 | int32_t divisor = |
| 1396 | HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
| 1397 | int32_t test_value = 0; |
| 1398 | int32_t power = 0; |
| 1399 | |
| 1400 | if (divisor > 0) { |
| 1401 | test_value = divisor - 1; |
| 1402 | power = WhichPowerOf2(divisor); |
| 1403 | } else { |
| 1404 | // Check for (0 / -x) that will produce negative zero. |
| 1405 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1406 | __ tst(dividend, Operand(dividend)); |
| 1407 | DeoptimizeIf(eq, instr->environment()); |
| 1408 | } |
| 1409 | // Check for (kMinInt / -1). |
| 1410 | if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1411 | __ cmp(dividend, Operand(kMinInt)); |
| 1412 | DeoptimizeIf(eq, instr->environment()); |
| 1413 | } |
| 1414 | test_value = - divisor - 1; |
| 1415 | power = WhichPowerOf2(-divisor); |
| 1416 | } |
| 1417 | |
| 1418 | if (test_value != 0) { |
| 1419 | // Deoptimize if remainder is not 0. |
| 1420 | __ tst(dividend, Operand(test_value)); |
| 1421 | DeoptimizeIf(ne, instr->environment()); |
| 1422 | __ mov(dividend, Operand(dividend, ASR, power)); |
| 1423 | } |
| 1424 | if (divisor < 0) __ rsb(dividend, dividend, Operand(0)); |
| 1425 | |
| 1426 | return; |
| 1427 | } |
| 1428 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1429 | const Register left = ToRegister(instr->left()); |
| 1430 | const Register right = ToRegister(instr->right()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1431 | const Register scratch = scratch0(); |
| 1432 | const Register result = ToRegister(instr->result()); |
| 1433 | |
| 1434 | // Check for x / 0. |
| 1435 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1436 | __ cmp(right, Operand::Zero()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1437 | DeoptimizeIf(eq, instr->environment()); |
| 1438 | } |
| 1439 | |
| 1440 | // Check for (0 / -x) that will produce negative zero. |
| 1441 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1442 | Label left_not_zero; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1443 | __ cmp(left, Operand::Zero()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1444 | __ b(ne, &left_not_zero); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1445 | __ cmp(right, Operand::Zero()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1446 | DeoptimizeIf(mi, instr->environment()); |
| 1447 | __ bind(&left_not_zero); |
| 1448 | } |
| 1449 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1450 | // Check for (kMinInt / -1). |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1451 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1452 | Label left_not_min_int; |
| 1453 | __ cmp(left, Operand(kMinInt)); |
| 1454 | __ b(ne, &left_not_min_int); |
| 1455 | __ cmp(right, Operand(-1)); |
| 1456 | DeoptimizeIf(eq, instr->environment()); |
| 1457 | __ bind(&left_not_min_int); |
| 1458 | } |
| 1459 | |
| 1460 | Label done, deoptimize; |
| 1461 | // Test for a few common cases first. |
| 1462 | __ cmp(right, Operand(1)); |
| 1463 | __ mov(result, left, LeaveCC, eq); |
| 1464 | __ b(eq, &done); |
| 1465 | |
| 1466 | __ cmp(right, Operand(2)); |
| 1467 | __ tst(left, Operand(1), eq); |
| 1468 | __ mov(result, Operand(left, ASR, 1), LeaveCC, eq); |
| 1469 | __ b(eq, &done); |
| 1470 | |
| 1471 | __ cmp(right, Operand(4)); |
| 1472 | __ tst(left, Operand(3), eq); |
| 1473 | __ mov(result, Operand(left, ASR, 2), LeaveCC, eq); |
| 1474 | __ b(eq, &done); |
| 1475 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1476 | // Call the stub. The numbers in r0 and r1 have |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1477 | // to be tagged to Smis. If that is not possible, deoptimize. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1478 | DeferredDivI* deferred = new(zone()) DeferredDivI(this, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1479 | |
| 1480 | __ TrySmiTag(left, &deoptimize, scratch); |
| 1481 | __ TrySmiTag(right, &deoptimize, scratch); |
| 1482 | |
| 1483 | __ b(al, deferred->entry()); |
| 1484 | __ bind(deferred->exit()); |
| 1485 | |
| 1486 | // If the result in r0 is a Smi, untag it, else deoptimize. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1487 | __ JumpIfNotSmi(result, &deoptimize); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1488 | __ SmiUntag(result); |
| 1489 | __ b(&done); |
| 1490 | |
| 1491 | __ bind(&deoptimize); |
| 1492 | DeoptimizeIf(al, instr->environment()); |
| 1493 | __ bind(&done); |
| 1494 | } |
| 1495 | |
| 1496 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1497 | void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
| 1498 | DwVfpRegister addend = ToDoubleRegister(instr->addend()); |
| 1499 | DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1500 | DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1501 | |
| 1502 | // This is computed in-place. |
| 1503 | ASSERT(addend.is(ToDoubleRegister(instr->result()))); |
| 1504 | |
| 1505 | __ vmla(addend, multiplier, multiplicand); |
| 1506 | } |
| 1507 | |
| 1508 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1509 | void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) { |
| 1510 | DwVfpRegister minuend = ToDoubleRegister(instr->minuend()); |
| 1511 | DwVfpRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1512 | DwVfpRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1513 | |
| 1514 | // This is computed in-place. |
| 1515 | ASSERT(minuend.is(ToDoubleRegister(instr->result()))); |
| 1516 | |
| 1517 | __ vmls(minuend, multiplier, multiplicand); |
| 1518 | } |
| 1519 | |
| 1520 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1521 | void LCodeGen::DoMathFloorOfDiv(LMathFloorOfDiv* instr) { |
| 1522 | const Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1523 | const Register left = ToRegister(instr->left()); |
| 1524 | const Register remainder = ToRegister(instr->temp()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1525 | const Register scratch = scratch0(); |
| 1526 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1527 | if (!CpuFeatures::IsSupported(SUDIV)) { |
| 1528 | // If the CPU doesn't support sdiv instruction, we only optimize when we |
| 1529 | // have magic numbers for the divisor. The standard integer division routine |
| 1530 | // is usually slower than transitionning to VFP. |
| 1531 | ASSERT(instr->right()->IsConstantOperand()); |
| 1532 | int32_t divisor = ToInteger32(LConstantOperand::cast(instr->right())); |
| 1533 | ASSERT(LChunkBuilder::HasMagicNumberForDivisor(divisor)); |
| 1534 | if (divisor < 0) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1535 | __ cmp(left, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1536 | DeoptimizeIf(eq, instr->environment()); |
| 1537 | } |
| 1538 | EmitSignedIntegerDivisionByConstant(result, |
| 1539 | left, |
| 1540 | divisor, |
| 1541 | remainder, |
| 1542 | scratch, |
| 1543 | instr->environment()); |
| 1544 | // We performed a truncating division. Correct the result if necessary. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1545 | __ cmp(remainder, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1546 | __ teq(remainder, Operand(divisor), ne); |
| 1547 | __ sub(result, result, Operand(1), LeaveCC, mi); |
| 1548 | } else { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1549 | CpuFeatureScope scope(masm(), SUDIV); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1550 | const Register right = ToRegister(instr->right()); |
| 1551 | |
| 1552 | // Check for x / 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1553 | __ cmp(right, Operand::Zero()); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1554 | DeoptimizeIf(eq, instr->environment()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1555 | |
| 1556 | // Check for (kMinInt / -1). |
| 1557 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1558 | Label left_not_min_int; |
| 1559 | __ cmp(left, Operand(kMinInt)); |
| 1560 | __ b(ne, &left_not_min_int); |
| 1561 | __ cmp(right, Operand(-1)); |
| 1562 | DeoptimizeIf(eq, instr->environment()); |
| 1563 | __ bind(&left_not_min_int); |
| 1564 | } |
| 1565 | |
| 1566 | // Check for (0 / -x) that will produce negative zero. |
| 1567 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1568 | __ cmp(right, Operand::Zero()); |
| 1569 | __ cmp(left, Operand::Zero(), mi); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1570 | // "right" can't be null because the code would have already been |
| 1571 | // deoptimized. The Z flag is set only if (right < 0) and (left == 0). |
| 1572 | // In this case we need to deoptimize to produce a -0. |
| 1573 | DeoptimizeIf(eq, instr->environment()); |
| 1574 | } |
| 1575 | |
| 1576 | Label done; |
| 1577 | __ sdiv(result, left, right); |
| 1578 | // If both operands have the same sign then we are done. |
| 1579 | __ eor(remainder, left, Operand(right), SetCC); |
| 1580 | __ b(pl, &done); |
| 1581 | |
| 1582 | // Check if the result needs to be corrected. |
| 1583 | __ mls(remainder, result, right, left); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1584 | __ cmp(remainder, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1585 | __ sub(result, result, Operand(1), LeaveCC, ne); |
| 1586 | |
| 1587 | __ bind(&done); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1588 | } |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1592 | void LCodeGen::DoDeferredBinaryOpStub(LPointerMap* pointer_map, |
| 1593 | LOperand* left_argument, |
| 1594 | LOperand* right_argument, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1595 | Token::Value op) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1596 | Register left = ToRegister(left_argument); |
| 1597 | Register right = ToRegister(right_argument); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1598 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1599 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegistersAndDoubles); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1600 | // Move left to r1 and right to r0 for the stub call. |
| 1601 | if (left.is(r1)) { |
| 1602 | __ Move(r0, right); |
| 1603 | } else if (left.is(r0) && right.is(r1)) { |
| 1604 | __ Swap(r0, r1, r2); |
| 1605 | } else if (left.is(r0)) { |
| 1606 | ASSERT(!right.is(r1)); |
| 1607 | __ mov(r1, r0); |
| 1608 | __ mov(r0, right); |
| 1609 | } else { |
| 1610 | ASSERT(!left.is(r0) && !right.is(r0)); |
| 1611 | __ mov(r0, right); |
| 1612 | __ mov(r1, left); |
| 1613 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1614 | BinaryOpStub stub(op, OVERWRITE_LEFT); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1615 | __ CallStub(&stub); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1616 | RecordSafepointWithRegistersAndDoubles(pointer_map, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1617 | 0, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1618 | Safepoint::kNoLazyDeopt); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1619 | // Overwrite the stored value of r0 with the result of the stub. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1620 | __ StoreToSafepointRegistersAndDoublesSlot(r0, r0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | void LCodeGen::DoMulI(LMulI* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1625 | Register scratch = scratch0(); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1626 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1627 | // Note that result may alias left. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1628 | Register left = ToRegister(instr->left()); |
| 1629 | LOperand* right_op = instr->right(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1630 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1631 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1632 | bool bailout_on_minus_zero = |
| 1633 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1635 | if (right_op->IsConstantOperand() && !can_overflow) { |
| 1636 | // Use optimized code for specific constants. |
| 1637 | int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
| 1638 | |
| 1639 | if (bailout_on_minus_zero && (constant < 0)) { |
| 1640 | // The case of a null constant will be handled separately. |
| 1641 | // If constant is negative and left is null, the result should be -0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1642 | __ cmp(left, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1643 | DeoptimizeIf(eq, instr->environment()); |
| 1644 | } |
| 1645 | |
| 1646 | switch (constant) { |
| 1647 | case -1: |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1648 | __ rsb(result, left, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1649 | break; |
| 1650 | case 0: |
| 1651 | if (bailout_on_minus_zero) { |
| 1652 | // If left is strictly negative and the constant is null, the |
| 1653 | // result is -0. Deoptimize if required, otherwise return 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1654 | __ cmp(left, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1655 | DeoptimizeIf(mi, instr->environment()); |
| 1656 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1657 | __ mov(result, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1658 | break; |
| 1659 | case 1: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1660 | __ Move(result, left); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1661 | break; |
| 1662 | default: |
| 1663 | // Multiplying by powers of two and powers of two plus or minus |
| 1664 | // one can be done faster with shifted operands. |
| 1665 | // For other constants we emit standard code. |
| 1666 | int32_t mask = constant >> 31; |
| 1667 | uint32_t constant_abs = (constant + mask) ^ mask; |
| 1668 | |
| 1669 | if (IsPowerOf2(constant_abs) || |
| 1670 | IsPowerOf2(constant_abs - 1) || |
| 1671 | IsPowerOf2(constant_abs + 1)) { |
| 1672 | if (IsPowerOf2(constant_abs)) { |
| 1673 | int32_t shift = WhichPowerOf2(constant_abs); |
| 1674 | __ mov(result, Operand(left, LSL, shift)); |
| 1675 | } else if (IsPowerOf2(constant_abs - 1)) { |
| 1676 | int32_t shift = WhichPowerOf2(constant_abs - 1); |
| 1677 | __ add(result, left, Operand(left, LSL, shift)); |
| 1678 | } else if (IsPowerOf2(constant_abs + 1)) { |
| 1679 | int32_t shift = WhichPowerOf2(constant_abs + 1); |
| 1680 | __ rsb(result, left, Operand(left, LSL, shift)); |
| 1681 | } |
| 1682 | |
| 1683 | // Correct the sign of the result is the constant is negative. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1684 | if (constant < 0) __ rsb(result, result, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1685 | |
| 1686 | } else { |
| 1687 | // Generate standard code. |
| 1688 | __ mov(ip, Operand(constant)); |
| 1689 | __ mul(result, left, ip); |
| 1690 | } |
| 1691 | } |
| 1692 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1693 | } else { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1694 | Register right = EmitLoadRegister(right_op, scratch); |
| 1695 | if (bailout_on_minus_zero) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1696 | __ orr(ToRegister(instr->temp()), left, right); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1697 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1698 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1699 | if (can_overflow) { |
| 1700 | // scratch:result = left * right. |
| 1701 | __ smull(result, scratch, left, right); |
| 1702 | __ cmp(scratch, Operand(result, ASR, 31)); |
| 1703 | DeoptimizeIf(ne, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1704 | } else { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1705 | __ mul(result, left, right); |
| 1706 | } |
| 1707 | |
| 1708 | if (bailout_on_minus_zero) { |
| 1709 | // Bail out if the result is supposed to be negative zero. |
| 1710 | Label done; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1711 | __ cmp(result, Operand::Zero()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1712 | __ b(ne, &done); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1713 | __ cmp(ToRegister(instr->temp()), Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1714 | DeoptimizeIf(mi, instr->environment()); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1715 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1716 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | |
| 1721 | void LCodeGen::DoBitI(LBitI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1722 | LOperand* left_op = instr->left(); |
| 1723 | LOperand* right_op = instr->right(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1724 | ASSERT(left_op->IsRegister()); |
| 1725 | Register left = ToRegister(left_op); |
| 1726 | Register result = ToRegister(instr->result()); |
| 1727 | Operand right(no_reg); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1728 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1729 | if (right_op->IsStackSlot() || right_op->IsArgument()) { |
| 1730 | right = Operand(EmitLoadRegister(right_op, ip)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1731 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1732 | ASSERT(right_op->IsRegister() || right_op->IsConstantOperand()); |
| 1733 | right = ToOperand(right_op); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1736 | switch (instr->op()) { |
| 1737 | case Token::BIT_AND: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1738 | __ and_(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1739 | break; |
| 1740 | case Token::BIT_OR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1741 | __ orr(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1742 | break; |
| 1743 | case Token::BIT_XOR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1744 | __ eor(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1745 | break; |
| 1746 | default: |
| 1747 | UNREACHABLE(); |
| 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | |
| 1753 | void LCodeGen::DoShiftI(LShiftI* instr) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1754 | // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
| 1755 | // result may alias either of them. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1756 | LOperand* right_op = instr->right(); |
| 1757 | Register left = ToRegister(instr->left()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1758 | Register result = ToRegister(instr->result()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1759 | Register scratch = scratch0(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1760 | if (right_op->IsRegister()) { |
| 1761 | // Mask the right_op operand. |
| 1762 | __ and_(scratch, ToRegister(right_op), Operand(0x1F)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1763 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1764 | case Token::ROR: |
| 1765 | __ mov(result, Operand(left, ROR, scratch)); |
| 1766 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | case Token::SAR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1768 | __ mov(result, Operand(left, ASR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | case Token::SHR: |
| 1771 | if (instr->can_deopt()) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1772 | __ mov(result, Operand(left, LSR, scratch), SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1773 | DeoptimizeIf(mi, instr->environment()); |
| 1774 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1775 | __ mov(result, Operand(left, LSR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1776 | } |
| 1777 | break; |
| 1778 | case Token::SHL: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1779 | __ mov(result, Operand(left, LSL, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1780 | break; |
| 1781 | default: |
| 1782 | UNREACHABLE(); |
| 1783 | break; |
| 1784 | } |
| 1785 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1786 | // Mask the right_op operand. |
| 1787 | int value = ToInteger32(LConstantOperand::cast(right_op)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1788 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1789 | switch (instr->op()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1790 | case Token::ROR: |
| 1791 | if (shift_count != 0) { |
| 1792 | __ mov(result, Operand(left, ROR, shift_count)); |
| 1793 | } else { |
| 1794 | __ Move(result, left); |
| 1795 | } |
| 1796 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1797 | case Token::SAR: |
| 1798 | if (shift_count != 0) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1799 | __ mov(result, Operand(left, ASR, shift_count)); |
| 1800 | } else { |
| 1801 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1802 | } |
| 1803 | break; |
| 1804 | case Token::SHR: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1805 | if (shift_count != 0) { |
| 1806 | __ mov(result, Operand(left, LSR, shift_count)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1807 | } else { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1808 | if (instr->can_deopt()) { |
| 1809 | __ tst(left, Operand(0x80000000)); |
| 1810 | DeoptimizeIf(ne, instr->environment()); |
| 1811 | } |
| 1812 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1813 | } |
| 1814 | break; |
| 1815 | case Token::SHL: |
| 1816 | if (shift_count != 0) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1817 | __ mov(result, Operand(left, LSL, shift_count)); |
| 1818 | } else { |
| 1819 | __ Move(result, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1820 | } |
| 1821 | break; |
| 1822 | default: |
| 1823 | UNREACHABLE(); |
| 1824 | break; |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | void LCodeGen::DoSubI(LSubI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1831 | LOperand* left = instr->left(); |
| 1832 | LOperand* right = instr->right(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1833 | LOperand* result = instr->result(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1834 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1835 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
| 1836 | |
| 1837 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1838 | Register right_reg = EmitLoadRegister(right, ip); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1839 | __ sub(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1840 | } else { |
| 1841 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1842 | __ sub(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | if (can_overflow) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1846 | DeoptimizeIf(vs, instr->environment()); |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1851 | void LCodeGen::DoRSubI(LRSubI* instr) { |
| 1852 | LOperand* left = instr->left(); |
| 1853 | LOperand* right = instr->right(); |
| 1854 | LOperand* result = instr->result(); |
| 1855 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1856 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
| 1857 | |
| 1858 | if (right->IsStackSlot() || right->IsArgument()) { |
| 1859 | Register right_reg = EmitLoadRegister(right, ip); |
| 1860 | __ rsb(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
| 1861 | } else { |
| 1862 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
| 1863 | __ rsb(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
| 1864 | } |
| 1865 | |
| 1866 | if (can_overflow) { |
| 1867 | DeoptimizeIf(vs, instr->environment()); |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1872 | void LCodeGen::DoConstantI(LConstantI* instr) { |
| 1873 | ASSERT(instr->result()->IsRegister()); |
| 1874 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1875 | } |
| 1876 | |
| 1877 | |
| 1878 | void LCodeGen::DoConstantD(LConstantD* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1879 | ASSERT(instr->result()->IsDoubleRegister()); |
| 1880 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 1881 | double v = instr->value(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1882 | __ Vmov(result, v, scratch0()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | void LCodeGen::DoConstantT(LConstantT* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1887 | Handle<Object> value = instr->value(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1888 | ALLOW_HANDLE_DEREF(isolate(), "smi check"); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1889 | if (value->IsSmi()) { |
| 1890 | __ mov(ToRegister(instr->result()), Operand(value)); |
| 1891 | } else { |
| 1892 | __ LoadHeapObject(ToRegister(instr->result()), |
| 1893 | Handle<HeapObject>::cast(value)); |
| 1894 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1898 | void LCodeGen::DoFixedArrayBaseLength(LFixedArrayBaseLength* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1899 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1900 | Register array = ToRegister(instr->value()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1901 | __ ldr(result, FieldMemOperand(array, FixedArrayBase::kLengthOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1905 | void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) { |
| 1906 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1907 | Register map = ToRegister(instr->value()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1908 | __ EnumLength(result, map); |
| 1909 | } |
| 1910 | |
| 1911 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1912 | void LCodeGen::DoElementsKind(LElementsKind* instr) { |
| 1913 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1914 | Register input = ToRegister(instr->value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1915 | |
| 1916 | // Load map into |result|. |
| 1917 | __ ldr(result, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 1918 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 1919 | // but the following bit field extraction takes care of that anyway. |
| 1920 | __ ldr(result, FieldMemOperand(result, Map::kBitField2Offset)); |
| 1921 | // Retrieve elements_kind from bit field 2. |
| 1922 | __ ubfx(result, result, Map::kElementsKindShift, Map::kElementsKindBitCount); |
| 1923 | } |
| 1924 | |
| 1925 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1926 | void LCodeGen::DoValueOf(LValueOf* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1927 | Register input = ToRegister(instr->value()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1928 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1929 | Register map = ToRegister(instr->temp()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1930 | Label done; |
| 1931 | |
| 1932 | // If the object is a smi return the object. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1933 | __ tst(input, Operand(kSmiTagMask)); |
| 1934 | __ Move(result, input, eq); |
| 1935 | __ b(eq, &done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1936 | |
| 1937 | // If the object is not a value type, return the object. |
| 1938 | __ CompareObjectType(input, map, map, JS_VALUE_TYPE); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1939 | __ Move(result, input, ne); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1940 | __ b(ne, &done); |
| 1941 | __ ldr(result, FieldMemOperand(input, JSValue::kValueOffset)); |
| 1942 | |
| 1943 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1947 | void LCodeGen::DoDateField(LDateField* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1948 | Register object = ToRegister(instr->date()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1949 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1950 | Register scratch = ToRegister(instr->temp()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1951 | Smi* index = instr->index(); |
| 1952 | Label runtime, done; |
| 1953 | ASSERT(object.is(result)); |
| 1954 | ASSERT(object.is(r0)); |
| 1955 | ASSERT(!scratch.is(scratch0())); |
| 1956 | ASSERT(!scratch.is(object)); |
| 1957 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1958 | __ tst(object, Operand(kSmiTagMask)); |
| 1959 | DeoptimizeIf(eq, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1960 | __ CompareObjectType(object, scratch, scratch, JS_DATE_TYPE); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1961 | DeoptimizeIf(ne, instr->environment()); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1962 | |
| 1963 | if (index->value() == 0) { |
| 1964 | __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset)); |
| 1965 | } else { |
| 1966 | if (index->value() < JSDate::kFirstUncachedField) { |
| 1967 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 1968 | __ mov(scratch, Operand(stamp)); |
| 1969 | __ ldr(scratch, MemOperand(scratch)); |
| 1970 | __ ldr(scratch0(), FieldMemOperand(object, JSDate::kCacheStampOffset)); |
| 1971 | __ cmp(scratch, scratch0()); |
| 1972 | __ b(ne, &runtime); |
| 1973 | __ ldr(result, FieldMemOperand(object, JSDate::kValueOffset + |
| 1974 | kPointerSize * index->value())); |
| 1975 | __ jmp(&done); |
| 1976 | } |
| 1977 | __ bind(&runtime); |
| 1978 | __ PrepareCallCFunction(2, scratch); |
| 1979 | __ mov(r1, Operand(index)); |
| 1980 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
| 1981 | __ bind(&done); |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1986 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 1987 | SeqStringSetCharGenerator::Generate(masm(), |
| 1988 | instr->encoding(), |
| 1989 | ToRegister(instr->string()), |
| 1990 | ToRegister(instr->index()), |
| 1991 | ToRegister(instr->value())); |
| 1992 | } |
| 1993 | |
| 1994 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1995 | void LCodeGen::DoBitNotI(LBitNotI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1996 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1997 | Register result = ToRegister(instr->result()); |
| 1998 | __ mvn(result, Operand(input)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | |
| 2002 | void LCodeGen::DoThrow(LThrow* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2003 | Register input_reg = EmitLoadRegister(instr->value(), ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2004 | __ push(input_reg); |
| 2005 | CallRuntime(Runtime::kThrow, 1, instr); |
| 2006 | |
| 2007 | if (FLAG_debug_code) { |
| 2008 | __ stop("Unreachable code."); |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | |
| 2013 | void LCodeGen::DoAddI(LAddI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2014 | LOperand* left = instr->left(); |
| 2015 | LOperand* right = instr->right(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2016 | LOperand* result = instr->result(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2017 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 2018 | SBit set_cond = can_overflow ? SetCC : LeaveCC; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2019 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2020 | if (right->IsStackSlot() || right->IsArgument()) { |
| 2021 | Register right_reg = EmitLoadRegister(right, ip); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2022 | __ add(ToRegister(result), ToRegister(left), Operand(right_reg), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2023 | } else { |
| 2024 | ASSERT(right->IsRegister() || right->IsConstantOperand()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2025 | __ add(ToRegister(result), ToRegister(left), ToOperand(right), set_cond); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2026 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2027 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2028 | if (can_overflow) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2029 | DeoptimizeIf(vs, instr->environment()); |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2034 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2035 | LOperand* left = instr->left(); |
| 2036 | LOperand* right = instr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2037 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2038 | if (instr->hydrogen()->representation().IsInteger32()) { |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2039 | Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2040 | Register left_reg = ToRegister(left); |
| 2041 | Operand right_op = (right->IsRegister() || right->IsConstantOperand()) |
| 2042 | ? ToOperand(right) |
| 2043 | : Operand(EmitLoadRegister(right, ip)); |
| 2044 | Register result_reg = ToRegister(instr->result()); |
| 2045 | __ cmp(left_reg, right_op); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2046 | __ Move(result_reg, left_reg, condition); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2047 | __ mov(result_reg, right_op, LeaveCC, NegateCondition(condition)); |
| 2048 | } else { |
| 2049 | ASSERT(instr->hydrogen()->representation().IsDouble()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2050 | DwVfpRegister left_reg = ToDoubleRegister(left); |
| 2051 | DwVfpRegister right_reg = ToDoubleRegister(right); |
| 2052 | DwVfpRegister result_reg = ToDoubleRegister(instr->result()); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2053 | Label result_is_nan, return_left, return_right, check_zero, done; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2054 | __ VFPCompareAndSetFlags(left_reg, right_reg); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2055 | if (operation == HMathMinMax::kMathMin) { |
| 2056 | __ b(mi, &return_left); |
| 2057 | __ b(gt, &return_right); |
| 2058 | } else { |
| 2059 | __ b(mi, &return_right); |
| 2060 | __ b(gt, &return_left); |
| 2061 | } |
| 2062 | __ b(vs, &result_is_nan); |
| 2063 | // Left equals right => check for -0. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2064 | __ VFPCompareAndSetFlags(left_reg, 0.0); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2065 | if (left_reg.is(result_reg) || right_reg.is(result_reg)) { |
| 2066 | __ b(ne, &done); // left == right != 0. |
| 2067 | } else { |
| 2068 | __ b(ne, &return_left); // left == right != 0. |
| 2069 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2070 | // At this point, both left and right are either 0 or -0. |
| 2071 | if (operation == HMathMinMax::kMathMin) { |
| 2072 | // We could use a single 'vorr' instruction here if we had NEON support. |
| 2073 | __ vneg(left_reg, left_reg); |
| 2074 | __ vsub(result_reg, left_reg, right_reg); |
| 2075 | __ vneg(result_reg, result_reg); |
| 2076 | } else { |
| 2077 | // Since we operate on +0 and/or -0, vadd and vand have the same effect; |
| 2078 | // the decision for vadd is easy because vand is a NEON instruction. |
| 2079 | __ vadd(result_reg, left_reg, right_reg); |
| 2080 | } |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2081 | __ b(&done); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2082 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2083 | __ bind(&result_is_nan); |
| 2084 | __ vadd(result_reg, left_reg, right_reg); |
| 2085 | __ b(&done); |
| 2086 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2087 | __ bind(&return_right); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2088 | __ Move(result_reg, right_reg); |
| 2089 | if (!left_reg.is(result_reg)) { |
| 2090 | __ b(&done); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2091 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2092 | |
| 2093 | __ bind(&return_left); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2094 | __ Move(result_reg, left_reg); |
| 2095 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2096 | __ bind(&done); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2101 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2102 | DwVfpRegister left = ToDoubleRegister(instr->left()); |
| 2103 | DwVfpRegister right = ToDoubleRegister(instr->right()); |
| 2104 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2105 | switch (instr->op()) { |
| 2106 | case Token::ADD: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2107 | __ vadd(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2108 | break; |
| 2109 | case Token::SUB: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2110 | __ vsub(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2111 | break; |
| 2112 | case Token::MUL: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2113 | __ vmul(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2114 | break; |
| 2115 | case Token::DIV: |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2116 | __ vdiv(result, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | case Token::MOD: { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2119 | // Save r0-r3 on the stack. |
| 2120 | __ stm(db_w, sp, r0.bit() | r1.bit() | r2.bit() | r3.bit()); |
| 2121 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2122 | __ PrepareCallCFunction(0, 2, scratch0()); |
| 2123 | __ SetCallCDoubleArguments(left, right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2124 | __ CallCFunction( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2125 | ExternalReference::double_fp_operation(Token::MOD, isolate()), |
| 2126 | 0, 2); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2127 | // Move the result in the double result register. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2128 | __ GetCFunctionDoubleResult(result); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2129 | |
| 2130 | // Restore r0-r3. |
| 2131 | __ ldm(ia_w, sp, r0.bit() | r1.bit() | r2.bit() | r3.bit()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2132 | break; |
| 2133 | } |
| 2134 | default: |
| 2135 | UNREACHABLE(); |
| 2136 | break; |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | |
| 2141 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2142 | ASSERT(ToRegister(instr->left()).is(r1)); |
| 2143 | ASSERT(ToRegister(instr->right()).is(r0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2144 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2145 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2146 | BinaryOpStub stub(instr->op(), NO_OVERWRITE); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2147 | // Block literal pool emission to ensure nop indicating no inlined smi code |
| 2148 | // is in the correct position. |
| 2149 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2150 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2151 | __ nop(); // Signals no inlined code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2155 | int LCodeGen::GetNextEmittedBlock() const { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2156 | for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { |
| 2157 | if (!chunk_->GetLabel(i)->HasReplacement()) return i; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2158 | } |
| 2159 | return -1; |
| 2160 | } |
| 2161 | |
| 2162 | |
| 2163 | void LCodeGen::EmitBranch(int left_block, int right_block, Condition cc) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2164 | int next_block = GetNextEmittedBlock(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2165 | right_block = chunk_->LookupDestination(right_block); |
| 2166 | left_block = chunk_->LookupDestination(left_block); |
| 2167 | |
| 2168 | if (right_block == left_block) { |
| 2169 | EmitGoto(left_block); |
| 2170 | } else if (left_block == next_block) { |
| 2171 | __ b(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
| 2172 | } else if (right_block == next_block) { |
| 2173 | __ b(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2174 | } else { |
| 2175 | __ b(cc, chunk_->GetAssemblyLabel(left_block)); |
| 2176 | __ b(chunk_->GetAssemblyLabel(right_block)); |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | |
| 2181 | void LCodeGen::DoBranch(LBranch* instr) { |
| 2182 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2183 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2184 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2185 | Representation r = instr->hydrogen()->value()->representation(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2186 | if (r.IsInteger32()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2187 | Register reg = ToRegister(instr->value()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2188 | __ cmp(reg, Operand::Zero()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2189 | EmitBranch(true_block, false_block, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2190 | } else if (r.IsDouble()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2191 | DwVfpRegister reg = ToDoubleRegister(instr->value()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2192 | // Test the double value. Zero and NaN are false. |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2193 | __ VFPCompareAndSetFlags(reg, 0.0); |
| 2194 | __ cmp(r0, r0, vs); // If NaN, set the Z flag. |
| 2195 | EmitBranch(true_block, false_block, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2196 | } else { |
| 2197 | ASSERT(r.IsTagged()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2198 | Register reg = ToRegister(instr->value()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2199 | HType type = instr->hydrogen()->value()->type(); |
| 2200 | if (type.IsBoolean()) { |
| 2201 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2202 | EmitBranch(true_block, false_block, eq); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2203 | } else if (type.IsSmi()) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2204 | __ cmp(reg, Operand::Zero()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2205 | EmitBranch(true_block, false_block, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2206 | } else { |
| 2207 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2208 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2209 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2210 | ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types(); |
| 2211 | // Avoid deopts in the case where we've never executed this path before. |
| 2212 | if (expected.IsEmpty()) expected = ToBooleanStub::all_types(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2213 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2214 | if (expected.Contains(ToBooleanStub::UNDEFINED)) { |
| 2215 | // undefined -> false. |
| 2216 | __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
| 2217 | __ b(eq, false_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2218 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2219 | if (expected.Contains(ToBooleanStub::BOOLEAN)) { |
| 2220 | // Boolean -> its value. |
| 2221 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 2222 | __ b(eq, true_label); |
| 2223 | __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 2224 | __ b(eq, false_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2225 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2226 | if (expected.Contains(ToBooleanStub::NULL_TYPE)) { |
| 2227 | // 'null' -> false. |
| 2228 | __ CompareRoot(reg, Heap::kNullValueRootIndex); |
| 2229 | __ b(eq, false_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | if (expected.Contains(ToBooleanStub::SMI)) { |
| 2233 | // Smis: 0 -> false, all other -> true. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2234 | __ cmp(reg, Operand::Zero()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2235 | __ b(eq, false_label); |
| 2236 | __ JumpIfSmi(reg, true_label); |
| 2237 | } else if (expected.NeedsMap()) { |
| 2238 | // If we need a map later and have a Smi -> deopt. |
| 2239 | __ tst(reg, Operand(kSmiTagMask)); |
| 2240 | DeoptimizeIf(eq, instr->environment()); |
| 2241 | } |
| 2242 | |
| 2243 | const Register map = scratch0(); |
| 2244 | if (expected.NeedsMap()) { |
| 2245 | __ ldr(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2246 | |
| 2247 | if (expected.CanBeUndetectable()) { |
| 2248 | // Undetectable -> false. |
| 2249 | __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 2250 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 2251 | __ b(ne, false_label); |
| 2252 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) { |
| 2256 | // spec object -> true. |
| 2257 | __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 2258 | __ b(ge, true_label); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | if (expected.Contains(ToBooleanStub::STRING)) { |
| 2262 | // String value -> false iff empty. |
| 2263 | Label not_string; |
| 2264 | __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
| 2265 | __ b(ge, ¬_string); |
| 2266 | __ ldr(ip, FieldMemOperand(reg, String::kLengthOffset)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2267 | __ cmp(ip, Operand::Zero()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2268 | __ b(ne, true_label); |
| 2269 | __ b(false_label); |
| 2270 | __ bind(¬_string); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2273 | if (expected.Contains(ToBooleanStub::SYMBOL)) { |
| 2274 | // Symbol value -> true. |
| 2275 | __ CompareInstanceType(map, ip, SYMBOL_TYPE); |
| 2276 | __ b(eq, true_label); |
| 2277 | } |
| 2278 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2279 | if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 2280 | // heap number -> false iff +0, -0, or NaN. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2281 | DwVfpRegister dbl_scratch = double_scratch0(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2282 | Label not_heap_number; |
| 2283 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 2284 | __ b(ne, ¬_heap_number); |
| 2285 | __ vldr(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2286 | __ VFPCompareAndSetFlags(dbl_scratch, 0.0); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 2287 | __ cmp(r0, r0, vs); // NaN -> false. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2288 | __ b(eq, false_label); // +0, -0 -> false. |
| 2289 | __ b(true_label); |
| 2290 | __ bind(¬_heap_number); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2293 | // We've seen something for the first time -> deopt. |
| 2294 | DeoptimizeIf(al, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2295 | } |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2300 | void LCodeGen::EmitGoto(int block) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2301 | if (!IsNextEmittedBlock(block)) { |
| 2302 | __ jmp(chunk_->GetAssemblyLabel(chunk_->LookupDestination(block))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2307 | void LCodeGen::DoGoto(LGoto* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2308 | EmitGoto(instr->block_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | |
| 2312 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2313 | Condition cond = kNoCondition; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2314 | switch (op) { |
| 2315 | case Token::EQ: |
| 2316 | case Token::EQ_STRICT: |
| 2317 | cond = eq; |
| 2318 | break; |
| 2319 | case Token::LT: |
| 2320 | cond = is_unsigned ? lo : lt; |
| 2321 | break; |
| 2322 | case Token::GT: |
| 2323 | cond = is_unsigned ? hi : gt; |
| 2324 | break; |
| 2325 | case Token::LTE: |
| 2326 | cond = is_unsigned ? ls : le; |
| 2327 | break; |
| 2328 | case Token::GTE: |
| 2329 | cond = is_unsigned ? hs : ge; |
| 2330 | break; |
| 2331 | case Token::IN: |
| 2332 | case Token::INSTANCEOF: |
| 2333 | default: |
| 2334 | UNREACHABLE(); |
| 2335 | } |
| 2336 | return cond; |
| 2337 | } |
| 2338 | |
| 2339 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2340 | void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2341 | LOperand* left = instr->left(); |
| 2342 | LOperand* right = instr->right(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2343 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2344 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2345 | Condition cond = TokenToCondition(instr->op(), false); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2346 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2347 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2348 | // We can statically evaluate the comparison. |
| 2349 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2350 | double right_val = ToDouble(LConstantOperand::cast(right)); |
| 2351 | int next_block = |
| 2352 | EvalComparison(instr->op(), left_val, right_val) ? true_block |
| 2353 | : false_block; |
| 2354 | EmitGoto(next_block); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2355 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2356 | if (instr->is_double()) { |
| 2357 | // Compare left and right operands as doubles and load the |
| 2358 | // resulting flags into the normal status register. |
| 2359 | __ VFPCompareAndSetFlags(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 2360 | // If a NaN is involved, i.e. the result is unordered (V set), |
| 2361 | // jump to false block label. |
| 2362 | __ b(vs, chunk_->GetAssemblyLabel(false_block)); |
| 2363 | } else { |
| 2364 | if (right->IsConstantOperand()) { |
| 2365 | __ cmp(ToRegister(left), |
| 2366 | Operand(ToInteger32(LConstantOperand::cast(right)))); |
| 2367 | } else if (left->IsConstantOperand()) { |
| 2368 | __ cmp(ToRegister(right), |
| 2369 | Operand(ToInteger32(LConstantOperand::cast(left)))); |
| 2370 | // We transposed the operands. Reverse the condition. |
| 2371 | cond = ReverseCondition(cond); |
| 2372 | } else { |
| 2373 | __ cmp(ToRegister(left), ToRegister(right)); |
| 2374 | } |
| 2375 | } |
| 2376 | EmitBranch(true_block, false_block, cond); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2377 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 2381 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2382 | Register left = ToRegister(instr->left()); |
| 2383 | Register right = ToRegister(instr->right()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2384 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2385 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2386 | |
| 2387 | __ cmp(left, Operand(right)); |
| 2388 | EmitBranch(true_block, false_block, eq); |
| 2389 | } |
| 2390 | |
| 2391 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2392 | void LCodeGen::DoCmpConstantEqAndBranch(LCmpConstantEqAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2393 | Register left = ToRegister(instr->left()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2394 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2395 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2396 | |
| 2397 | __ cmp(left, Operand(instr->hydrogen()->right())); |
| 2398 | EmitBranch(true_block, false_block, eq); |
| 2399 | } |
| 2400 | |
| 2401 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2402 | void LCodeGen::DoIsNilAndBranch(LIsNilAndBranch* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2403 | Register scratch = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2404 | Register reg = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2405 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2406 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2407 | // If the expression is known to be untagged or a smi, then it's definitely |
| 2408 | // not null, and it can't be a an undetectable object. |
| 2409 | if (instr->hydrogen()->representation().IsSpecialization() || |
| 2410 | instr->hydrogen()->type().IsSmi()) { |
| 2411 | EmitGoto(false_block); |
| 2412 | return; |
| 2413 | } |
| 2414 | |
| 2415 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2416 | Heap::RootListIndex nil_value = instr->nil() == kNullValue ? |
| 2417 | Heap::kNullValueRootIndex : |
| 2418 | Heap::kUndefinedValueRootIndex; |
| 2419 | __ LoadRoot(ip, nil_value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2420 | __ cmp(reg, ip); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2421 | if (instr->kind() == kStrictEquality) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2422 | EmitBranch(true_block, false_block, eq); |
| 2423 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2424 | Heap::RootListIndex other_nil_value = instr->nil() == kNullValue ? |
| 2425 | Heap::kUndefinedValueRootIndex : |
| 2426 | Heap::kNullValueRootIndex; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2427 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2428 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2429 | __ b(eq, true_label); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2430 | __ LoadRoot(ip, other_nil_value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2431 | __ cmp(reg, ip); |
| 2432 | __ b(eq, true_label); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2433 | __ JumpIfSmi(reg, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2434 | // Check for undetectable objects by looking in the bit field in |
| 2435 | // the map. The object has already been smi checked. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2436 | __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2437 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 2438 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
| 2439 | EmitBranch(true_block, false_block, ne); |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2444 | Condition LCodeGen::EmitIsObject(Register input, |
| 2445 | Register temp1, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2446 | Label* is_not_object, |
| 2447 | Label* is_object) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2448 | Register temp2 = scratch0(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2449 | __ JumpIfSmi(input, is_not_object); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2450 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2451 | __ LoadRoot(temp2, Heap::kNullValueRootIndex); |
| 2452 | __ cmp(input, temp2); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2453 | __ b(eq, is_object); |
| 2454 | |
| 2455 | // Load map. |
| 2456 | __ ldr(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2457 | // Undetectable objects behave like undefined. |
| 2458 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
| 2459 | __ tst(temp2, Operand(1 << Map::kIsUndetectable)); |
| 2460 | __ b(ne, is_not_object); |
| 2461 | |
| 2462 | // Load instance type and check that it is in object type range. |
| 2463 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2464 | __ cmp(temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2465 | __ b(lt, is_not_object); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2466 | __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2467 | return le; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2471 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2472 | Register reg = ToRegister(instr->value()); |
| 2473 | Register temp1 = ToRegister(instr->temp()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2474 | |
| 2475 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2476 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2477 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2478 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2479 | |
| 2480 | Condition true_cond = |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2481 | EmitIsObject(reg, temp1, false_label, true_label); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2482 | |
| 2483 | EmitBranch(true_block, false_block, true_cond); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2487 | Condition LCodeGen::EmitIsString(Register input, |
| 2488 | Register temp1, |
| 2489 | Label* is_not_string) { |
| 2490 | __ JumpIfSmi(input, is_not_string); |
| 2491 | __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE); |
| 2492 | |
| 2493 | return lt; |
| 2494 | } |
| 2495 | |
| 2496 | |
| 2497 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2498 | Register reg = ToRegister(instr->value()); |
| 2499 | Register temp1 = ToRegister(instr->temp()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2500 | |
| 2501 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2502 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2503 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2504 | |
| 2505 | Condition true_cond = |
| 2506 | EmitIsString(reg, temp1, false_label); |
| 2507 | |
| 2508 | EmitBranch(true_block, false_block, true_cond); |
| 2509 | } |
| 2510 | |
| 2511 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2512 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
| 2513 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2514 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2515 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2516 | Register input_reg = EmitLoadRegister(instr->value(), ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2517 | __ tst(input_reg, Operand(kSmiTagMask)); |
| 2518 | EmitBranch(true_block, false_block, eq); |
| 2519 | } |
| 2520 | |
| 2521 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2522 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2523 | Register input = ToRegister(instr->value()); |
| 2524 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2525 | |
| 2526 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2527 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2528 | |
| 2529 | __ JumpIfSmi(input, chunk_->GetAssemblyLabel(false_block)); |
| 2530 | __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2531 | __ ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset)); |
| 2532 | __ tst(temp, Operand(1 << Map::kIsUndetectable)); |
| 2533 | EmitBranch(true_block, false_block, ne); |
| 2534 | } |
| 2535 | |
| 2536 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2537 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2538 | switch (op) { |
| 2539 | case Token::EQ_STRICT: |
| 2540 | case Token::EQ: |
| 2541 | return eq; |
| 2542 | case Token::LT: |
| 2543 | return lt; |
| 2544 | case Token::GT: |
| 2545 | return gt; |
| 2546 | case Token::LTE: |
| 2547 | return le; |
| 2548 | case Token::GTE: |
| 2549 | return ge; |
| 2550 | default: |
| 2551 | UNREACHABLE(); |
| 2552 | return kNoCondition; |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | |
| 2557 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
| 2558 | Token::Value op = instr->op(); |
| 2559 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2560 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2561 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2562 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2563 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2564 | // This instruction also signals no smi code inlined. |
| 2565 | __ cmp(r0, Operand::Zero()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2566 | |
| 2567 | Condition condition = ComputeCompareCondition(op); |
| 2568 | |
| 2569 | EmitBranch(true_block, false_block, condition); |
| 2570 | } |
| 2571 | |
| 2572 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2573 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2574 | InstanceType from = instr->from(); |
| 2575 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2576 | if (from == FIRST_TYPE) return to; |
| 2577 | ASSERT(from == to || to == LAST_TYPE); |
| 2578 | return from; |
| 2579 | } |
| 2580 | |
| 2581 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2582 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2583 | InstanceType from = instr->from(); |
| 2584 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2585 | if (from == to) return eq; |
| 2586 | if (to == LAST_TYPE) return hs; |
| 2587 | if (from == FIRST_TYPE) return ls; |
| 2588 | UNREACHABLE(); |
| 2589 | return eq; |
| 2590 | } |
| 2591 | |
| 2592 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2593 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2594 | Register scratch = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2595 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2596 | |
| 2597 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2598 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2599 | |
| 2600 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2601 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2602 | __ JumpIfSmi(input, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2603 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2604 | __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); |
| 2605 | EmitBranch(true_block, false_block, BranchCondition(instr->hydrogen())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2609 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2610 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2611 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2612 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2613 | __ AssertString(input); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2614 | |
| 2615 | __ ldr(result, FieldMemOperand(input, String::kHashFieldOffset)); |
| 2616 | __ IndexFromHash(result, result); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2620 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2621 | LHasCachedArrayIndexAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2622 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2623 | Register scratch = scratch0(); |
| 2624 | |
| 2625 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2626 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2627 | |
| 2628 | __ ldr(scratch, |
| 2629 | FieldMemOperand(input, String::kHashFieldOffset)); |
| 2630 | __ tst(scratch, Operand(String::kContainsCachedArrayIndexMask)); |
| 2631 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2635 | // Branches to a label or falls through with the answer in flags. Trashes |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2636 | // the temp registers, but not the input. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2637 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 2638 | Label* is_false, |
| 2639 | Handle<String>class_name, |
| 2640 | Register input, |
| 2641 | Register temp, |
| 2642 | Register temp2) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2643 | ASSERT(!input.is(temp)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2644 | ASSERT(!input.is(temp2)); |
| 2645 | ASSERT(!temp.is(temp2)); |
| 2646 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2647 | __ JumpIfSmi(input, is_false); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2648 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2649 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Function"))) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2650 | // Assuming the following assertions, we can use the same compares to test |
| 2651 | // for both being a function type and being in the object type range. |
| 2652 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 2653 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2654 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2655 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2656 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2657 | STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 2658 | __ CompareObjectType(input, temp, temp2, FIRST_SPEC_OBJECT_TYPE); |
| 2659 | __ b(lt, is_false); |
| 2660 | __ b(eq, is_true); |
| 2661 | __ cmp(temp2, Operand(LAST_SPEC_OBJECT_TYPE)); |
| 2662 | __ b(eq, is_true); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2663 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2664 | // Faster code path to avoid two compares: subtract lower bound from the |
| 2665 | // actual type and do a signed compare with the width of the type range. |
| 2666 | __ ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2667 | __ ldrb(temp2, FieldMemOperand(temp, Map::kInstanceTypeOffset)); |
| 2668 | __ sub(temp2, temp2, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2669 | __ cmp(temp2, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE - |
| 2670 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 2671 | __ b(gt, is_false); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2674 | // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2675 | // Check if the constructor in the map is a function. |
| 2676 | __ ldr(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
| 2677 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2678 | // Objects with a non-function constructor have class 'Object'. |
| 2679 | __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2680 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Object"))) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2681 | __ b(ne, is_true); |
| 2682 | } else { |
| 2683 | __ b(ne, is_false); |
| 2684 | } |
| 2685 | |
| 2686 | // temp now contains the constructor function. Grab the |
| 2687 | // instance class name from there. |
| 2688 | __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2689 | __ ldr(temp, FieldMemOperand(temp, |
| 2690 | SharedFunctionInfo::kInstanceClassNameOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2691 | // The class name we are testing against is internalized since it's a literal. |
| 2692 | // The name in the constructor is internalized because of the way the context |
| 2693 | // is booted. This routine isn't expected to work for random API-created |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2694 | // classes and it doesn't have to because you can't access it with natives |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2695 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2696 | // identity comparison. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2697 | __ cmp(temp, Operand(class_name)); |
| 2698 | // End with the answer in flags. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2702 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2703 | Register input = ToRegister(instr->value()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2704 | Register temp = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2705 | Register temp2 = ToRegister(instr->temp()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2706 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2707 | |
| 2708 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2709 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2710 | |
| 2711 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 2712 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 2713 | |
| 2714 | EmitClassOfTest(true_label, false_label, class_name, input, temp, temp2); |
| 2715 | |
| 2716 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | |
| 2720 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2721 | Register reg = ToRegister(instr->value()); |
| 2722 | Register temp = ToRegister(instr->temp()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2723 | int true_block = instr->true_block_id(); |
| 2724 | int false_block = instr->false_block_id(); |
| 2725 | |
| 2726 | __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2727 | __ cmp(temp, Operand(instr->map())); |
| 2728 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | |
| 2732 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2733 | ASSERT(ToRegister(instr->left()).is(r0)); // Object is in r0. |
| 2734 | ASSERT(ToRegister(instr->right()).is(r1)); // Function is in r1. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2735 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2736 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2737 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2738 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2739 | __ cmp(r0, Operand::Zero()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2740 | __ mov(r0, Operand(factory()->false_value()), LeaveCC, ne); |
| 2741 | __ mov(r0, Operand(factory()->true_value()), LeaveCC, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2745 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2746 | class DeferredInstanceOfKnownGlobal: public LDeferredCode { |
| 2747 | public: |
| 2748 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2749 | LInstanceOfKnownGlobal* instr) |
| 2750 | : LDeferredCode(codegen), instr_(instr) { } |
| 2751 | virtual void Generate() { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2752 | codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2753 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2754 | virtual LInstruction* instr() { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2755 | Label* map_check() { return &map_check_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2756 | private: |
| 2757 | LInstanceOfKnownGlobal* instr_; |
| 2758 | Label map_check_; |
| 2759 | }; |
| 2760 | |
| 2761 | DeferredInstanceOfKnownGlobal* deferred; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2762 | deferred = new(zone()) DeferredInstanceOfKnownGlobal(this, instr); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2763 | |
| 2764 | Label done, false_result; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2765 | Register object = ToRegister(instr->value()); |
| 2766 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2767 | Register result = ToRegister(instr->result()); |
| 2768 | |
| 2769 | ASSERT(object.is(r0)); |
| 2770 | ASSERT(result.is(r0)); |
| 2771 | |
| 2772 | // A Smi is not instance of anything. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2773 | __ JumpIfSmi(object, &false_result); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2774 | |
| 2775 | // This is the inlined call site instanceof cache. The two occurences of the |
| 2776 | // hole value will be patched to the last map/result pair generated by the |
| 2777 | // instanceof stub. |
| 2778 | Label cache_miss; |
| 2779 | Register map = temp; |
| 2780 | __ ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2781 | { |
| 2782 | // Block constant pool emission to ensure the positions of instructions are |
| 2783 | // as expected by the patcher. See InstanceofStub::Generate(). |
| 2784 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
| 2785 | __ bind(deferred->map_check()); // Label for calculating code patching. |
| 2786 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2787 | // root array to force relocation to be able to later patch with |
| 2788 | // the cached map. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2789 | PredictableCodeSizeScope predictable(masm_, 5 * Assembler::kInstrSize); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2790 | Handle<JSGlobalPropertyCell> cell = |
| 2791 | factory()->NewJSGlobalPropertyCell(factory()->the_hole_value()); |
| 2792 | __ mov(ip, Operand(Handle<Object>(cell))); |
| 2793 | __ ldr(ip, FieldMemOperand(ip, JSGlobalPropertyCell::kValueOffset)); |
| 2794 | __ cmp(map, Operand(ip)); |
| 2795 | __ b(ne, &cache_miss); |
| 2796 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2797 | // root array to force relocation to be able to later patch |
| 2798 | // with true or false. |
| 2799 | __ mov(result, Operand(factory()->the_hole_value())); |
| 2800 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2801 | __ b(&done); |
| 2802 | |
| 2803 | // The inlined call site cache did not match. Check null and string before |
| 2804 | // calling the deferred code. |
| 2805 | __ bind(&cache_miss); |
| 2806 | // Null is not instance of anything. |
| 2807 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2808 | __ cmp(object, Operand(ip)); |
| 2809 | __ b(eq, &false_result); |
| 2810 | |
| 2811 | // String values is not instance of anything. |
| 2812 | Condition is_string = masm_->IsObjectStringType(object, temp); |
| 2813 | __ b(is_string, &false_result); |
| 2814 | |
| 2815 | // Go to the deferred code. |
| 2816 | __ b(deferred->entry()); |
| 2817 | |
| 2818 | __ bind(&false_result); |
| 2819 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 2820 | |
| 2821 | // Here result has either true or false. Deferred code also produces true or |
| 2822 | // false object. |
| 2823 | __ bind(deferred->exit()); |
| 2824 | __ bind(&done); |
| 2825 | } |
| 2826 | |
| 2827 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2828 | void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2829 | Label* map_check) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2830 | Register result = ToRegister(instr->result()); |
| 2831 | ASSERT(result.is(r0)); |
| 2832 | |
| 2833 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 2834 | flags = static_cast<InstanceofStub::Flags>( |
| 2835 | flags | InstanceofStub::kArgsInRegisters); |
| 2836 | flags = static_cast<InstanceofStub::Flags>( |
| 2837 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 2838 | flags = static_cast<InstanceofStub::Flags>( |
| 2839 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 2840 | InstanceofStub stub(flags); |
| 2841 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2842 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2843 | |
| 2844 | // Get the temp register reserved by the instruction. This needs to be r4 as |
| 2845 | // its slot of the pushing of safepoint registers is used to communicate the |
| 2846 | // offset to the location of the map check. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2847 | Register temp = ToRegister(instr->temp()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2848 | ASSERT(temp.is(r4)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2849 | __ LoadHeapObject(InstanceofStub::right(), instr->function()); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2850 | static const int kAdditionalDelta = 5; |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2851 | // Make sure that code size is predicable, since we use specific constants |
| 2852 | // offsets in the code to find embedded values.. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2853 | PredictableCodeSizeScope predictable(masm_, 6 * Assembler::kInstrSize); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2854 | int delta = masm_->InstructionsGeneratedSince(map_check) + kAdditionalDelta; |
| 2855 | Label before_push_delta; |
| 2856 | __ bind(&before_push_delta); |
| 2857 | __ BlockConstPoolFor(kAdditionalDelta); |
| 2858 | __ mov(temp, Operand(delta * kPointerSize)); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 2859 | // The mov above can generate one or two instructions. The delta was computed |
| 2860 | // for two instructions, so we need to pad here in case of one instruction. |
| 2861 | if (masm_->InstructionsGeneratedSince(&before_push_delta) != 2) { |
| 2862 | ASSERT_EQ(1, masm_->InstructionsGeneratedSince(&before_push_delta)); |
| 2863 | __ nop(); |
| 2864 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2865 | __ StoreToSafepointRegisterSlot(temp, temp); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2866 | CallCodeGeneric(stub.GetCode(isolate()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2867 | RelocInfo::CODE_TARGET, |
| 2868 | instr, |
| 2869 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2870 | LEnvironment* env = instr->GetDeferredLazyDeoptimizationEnvironment(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2871 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2872 | // Put the result value into the result register slot and |
| 2873 | // restore all registers. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2874 | __ StoreToSafepointRegisterSlot(result, result); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2877 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2878 | void LCodeGen::DoInstanceSize(LInstanceSize* instr) { |
| 2879 | Register object = ToRegister(instr->object()); |
| 2880 | Register result = ToRegister(instr->result()); |
| 2881 | __ ldr(result, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2882 | __ ldrb(result, FieldMemOperand(result, Map::kInstanceSizeOffset)); |
| 2883 | } |
| 2884 | |
| 2885 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2886 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 2887 | Token::Value op = instr->op(); |
| 2888 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2889 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2890 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2891 | // This instruction also signals no smi code inlined. |
| 2892 | __ cmp(r0, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2893 | |
| 2894 | Condition condition = ComputeCompareCondition(op); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2895 | __ LoadRoot(ToRegister(instr->result()), |
| 2896 | Heap::kTrueValueRootIndex, |
| 2897 | condition); |
| 2898 | __ LoadRoot(ToRegister(instr->result()), |
| 2899 | Heap::kFalseValueRootIndex, |
| 2900 | NegateCondition(condition)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2904 | void LCodeGen::DoReturn(LReturn* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2905 | if (FLAG_trace && info()->IsOptimizing()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2906 | // Push the return value on the stack as the parameter. |
| 2907 | // Runtime::TraceExit returns its parameter in r0. |
| 2908 | __ push(r0); |
| 2909 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 2910 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2911 | if (info()->saves_caller_doubles()) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2912 | ASSERT(NeedsEagerFrame()); |
| 2913 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 2914 | BitVector::Iterator save_iterator(doubles); |
| 2915 | int count = 0; |
| 2916 | while (!save_iterator.Done()) { |
| 2917 | __ vldr(DwVfpRegister::FromAllocationIndex(save_iterator.Current()), |
| 2918 | MemOperand(sp, count * kDoubleSize)); |
| 2919 | save_iterator.Advance(); |
| 2920 | count++; |
| 2921 | } |
| 2922 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2923 | if (NeedsEagerFrame()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2924 | __ mov(sp, fp); |
| 2925 | __ ldm(ia_w, sp, fp.bit() | lr.bit()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2926 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2927 | if (instr->has_constant_parameter_count()) { |
| 2928 | int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 2929 | int32_t sp_delta = (parameter_count + 1) * kPointerSize; |
| 2930 | if (sp_delta != 0) { |
| 2931 | __ add(sp, sp, Operand(sp_delta)); |
| 2932 | } |
| 2933 | } else { |
| 2934 | Register reg = ToRegister(instr->parameter_count()); |
| 2935 | // The argument count parameter is a smi |
| 2936 | __ SmiUntag(reg); |
| 2937 | __ add(sp, sp, Operand(reg, LSL, kPointerSizeLog2)); |
| 2938 | } |
| 2939 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2940 | __ Jump(lr); |
| 2941 | } |
| 2942 | |
| 2943 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2944 | void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2945 | Register result = ToRegister(instr->result()); |
| 2946 | __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell()))); |
| 2947 | __ ldr(result, FieldMemOperand(ip, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2948 | if (instr->hydrogen()->RequiresHoleCheck()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2949 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2950 | __ cmp(result, ip); |
| 2951 | DeoptimizeIf(eq, instr->environment()); |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2956 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
| 2957 | ASSERT(ToRegister(instr->global_object()).is(r0)); |
| 2958 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2959 | |
| 2960 | __ mov(r2, Operand(instr->name())); |
| 2961 | RelocInfo::Mode mode = instr->for_typeof() ? RelocInfo::CODE_TARGET |
| 2962 | : RelocInfo::CODE_TARGET_CONTEXT; |
| 2963 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2964 | CallCode(ic, mode, instr); |
| 2965 | } |
| 2966 | |
| 2967 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2968 | void LCodeGen::DoStoreGlobalCell(LStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2969 | Register value = ToRegister(instr->value()); |
| 2970 | Register cell = scratch0(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2971 | |
| 2972 | // Load the cell. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2973 | __ mov(cell, Operand(instr->hydrogen()->cell())); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2974 | |
| 2975 | // If the cell we are storing to contains the hole it could have |
| 2976 | // been deleted from the property dictionary. In that case, we need |
| 2977 | // to update the property details in the property dictionary to mark |
| 2978 | // it as no longer deleted. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2979 | if (instr->hydrogen()->RequiresHoleCheck()) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2980 | // We use a temp to check the payload (CompareRoot might clobber ip). |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2981 | Register payload = ToRegister(instr->temp()); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2982 | __ ldr(payload, FieldMemOperand(cell, JSGlobalPropertyCell::kValueOffset)); |
| 2983 | __ CompareRoot(payload, Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2984 | DeoptimizeIf(eq, instr->environment()); |
| 2985 | } |
| 2986 | |
| 2987 | // Store the value. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2988 | __ str(value, FieldMemOperand(cell, JSGlobalPropertyCell::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2989 | // Cells are always rescanned, so no write barrier here. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2993 | void LCodeGen::DoStoreGlobalGeneric(LStoreGlobalGeneric* instr) { |
| 2994 | ASSERT(ToRegister(instr->global_object()).is(r1)); |
| 2995 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 2996 | |
| 2997 | __ mov(r2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2998 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2999 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 3000 | : isolate()->builtins()->StoreIC_Initialize(); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3001 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
| 3002 | } |
| 3003 | |
| 3004 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3005 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3006 | Register context = ToRegister(instr->context()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3007 | Register result = ToRegister(instr->result()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3008 | __ ldr(result, ContextOperand(context, instr->slot_index())); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3009 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3010 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3011 | __ cmp(result, ip); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3012 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3013 | DeoptimizeIf(eq, instr->environment()); |
| 3014 | } else { |
| 3015 | __ mov(result, Operand(factory()->undefined_value()), LeaveCC, eq); |
| 3016 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3017 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3021 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 3022 | Register context = ToRegister(instr->context()); |
| 3023 | Register value = ToRegister(instr->value()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3024 | Register scratch = scratch0(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3025 | MemOperand target = ContextOperand(context, instr->slot_index()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3026 | |
| 3027 | Label skip_assignment; |
| 3028 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3029 | if (instr->hydrogen()->RequiresHoleCheck()) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3030 | __ ldr(scratch, target); |
| 3031 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3032 | __ cmp(scratch, ip); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3033 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 3034 | DeoptimizeIf(eq, instr->environment()); |
| 3035 | } else { |
| 3036 | __ b(ne, &skip_assignment); |
| 3037 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3038 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3039 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3040 | __ str(value, target); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3041 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 3042 | HType type = instr->hydrogen()->value()->type(); |
| 3043 | SmiCheck check_needed = |
| 3044 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3045 | __ RecordWriteContextSlot(context, |
| 3046 | target.offset(), |
| 3047 | value, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3048 | scratch, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 3049 | GetLinkRegisterState(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3050 | kSaveFPRegs, |
| 3051 | EMIT_REMEMBERED_SET, |
| 3052 | check_needed); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3053 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3054 | |
| 3055 | __ bind(&skip_assignment); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3059 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3060 | int offset = instr->hydrogen()->offset(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3061 | Register object = ToRegister(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3062 | if (instr->hydrogen()->representation().IsDouble()) { |
| 3063 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3064 | __ vldr(result, FieldMemOperand(object, offset)); |
| 3065 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3068 | Register result = ToRegister(instr->result()); |
| 3069 | if (instr->hydrogen()->is_in_object()) { |
| 3070 | __ ldr(result, FieldMemOperand(object, offset)); |
| 3071 | } else { |
| 3072 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 3073 | __ ldr(result, FieldMemOperand(result, offset)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3074 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3078 | void LCodeGen::EmitLoadFieldOrConstantFunction(Register result, |
| 3079 | Register object, |
| 3080 | Handle<Map> type, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3081 | Handle<String> name, |
| 3082 | LEnvironment* env) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3083 | LookupResult lookup(isolate()); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3084 | type->LookupDescriptor(NULL, *name, &lookup); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3085 | ASSERT(lookup.IsFound() || lookup.IsCacheable()); |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 3086 | if (lookup.IsField()) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3087 | int index = lookup.GetLocalFieldIndexFromMap(*type); |
| 3088 | int offset = index * kPointerSize; |
| 3089 | if (index < 0) { |
| 3090 | // Negative property indices are in-object properties, indexed |
| 3091 | // from the end of the fixed part of the object. |
| 3092 | __ ldr(result, FieldMemOperand(object, offset + type->instance_size())); |
| 3093 | } else { |
| 3094 | // Non-negative property indices are in the properties array. |
| 3095 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 3096 | __ ldr(result, FieldMemOperand(result, offset + FixedArray::kHeaderSize)); |
| 3097 | } |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 3098 | } else if (lookup.IsConstantFunction()) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3099 | Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*type)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3100 | __ LoadHeapObject(result, function); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3101 | } else { |
| 3102 | // Negative lookup. |
| 3103 | // Check prototypes. |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 3104 | Handle<HeapObject> current(HeapObject::cast((*type)->prototype())); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3105 | Heap* heap = type->GetHeap(); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 3106 | while (*current != heap->null_value()) { |
| 3107 | __ LoadHeapObject(result, current); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3108 | __ ldr(result, FieldMemOperand(result, HeapObject::kMapOffset)); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 3109 | __ cmp(result, Operand(Handle<Map>(current->map()))); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3110 | DeoptimizeIf(ne, env); |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 3111 | current = |
| 3112 | Handle<HeapObject>(HeapObject::cast(current->map()->prototype())); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3113 | } |
| 3114 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | |
| 3119 | void LCodeGen::DoLoadNamedFieldPolymorphic(LLoadNamedFieldPolymorphic* instr) { |
| 3120 | Register object = ToRegister(instr->object()); |
| 3121 | Register result = ToRegister(instr->result()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3122 | Register object_map = scratch0(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3123 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3124 | int map_count = instr->hydrogen()->types()->length(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3125 | bool need_generic = instr->hydrogen()->need_generic(); |
| 3126 | |
| 3127 | if (map_count == 0 && !need_generic) { |
| 3128 | DeoptimizeIf(al, instr->environment()); |
| 3129 | return; |
| 3130 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3131 | Handle<String> name = instr->hydrogen()->name(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3132 | Label done; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3133 | __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3134 | for (int i = 0; i < map_count; ++i) { |
| 3135 | bool last = (i == map_count - 1); |
| 3136 | Handle<Map> map = instr->hydrogen()->types()->at(i); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3137 | Label check_passed; |
| 3138 | __ CompareMap( |
| 3139 | object_map, map, &check_passed, ALLOW_ELEMENT_TRANSITION_MAPS); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3140 | if (last && !need_generic) { |
| 3141 | DeoptimizeIf(ne, instr->environment()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3142 | __ bind(&check_passed); |
| 3143 | EmitLoadFieldOrConstantFunction( |
| 3144 | result, object, map, name, instr->environment()); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3145 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3146 | Label next; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3147 | __ b(ne, &next); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3148 | __ bind(&check_passed); |
| 3149 | EmitLoadFieldOrConstantFunction( |
| 3150 | result, object, map, name, instr->environment()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3151 | __ b(&done); |
| 3152 | __ bind(&next); |
| 3153 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3154 | } |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3155 | if (need_generic) { |
| 3156 | __ mov(r2, Operand(name)); |
| 3157 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3158 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3159 | } |
| 3160 | __ bind(&done); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3164 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
| 3165 | ASSERT(ToRegister(instr->object()).is(r0)); |
| 3166 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 3167 | |
| 3168 | // Name is always in r2. |
| 3169 | __ mov(r2, Operand(instr->name())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3170 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3171 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3175 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3176 | Register scratch = scratch0(); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3177 | Register function = ToRegister(instr->function()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3178 | Register result = ToRegister(instr->result()); |
| 3179 | |
| 3180 | // Check that the function really is a function. Load map into the |
| 3181 | // result register. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3182 | __ CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3183 | DeoptimizeIf(ne, instr->environment()); |
| 3184 | |
| 3185 | // Make sure that the function has an instance prototype. |
| 3186 | Label non_instance; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3187 | __ ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 3188 | __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3189 | __ b(ne, &non_instance); |
| 3190 | |
| 3191 | // Get the prototype or initial map from the function. |
| 3192 | __ ldr(result, |
| 3193 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 3194 | |
| 3195 | // Check that the function has a prototype or an initial map. |
| 3196 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3197 | __ cmp(result, ip); |
| 3198 | DeoptimizeIf(eq, instr->environment()); |
| 3199 | |
| 3200 | // If the function does not have an initial map, we're done. |
| 3201 | Label done; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3202 | __ CompareObjectType(result, scratch, scratch, MAP_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 3203 | __ b(ne, &done); |
| 3204 | |
| 3205 | // Get the prototype from the initial map. |
| 3206 | __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 3207 | __ jmp(&done); |
| 3208 | |
| 3209 | // Non-instance prototype: Fetch prototype from constructor field |
| 3210 | // in initial map. |
| 3211 | __ bind(&non_instance); |
| 3212 | __ ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 3213 | |
| 3214 | // All done. |
| 3215 | __ bind(&done); |
| 3216 | } |
| 3217 | |
| 3218 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3219 | void LCodeGen::DoLoadExternalArrayPointer( |
| 3220 | LLoadExternalArrayPointer* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3221 | Register to_reg = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3222 | Register from_reg = ToRegister(instr->object()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3223 | __ ldr(to_reg, FieldMemOperand(from_reg, |
| 3224 | ExternalArray::kExternalPointerOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3228 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3229 | Register arguments = ToRegister(instr->arguments()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3230 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3231 | if (instr->length()->IsConstantOperand() && |
| 3232 | instr->index()->IsConstantOperand()) { |
| 3233 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3234 | int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 3235 | int index = (const_length - const_index) + 1; |
| 3236 | __ ldr(result, MemOperand(arguments, index * kPointerSize)); |
| 3237 | } else { |
| 3238 | Register length = ToRegister(instr->length()); |
| 3239 | Register index = ToRegister(instr->index()); |
| 3240 | // There are two words between the frame pointer and the last argument. |
| 3241 | // Subtracting from length accounts for one of them add one more. |
| 3242 | __ sub(length, length, index); |
| 3243 | __ add(length, length, Operand(1)); |
| 3244 | __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2)); |
| 3245 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3249 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
| 3250 | Register external_pointer = ToRegister(instr->elements()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3251 | Register key = no_reg; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3252 | ElementsKind elements_kind = instr->elements_kind(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3253 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3254 | int constant_key = 0; |
| 3255 | if (key_is_constant) { |
| 3256 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3257 | if (constant_key & 0xF0000000) { |
| 3258 | Abort("array index constant value too big."); |
| 3259 | } |
| 3260 | } else { |
| 3261 | key = ToRegister(instr->key()); |
| 3262 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3263 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 3264 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 3265 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 3266 | int additional_offset = instr->additional_index() << element_size_shift; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3267 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3268 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 3269 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3270 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3271 | Operand operand = key_is_constant |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3272 | ? Operand(constant_key << element_size_shift) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3273 | : Operand(key, LSL, shift_size); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3274 | __ add(scratch0(), external_pointer, operand); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3275 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
| 3276 | __ vldr(kScratchDoubleReg.low(), scratch0(), additional_offset); |
| 3277 | __ vcvt_f64_f32(result, kScratchDoubleReg.low()); |
| 3278 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
| 3279 | __ vldr(result, scratch0(), additional_offset); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3280 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3281 | } else { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3282 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3283 | MemOperand mem_operand = PrepareKeyedOperand( |
| 3284 | key, external_pointer, key_is_constant, constant_key, |
| 3285 | element_size_shift, shift_size, |
| 3286 | instr->additional_index(), additional_offset); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3287 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3288 | case EXTERNAL_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3289 | __ ldrsb(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3290 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3291 | case EXTERNAL_PIXEL_ELEMENTS: |
| 3292 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3293 | __ ldrb(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3294 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3295 | case EXTERNAL_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3296 | __ ldrsh(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3297 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3298 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3299 | __ ldrh(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3300 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3301 | case EXTERNAL_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3302 | __ ldr(result, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3303 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3304 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3305 | __ ldr(result, mem_operand); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3306 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 3307 | __ cmp(result, Operand(0x80000000)); |
| 3308 | DeoptimizeIf(cs, instr->environment()); |
| 3309 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3310 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3311 | case EXTERNAL_FLOAT_ELEMENTS: |
| 3312 | case EXTERNAL_DOUBLE_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3313 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 3314 | case FAST_HOLEY_ELEMENTS: |
| 3315 | case FAST_HOLEY_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3316 | case FAST_DOUBLE_ELEMENTS: |
| 3317 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3318 | case FAST_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3319 | case DICTIONARY_ELEMENTS: |
| 3320 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3321 | UNREACHABLE(); |
| 3322 | break; |
| 3323 | } |
| 3324 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3328 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
| 3329 | Register elements = ToRegister(instr->elements()); |
| 3330 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 3331 | Register key = no_reg; |
| 3332 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3333 | Register scratch = scratch0(); |
| 3334 | |
| 3335 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 3336 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 3337 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 3338 | int constant_key = 0; |
| 3339 | if (key_is_constant) { |
| 3340 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 3341 | if (constant_key & 0xF0000000) { |
| 3342 | Abort("array index constant value too big."); |
| 3343 | } |
| 3344 | } else { |
| 3345 | key = ToRegister(instr->key()); |
| 3346 | } |
| 3347 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3348 | int base_offset = (FixedDoubleArray::kHeaderSize - kHeapObjectTag) + |
| 3349 | ((constant_key + instr->additional_index()) << element_size_shift); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3350 | if (!key_is_constant) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3351 | __ add(elements, elements, Operand(key, LSL, shift_size)); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3352 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3353 | __ add(elements, elements, Operand(base_offset)); |
| 3354 | __ vldr(result, elements, 0); |
| 3355 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3356 | __ ldr(scratch, MemOperand(elements, sizeof(kHoleNanLower32))); |
| 3357 | __ cmp(scratch, Operand(kHoleNanUpper32)); |
| 3358 | DeoptimizeIf(eq, instr->environment()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3359 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | |
| 3363 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3364 | Register elements = ToRegister(instr->elements()); |
| 3365 | Register result = ToRegister(instr->result()); |
| 3366 | Register scratch = scratch0(); |
| 3367 | Register store_base = scratch; |
| 3368 | int offset = 0; |
| 3369 | |
| 3370 | if (instr->key()->IsConstantOperand()) { |
| 3371 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 3372 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 3373 | instr->additional_index()); |
| 3374 | store_base = elements; |
| 3375 | } else { |
| 3376 | Register key = EmitLoadRegister(instr->key(), scratch0()); |
| 3377 | // Even though the HLoadKeyed instruction forces the input |
| 3378 | // representation for the key to be an integer, the input gets replaced |
| 3379 | // during bound check elimination with the index argument to the bounds |
| 3380 | // check, which can be tagged, so that case must be handled here, too. |
| 3381 | if (instr->hydrogen()->key()->representation().IsTagged()) { |
| 3382 | __ add(scratch, elements, |
| 3383 | Operand(key, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 3384 | } else { |
| 3385 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 3386 | } |
| 3387 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 3388 | } |
| 3389 | __ ldr(result, FieldMemOperand(store_base, offset)); |
| 3390 | |
| 3391 | // Check for the hole value. |
| 3392 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3393 | if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) { |
| 3394 | __ tst(result, Operand(kSmiTagMask)); |
| 3395 | DeoptimizeIf(ne, instr->environment()); |
| 3396 | } else { |
| 3397 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 3398 | __ cmp(result, scratch); |
| 3399 | DeoptimizeIf(eq, instr->environment()); |
| 3400 | } |
| 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | |
| 3405 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
| 3406 | if (instr->is_external()) { |
| 3407 | DoLoadKeyedExternalArray(instr); |
| 3408 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3409 | DoLoadKeyedFixedDoubleArray(instr); |
| 3410 | } else { |
| 3411 | DoLoadKeyedFixedArray(instr); |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | |
| 3416 | MemOperand LCodeGen::PrepareKeyedOperand(Register key, |
| 3417 | Register base, |
| 3418 | bool key_is_constant, |
| 3419 | int constant_key, |
| 3420 | int element_size, |
| 3421 | int shift_size, |
| 3422 | int additional_index, |
| 3423 | int additional_offset) { |
| 3424 | if (additional_index != 0 && !key_is_constant) { |
| 3425 | additional_index *= 1 << (element_size - shift_size); |
| 3426 | __ add(scratch0(), key, Operand(additional_index)); |
| 3427 | } |
| 3428 | |
| 3429 | if (key_is_constant) { |
| 3430 | return MemOperand(base, |
| 3431 | (constant_key << element_size) + additional_offset); |
| 3432 | } |
| 3433 | |
| 3434 | if (additional_index == 0) { |
| 3435 | if (shift_size >= 0) { |
| 3436 | return MemOperand(base, key, LSL, shift_size); |
| 3437 | } else { |
| 3438 | ASSERT_EQ(-1, shift_size); |
| 3439 | return MemOperand(base, key, LSR, 1); |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | if (shift_size >= 0) { |
| 3444 | return MemOperand(base, scratch0(), LSL, shift_size); |
| 3445 | } else { |
| 3446 | ASSERT_EQ(-1, shift_size); |
| 3447 | return MemOperand(base, scratch0(), LSR, 1); |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3452 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
| 3453 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 3454 | ASSERT(ToRegister(instr->key()).is(r0)); |
| 3455 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3456 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3457 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | |
| 3461 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3462 | Register scratch = scratch0(); |
| 3463 | Register result = ToRegister(instr->result()); |
| 3464 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3465 | if (instr->hydrogen()->from_inlined()) { |
| 3466 | __ sub(result, sp, Operand(2 * kPointerSize)); |
| 3467 | } else { |
| 3468 | // Check if the calling frame is an arguments adaptor frame. |
| 3469 | Label done, adapted; |
| 3470 | __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3471 | __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 3472 | __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3473 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3474 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3475 | // frame below the adaptor frame if adapted. |
| 3476 | __ mov(result, fp, LeaveCC, ne); |
| 3477 | __ mov(result, scratch, LeaveCC, eq); |
| 3478 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | |
| 3482 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3483 | Register elem = ToRegister(instr->elements()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3484 | Register result = ToRegister(instr->result()); |
| 3485 | |
| 3486 | Label done; |
| 3487 | |
| 3488 | // If no arguments adaptor frame the number of arguments is fixed. |
| 3489 | __ cmp(fp, elem); |
| 3490 | __ mov(result, Operand(scope()->num_parameters())); |
| 3491 | __ b(eq, &done); |
| 3492 | |
| 3493 | // Arguments adaptor frame present. Get argument length from there. |
| 3494 | __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3495 | __ ldr(result, |
| 3496 | MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3497 | __ SmiUntag(result); |
| 3498 | |
| 3499 | // Argument length is in result register. |
| 3500 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3504 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3505 | Register receiver = ToRegister(instr->receiver()); |
| 3506 | Register function = ToRegister(instr->function()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3507 | Register scratch = scratch0(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3508 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3509 | // If the receiver is null or undefined, we have to pass the global |
| 3510 | // object as a receiver to normal functions. Values have to be |
| 3511 | // passed unchanged to builtins and strict-mode functions. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3512 | Label global_object, receiver_ok; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3513 | |
| 3514 | // Do not transform the receiver to object for strict mode |
| 3515 | // functions. |
| 3516 | __ ldr(scratch, |
| 3517 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3518 | __ ldr(scratch, |
| 3519 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 3520 | __ tst(scratch, |
| 3521 | Operand(1 << (SharedFunctionInfo::kStrictModeFunction + kSmiTagSize))); |
| 3522 | __ b(ne, &receiver_ok); |
| 3523 | |
| 3524 | // Do not transform the receiver to object for builtins. |
| 3525 | __ tst(scratch, Operand(1 << (SharedFunctionInfo::kNative + kSmiTagSize))); |
| 3526 | __ b(ne, &receiver_ok); |
| 3527 | |
| 3528 | // Normal function. Replace undefined or null with global receiver. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3529 | __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
| 3530 | __ cmp(receiver, scratch); |
| 3531 | __ b(eq, &global_object); |
| 3532 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 3533 | __ cmp(receiver, scratch); |
| 3534 | __ b(eq, &global_object); |
| 3535 | |
| 3536 | // Deoptimize if the receiver is not a JS object. |
| 3537 | __ tst(receiver, Operand(kSmiTagMask)); |
| 3538 | DeoptimizeIf(eq, instr->environment()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3539 | __ CompareObjectType(receiver, scratch, scratch, FIRST_SPEC_OBJECT_TYPE); |
| 3540 | DeoptimizeIf(lt, instr->environment()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3541 | __ jmp(&receiver_ok); |
| 3542 | |
| 3543 | __ bind(&global_object); |
| 3544 | __ ldr(receiver, GlobalObjectOperand()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3545 | __ ldr(receiver, |
| 3546 | FieldMemOperand(receiver, JSGlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3547 | __ bind(&receiver_ok); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | |
| 3551 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3552 | Register receiver = ToRegister(instr->receiver()); |
| 3553 | Register function = ToRegister(instr->function()); |
| 3554 | Register length = ToRegister(instr->length()); |
| 3555 | Register elements = ToRegister(instr->elements()); |
| 3556 | Register scratch = scratch0(); |
| 3557 | ASSERT(receiver.is(r0)); // Used for parameter count. |
| 3558 | ASSERT(function.is(r1)); // Required by InvokeFunction. |
| 3559 | ASSERT(ToRegister(instr->result()).is(r0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3560 | |
| 3561 | // Copy the arguments to this function possibly from the |
| 3562 | // adaptor frame below it. |
| 3563 | const uint32_t kArgumentsLimit = 1 * KB; |
| 3564 | __ cmp(length, Operand(kArgumentsLimit)); |
| 3565 | DeoptimizeIf(hi, instr->environment()); |
| 3566 | |
| 3567 | // Push the receiver and use the register to keep the original |
| 3568 | // number of arguments. |
| 3569 | __ push(receiver); |
| 3570 | __ mov(receiver, length); |
| 3571 | // The arguments are at a one pointer size offset from elements. |
| 3572 | __ add(elements, elements, Operand(1 * kPointerSize)); |
| 3573 | |
| 3574 | // Loop through the arguments pushing them onto the execution |
| 3575 | // stack. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3576 | Label invoke, loop; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3577 | // length is a small non-negative integer, due to the test above. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3578 | __ cmp(length, Operand::Zero()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3579 | __ b(eq, &invoke); |
| 3580 | __ bind(&loop); |
| 3581 | __ ldr(scratch, MemOperand(elements, length, LSL, 2)); |
| 3582 | __ push(scratch); |
| 3583 | __ sub(length, length, Operand(1), SetCC); |
| 3584 | __ b(ne, &loop); |
| 3585 | |
| 3586 | __ bind(&invoke); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3587 | ASSERT(instr->HasPointerMap()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3588 | LPointerMap* pointers = instr->pointer_map(); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3589 | RecordPosition(pointers->position()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3590 | SafepointGenerator safepoint_generator( |
| 3591 | this, pointers, Safepoint::kLazyDeopt); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3592 | // The number of arguments is stored in receiver which is r0, as expected |
| 3593 | // by InvokeFunction. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3594 | ParameterCount actual(receiver); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3595 | __ InvokeFunction(function, actual, CALL_FUNCTION, |
| 3596 | safepoint_generator, CALL_AS_METHOD); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3597 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | |
| 3601 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3602 | LOperand* argument = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3603 | if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
| 3604 | Abort("DoPushArgument not implemented for double type."); |
| 3605 | } else { |
| 3606 | Register argument_reg = EmitLoadRegister(argument, ip); |
| 3607 | __ push(argument_reg); |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3612 | void LCodeGen::DoDrop(LDrop* instr) { |
| 3613 | __ Drop(instr->count()); |
| 3614 | } |
| 3615 | |
| 3616 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3617 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3618 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3619 | __ ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3623 | void LCodeGen::DoContext(LContext* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3624 | // If there is a non-return use, the context must be moved to a register. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3625 | Register result = ToRegister(instr->result()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3626 | for (HUseIterator it(instr->hydrogen()->uses()); !it.Done(); it.Advance()) { |
| 3627 | if (!it.value()->IsReturn()) { |
| 3628 | __ mov(result, cp); |
| 3629 | return; |
| 3630 | } |
| 3631 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | |
| 3635 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 3636 | Register context = ToRegister(instr->context()); |
| 3637 | Register result = ToRegister(instr->result()); |
| 3638 | __ ldr(result, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3639 | MemOperand(context, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3643 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
| 3644 | __ push(cp); // The context is the first argument. |
| 3645 | __ LoadHeapObject(scratch0(), instr->hydrogen()->pairs()); |
| 3646 | __ push(scratch0()); |
| 3647 | __ mov(scratch0(), Operand(Smi::FromInt(instr->hydrogen()->flags()))); |
| 3648 | __ push(scratch0()); |
| 3649 | CallRuntime(Runtime::kDeclareGlobals, 3, instr); |
| 3650 | } |
| 3651 | |
| 3652 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3653 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
| 3654 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3655 | __ ldr(result, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | |
| 3659 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3660 | Register global = ToRegister(instr->global_object()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3661 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3662 | __ ldr(result, FieldMemOperand(global, GlobalObject::kGlobalReceiverOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | |
| 3666 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3667 | int formal_parameter_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3668 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3669 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3670 | CallKind call_kind, |
| 3671 | R1State r1_state) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3672 | bool dont_adapt_arguments = |
| 3673 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3674 | bool can_invoke_directly = |
| 3675 | dont_adapt_arguments || formal_parameter_count == arity; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3676 | |
| 3677 | LPointerMap* pointers = instr->pointer_map(); |
| 3678 | RecordPosition(pointers->position()); |
| 3679 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3680 | if (can_invoke_directly) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3681 | if (r1_state == R1_UNINITIALIZED) { |
| 3682 | __ LoadHeapObject(r1, function); |
| 3683 | } |
| 3684 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3685 | // Change context. |
| 3686 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3687 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3688 | // Set r0 to arguments count if adaption is not needed. Assumes that r0 |
| 3689 | // is available to write to at this point. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3690 | if (dont_adapt_arguments) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3691 | __ mov(r0, Operand(arity)); |
| 3692 | } |
| 3693 | |
| 3694 | // Invoke function. |
| 3695 | __ SetCallKind(r5, call_kind); |
| 3696 | __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 3697 | __ Call(ip); |
| 3698 | |
| 3699 | // Set up deoptimization. |
| 3700 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3701 | } else { |
| 3702 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3703 | ParameterCount count(arity); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3704 | ParameterCount expected(formal_parameter_count); |
| 3705 | __ InvokeFunction( |
| 3706 | function, expected, count, CALL_FUNCTION, generator, call_kind); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3707 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3708 | |
| 3709 | // Restore context. |
| 3710 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3711 | } |
| 3712 | |
| 3713 | |
| 3714 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3715 | ASSERT(ToRegister(instr->result()).is(r0)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3716 | CallKnownFunction(instr->hydrogen()->function(), |
| 3717 | instr->hydrogen()->formal_parameter_count(), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3718 | instr->arity(), |
| 3719 | instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 3720 | CALL_AS_METHOD, |
| 3721 | R1_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3725 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3726 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3727 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3728 | Register scratch = scratch0(); |
| 3729 | |
| 3730 | // Deoptimize if not a heap number. |
| 3731 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3732 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3733 | __ cmp(scratch, Operand(ip)); |
| 3734 | DeoptimizeIf(ne, instr->environment()); |
| 3735 | |
| 3736 | Label done; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3737 | Register exponent = scratch0(); |
| 3738 | scratch = no_reg; |
| 3739 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3740 | // Check the sign of the argument. If the argument is positive, just |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3741 | // return it. |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3742 | __ tst(exponent, Operand(HeapNumber::kSignMask)); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3743 | // Move the input to the result if necessary. |
| 3744 | __ Move(result, input); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3745 | __ b(eq, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3746 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3747 | // Input is negative. Reverse its sign. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3748 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3749 | { |
| 3750 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3751 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3752 | // Registers were saved at the safepoint, so we can use |
| 3753 | // many scratch registers. |
| 3754 | Register tmp1 = input.is(r1) ? r0 : r1; |
| 3755 | Register tmp2 = input.is(r2) ? r0 : r2; |
| 3756 | Register tmp3 = input.is(r3) ? r0 : r3; |
| 3757 | Register tmp4 = input.is(r4) ? r0 : r4; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3758 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3759 | // exponent: floating point exponent value. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3760 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3761 | Label allocated, slow; |
| 3762 | __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 3763 | __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
| 3764 | __ b(&allocated); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3765 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3766 | // Slow case: Call the runtime system to do the number allocation. |
| 3767 | __ bind(&slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3768 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3769 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
| 3770 | // Set the pointer to the new heap number in tmp. |
| 3771 | if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0)); |
| 3772 | // Restore input_reg after call to runtime. |
| 3773 | __ LoadFromSafepointRegisterSlot(input, input); |
| 3774 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3775 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3776 | __ bind(&allocated); |
| 3777 | // exponent: floating point exponent value. |
| 3778 | // tmp1: allocated heap number. |
| 3779 | __ bic(exponent, exponent, Operand(HeapNumber::kSignMask)); |
| 3780 | __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
| 3781 | __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3782 | __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3783 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3784 | __ StoreToSafepointRegisterSlot(tmp1, result); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3785 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3786 | |
| 3787 | __ bind(&done); |
| 3788 | } |
| 3789 | |
| 3790 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3791 | void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3792 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3793 | Register result = ToRegister(instr->result()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3794 | __ cmp(input, Operand::Zero()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3795 | __ Move(result, input, pl); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3796 | // We can make rsb conditional because the previous cmp instruction |
| 3797 | // will clear the V (overflow) flag and rsb won't set this flag |
| 3798 | // if input is positive. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3799 | __ rsb(result, input, Operand::Zero(), SetCC, mi); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3800 | // Deoptimize on overflow. |
| 3801 | DeoptimizeIf(vs, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3805 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3806 | // Class for deferred case. |
| 3807 | class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { |
| 3808 | public: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3809 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3810 | : LDeferredCode(codegen), instr_(instr) { } |
| 3811 | virtual void Generate() { |
| 3812 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3813 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3814 | virtual LInstruction* instr() { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3815 | private: |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3816 | LMathAbs* instr_; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3817 | }; |
| 3818 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3819 | Representation r = instr->hydrogen()->value()->representation(); |
| 3820 | if (r.IsDouble()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3821 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3822 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3823 | __ vabs(result, input); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3824 | } else if (r.IsInteger32()) { |
| 3825 | EmitIntegerMathAbs(instr); |
| 3826 | } else { |
| 3827 | // Representation is tagged. |
| 3828 | DeferredMathAbsTaggedHeapNumber* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3829 | new(zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3830 | Register input = ToRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3831 | // Smi check. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3832 | __ JumpIfNotSmi(input, deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3833 | // If smi, handle it directly. |
| 3834 | EmitIntegerMathAbs(instr); |
| 3835 | __ bind(deferred->exit()); |
| 3836 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
| 3839 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3840 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3841 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3842 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3843 | Register input_high = scratch0(); |
| 3844 | Label done, exact; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3845 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3846 | __ vmov(input_high, input.high()); |
| 3847 | __ TryInt32Floor(result, input, input_high, double_scratch0(), &done, &exact); |
| 3848 | DeoptimizeIf(al, instr->environment()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3849 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3850 | __ bind(&exact); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3851 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3852 | // Test for -0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3853 | __ cmp(result, Operand::Zero()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3854 | __ b(ne, &done); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3855 | __ cmp(input_high, Operand::Zero()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3856 | DeoptimizeIf(mi, instr->environment()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3857 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3858 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3862 | void LCodeGen::DoMathRound(LMathRound* instr) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3863 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3864 | Register result = ToRegister(instr->result()); |
| 3865 | DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp()); |
| 3866 | DwVfpRegister input_plus_dot_five = double_scratch1; |
| 3867 | Register input_high = scratch0(); |
| 3868 | DwVfpRegister dot_five = double_scratch0(); |
| 3869 | Label convert, done; |
| 3870 | |
| 3871 | __ Vmov(dot_five, 0.5, scratch0()); |
| 3872 | __ vabs(double_scratch1, input); |
| 3873 | __ VFPCompareAndSetFlags(double_scratch1, dot_five); |
| 3874 | // If input is in [-0.5, -0], the result is -0. |
| 3875 | // If input is in [+0, +0.5[, the result is +0. |
| 3876 | // If the input is +0.5, the result is 1. |
| 3877 | __ b(hi, &convert); // Out of [-0.5, +0.5]. |
| 3878 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3879 | __ vmov(input_high, input.high()); |
| 3880 | __ cmp(input_high, Operand::Zero()); |
| 3881 | DeoptimizeIf(mi, instr->environment()); // [-0.5, -0]. |
| 3882 | } |
| 3883 | __ VFPCompareAndSetFlags(input, dot_five); |
| 3884 | __ mov(result, Operand(1), LeaveCC, eq); // +0.5. |
| 3885 | // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on |
| 3886 | // flag kBailoutOnMinusZero. |
| 3887 | __ mov(result, Operand::Zero(), LeaveCC, ne); |
| 3888 | __ b(&done); |
| 3889 | |
| 3890 | __ bind(&convert); |
| 3891 | __ vadd(input_plus_dot_five, input, dot_five); |
| 3892 | __ vmov(input_high, input_plus_dot_five.high()); |
| 3893 | // Reuse dot_five (double_scratch0) as we no longer need this value. |
| 3894 | __ TryInt32Floor(result, input_plus_dot_five, input_high, double_scratch0(), |
| 3895 | &done, &done); |
| 3896 | DeoptimizeIf(al, instr->environment()); |
| 3897 | __ bind(&done); |
| 3898 | } |
| 3899 | |
| 3900 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3901 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3902 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3903 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3904 | __ vsqrt(result, input); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3908 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3909 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 3910 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 3911 | DwVfpRegister temp = ToDoubleRegister(instr->temp()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3912 | |
| 3913 | // Note that according to ECMA-262 15.8.2.13: |
| 3914 | // Math.pow(-Infinity, 0.5) == Infinity |
| 3915 | // Math.sqrt(-Infinity) == NaN |
| 3916 | Label done; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3917 | __ vmov(temp, -V8_INFINITY, scratch0()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3918 | __ VFPCompareAndSetFlags(input, temp); |
| 3919 | __ vneg(result, temp, eq); |
| 3920 | __ b(&done, eq); |
| 3921 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3922 | // Add +0 to convert -0 to +0. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3923 | __ vadd(result, input, kDoubleRegZero); |
| 3924 | __ vsqrt(result, result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3925 | __ bind(&done); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3929 | void LCodeGen::DoPower(LPower* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3930 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3931 | // Having marked this as a call, we can use any registers. |
| 3932 | // Just make sure that the input/output registers are the expected ones. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3933 | ASSERT(!instr->right()->IsDoubleRegister() || |
| 3934 | ToDoubleRegister(instr->right()).is(d2)); |
| 3935 | ASSERT(!instr->right()->IsRegister() || |
| 3936 | ToRegister(instr->right()).is(r2)); |
| 3937 | ASSERT(ToDoubleRegister(instr->left()).is(d1)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3938 | ASSERT(ToDoubleRegister(instr->result()).is(d3)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3939 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3940 | if (exponent_type.IsTagged()) { |
| 3941 | Label no_deopt; |
| 3942 | __ JumpIfSmi(r2, &no_deopt); |
| 3943 | __ ldr(r7, FieldMemOperand(r2, HeapObject::kMapOffset)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3944 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3945 | __ cmp(r7, Operand(ip)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3946 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3947 | __ bind(&no_deopt); |
| 3948 | MathPowStub stub(MathPowStub::TAGGED); |
| 3949 | __ CallStub(&stub); |
| 3950 | } else if (exponent_type.IsInteger32()) { |
| 3951 | MathPowStub stub(MathPowStub::INTEGER); |
| 3952 | __ CallStub(&stub); |
| 3953 | } else { |
| 3954 | ASSERT(exponent_type.IsDouble()); |
| 3955 | MathPowStub stub(MathPowStub::DOUBLE); |
| 3956 | __ CallStub(&stub); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3957 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3961 | void LCodeGen::DoRandom(LRandom* instr) { |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3962 | class DeferredDoRandom: public LDeferredCode { |
| 3963 | public: |
| 3964 | DeferredDoRandom(LCodeGen* codegen, LRandom* instr) |
| 3965 | : LDeferredCode(codegen), instr_(instr) { } |
| 3966 | virtual void Generate() { codegen()->DoDeferredRandom(instr_); } |
| 3967 | virtual LInstruction* instr() { return instr_; } |
| 3968 | private: |
| 3969 | LRandom* instr_; |
| 3970 | }; |
| 3971 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3972 | DeferredDoRandom* deferred = new(zone()) DeferredDoRandom(this, instr); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3973 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3974 | // Having marked this instruction as a call we can use any |
| 3975 | // registers. |
| 3976 | ASSERT(ToDoubleRegister(instr->result()).is(d7)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3977 | ASSERT(ToRegister(instr->global_object()).is(r0)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3978 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3979 | static const int kSeedSize = sizeof(uint32_t); |
| 3980 | STATIC_ASSERT(kPointerSize == kSeedSize); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3981 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3982 | __ ldr(r0, FieldMemOperand(r0, GlobalObject::kNativeContextOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3983 | static const int kRandomSeedOffset = |
| 3984 | FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3985 | __ ldr(r2, FieldMemOperand(r0, kRandomSeedOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3986 | // r2: FixedArray of the native context's random seeds |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3987 | |
| 3988 | // Load state[0]. |
| 3989 | __ ldr(r1, FieldMemOperand(r2, ByteArray::kHeaderSize)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3990 | __ cmp(r1, Operand::Zero()); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3991 | __ b(eq, deferred->entry()); |
| 3992 | // Load state[1]. |
| 3993 | __ ldr(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize)); |
| 3994 | // r1: state[0]. |
| 3995 | // r0: state[1]. |
| 3996 | |
| 3997 | // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3998 | __ and_(r3, r1, Operand(0xFFFF)); |
| 3999 | __ mov(r4, Operand(18273)); |
| 4000 | __ mul(r3, r3, r4); |
| 4001 | __ add(r1, r3, Operand(r1, LSR, 16)); |
| 4002 | // Save state[0]. |
| 4003 | __ str(r1, FieldMemOperand(r2, ByteArray::kHeaderSize)); |
| 4004 | |
| 4005 | // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 4006 | __ and_(r3, r0, Operand(0xFFFF)); |
| 4007 | __ mov(r4, Operand(36969)); |
| 4008 | __ mul(r3, r3, r4); |
| 4009 | __ add(r0, r3, Operand(r0, LSR, 16)); |
| 4010 | // Save state[1]. |
| 4011 | __ str(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize)); |
| 4012 | |
| 4013 | // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 4014 | __ and_(r0, r0, Operand(0x3FFFF)); |
| 4015 | __ add(r0, r0, Operand(r1, LSL, 14)); |
| 4016 | |
| 4017 | __ bind(deferred->exit()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4018 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 4019 | // Create this constant using mov/orr to avoid PC relative load. |
| 4020 | __ mov(r1, Operand(0x41000000)); |
| 4021 | __ orr(r1, r1, Operand(0x300000)); |
| 4022 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 4023 | __ vmov(d7, r0, r1); |
| 4024 | // Move 0x4130000000000000 to VFP. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4025 | __ mov(r0, Operand::Zero()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4026 | __ vmov(d8, r0, r1); |
| 4027 | // Subtract and store the result in the heap number. |
| 4028 | __ vsub(d7, d7, d8); |
| 4029 | } |
| 4030 | |
| 4031 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4032 | void LCodeGen::DoDeferredRandom(LRandom* instr) { |
| 4033 | __ PrepareCallCFunction(1, scratch0()); |
| 4034 | __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
| 4035 | // Return value is in r0. |
| 4036 | } |
| 4037 | |
| 4038 | |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4039 | void LCodeGen::DoMathExp(LMathExp* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4040 | DwVfpRegister input = ToDoubleRegister(instr->value()); |
| 4041 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 4042 | DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 4043 | DwVfpRegister double_scratch2 = double_scratch0(); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4044 | Register temp1 = ToRegister(instr->temp1()); |
| 4045 | Register temp2 = ToRegister(instr->temp2()); |
| 4046 | |
| 4047 | MathExpGenerator::EmitMathExp( |
| 4048 | masm(), input, result, double_scratch1, double_scratch2, |
| 4049 | temp1, temp2, scratch0()); |
| 4050 | } |
| 4051 | |
| 4052 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4053 | void LCodeGen::DoMathLog(LMathLog* instr) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4054 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 4055 | TranscendentalCacheStub stub(TranscendentalCache::LOG, |
| 4056 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4057 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4061 | void LCodeGen::DoMathTan(LMathTan* instr) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4062 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 4063 | TranscendentalCacheStub stub(TranscendentalCache::TAN, |
| 4064 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4065 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4069 | void LCodeGen::DoMathCos(LMathCos* instr) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4070 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 4071 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 4072 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4073 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4077 | void LCodeGen::DoMathSin(LMathSin* instr) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4078 | ASSERT(ToDoubleRegister(instr->result()).is(d2)); |
| 4079 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 4080 | TranscendentalCacheStub::UNTAGGED); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4081 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4085 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
| 4086 | ASSERT(ToRegister(instr->function()).is(r1)); |
| 4087 | ASSERT(instr->HasPointerMap()); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4088 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4089 | Handle<JSFunction> known_function = instr->hydrogen()->known_function(); |
| 4090 | if (known_function.is_null()) { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4091 | LPointerMap* pointers = instr->pointer_map(); |
| 4092 | RecordPosition(pointers->position()); |
| 4093 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 4094 | ParameterCount count(instr->arity()); |
| 4095 | __ InvokeFunction(r1, count, CALL_FUNCTION, generator, CALL_AS_METHOD); |
| 4096 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4097 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4098 | CallKnownFunction(known_function, |
| 4099 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4100 | instr->arity(), |
| 4101 | instr, |
| 4102 | CALL_AS_METHOD, |
| 4103 | R1_CONTAINS_TARGET); |
| 4104 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4108 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4109 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4110 | |
| 4111 | int arity = instr->arity(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4112 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4113 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arity); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4114 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4115 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | |
| 4119 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
| 4120 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4121 | |
| 4122 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4123 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
| 4124 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4125 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4126 | __ mov(r2, Operand(instr->name())); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4127 | CallCode(ic, mode, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4128 | // Restore context register. |
| 4129 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4130 | } |
| 4131 | |
| 4132 | |
| 4133 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4134 | ASSERT(ToRegister(instr->function()).is(r1)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4135 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4136 | |
| 4137 | int arity = instr->arity(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4138 | CallFunctionStub stub(arity, NO_CALL_FUNCTION_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4139 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4140 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | |
| 4144 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4145 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4146 | |
| 4147 | int arity = instr->arity(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4148 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET_CONTEXT; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4149 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4150 | isolate()->stub_cache()->ComputeCallInitialize(arity, mode); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4151 | __ mov(r2, Operand(instr->name())); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4152 | CallCode(ic, mode, instr, NEVER_INLINE_TARGET_ADDRESS); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4153 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4154 | } |
| 4155 | |
| 4156 | |
| 4157 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 4158 | ASSERT(ToRegister(instr->result()).is(r0)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4159 | CallKnownFunction(instr->hydrogen()->target(), |
| 4160 | instr->hydrogen()->formal_parameter_count(), |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 4161 | instr->arity(), |
| 4162 | instr, |
| 4163 | CALL_AS_FUNCTION, |
| 4164 | R1_UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | |
| 4168 | void LCodeGen::DoCallNew(LCallNew* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4169 | ASSERT(ToRegister(instr->constructor()).is(r1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4170 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4171 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4172 | __ mov(r0, Operand(instr->arity())); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4173 | if (FLAG_optimize_constructed_arrays) { |
| 4174 | // No cell in r2 for construct type feedback in optimized code |
| 4175 | Handle<Object> undefined_value(isolate()->heap()->undefined_value(), |
| 4176 | isolate()); |
| 4177 | __ mov(r2, Operand(undefined_value)); |
| 4178 | } |
| 4179 | CallConstructStub stub(NO_CALL_FUNCTION_FLAGS); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4180 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4184 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
| 4185 | ASSERT(ToRegister(instr->constructor()).is(r1)); |
| 4186 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 4187 | ASSERT(FLAG_optimize_constructed_arrays); |
| 4188 | |
| 4189 | __ mov(r0, Operand(instr->arity())); |
| 4190 | __ mov(r2, Operand(instr->hydrogen()->property_cell())); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4191 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4192 | if (instr->arity() == 0) { |
| 4193 | ArrayNoArgumentConstructorStub stub(kind); |
| 4194 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4195 | } else if (instr->arity() == 1) { |
| 4196 | ArraySingleArgumentConstructorStub stub(kind); |
| 4197 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4198 | } else { |
| 4199 | ArrayNArgumentsConstructorStub stub(kind); |
| 4200 | CallCode(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL, instr); |
| 4201 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4205 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 4206 | CallRuntime(instr->function(), instr->arity(), instr); |
| 4207 | } |
| 4208 | |
| 4209 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4210 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 4211 | Register result = ToRegister(instr->result()); |
| 4212 | Register base = ToRegister(instr->base_object()); |
| 4213 | __ add(result, base, Operand(instr->offset())); |
| 4214 | } |
| 4215 | |
| 4216 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4217 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4218 | Representation representation = instr->representation(); |
| 4219 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4220 | Register object = ToRegister(instr->object()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4221 | Register scratch = scratch0(); |
| 4222 | int offset = instr->offset(); |
| 4223 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4224 | Handle<Map> transition = instr->transition(); |
| 4225 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4226 | if (FLAG_track_fields && representation.IsSmi()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4227 | Register value = ToRegister(instr->value()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4228 | __ SmiTag(value, value, SetCC); |
| 4229 | if (!instr->hydrogen()->value()->range()->IsInSmiRange()) { |
| 4230 | DeoptimizeIf(vs, instr->environment()); |
| 4231 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4232 | } else if (FLAG_track_double_fields && representation.IsDouble()) { |
| 4233 | ASSERT(transition.is_null()); |
| 4234 | ASSERT(instr->is_in_object()); |
| 4235 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4236 | DwVfpRegister value = ToDoubleRegister(instr->value()); |
| 4237 | __ vstr(value, FieldMemOperand(object, offset)); |
| 4238 | return; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4241 | if (!transition.is_null()) { |
| 4242 | if (transition->CanBeDeprecated()) { |
| 4243 | transition_maps_.Add(transition, info()->zone()); |
| 4244 | } |
| 4245 | __ mov(scratch, Operand(transition)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4246 | __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4247 | if (instr->hydrogen()->NeedsWriteBarrierForMap()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4248 | Register temp = ToRegister(instr->temp()); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4249 | // Update the write barrier for the map field. |
| 4250 | __ RecordWriteField(object, |
| 4251 | HeapObject::kMapOffset, |
| 4252 | scratch, |
| 4253 | temp, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4254 | GetLinkRegisterState(), |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 4255 | kSaveFPRegs, |
| 4256 | OMIT_REMEMBERED_SET, |
| 4257 | OMIT_SMI_CHECK); |
| 4258 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | // Do the store. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 4262 | Register value = ToRegister(instr->value()); |
| 4263 | ASSERT(!object.is(value)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4264 | HType type = instr->hydrogen()->value()->type(); |
| 4265 | SmiCheck check_needed = |
| 4266 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4267 | if (instr->is_in_object()) { |
| 4268 | __ str(value, FieldMemOperand(object, offset)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4269 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4270 | // Update the write barrier for the object for in-object properties. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4271 | __ RecordWriteField(object, |
| 4272 | offset, |
| 4273 | value, |
| 4274 | scratch, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4275 | GetLinkRegisterState(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4276 | kSaveFPRegs, |
| 4277 | EMIT_REMEMBERED_SET, |
| 4278 | check_needed); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4279 | } |
| 4280 | } else { |
| 4281 | __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 4282 | __ str(value, FieldMemOperand(scratch, offset)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4283 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4284 | // Update the write barrier for the properties array. |
| 4285 | // object is used as a scratch register. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4286 | __ RecordWriteField(scratch, |
| 4287 | offset, |
| 4288 | value, |
| 4289 | object, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4290 | GetLinkRegisterState(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4291 | kSaveFPRegs, |
| 4292 | EMIT_REMEMBERED_SET, |
| 4293 | check_needed); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4294 | } |
| 4295 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | |
| 4299 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
| 4300 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 4301 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 4302 | |
| 4303 | // Name is always in r2. |
| 4304 | __ mov(r2, Operand(instr->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4305 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4306 | ? isolate()->builtins()->StoreIC_Initialize_Strict() |
| 4307 | : isolate()->builtins()->StoreIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4308 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | |
| 4312 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4313 | if (instr->hydrogen()->skip_check()) return; |
| 4314 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 4315 | if (instr->index()->IsConstantOperand()) { |
| 4316 | int constant_index = |
| 4317 | ToInteger32(LConstantOperand::cast(instr->index())); |
| 4318 | if (instr->hydrogen()->length()->representation().IsTagged()) { |
| 4319 | __ mov(ip, Operand(Smi::FromInt(constant_index))); |
| 4320 | } else { |
| 4321 | __ mov(ip, Operand(constant_index)); |
| 4322 | } |
| 4323 | __ cmp(ip, ToRegister(instr->length())); |
| 4324 | } else { |
| 4325 | __ cmp(ToRegister(instr->index()), ToRegister(instr->length())); |
| 4326 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4327 | DeoptimizeIf(hs, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4331 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
| 4332 | Register external_pointer = ToRegister(instr->elements()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4333 | Register key = no_reg; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4334 | ElementsKind elements_kind = instr->elements_kind(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4335 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4336 | int constant_key = 0; |
| 4337 | if (key_is_constant) { |
| 4338 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4339 | if (constant_key & 0xF0000000) { |
| 4340 | Abort("array index constant value too big."); |
| 4341 | } |
| 4342 | } else { |
| 4343 | key = ToRegister(instr->key()); |
| 4344 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4345 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 4346 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 4347 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 4348 | int additional_offset = instr->additional_index() << element_size_shift; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4349 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4350 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS || |
| 4351 | elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 4352 | DwVfpRegister value(ToDoubleRegister(instr->value())); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4353 | Operand operand(key_is_constant |
| 4354 | ? Operand(constant_key << element_size_shift) |
| 4355 | : Operand(key, LSL, shift_size)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4356 | __ add(scratch0(), external_pointer, operand); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4357 | if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4358 | __ vcvt_f32_f64(double_scratch0().low(), value); |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4359 | __ vstr(double_scratch0().low(), scratch0(), additional_offset); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4360 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 4361 | __ vstr(value, scratch0(), additional_offset); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4362 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4363 | } else { |
| 4364 | Register value(ToRegister(instr->value())); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4365 | MemOperand mem_operand = PrepareKeyedOperand( |
| 4366 | key, external_pointer, key_is_constant, constant_key, |
| 4367 | element_size_shift, shift_size, |
| 4368 | instr->additional_index(), additional_offset); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4369 | switch (elements_kind) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4370 | case EXTERNAL_PIXEL_ELEMENTS: |
| 4371 | case EXTERNAL_BYTE_ELEMENTS: |
| 4372 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4373 | __ strb(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4374 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4375 | case EXTERNAL_SHORT_ELEMENTS: |
| 4376 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4377 | __ strh(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4378 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4379 | case EXTERNAL_INT_ELEMENTS: |
| 4380 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4381 | __ str(value, mem_operand); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4382 | break; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4383 | case EXTERNAL_FLOAT_ELEMENTS: |
| 4384 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 4385 | case FAST_DOUBLE_ELEMENTS: |
| 4386 | case FAST_ELEMENTS: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4387 | case FAST_SMI_ELEMENTS: |
| 4388 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 4389 | case FAST_HOLEY_ELEMENTS: |
| 4390 | case FAST_HOLEY_SMI_ELEMENTS: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4391 | case DICTIONARY_ELEMENTS: |
| 4392 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4393 | UNREACHABLE(); |
| 4394 | break; |
| 4395 | } |
| 4396 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4400 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
| 4401 | DwVfpRegister value = ToDoubleRegister(instr->value()); |
| 4402 | Register elements = ToRegister(instr->elements()); |
| 4403 | Register key = no_reg; |
| 4404 | Register scratch = scratch0(); |
| 4405 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4406 | int constant_key = 0; |
| 4407 | |
| 4408 | // Calculate the effective address of the slot in the array to store the |
| 4409 | // double value. |
| 4410 | if (key_is_constant) { |
| 4411 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4412 | if (constant_key & 0xF0000000) { |
| 4413 | Abort("array index constant value too big."); |
| 4414 | } |
| 4415 | } else { |
| 4416 | key = ToRegister(instr->key()); |
| 4417 | } |
| 4418 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 4419 | int shift_size = (instr->hydrogen()->key()->representation().IsTagged()) |
| 4420 | ? (element_size_shift - kSmiTagSize) : element_size_shift; |
| 4421 | Operand operand = key_is_constant |
| 4422 | ? Operand((constant_key << element_size_shift) + |
| 4423 | FixedDoubleArray::kHeaderSize - kHeapObjectTag) |
| 4424 | : Operand(key, LSL, shift_size); |
| 4425 | __ add(scratch, elements, operand); |
| 4426 | if (!key_is_constant) { |
| 4427 | __ add(scratch, scratch, |
| 4428 | Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag)); |
| 4429 | } |
| 4430 | |
| 4431 | if (instr->NeedsCanonicalization()) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4432 | // Force a canonical NaN. |
| 4433 | if (masm()->emit_debug_code()) { |
| 4434 | __ vmrs(ip); |
| 4435 | __ tst(ip, Operand(kVFPDefaultNaNModeControlBit)); |
| 4436 | __ Assert(ne, "Default NaN mode not set"); |
| 4437 | } |
| 4438 | __ VFPCanonicalizeNaN(value); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4439 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4440 | __ vstr(value, scratch, instr->additional_index() << element_size_shift); |
| 4441 | } |
| 4442 | |
| 4443 | |
| 4444 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| 4445 | Register value = ToRegister(instr->value()); |
| 4446 | Register elements = ToRegister(instr->elements()); |
| 4447 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) |
| 4448 | : no_reg; |
| 4449 | Register scratch = scratch0(); |
| 4450 | Register store_base = scratch; |
| 4451 | int offset = 0; |
| 4452 | |
| 4453 | // Do the store. |
| 4454 | if (instr->key()->IsConstantOperand()) { |
| 4455 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 4456 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 4457 | offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) + |
| 4458 | instr->additional_index()); |
| 4459 | store_base = elements; |
| 4460 | } else { |
| 4461 | // Even though the HLoadKeyed instruction forces the input |
| 4462 | // representation for the key to be an integer, the input gets replaced |
| 4463 | // during bound check elimination with the index argument to the bounds |
| 4464 | // check, which can be tagged, so that case must be handled here, too. |
| 4465 | if (instr->hydrogen()->key()->representation().IsTagged()) { |
| 4466 | __ add(scratch, elements, |
| 4467 | Operand(key, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4468 | } else { |
| 4469 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 4470 | } |
| 4471 | offset = FixedArray::OffsetOfElementAt(instr->additional_index()); |
| 4472 | } |
| 4473 | __ str(value, FieldMemOperand(store_base, offset)); |
| 4474 | |
| 4475 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 4476 | HType type = instr->hydrogen()->value()->type(); |
| 4477 | SmiCheck check_needed = |
| 4478 | type.IsHeapObject() ? OMIT_SMI_CHECK : INLINE_SMI_CHECK; |
| 4479 | // Compute address of modified element and store it into key register. |
| 4480 | __ add(key, store_base, Operand(offset - kHeapObjectTag)); |
| 4481 | __ RecordWrite(elements, |
| 4482 | key, |
| 4483 | value, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4484 | GetLinkRegisterState(), |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 4485 | kSaveFPRegs, |
| 4486 | EMIT_REMEMBERED_SET, |
| 4487 | check_needed); |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | |
| 4492 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4493 | // By cases: external, fast double |
| 4494 | if (instr->is_external()) { |
| 4495 | DoStoreKeyedExternalArray(instr); |
| 4496 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4497 | DoStoreKeyedFixedDoubleArray(instr); |
| 4498 | } else { |
| 4499 | DoStoreKeyedFixedArray(instr); |
| 4500 | } |
| 4501 | } |
| 4502 | |
| 4503 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4504 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
| 4505 | ASSERT(ToRegister(instr->object()).is(r2)); |
| 4506 | ASSERT(ToRegister(instr->key()).is(r1)); |
| 4507 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 4508 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4509 | Handle<Code> ic = (instr->strict_mode_flag() == kStrictMode) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4510 | ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() |
| 4511 | : isolate()->builtins()->KeyedStoreIC_Initialize(); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4512 | CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4516 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4517 | Register object_reg = ToRegister(instr->object()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4518 | Register scratch = scratch0(); |
| 4519 | |
| 4520 | Handle<Map> from_map = instr->original_map(); |
| 4521 | Handle<Map> to_map = instr->transitioned_map(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4522 | ElementsKind from_kind = instr->from_kind(); |
| 4523 | ElementsKind to_kind = instr->to_kind(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4524 | |
| 4525 | Label not_applicable; |
| 4526 | __ ldr(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4527 | __ cmp(scratch, Operand(from_map)); |
| 4528 | __ b(ne, ¬_applicable); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4529 | |
| 4530 | if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4531 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
| 4532 | __ mov(new_map_reg, Operand(to_map)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4533 | __ str(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4534 | // Write barrier. |
| 4535 | __ RecordWriteField(object_reg, HeapObject::kMapOffset, new_map_reg, |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 4536 | scratch, GetLinkRegisterState(), kDontSaveFPRegs); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4537 | } else if (FLAG_compiled_transitions) { |
| 4538 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4539 | __ Move(r0, object_reg); |
| 4540 | __ Move(r1, to_map); |
| 4541 | TransitionElementsKindStub stub(from_kind, to_kind); |
| 4542 | __ CallStub(&stub); |
| 4543 | RecordSafepointWithRegisters( |
| 4544 | instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4545 | } else if (IsFastSmiElementsKind(from_kind) && |
| 4546 | IsFastDoubleElementsKind(to_kind)) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4547 | Register fixed_object_reg = ToRegister(instr->temp()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4548 | ASSERT(fixed_object_reg.is(r2)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4549 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4550 | ASSERT(new_map_reg.is(r3)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4551 | __ mov(new_map_reg, Operand(to_map)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4552 | __ mov(fixed_object_reg, object_reg); |
| 4553 | CallCode(isolate()->builtins()->TransitionElementsSmiToDouble(), |
| 4554 | RelocInfo::CODE_TARGET, instr); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4555 | } else if (IsFastDoubleElementsKind(from_kind) && |
| 4556 | IsFastObjectElementsKind(to_kind)) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4557 | Register fixed_object_reg = ToRegister(instr->temp()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4558 | ASSERT(fixed_object_reg.is(r2)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4559 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4560 | ASSERT(new_map_reg.is(r3)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4561 | __ mov(new_map_reg, Operand(to_map)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4562 | __ mov(fixed_object_reg, object_reg); |
| 4563 | CallCode(isolate()->builtins()->TransitionElementsDoubleToObject(), |
| 4564 | RelocInfo::CODE_TARGET, instr); |
| 4565 | } else { |
| 4566 | UNREACHABLE(); |
| 4567 | } |
| 4568 | __ bind(¬_applicable); |
| 4569 | } |
| 4570 | |
| 4571 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4572 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4573 | Register object = ToRegister(instr->object()); |
| 4574 | Register temp = ToRegister(instr->temp()); |
| 4575 | __ TestJSArrayForAllocationSiteInfo(object, temp); |
| 4576 | DeoptimizeIf(eq, instr->environment()); |
| 4577 | } |
| 4578 | |
| 4579 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4580 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
| 4581 | __ push(ToRegister(instr->left())); |
| 4582 | __ push(ToRegister(instr->right())); |
| 4583 | StringAddStub stub(NO_STRING_CHECK_IN_STUB); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4584 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4588 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4589 | class DeferredStringCharCodeAt: public LDeferredCode { |
| 4590 | public: |
| 4591 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 4592 | : LDeferredCode(codegen), instr_(instr) { } |
| 4593 | virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4594 | virtual LInstruction* instr() { return instr_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4595 | private: |
| 4596 | LStringCharCodeAt* instr_; |
| 4597 | }; |
| 4598 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4599 | DeferredStringCharCodeAt* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4600 | new(zone()) DeferredStringCharCodeAt(this, instr); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4601 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4602 | StringCharLoadGenerator::Generate(masm(), |
| 4603 | ToRegister(instr->string()), |
| 4604 | ToRegister(instr->index()), |
| 4605 | ToRegister(instr->result()), |
| 4606 | deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4607 | __ bind(deferred->exit()); |
| 4608 | } |
| 4609 | |
| 4610 | |
| 4611 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4612 | Register string = ToRegister(instr->string()); |
| 4613 | Register result = ToRegister(instr->result()); |
| 4614 | Register scratch = scratch0(); |
| 4615 | |
| 4616 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4617 | // result register contain a valid pointer because it is already |
| 4618 | // contained in the register pointer map. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4619 | __ mov(result, Operand::Zero()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4620 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4621 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4622 | __ push(string); |
| 4623 | // Push the index as a smi. This is safe because of the checks in |
| 4624 | // DoStringCharCodeAt above. |
| 4625 | if (instr->index()->IsConstantOperand()) { |
| 4626 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4627 | __ mov(scratch, Operand(Smi::FromInt(const_index))); |
| 4628 | __ push(scratch); |
| 4629 | } else { |
| 4630 | Register index = ToRegister(instr->index()); |
| 4631 | __ SmiTag(index); |
| 4632 | __ push(index); |
| 4633 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4634 | CallRuntimeFromDeferred(Runtime::kStringCharCodeAt, 2, instr); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4635 | __ AssertSmi(r0); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4636 | __ SmiUntag(r0); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4637 | __ StoreToSafepointRegisterSlot(r0, result); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4641 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
| 4642 | class DeferredStringCharFromCode: public LDeferredCode { |
| 4643 | public: |
| 4644 | DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 4645 | : LDeferredCode(codegen), instr_(instr) { } |
| 4646 | virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4647 | virtual LInstruction* instr() { return instr_; } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4648 | private: |
| 4649 | LStringCharFromCode* instr_; |
| 4650 | }; |
| 4651 | |
| 4652 | DeferredStringCharFromCode* deferred = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4653 | new(zone()) DeferredStringCharFromCode(this, instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4654 | |
| 4655 | ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4656 | Register char_code = ToRegister(instr->char_code()); |
| 4657 | Register result = ToRegister(instr->result()); |
| 4658 | ASSERT(!char_code.is(result)); |
| 4659 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4660 | __ cmp(char_code, Operand(String::kMaxOneByteCharCode)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4661 | __ b(hi, deferred->entry()); |
| 4662 | __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 4663 | __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2)); |
| 4664 | __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 4665 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4666 | __ cmp(result, ip); |
| 4667 | __ b(eq, deferred->entry()); |
| 4668 | __ bind(deferred->exit()); |
| 4669 | } |
| 4670 | |
| 4671 | |
| 4672 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4673 | Register char_code = ToRegister(instr->char_code()); |
| 4674 | Register result = ToRegister(instr->result()); |
| 4675 | |
| 4676 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4677 | // result register contain a valid pointer because it is already |
| 4678 | // contained in the register pointer map. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4679 | __ mov(result, Operand::Zero()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4680 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4681 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4682 | __ SmiTag(char_code); |
| 4683 | __ push(char_code); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4684 | CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4685 | __ StoreToSafepointRegisterSlot(r0, result); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4689 | void LCodeGen::DoStringLength(LStringLength* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4690 | Register string = ToRegister(instr->string()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4691 | Register result = ToRegister(instr->result()); |
| 4692 | __ ldr(result, FieldMemOperand(string, String::kLengthOffset)); |
| 4693 | } |
| 4694 | |
| 4695 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4696 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4697 | LOperand* input = instr->value(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4698 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 4699 | LOperand* output = instr->result(); |
| 4700 | ASSERT(output->IsDoubleRegister()); |
| 4701 | SwVfpRegister single_scratch = double_scratch0().low(); |
| 4702 | if (input->IsStackSlot()) { |
| 4703 | Register scratch = scratch0(); |
| 4704 | __ ldr(scratch, ToMemOperand(input)); |
| 4705 | __ vmov(single_scratch, scratch); |
| 4706 | } else { |
| 4707 | __ vmov(single_scratch, ToRegister(input)); |
| 4708 | } |
| 4709 | __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4713 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4714 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4715 | LOperand* output = instr->result(); |
| 4716 | |
| 4717 | SwVfpRegister flt_scratch = double_scratch0().low(); |
| 4718 | __ vmov(flt_scratch, ToRegister(input)); |
| 4719 | __ vcvt_f64_u32(ToDoubleRegister(output), flt_scratch); |
| 4720 | } |
| 4721 | |
| 4722 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4723 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 4724 | class DeferredNumberTagI: public LDeferredCode { |
| 4725 | public: |
| 4726 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 4727 | : LDeferredCode(codegen), instr_(instr) { } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4728 | virtual void Generate() { |
| 4729 | codegen()->DoDeferredNumberTagI(instr_, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4730 | instr_->value(), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4731 | SIGNED_INT32); |
| 4732 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4733 | virtual LInstruction* instr() { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4734 | private: |
| 4735 | LNumberTagI* instr_; |
| 4736 | }; |
| 4737 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4738 | Register src = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4739 | Register dst = ToRegister(instr->result()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4740 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4741 | DeferredNumberTagI* deferred = new(zone()) DeferredNumberTagI(this, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4742 | __ SmiTag(dst, src, SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4743 | __ b(vs, deferred->entry()); |
| 4744 | __ bind(deferred->exit()); |
| 4745 | } |
| 4746 | |
| 4747 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4748 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
| 4749 | class DeferredNumberTagU: public LDeferredCode { |
| 4750 | public: |
| 4751 | DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4752 | : LDeferredCode(codegen), instr_(instr) { } |
| 4753 | virtual void Generate() { |
| 4754 | codegen()->DoDeferredNumberTagI(instr_, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4755 | instr_->value(), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4756 | UNSIGNED_INT32); |
| 4757 | } |
| 4758 | virtual LInstruction* instr() { return instr_; } |
| 4759 | private: |
| 4760 | LNumberTagU* instr_; |
| 4761 | }; |
| 4762 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4763 | LOperand* input = instr->value(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4764 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 4765 | Register reg = ToRegister(input); |
| 4766 | |
| 4767 | DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr); |
| 4768 | __ cmp(reg, Operand(Smi::kMaxValue)); |
| 4769 | __ b(hi, deferred->entry()); |
| 4770 | __ SmiTag(reg, reg); |
| 4771 | __ bind(deferred->exit()); |
| 4772 | } |
| 4773 | |
| 4774 | |
| 4775 | void LCodeGen::DoDeferredNumberTagI(LInstruction* instr, |
| 4776 | LOperand* value, |
| 4777 | IntegerSignedness signedness) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4778 | Label slow; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4779 | Register src = ToRegister(value); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4780 | Register dst = ToRegister(instr->result()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4781 | DwVfpRegister dbl_scratch = double_scratch0(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4782 | SwVfpRegister flt_scratch = dbl_scratch.low(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4783 | |
| 4784 | // Preserve the value of all registers. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4785 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4786 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4787 | Label done; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4788 | if (signedness == SIGNED_INT32) { |
| 4789 | // There was overflow, so bits 30 and 31 of the original integer |
| 4790 | // disagree. Try to allocate a heap number in new space and store |
| 4791 | // the value in there. If that fails, call the runtime system. |
| 4792 | if (dst.is(src)) { |
| 4793 | __ SmiUntag(src, dst); |
| 4794 | __ eor(src, src, Operand(0x80000000)); |
| 4795 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4796 | __ vmov(flt_scratch, src); |
| 4797 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4798 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4799 | __ vmov(flt_scratch, src); |
| 4800 | __ vcvt_f64_u32(dbl_scratch, flt_scratch); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4801 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4802 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4803 | if (FLAG_inline_new) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4804 | __ LoadRoot(scratch0(), Heap::kHeapNumberMapRootIndex); |
| 4805 | __ AllocateHeapNumber(r5, r3, r4, scratch0(), &slow, DONT_TAG_RESULT); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4806 | __ Move(dst, r5); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4807 | __ b(&done); |
| 4808 | } |
| 4809 | |
| 4810 | // Slow case: Call the runtime system to do the number allocation. |
| 4811 | __ bind(&slow); |
| 4812 | |
| 4813 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 4814 | // register is stored, as this register is in the pointer map, but contains an |
| 4815 | // integer value. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4816 | __ mov(ip, Operand::Zero()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4817 | __ StoreToSafepointRegisterSlot(ip, dst); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4818 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4819 | __ Move(dst, r0); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4820 | __ sub(dst, dst, Operand(kHeapObjectTag)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4821 | |
| 4822 | // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 4823 | // number. |
| 4824 | __ bind(&done); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4825 | __ vstr(dbl_scratch, dst, HeapNumber::kValueOffset); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4826 | __ add(dst, dst, Operand(kHeapObjectTag)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4827 | __ StoreToSafepointRegisterSlot(dst, dst); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | |
| 4831 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
| 4832 | class DeferredNumberTagD: public LDeferredCode { |
| 4833 | public: |
| 4834 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 4835 | : LDeferredCode(codegen), instr_(instr) { } |
| 4836 | virtual void Generate() { codegen()->DoDeferredNumberTagD(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4837 | virtual LInstruction* instr() { return instr_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4838 | private: |
| 4839 | LNumberTagD* instr_; |
| 4840 | }; |
| 4841 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4842 | DwVfpRegister input_reg = ToDoubleRegister(instr->value()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4843 | Register scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4844 | Register reg = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4845 | Register temp1 = ToRegister(instr->temp()); |
| 4846 | Register temp2 = ToRegister(instr->temp2()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4847 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4848 | bool convert_hole = false; |
| 4849 | HValue* change_input = instr->hydrogen()->value(); |
| 4850 | if (change_input->IsLoadKeyed()) { |
| 4851 | HLoadKeyed* load = HLoadKeyed::cast(change_input); |
| 4852 | convert_hole = load->UsesMustHandleHole(); |
| 4853 | } |
| 4854 | |
| 4855 | Label no_special_nan_handling; |
| 4856 | Label done; |
| 4857 | if (convert_hole) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4858 | DwVfpRegister input_reg = ToDoubleRegister(instr->value()); |
| 4859 | __ VFPCompareAndSetFlags(input_reg, input_reg); |
| 4860 | __ b(vc, &no_special_nan_handling); |
| 4861 | __ vmov(scratch, input_reg.high()); |
| 4862 | __ cmp(scratch, Operand(kHoleNanUpper32)); |
| 4863 | // If not the hole NaN, force the NaN to be canonical. |
| 4864 | __ VFPCanonicalizeNaN(input_reg, ne); |
| 4865 | __ b(ne, &no_special_nan_handling); |
| 4866 | __ Move(reg, factory()->the_hole_value()); |
| 4867 | __ b(&done); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | __ bind(&no_special_nan_handling); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4871 | DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4872 | if (FLAG_inline_new) { |
| 4873 | __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4874 | // We want the untagged address first for performance |
| 4875 | __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry(), |
| 4876 | DONT_TAG_RESULT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4877 | } else { |
| 4878 | __ jmp(deferred->entry()); |
| 4879 | } |
| 4880 | __ bind(deferred->exit()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4881 | __ vstr(input_reg, reg, HeapNumber::kValueOffset); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4882 | // Now that we have finished with the object's real address tag it |
| 4883 | __ add(reg, reg, Operand(kHeapObjectTag)); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4884 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | |
| 4888 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 4889 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4890 | // result register contain a valid pointer because it is already |
| 4891 | // contained in the register pointer map. |
| 4892 | Register reg = ToRegister(instr->result()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4893 | __ mov(reg, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4894 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4895 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 4896 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4897 | __ sub(r0, r0, Operand(kHeapObjectTag)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4898 | __ StoreToSafepointRegisterSlot(r0, reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4899 | } |
| 4900 | |
| 4901 | |
| 4902 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4903 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4904 | __ SmiTag(ToRegister(instr->result()), ToRegister(instr->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | |
| 4908 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4909 | Register input = ToRegister(instr->value()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4910 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4911 | if (instr->needs_check()) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4912 | STATIC_ASSERT(kHeapObjectTag == 1); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4913 | // If the input is a HeapObject, SmiUntag will set the carry flag. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4914 | __ SmiUntag(result, input, SetCC); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 4915 | DeoptimizeIf(cs, instr->environment()); |
| 4916 | } else { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4917 | __ SmiUntag(result, input); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4918 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | |
| 4922 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4923 | DwVfpRegister result_reg, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4924 | bool deoptimize_on_undefined, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4925 | bool deoptimize_on_minus_zero, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4926 | LEnvironment* env, |
| 4927 | NumberUntagDMode mode) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4928 | Register scratch = scratch0(); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4929 | SwVfpRegister flt_scratch = double_scratch0().low(); |
| 4930 | ASSERT(!result_reg.is(double_scratch0())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4931 | |
| 4932 | Label load_smi, heap_number, done; |
| 4933 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4934 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
| 4935 | // Smi check. |
| 4936 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4937 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4938 | // Heap number map check. |
| 4939 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4940 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 4941 | __ cmp(scratch, Operand(ip)); |
| 4942 | if (deoptimize_on_undefined) { |
| 4943 | DeoptimizeIf(ne, env); |
| 4944 | } else { |
| 4945 | Label heap_number; |
| 4946 | __ b(eq, &heap_number); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4947 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4948 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4949 | __ cmp(input_reg, Operand(ip)); |
| 4950 | DeoptimizeIf(ne, env); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4951 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4952 | // Convert undefined to NaN. |
| 4953 | __ LoadRoot(ip, Heap::kNanValueRootIndex); |
| 4954 | __ sub(ip, ip, Operand(kHeapObjectTag)); |
| 4955 | __ vldr(result_reg, ip, HeapNumber::kValueOffset); |
| 4956 | __ jmp(&done); |
| 4957 | |
| 4958 | __ bind(&heap_number); |
| 4959 | } |
| 4960 | // Heap number to double register conversion. |
| 4961 | __ sub(ip, input_reg, Operand(kHeapObjectTag)); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4962 | __ vldr(result_reg, ip, HeapNumber::kValueOffset); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4963 | if (deoptimize_on_minus_zero) { |
| 4964 | __ vmov(ip, result_reg.low()); |
| 4965 | __ cmp(ip, Operand::Zero()); |
| 4966 | __ b(ne, &done); |
| 4967 | __ vmov(ip, result_reg.high()); |
| 4968 | __ cmp(ip, Operand(HeapNumber::kSignMask)); |
| 4969 | DeoptimizeIf(eq, env); |
| 4970 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4971 | __ jmp(&done); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 4972 | } else if (mode == NUMBER_CANDIDATE_IS_SMI_OR_HOLE) { |
| 4973 | __ SmiUntag(scratch, input_reg, SetCC); |
| 4974 | DeoptimizeIf(cs, env); |
| 4975 | } else if (mode == NUMBER_CANDIDATE_IS_SMI_CONVERT_HOLE) { |
| 4976 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
| 4977 | __ Vmov(result_reg, |
| 4978 | FixedDoubleArray::hole_nan_as_double(), |
| 4979 | no_reg); |
| 4980 | __ b(&done); |
| 4981 | } else { |
| 4982 | __ SmiUntag(scratch, input_reg); |
| 4983 | ASSERT(mode == NUMBER_CANDIDATE_IS_SMI); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4984 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4985 | |
| 4986 | // Smi to double register conversion |
| 4987 | __ bind(&load_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4988 | // scratch: untagged value of input_reg |
| 4989 | __ vmov(flt_scratch, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4990 | __ vcvt_f64_s32(result_reg, flt_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4991 | __ bind(&done); |
| 4992 | } |
| 4993 | |
| 4994 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4995 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4996 | Register input_reg = ToRegister(instr->value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4997 | Register scratch1 = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4998 | Register scratch2 = ToRegister(instr->temp()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4999 | DwVfpRegister double_scratch = double_scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5000 | DwVfpRegister double_scratch2 = ToDoubleRegister(instr->temp3()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5001 | |
| 5002 | ASSERT(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
| 5003 | ASSERT(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
| 5004 | |
| 5005 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5006 | |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 5007 | // The input was optimistically untagged; revert it. |
| 5008 | // The carry flag is set when we reach this deferred code as we just executed |
| 5009 | // SmiUntag(heap_object, SetCC) |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5010 | STATIC_ASSERT(kHeapObjectTag == 1); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 5011 | __ adc(input_reg, input_reg, Operand(input_reg)); |
| 5012 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5013 | // Heap number map check. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5014 | __ ldr(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5015 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5016 | __ cmp(scratch1, Operand(ip)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5017 | |
| 5018 | if (instr->truncating()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5019 | Register scratch3 = ToRegister(instr->temp2()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5020 | ASSERT(!scratch3.is(input_reg) && |
| 5021 | !scratch3.is(scratch1) && |
| 5022 | !scratch3.is(scratch2)); |
| 5023 | // Performs a truncating conversion of a floating point number as used by |
| 5024 | // the JS bitwise operations. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5025 | Label heap_number; |
| 5026 | __ b(eq, &heap_number); |
| 5027 | // Check for undefined. Undefined is converted to zero for truncating |
| 5028 | // conversions. |
| 5029 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5030 | __ cmp(input_reg, Operand(ip)); |
| 5031 | DeoptimizeIf(ne, instr->environment()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5032 | __ mov(input_reg, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5033 | __ b(&done); |
| 5034 | |
| 5035 | __ bind(&heap_number); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5036 | __ sub(scratch1, input_reg, Operand(kHeapObjectTag)); |
| 5037 | __ vldr(double_scratch2, scratch1, HeapNumber::kValueOffset); |
| 5038 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5039 | __ ECMAToInt32(input_reg, double_scratch2, |
| 5040 | scratch1, scratch2, scratch3, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5041 | |
| 5042 | } else { |
| 5043 | // Deoptimize if we don't have a heap number. |
| 5044 | DeoptimizeIf(ne, instr->environment()); |
| 5045 | |
| 5046 | __ sub(ip, input_reg, Operand(kHeapObjectTag)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5047 | __ vldr(double_scratch, ip, HeapNumber::kValueOffset); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5048 | __ TryDoubleToInt32Exact(input_reg, double_scratch, double_scratch2); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5049 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5050 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5051 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5052 | __ cmp(input_reg, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5053 | __ b(ne, &done); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5054 | __ vmov(scratch1, double_scratch.high()); |
| 5055 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5056 | DeoptimizeIf(ne, instr->environment()); |
| 5057 | } |
| 5058 | } |
| 5059 | __ bind(&done); |
| 5060 | } |
| 5061 | |
| 5062 | |
| 5063 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5064 | class DeferredTaggedToI: public LDeferredCode { |
| 5065 | public: |
| 5066 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 5067 | : LDeferredCode(codegen), instr_(instr) { } |
| 5068 | virtual void Generate() { codegen()->DoDeferredTaggedToI(instr_); } |
| 5069 | virtual LInstruction* instr() { return instr_; } |
| 5070 | private: |
| 5071 | LTaggedToI* instr_; |
| 5072 | }; |
| 5073 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5074 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5075 | ASSERT(input->IsRegister()); |
| 5076 | ASSERT(input->Equals(instr->result())); |
| 5077 | |
| 5078 | Register input_reg = ToRegister(input); |
| 5079 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5080 | DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5081 | |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 5082 | // Optimistically untag the input. |
| 5083 | // If the input is a HeapObject, SmiUntag will set the carry flag. |
| 5084 | __ SmiUntag(input_reg, SetCC); |
| 5085 | // Branch to deferred code if the input was tagged. |
| 5086 | // The deferred code will take care of restoring the tag. |
| 5087 | __ b(cs, deferred->entry()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5088 | __ bind(deferred->exit()); |
| 5089 | } |
| 5090 | |
| 5091 | |
| 5092 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5093 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5094 | ASSERT(input->IsRegister()); |
| 5095 | LOperand* result = instr->result(); |
| 5096 | ASSERT(result->IsDoubleRegister()); |
| 5097 | |
| 5098 | Register input_reg = ToRegister(input); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5099 | DwVfpRegister result_reg = ToDoubleRegister(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5100 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5101 | NumberUntagDMode mode = NUMBER_CANDIDATE_IS_ANY_TAGGED; |
| 5102 | HValue* value = instr->hydrogen()->value(); |
| 5103 | if (value->type().IsSmi()) { |
| 5104 | if (value->IsLoadKeyed()) { |
| 5105 | HLoadKeyed* load = HLoadKeyed::cast(value); |
| 5106 | if (load->UsesMustHandleHole()) { |
| 5107 | if (load->hole_mode() == ALLOW_RETURN_HOLE) { |
| 5108 | mode = NUMBER_CANDIDATE_IS_SMI_CONVERT_HOLE; |
| 5109 | } else { |
| 5110 | mode = NUMBER_CANDIDATE_IS_SMI_OR_HOLE; |
| 5111 | } |
| 5112 | } else { |
| 5113 | mode = NUMBER_CANDIDATE_IS_SMI; |
| 5114 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5115 | } else { |
| 5116 | mode = NUMBER_CANDIDATE_IS_SMI; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5117 | } |
| 5118 | } |
| 5119 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5120 | EmitNumberUntagD(input_reg, result_reg, |
| 5121 | instr->hydrogen()->deoptimize_on_undefined(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5122 | instr->hydrogen()->deoptimize_on_minus_zero(), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5123 | instr->environment(), |
| 5124 | mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | |
| 5128 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5129 | Register result_reg = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5130 | Register scratch1 = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5131 | Register scratch2 = ToRegister(instr->temp()); |
| 5132 | DwVfpRegister double_input = ToDoubleRegister(instr->value()); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 5133 | DwVfpRegister double_scratch = double_scratch0(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5134 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5135 | Label done; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 5136 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5137 | if (instr->truncating()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5138 | Register scratch3 = ToRegister(instr->temp2()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5139 | __ ECMAToInt32(result_reg, double_input, |
| 5140 | scratch1, scratch2, scratch3, double_scratch); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5141 | } else { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5142 | __ TryDoubleToInt32Exact(result_reg, double_input, double_scratch); |
| 5143 | // Deoptimize if the input wasn't a int32 (inside a double). |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5144 | DeoptimizeIf(ne, instr->environment()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5145 | } |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5146 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | |
| 5150 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5151 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5152 | __ tst(ToRegister(input), Operand(kSmiTagMask)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5153 | DeoptimizeIf(ne, instr->environment()); |
| 5154 | } |
| 5155 | |
| 5156 | |
| 5157 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5158 | LOperand* input = instr->value(); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5159 | __ tst(ToRegister(input), Operand(kSmiTagMask)); |
| 5160 | DeoptimizeIf(eq, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | |
| 5164 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5165 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5166 | Register scratch = scratch0(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5167 | |
| 5168 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5169 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5170 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5171 | if (instr->hydrogen()->is_interval_check()) { |
| 5172 | InstanceType first; |
| 5173 | InstanceType last; |
| 5174 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 5175 | |
| 5176 | __ cmp(scratch, Operand(first)); |
| 5177 | |
| 5178 | // If there is only one type in the interval check for equality. |
| 5179 | if (first == last) { |
| 5180 | DeoptimizeIf(ne, instr->environment()); |
| 5181 | } else { |
| 5182 | DeoptimizeIf(lo, instr->environment()); |
| 5183 | // Omit check for the last type. |
| 5184 | if (last != LAST_TYPE) { |
| 5185 | __ cmp(scratch, Operand(last)); |
| 5186 | DeoptimizeIf(hi, instr->environment()); |
| 5187 | } |
| 5188 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5189 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5190 | uint8_t mask; |
| 5191 | uint8_t tag; |
| 5192 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 5193 | |
| 5194 | if (IsPowerOf2(mask)) { |
| 5195 | ASSERT(tag == 0 || IsPowerOf2(tag)); |
| 5196 | __ tst(scratch, Operand(mask)); |
| 5197 | DeoptimizeIf(tag == 0 ? ne : eq, instr->environment()); |
| 5198 | } else { |
| 5199 | __ and_(scratch, scratch, Operand(mask)); |
| 5200 | __ cmp(scratch, Operand(tag)); |
| 5201 | DeoptimizeIf(ne, instr->environment()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5202 | } |
| 5203 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | |
| 5207 | void LCodeGen::DoCheckFunction(LCheckFunction* instr) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5208 | Register reg = ToRegister(instr->value()); |
| 5209 | Handle<JSFunction> target = instr->hydrogen()->target(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5210 | ALLOW_HANDLE_DEREF(isolate(), "smi check"); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5211 | if (isolate()->heap()->InNewSpace(*target)) { |
| 5212 | Register reg = ToRegister(instr->value()); |
| 5213 | Handle<JSGlobalPropertyCell> cell = |
| 5214 | isolate()->factory()->NewJSGlobalPropertyCell(target); |
| 5215 | __ mov(ip, Operand(Handle<Object>(cell))); |
| 5216 | __ ldr(ip, FieldMemOperand(ip, JSGlobalPropertyCell::kValueOffset)); |
| 5217 | __ cmp(reg, ip); |
| 5218 | } else { |
| 5219 | __ cmp(reg, Operand(target)); |
| 5220 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5221 | DeoptimizeIf(ne, instr->environment()); |
| 5222 | } |
| 5223 | |
| 5224 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5225 | void LCodeGen::DoCheckMapCommon(Register map_reg, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5226 | Handle<Map> map, |
| 5227 | CompareMapMode mode, |
| 5228 | LEnvironment* env) { |
| 5229 | Label success; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5230 | __ CompareMap(map_reg, map, &success, mode); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5231 | DeoptimizeIf(ne, env); |
| 5232 | __ bind(&success); |
| 5233 | } |
| 5234 | |
| 5235 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5236 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5237 | Register map_reg = scratch0(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5238 | LOperand* input = instr->value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5239 | ASSERT(input->IsRegister()); |
| 5240 | Register reg = ToRegister(input); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5241 | |
| 5242 | Label success; |
| 5243 | SmallMapList* map_set = instr->hydrogen()->map_set(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5244 | __ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5245 | for (int i = 0; i < map_set->length() - 1; i++) { |
| 5246 | Handle<Map> map = map_set->at(i); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5247 | __ CompareMap(map_reg, map, &success, REQUIRE_EXACT_MAP); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5248 | __ b(eq, &success); |
| 5249 | } |
| 5250 | Handle<Map> map = map_set->last(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5251 | DoCheckMapCommon(map_reg, map, REQUIRE_EXACT_MAP, instr->environment()); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5252 | __ bind(&success); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5256 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5257 | DwVfpRegister value_reg = ToDoubleRegister(instr->unclamped()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5258 | Register result_reg = ToRegister(instr->result()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5259 | DwVfpRegister temp_reg = ToDoubleRegister(instr->temp()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5260 | __ ClampDoubleToUint8(result_reg, value_reg, temp_reg); |
| 5261 | } |
| 5262 | |
| 5263 | |
| 5264 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5265 | Register unclamped_reg = ToRegister(instr->unclamped()); |
| 5266 | Register result_reg = ToRegister(instr->result()); |
| 5267 | __ ClampUint8(result_reg, unclamped_reg); |
| 5268 | } |
| 5269 | |
| 5270 | |
| 5271 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 5272 | Register scratch = scratch0(); |
| 5273 | Register input_reg = ToRegister(instr->unclamped()); |
| 5274 | Register result_reg = ToRegister(instr->result()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5275 | DwVfpRegister temp_reg = ToDoubleRegister(instr->temp()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5276 | Label is_smi, done, heap_number; |
| 5277 | |
| 5278 | // Both smi and heap number cases are handled. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5279 | __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5280 | |
| 5281 | // Check for heap number |
| 5282 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 5283 | __ cmp(scratch, Operand(factory()->heap_number_map())); |
| 5284 | __ b(eq, &heap_number); |
| 5285 | |
| 5286 | // Check for undefined. Undefined is converted to zero for clamping |
| 5287 | // conversions. |
| 5288 | __ cmp(input_reg, Operand(factory()->undefined_value())); |
| 5289 | DeoptimizeIf(ne, instr->environment()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5290 | __ mov(result_reg, Operand::Zero()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5291 | __ jmp(&done); |
| 5292 | |
| 5293 | // Heap number |
| 5294 | __ bind(&heap_number); |
| 5295 | __ vldr(double_scratch0(), FieldMemOperand(input_reg, |
| 5296 | HeapNumber::kValueOffset)); |
| 5297 | __ ClampDoubleToUint8(result_reg, double_scratch0(), temp_reg); |
| 5298 | __ jmp(&done); |
| 5299 | |
| 5300 | // smi |
| 5301 | __ bind(&is_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5302 | __ ClampUint8(result_reg, result_reg); |
| 5303 | |
| 5304 | __ bind(&done); |
| 5305 | } |
| 5306 | |
| 5307 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5308 | void LCodeGen::DoCheckPrototypeMaps(LCheckPrototypeMaps* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5309 | Register prototype_reg = ToRegister(instr->temp()); |
| 5310 | Register map_reg = ToRegister(instr->temp2()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5311 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 5312 | ZoneList<Handle<JSObject> >* prototypes = instr->prototypes(); |
| 5313 | ZoneList<Handle<Map> >* maps = instr->maps(); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5314 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 5315 | ASSERT(prototypes->length() == maps->length()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5316 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 5317 | if (instr->hydrogen()->CanOmitPrototypeChecks()) { |
| 5318 | for (int i = 0; i < maps->length(); i++) { |
| 5319 | prototype_maps_.Add(maps->at(i), info()->zone()); |
| 5320 | } |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 5321 | } else { |
| 5322 | for (int i = 0; i < prototypes->length(); i++) { |
| 5323 | __ LoadHeapObject(prototype_reg, prototypes->at(i)); |
| 5324 | __ ldr(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); |
| 5325 | DoCheckMapCommon(map_reg, |
| 5326 | maps->at(i), |
| 5327 | ALLOW_ELEMENT_TRANSITION_MAPS, |
| 5328 | instr->environment()); |
| 5329 | } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5330 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5334 | void LCodeGen::DoAllocateObject(LAllocateObject* instr) { |
| 5335 | class DeferredAllocateObject: public LDeferredCode { |
| 5336 | public: |
| 5337 | DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
| 5338 | : LDeferredCode(codegen), instr_(instr) { } |
| 5339 | virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
| 5340 | virtual LInstruction* instr() { return instr_; } |
| 5341 | private: |
| 5342 | LAllocateObject* instr_; |
| 5343 | }; |
| 5344 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5345 | DeferredAllocateObject* deferred = |
| 5346 | new(zone()) DeferredAllocateObject(this, instr); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5347 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5348 | Register result = ToRegister(instr->result()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5349 | Register scratch = ToRegister(instr->temp()); |
| 5350 | Register scratch2 = ToRegister(instr->temp2()); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5351 | Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5352 | Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5353 | int instance_size = initial_map->instance_size(); |
| 5354 | ASSERT(initial_map->pre_allocated_property_fields() + |
| 5355 | initial_map->unused_property_fields() - |
| 5356 | initial_map->inobject_properties() == 0); |
| 5357 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5358 | __ Allocate(instance_size, result, scratch, scratch2, deferred->entry(), |
| 5359 | TAG_OBJECT); |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5360 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5361 | __ bind(deferred->exit()); |
| 5362 | if (FLAG_debug_code) { |
| 5363 | Label is_in_new_space; |
| 5364 | __ JumpIfInNewSpace(result, scratch, &is_in_new_space); |
| 5365 | __ Abort("Allocated object is not in new-space"); |
| 5366 | __ bind(&is_in_new_space); |
| 5367 | } |
| 5368 | |
fschneider@chromium.org | 35814e5 | 2012-03-01 15:43:35 +0000 | [diff] [blame] | 5369 | // Load the initial map. |
| 5370 | Register map = scratch; |
| 5371 | __ LoadHeapObject(map, constructor); |
| 5372 | __ ldr(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5373 | |
| 5374 | // Initialize map and fields of the newly allocated object. |
| 5375 | ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); |
| 5376 | __ str(map, FieldMemOperand(result, JSObject::kMapOffset)); |
| 5377 | __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); |
| 5378 | __ str(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); |
| 5379 | __ str(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); |
| 5380 | if (initial_map->inobject_properties() != 0) { |
| 5381 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5382 | for (int i = 0; i < initial_map->inobject_properties(); i++) { |
| 5383 | int property_offset = JSObject::kHeaderSize + i * kPointerSize; |
| 5384 | __ str(scratch, FieldMemOperand(result, property_offset)); |
| 5385 | } |
| 5386 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | |
| 5390 | void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
| 5391 | Register result = ToRegister(instr->result()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5392 | Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5393 | int instance_size = initial_map->instance_size(); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5394 | |
| 5395 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5396 | // result register contain a valid pointer because it is already |
| 5397 | // contained in the register pointer map. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5398 | __ mov(result, Operand::Zero()); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5399 | |
| 5400 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5401 | __ mov(r0, Operand(Smi::FromInt(instance_size))); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5402 | __ push(r0); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5403 | CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5404 | __ StoreToSafepointRegisterSlot(r0, result); |
| 5405 | } |
| 5406 | |
| 5407 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5408 | void LCodeGen::DoAllocate(LAllocate* instr) { |
| 5409 | class DeferredAllocate: public LDeferredCode { |
| 5410 | public: |
| 5411 | DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5412 | : LDeferredCode(codegen), instr_(instr) { } |
| 5413 | virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
| 5414 | virtual LInstruction* instr() { return instr_; } |
| 5415 | private: |
| 5416 | LAllocate* instr_; |
| 5417 | }; |
| 5418 | |
| 5419 | DeferredAllocate* deferred = |
| 5420 | new(zone()) DeferredAllocate(this, instr); |
| 5421 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5422 | Register result = ToRegister(instr->result()); |
| 5423 | Register scratch = ToRegister(instr->temp1()); |
| 5424 | Register scratch2 = ToRegister(instr->temp2()); |
| 5425 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5426 | // Allocate memory for the object. |
| 5427 | AllocationFlags flags = TAG_OBJECT; |
| 5428 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 5429 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 5430 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5431 | if (instr->hydrogen()->CanAllocateInOldPointerSpace()) { |
| 5432 | flags = static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE); |
| 5433 | } |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5434 | if (instr->size()->IsConstantOperand()) { |
| 5435 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5436 | __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5437 | } else { |
| 5438 | Register size = ToRegister(instr->size()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5439 | __ Allocate(size, |
| 5440 | result, |
| 5441 | scratch, |
| 5442 | scratch2, |
| 5443 | deferred->entry(), |
| 5444 | flags); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | __ bind(deferred->exit()); |
| 5448 | } |
| 5449 | |
| 5450 | |
| 5451 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5452 | Register result = ToRegister(instr->result()); |
| 5453 | |
| 5454 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5455 | // result register contain a valid pointer because it is already |
| 5456 | // contained in the register pointer map. |
| 5457 | __ mov(result, Operand(Smi::FromInt(0))); |
| 5458 | |
| 5459 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5460 | if (instr->size()->IsRegister()) { |
| 5461 | Register size = ToRegister(instr->size()); |
| 5462 | ASSERT(!size.is(result)); |
| 5463 | __ SmiTag(size); |
| 5464 | __ push(size); |
| 5465 | } else { |
| 5466 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5467 | __ Push(Smi::FromInt(size)); |
| 5468 | } |
| 5469 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5470 | if (instr->hydrogen()->CanAllocateInOldPointerSpace()) { |
| 5471 | CallRuntimeFromDeferred( |
| 5472 | Runtime::kAllocateInOldPointerSpace, 1, instr); |
| 5473 | } else { |
| 5474 | CallRuntimeFromDeferred( |
| 5475 | Runtime::kAllocateInNewSpace, 1, instr); |
| 5476 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 5477 | __ StoreToSafepointRegisterSlot(r0, result); |
| 5478 | } |
| 5479 | |
| 5480 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5481 | void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5482 | Handle<FixedArray> literals = instr->hydrogen()->literals(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5483 | ElementsKind boilerplate_elements_kind = |
| 5484 | instr->hydrogen()->boilerplate_elements_kind(); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5485 | AllocationSiteMode allocation_site_mode = |
| 5486 | instr->hydrogen()->allocation_site_mode(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5487 | |
| 5488 | // Deopt if the array literal boilerplate ElementsKind is of a type different |
| 5489 | // 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] | 5490 | // already been converted to TERMINAL_FAST_ELEMENTS_KIND. |
| 5491 | if (CanTransitionToMoreGeneralFastElementsKind( |
| 5492 | boilerplate_elements_kind, true)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5493 | __ LoadHeapObject(r1, instr->hydrogen()->boilerplate_object()); |
| 5494 | // Load map into r2. |
| 5495 | __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 5496 | // Load the map's "bit field 2". |
| 5497 | __ ldrb(r2, FieldMemOperand(r2, Map::kBitField2Offset)); |
| 5498 | // Retrieve elements_kind from bit field 2. |
| 5499 | __ ubfx(r2, r2, Map::kElementsKindShift, Map::kElementsKindBitCount); |
| 5500 | __ cmp(r2, Operand(boilerplate_elements_kind)); |
| 5501 | DeoptimizeIf(ne, instr->environment()); |
| 5502 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5503 | |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5504 | // Set up the parameters to the stub/runtime call. |
| 5505 | __ LoadHeapObject(r3, literals); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5506 | __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5507 | // Boilerplate already exists, constant elements are never accessed. |
| 5508 | // Pass an empty fixed array. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5509 | __ mov(r1, Operand(isolate()->factory()->empty_fixed_array())); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5510 | |
| 5511 | // Pick the right runtime function or stub to call. |
| 5512 | int length = instr->hydrogen()->length(); |
| 5513 | if (instr->hydrogen()->IsCopyOnWrite()) { |
| 5514 | ASSERT(instr->hydrogen()->depth() == 1); |
| 5515 | FastCloneShallowArrayStub::Mode mode = |
| 5516 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5517 | FastCloneShallowArrayStub stub(mode, DONT_TRACK_ALLOCATION_SITE, length); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5518 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5519 | } else if (instr->hydrogen()->depth() > 1) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5520 | __ Push(r3, r2, r1); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5521 | CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); |
| 5522 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5523 | __ Push(r3, r2, r1); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5524 | CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); |
| 5525 | } else { |
| 5526 | FastCloneShallowArrayStub::Mode mode = |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5527 | boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5528 | ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 5529 | : FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 5530 | FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5531 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5532 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 5536 | void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5537 | Handle<FixedArray> literals = instr->hydrogen()->literals(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5538 | Handle<FixedArray> constant_properties = |
| 5539 | instr->hydrogen()->constant_properties(); |
| 5540 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5541 | // Set up the parameters to the stub/runtime call. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5542 | __ LoadHeapObject(r3, literals); |
| 5543 | __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 5544 | __ mov(r1, Operand(constant_properties)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5545 | int flags = instr->hydrogen()->fast_elements() |
| 5546 | ? ObjectLiteral::kFastElements |
| 5547 | : ObjectLiteral::kNoFlags; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5548 | __ mov(r0, Operand(Smi::FromInt(flags))); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5549 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5550 | // Pick the right runtime function or stub to call. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5551 | int properties_count = instr->hydrogen()->constant_properties_length() / 2; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 5552 | if ((FLAG_track_double_fields && instr->hydrogen()->may_store_doubles()) || |
| 5553 | instr->hydrogen()->depth() > 1) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5554 | __ Push(r3, r2, r1, r0); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5555 | CallRuntime(Runtime::kCreateObjectLiteral, 4, instr); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5556 | } else if (flags != ObjectLiteral::kFastElements || |
| 5557 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 5558 | __ Push(r3, r2, r1, r0); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5559 | CallRuntime(Runtime::kCreateObjectLiteralShallow, 4, instr); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5560 | } else { |
| 5561 | FastCloneShallowObjectStub stub(properties_count); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5562 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5563 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5564 | } |
| 5565 | |
| 5566 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5567 | void LCodeGen::DoToFastProperties(LToFastProperties* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5568 | ASSERT(ToRegister(instr->value()).is(r0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5569 | __ push(r0); |
| 5570 | CallRuntime(Runtime::kToFastProperties, 1, instr); |
| 5571 | } |
| 5572 | |
| 5573 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5574 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5575 | Label materialized; |
| 5576 | // Registers will be used as follows: |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5577 | // r7 = literals array. |
| 5578 | // r1 = regexp literal. |
| 5579 | // r0 = regexp literal clone. |
| 5580 | // r2 and r4-r6 are used as temporaries. |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 5581 | int literal_offset = |
| 5582 | FixedArray::OffsetOfElementAt(instr->hydrogen()->literal_index()); |
| 5583 | __ LoadHeapObject(r7, instr->hydrogen()->literals()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5584 | __ ldr(r1, FieldMemOperand(r7, literal_offset)); |
| 5585 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5586 | __ cmp(r1, ip); |
| 5587 | __ b(ne, &materialized); |
| 5588 | |
| 5589 | // Create regexp literal using runtime function |
| 5590 | // Result will be in r0. |
| 5591 | __ mov(r6, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 5592 | __ mov(r5, Operand(instr->hydrogen()->pattern())); |
| 5593 | __ mov(r4, Operand(instr->hydrogen()->flags())); |
| 5594 | __ Push(r7, r6, r5, r4); |
| 5595 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
| 5596 | __ mov(r1, r0); |
| 5597 | |
| 5598 | __ bind(&materialized); |
| 5599 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 5600 | Label allocated, runtime_allocate; |
| 5601 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 5602 | __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5603 | __ jmp(&allocated); |
| 5604 | |
| 5605 | __ bind(&runtime_allocate); |
| 5606 | __ mov(r0, Operand(Smi::FromInt(size))); |
| 5607 | __ Push(r1, r0); |
| 5608 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 5609 | __ pop(r1); |
| 5610 | |
| 5611 | __ bind(&allocated); |
| 5612 | // Copy the content into the newly allocated memory. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5613 | __ CopyFields(r0, r1, double_scratch0(), double_scratch0().low(), |
| 5614 | size / kPointerSize); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | |
| 5618 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5619 | // Use the fast case closure allocation code that allocates in new |
| 5620 | // space for nested functions that don't need literals cloning. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5621 | bool pretenure = instr->hydrogen()->pretenure(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5622 | if (!pretenure && instr->hydrogen()->has_no_literals()) { |
| 5623 | FastNewClosureStub stub(instr->hydrogen()->language_mode(), |
| 5624 | instr->hydrogen()->is_generator()); |
| 5625 | __ mov(r1, Operand(instr->hydrogen()->shared_info())); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5626 | __ push(r1); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5627 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5628 | } else { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5629 | __ mov(r2, Operand(instr->hydrogen()->shared_info())); |
| 5630 | __ mov(r1, Operand(pretenure ? factory()->true_value() |
| 5631 | : factory()->false_value())); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5632 | __ Push(cp, r2, r1); |
| 5633 | CallRuntime(Runtime::kNewClosure, 3, instr); |
| 5634 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | |
| 5638 | void LCodeGen::DoTypeof(LTypeof* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5639 | Register input = ToRegister(instr->value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5640 | __ push(input); |
| 5641 | CallRuntime(Runtime::kTypeof, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5645 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5646 | Register input = ToRegister(instr->value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5647 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 5648 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 5649 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 5650 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 5651 | |
| 5652 | Condition final_branch_condition = EmitTypeofIs(true_label, |
| 5653 | false_label, |
| 5654 | input, |
| 5655 | instr->type_literal()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5656 | if (final_branch_condition != kNoCondition) { |
| 5657 | EmitBranch(true_block, false_block, final_branch_condition); |
| 5658 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | |
| 5662 | Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 5663 | Label* false_label, |
| 5664 | Register input, |
| 5665 | Handle<String> type_name) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5666 | Condition final_branch_condition = kNoCondition; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 5667 | Register scratch = scratch0(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5668 | if (type_name->Equals(heap()->number_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5669 | __ JumpIfSmi(input, true_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5670 | __ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5671 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 5672 | __ cmp(input, Operand(ip)); |
| 5673 | final_branch_condition = eq; |
| 5674 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5675 | } else if (type_name->Equals(heap()->string_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5676 | __ JumpIfSmi(input, false_label); |
| 5677 | __ CompareObjectType(input, input, scratch, FIRST_NONSTRING_TYPE); |
| 5678 | __ b(ge, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5679 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 5680 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5681 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5682 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5683 | } else if (type_name->Equals(heap()->symbol_string())) { |
| 5684 | __ JumpIfSmi(input, false_label); |
| 5685 | __ CompareObjectType(input, input, scratch, SYMBOL_TYPE); |
| 5686 | final_branch_condition = eq; |
| 5687 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5688 | } else if (type_name->Equals(heap()->boolean_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5689 | __ CompareRoot(input, Heap::kTrueValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5690 | __ b(eq, true_label); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5691 | __ CompareRoot(input, Heap::kFalseValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5692 | final_branch_condition = eq; |
| 5693 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5694 | } else if (FLAG_harmony_typeof && type_name->Equals(heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5695 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5696 | final_branch_condition = eq; |
| 5697 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5698 | } else if (type_name->Equals(heap()->undefined_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5699 | __ CompareRoot(input, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5700 | __ b(eq, true_label); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5701 | __ JumpIfSmi(input, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5702 | // Check for undetectable objects => true. |
| 5703 | __ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5704 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 5705 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 5706 | final_branch_condition = ne; |
| 5707 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5708 | } else if (type_name->Equals(heap()->function_string())) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5709 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5710 | __ JumpIfSmi(input, false_label); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5711 | __ CompareObjectType(input, scratch, input, JS_FUNCTION_TYPE); |
| 5712 | __ b(eq, true_label); |
| 5713 | __ cmp(input, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 5714 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5715 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5716 | } else if (type_name->Equals(heap()->object_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5717 | __ JumpIfSmi(input, false_label); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5718 | if (!FLAG_harmony_typeof) { |
| 5719 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5720 | __ b(eq, true_label); |
| 5721 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5722 | __ CompareObjectType(input, input, scratch, |
| 5723 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5724 | __ b(lt, false_label); |
| 5725 | __ CompareInstanceType(input, scratch, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 5726 | __ b(gt, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5727 | // Check for undetectable objects => false. |
| 5728 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 5729 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 5730 | final_branch_condition = eq; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5731 | |
| 5732 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5733 | __ b(false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | return final_branch_condition; |
| 5737 | } |
| 5738 | |
| 5739 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5740 | void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5741 | Register temp1 = ToRegister(instr->temp()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5742 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 5743 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 5744 | |
| 5745 | EmitIsConstructCall(temp1, scratch0()); |
| 5746 | EmitBranch(true_block, false_block, eq); |
| 5747 | } |
| 5748 | |
| 5749 | |
| 5750 | void LCodeGen::EmitIsConstructCall(Register temp1, Register temp2) { |
| 5751 | ASSERT(!temp1.is(temp2)); |
| 5752 | // Get the frame pointer for the calling frame. |
| 5753 | __ ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5754 | |
| 5755 | // Skip the arguments adaptor frame if it exists. |
| 5756 | Label check_frame_marker; |
| 5757 | __ ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset)); |
| 5758 | __ cmp(temp2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5759 | __ b(ne, &check_frame_marker); |
| 5760 | __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset)); |
| 5761 | |
| 5762 | // Check the marker in the calling frame. |
| 5763 | __ bind(&check_frame_marker); |
| 5764 | __ ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset)); |
| 5765 | __ cmp(temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
| 5766 | } |
| 5767 | |
| 5768 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5769 | void LCodeGen::EnsureSpaceForLazyDeopt() { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5770 | if (info()->IsStub()) return; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5771 | // Ensure that we have enough space after the previous lazy-bailout |
| 5772 | // instruction for patching the code here. |
| 5773 | int current_pc = masm()->pc_offset(); |
| 5774 | int patch_size = Deoptimizer::patch_size(); |
| 5775 | if (current_pc < last_lazy_deopt_pc_ + patch_size) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5776 | // Block literal pool emission for duration of padding. |
| 5777 | Assembler::BlockConstPoolScope block_const_pool(masm()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5778 | int padding_size = last_lazy_deopt_pc_ + patch_size - current_pc; |
| 5779 | ASSERT_EQ(0, padding_size % Assembler::kInstrSize); |
| 5780 | while (padding_size > 0) { |
| 5781 | __ nop(); |
| 5782 | padding_size -= Assembler::kInstrSize; |
| 5783 | } |
| 5784 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5785 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5789 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5790 | EnsureSpaceForLazyDeopt(); |
| 5791 | ASSERT(instr->HasEnvironment()); |
| 5792 | LEnvironment* env = instr->environment(); |
| 5793 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5794 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | |
| 5798 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5799 | DeoptimizeIf(al, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5803 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 5804 | // Nothing to see here, move on! |
| 5805 | } |
| 5806 | |
| 5807 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5808 | void LCodeGen::DoDeleteProperty(LDeleteProperty* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5809 | Register object = ToRegister(instr->object()); |
| 5810 | Register key = ToRegister(instr->key()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5811 | Register strict = scratch0(); |
| 5812 | __ mov(strict, Operand(Smi::FromInt(strict_mode_flag()))); |
| 5813 | __ Push(object, key, strict); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 5814 | ASSERT(instr->HasPointerMap()); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 5815 | LPointerMap* pointers = instr->pointer_map(); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 5816 | RecordPosition(pointers->position()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5817 | SafepointGenerator safepoint_generator( |
| 5818 | this, pointers, Safepoint::kLazyDeopt); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5819 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, safepoint_generator); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5820 | } |
| 5821 | |
| 5822 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5823 | void LCodeGen::DoIn(LIn* instr) { |
| 5824 | Register obj = ToRegister(instr->object()); |
| 5825 | Register key = ToRegister(instr->key()); |
| 5826 | __ Push(key, obj); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 5827 | ASSERT(instr->HasPointerMap()); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5828 | LPointerMap* pointers = instr->pointer_map(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5829 | RecordPosition(pointers->position()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5830 | SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5831 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5835 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5836 | PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 5837 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 5838 | RecordSafepointWithLazyDeopt( |
| 5839 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 5840 | ASSERT(instr->HasEnvironment()); |
| 5841 | LEnvironment* env = instr->environment(); |
| 5842 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5846 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5847 | class DeferredStackCheck: public LDeferredCode { |
| 5848 | public: |
| 5849 | DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
| 5850 | : LDeferredCode(codegen), instr_(instr) { } |
| 5851 | virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5852 | virtual LInstruction* instr() { return instr_; } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5853 | private: |
| 5854 | LStackCheck* instr_; |
| 5855 | }; |
| 5856 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5857 | ASSERT(instr->HasEnvironment()); |
| 5858 | LEnvironment* env = instr->environment(); |
| 5859 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 5860 | // prepare for lazy deoptimization explicitly here. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5861 | if (instr->hydrogen()->is_function_entry()) { |
| 5862 | // Perform stack overflow check. |
| 5863 | Label done; |
| 5864 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 5865 | __ cmp(sp, Operand(ip)); |
| 5866 | __ b(hs, &done); |
| 5867 | StackCheckStub stub; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5868 | PredictableCodeSizeScope predictable(masm_, 2 * Assembler::kInstrSize); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5869 | CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5870 | EnsureSpaceForLazyDeopt(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5871 | __ bind(&done); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5872 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5873 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5874 | } else { |
| 5875 | ASSERT(instr->hydrogen()->is_backwards_branch()); |
| 5876 | // Perform stack overflow check if this goto needs it before jumping. |
| 5877 | DeferredStackCheck* deferred_stack_check = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5878 | new(zone()) DeferredStackCheck(this, instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5879 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 5880 | __ cmp(sp, Operand(ip)); |
| 5881 | __ b(lo, deferred_stack_check->entry()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5882 | EnsureSpaceForLazyDeopt(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5883 | __ bind(instr->done_label()); |
| 5884 | deferred_stack_check->SetExit(instr->done_label()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5885 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5886 | // Don't record a deoptimization index for the safepoint here. |
| 5887 | // This will be done explicitly when emitting call and the safepoint in |
| 5888 | // the deferred code. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 5889 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | |
| 5893 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 5894 | // This is a pseudo-instruction that ensures that the environment here is |
| 5895 | // properly registered for deoptimization and records the assembler's PC |
| 5896 | // offset. |
| 5897 | LEnvironment* environment = instr->environment(); |
| 5898 | environment->SetSpilledRegisters(instr->SpilledRegisterArray(), |
| 5899 | instr->SpilledDoubleRegisterArray()); |
| 5900 | |
| 5901 | // If the environment were already registered, we would have no way of |
| 5902 | // backpatching it with the spill slot operands. |
| 5903 | ASSERT(!environment->HasBeenRegistered()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 5904 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 5905 | ASSERT(osr_pc_offset_ == -1); |
| 5906 | osr_pc_offset_ = masm()->pc_offset(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5907 | } |
| 5908 | |
| 5909 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5910 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
| 5911 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5912 | __ cmp(r0, ip); |
| 5913 | DeoptimizeIf(eq, instr->environment()); |
| 5914 | |
| 5915 | Register null_value = r5; |
| 5916 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 5917 | __ cmp(r0, null_value); |
| 5918 | DeoptimizeIf(eq, instr->environment()); |
| 5919 | |
| 5920 | __ tst(r0, Operand(kSmiTagMask)); |
| 5921 | DeoptimizeIf(eq, instr->environment()); |
| 5922 | |
| 5923 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 5924 | __ CompareObjectType(r0, r1, r1, LAST_JS_PROXY_TYPE); |
| 5925 | DeoptimizeIf(le, instr->environment()); |
| 5926 | |
| 5927 | Label use_cache, call_runtime; |
| 5928 | __ CheckEnumCache(null_value, &call_runtime); |
| 5929 | |
| 5930 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5931 | __ b(&use_cache); |
| 5932 | |
| 5933 | // Get the set of properties to enumerate. |
| 5934 | __ bind(&call_runtime); |
| 5935 | __ push(r0); |
| 5936 | CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr); |
| 5937 | |
| 5938 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5939 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 5940 | __ cmp(r1, ip); |
| 5941 | DeoptimizeIf(ne, instr->environment()); |
| 5942 | __ bind(&use_cache); |
| 5943 | } |
| 5944 | |
| 5945 | |
| 5946 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5947 | Register map = ToRegister(instr->map()); |
| 5948 | Register result = ToRegister(instr->result()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5949 | Label load_cache, done; |
| 5950 | __ EnumLength(result, map); |
| 5951 | __ cmp(result, Operand(Smi::FromInt(0))); |
| 5952 | __ b(ne, &load_cache); |
| 5953 | __ mov(result, Operand(isolate()->factory()->empty_fixed_array())); |
| 5954 | __ jmp(&done); |
| 5955 | |
| 5956 | __ bind(&load_cache); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5957 | __ LoadInstanceDescriptors(map, result); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5958 | __ ldr(result, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 5959 | FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5960 | __ ldr(result, |
| 5961 | FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5962 | __ cmp(result, Operand::Zero()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5963 | DeoptimizeIf(eq, instr->environment()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5964 | |
| 5965 | __ bind(&done); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | |
| 5969 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5970 | Register object = ToRegister(instr->value()); |
| 5971 | Register map = ToRegister(instr->map()); |
| 5972 | __ ldr(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5973 | __ cmp(map, scratch0()); |
| 5974 | DeoptimizeIf(ne, instr->environment()); |
| 5975 | } |
| 5976 | |
| 5977 | |
| 5978 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 5979 | Register object = ToRegister(instr->object()); |
| 5980 | Register index = ToRegister(instr->index()); |
| 5981 | Register result = ToRegister(instr->result()); |
| 5982 | Register scratch = scratch0(); |
| 5983 | |
| 5984 | Label out_of_object, done; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5985 | __ cmp(index, Operand::Zero()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 5986 | __ b(lt, &out_of_object); |
| 5987 | |
| 5988 | STATIC_ASSERT(kPointerSizeLog2 > kSmiTagSize); |
| 5989 | __ add(scratch, object, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5990 | __ ldr(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
| 5991 | |
| 5992 | __ b(&done); |
| 5993 | |
| 5994 | __ bind(&out_of_object); |
| 5995 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 5996 | // Index is equal to negated out of object property index plus 1. |
| 5997 | __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5998 | __ ldr(result, FieldMemOperand(scratch, |
| 5999 | FixedArray::kHeaderSize - kPointerSize)); |
| 6000 | __ bind(&done); |
| 6001 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 6002 | |
| 6003 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6004 | #undef __ |
| 6005 | |
| 6006 | } } // namespace v8::internal |