sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1 | // Copyright 2011 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 | |
| 28 | #include "arm/lithium-codegen-arm.h" |
| 29 | #include "code-stubs.h" |
| 30 | #include "stub-cache.h" |
| 31 | |
| 32 | namespace v8 { |
| 33 | namespace internal { |
| 34 | |
| 35 | |
| 36 | class SafepointGenerator : public PostCallGenerator { |
| 37 | public: |
| 38 | SafepointGenerator(LCodeGen* codegen, |
| 39 | LPointerMap* pointers, |
| 40 | int deoptimization_index) |
| 41 | : codegen_(codegen), |
| 42 | pointers_(pointers), |
| 43 | deoptimization_index_(deoptimization_index) { } |
| 44 | virtual ~SafepointGenerator() { } |
| 45 | |
| 46 | virtual void Generate() { |
| 47 | codegen_->RecordSafepoint(pointers_, deoptimization_index_); |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | LCodeGen* codegen_; |
| 52 | LPointerMap* pointers_; |
| 53 | int deoptimization_index_; |
| 54 | }; |
| 55 | |
| 56 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 57 | class LGapNode: public ZoneObject { |
| 58 | public: |
| 59 | explicit LGapNode(LOperand* operand) |
| 60 | : operand_(operand), resolved_(false), visited_id_(-1) { } |
| 61 | |
| 62 | LOperand* operand() const { return operand_; } |
| 63 | bool IsResolved() const { return !IsAssigned() || resolved_; } |
| 64 | void MarkResolved() { |
| 65 | ASSERT(!IsResolved()); |
| 66 | resolved_ = true; |
| 67 | } |
| 68 | int visited_id() const { return visited_id_; } |
| 69 | void set_visited_id(int id) { |
| 70 | ASSERT(id > visited_id_); |
| 71 | visited_id_ = id; |
| 72 | } |
| 73 | |
| 74 | bool IsAssigned() const { return assigned_from_.is_set(); } |
| 75 | LGapNode* assigned_from() const { return assigned_from_.get(); } |
| 76 | void set_assigned_from(LGapNode* n) { assigned_from_.set(n); } |
| 77 | |
| 78 | private: |
| 79 | LOperand* operand_; |
| 80 | SetOncePointer<LGapNode> assigned_from_; |
| 81 | bool resolved_; |
| 82 | int visited_id_; |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | LGapResolver::LGapResolver() |
| 87 | : nodes_(32), |
| 88 | identified_cycles_(4), |
| 89 | result_(16), |
| 90 | next_visited_id_(0) { |
| 91 | } |
| 92 | |
| 93 | |
| 94 | const ZoneList<LMoveOperands>* LGapResolver::Resolve( |
| 95 | const ZoneList<LMoveOperands>* moves, |
| 96 | LOperand* marker_operand) { |
| 97 | nodes_.Rewind(0); |
| 98 | identified_cycles_.Rewind(0); |
| 99 | result_.Rewind(0); |
| 100 | next_visited_id_ = 0; |
| 101 | |
| 102 | for (int i = 0; i < moves->length(); ++i) { |
| 103 | LMoveOperands move = moves->at(i); |
| 104 | if (!move.IsRedundant()) RegisterMove(move); |
| 105 | } |
| 106 | |
| 107 | for (int i = 0; i < identified_cycles_.length(); ++i) { |
| 108 | ResolveCycle(identified_cycles_[i], marker_operand); |
| 109 | } |
| 110 | |
| 111 | int unresolved_nodes; |
| 112 | do { |
| 113 | unresolved_nodes = 0; |
| 114 | for (int j = 0; j < nodes_.length(); j++) { |
| 115 | LGapNode* node = nodes_[j]; |
| 116 | if (!node->IsResolved() && node->assigned_from()->IsResolved()) { |
| 117 | AddResultMove(node->assigned_from(), node); |
| 118 | node->MarkResolved(); |
| 119 | } |
| 120 | if (!node->IsResolved()) ++unresolved_nodes; |
| 121 | } |
| 122 | } while (unresolved_nodes > 0); |
| 123 | return &result_; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | void LGapResolver::AddResultMove(LGapNode* from, LGapNode* to) { |
| 128 | AddResultMove(from->operand(), to->operand()); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | void LGapResolver::AddResultMove(LOperand* from, LOperand* to) { |
| 133 | result_.Add(LMoveOperands(from, to)); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | void LGapResolver::ResolveCycle(LGapNode* start, LOperand* marker_operand) { |
| 138 | ZoneList<LOperand*> cycle_operands(8); |
| 139 | cycle_operands.Add(marker_operand); |
| 140 | LGapNode* cur = start; |
| 141 | do { |
| 142 | cur->MarkResolved(); |
| 143 | cycle_operands.Add(cur->operand()); |
| 144 | cur = cur->assigned_from(); |
| 145 | } while (cur != start); |
| 146 | cycle_operands.Add(marker_operand); |
| 147 | |
| 148 | for (int i = cycle_operands.length() - 1; i > 0; --i) { |
| 149 | LOperand* from = cycle_operands[i]; |
| 150 | LOperand* to = cycle_operands[i - 1]; |
| 151 | AddResultMove(from, to); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | |
| 156 | bool LGapResolver::CanReach(LGapNode* a, LGapNode* b, int visited_id) { |
| 157 | ASSERT(a != b); |
| 158 | LGapNode* cur = a; |
| 159 | while (cur != b && cur->visited_id() != visited_id && cur->IsAssigned()) { |
| 160 | cur->set_visited_id(visited_id); |
| 161 | cur = cur->assigned_from(); |
| 162 | } |
| 163 | |
| 164 | return cur == b; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | bool LGapResolver::CanReach(LGapNode* a, LGapNode* b) { |
| 169 | ASSERT(a != b); |
| 170 | return CanReach(a, b, next_visited_id_++); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void LGapResolver::RegisterMove(LMoveOperands move) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 175 | if (move.source()->IsConstantOperand()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 176 | // Constant moves should be last in the machine code. Therefore add them |
| 177 | // first to the result set. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 178 | AddResultMove(move.source(), move.destination()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 179 | } else { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 180 | LGapNode* from = LookupNode(move.source()); |
| 181 | LGapNode* to = LookupNode(move.destination()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 182 | if (to->IsAssigned() && to->assigned_from() == from) { |
| 183 | move.Eliminate(); |
| 184 | return; |
| 185 | } |
| 186 | ASSERT(!to->IsAssigned()); |
| 187 | if (CanReach(from, to)) { |
| 188 | // This introduces a cycle. Save. |
| 189 | identified_cycles_.Add(from); |
| 190 | } |
| 191 | to->set_assigned_from(from); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |
| 196 | LGapNode* LGapResolver::LookupNode(LOperand* operand) { |
| 197 | for (int i = 0; i < nodes_.length(); ++i) { |
| 198 | if (nodes_[i]->operand()->Equals(operand)) return nodes_[i]; |
| 199 | } |
| 200 | |
| 201 | // No node found => create a new one. |
| 202 | LGapNode* result = new LGapNode(operand); |
| 203 | nodes_.Add(result); |
| 204 | return result; |
| 205 | } |
| 206 | |
| 207 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 208 | #define __ masm()-> |
| 209 | |
| 210 | bool LCodeGen::GenerateCode() { |
| 211 | HPhase phase("Code generation", chunk()); |
| 212 | ASSERT(is_unused()); |
| 213 | status_ = GENERATING; |
| 214 | CpuFeatures::Scope scope1(VFP3); |
| 215 | CpuFeatures::Scope scope2(ARMv7); |
| 216 | return GeneratePrologue() && |
| 217 | GenerateBody() && |
| 218 | GenerateDeferredCode() && |
| 219 | GenerateSafepointTable(); |
| 220 | } |
| 221 | |
| 222 | |
| 223 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 224 | ASSERT(is_done()); |
| 225 | code->set_stack_slots(StackSlotCount()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 226 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 227 | PopulateDeoptimizationData(code); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | void LCodeGen::Abort(const char* format, ...) { |
| 232 | if (FLAG_trace_bailout) { |
| 233 | SmartPointer<char> debug_name = graph()->debug_name()->ToCString(); |
| 234 | PrintF("Aborting LCodeGen in @\"%s\": ", *debug_name); |
| 235 | va_list arguments; |
| 236 | va_start(arguments, format); |
| 237 | OS::VPrint(format, arguments); |
| 238 | va_end(arguments); |
| 239 | PrintF("\n"); |
| 240 | } |
| 241 | status_ = ABORTED; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | void LCodeGen::Comment(const char* format, ...) { |
| 246 | if (!FLAG_code_comments) return; |
| 247 | char buffer[4 * KB]; |
| 248 | StringBuilder builder(buffer, ARRAY_SIZE(buffer)); |
| 249 | va_list arguments; |
| 250 | va_start(arguments, format); |
| 251 | builder.AddFormattedList(format, arguments); |
| 252 | va_end(arguments); |
| 253 | |
| 254 | // Copy the string before recording it in the assembler to avoid |
| 255 | // issues when the stack allocated buffer goes out of scope. |
| 256 | size_t length = builder.position(); |
| 257 | Vector<char> copy = Vector<char>::New(length + 1); |
| 258 | memcpy(copy.start(), builder.Finalize(), copy.length()); |
| 259 | masm()->RecordComment(copy.start()); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | bool LCodeGen::GeneratePrologue() { |
| 264 | ASSERT(is_generating()); |
| 265 | |
| 266 | #ifdef DEBUG |
| 267 | if (strlen(FLAG_stop_at) > 0 && |
| 268 | info_->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 269 | __ stop("stop_at"); |
| 270 | } |
| 271 | #endif |
| 272 | |
| 273 | // r1: Callee's JS function. |
| 274 | // cp: Callee's context. |
| 275 | // fp: Caller's frame pointer. |
| 276 | // lr: Caller's pc. |
| 277 | |
| 278 | __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
| 279 | __ add(fp, sp, Operand(2 * kPointerSize)); // Adjust FP to point to saved FP. |
| 280 | |
| 281 | // Reserve space for the stack slots needed by the code. |
| 282 | int slots = StackSlotCount(); |
| 283 | if (slots > 0) { |
| 284 | if (FLAG_debug_code) { |
| 285 | __ mov(r0, Operand(slots)); |
| 286 | __ mov(r2, Operand(kSlotsZapValue)); |
| 287 | Label loop; |
| 288 | __ bind(&loop); |
| 289 | __ push(r2); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 290 | __ sub(r0, r0, Operand(1), SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | __ b(ne, &loop); |
| 292 | } else { |
| 293 | __ sub(sp, sp, Operand(slots * kPointerSize)); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // Trace the call. |
| 298 | if (FLAG_trace) { |
| 299 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 300 | } |
| 301 | return !is_aborted(); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | bool LCodeGen::GenerateBody() { |
| 306 | ASSERT(is_generating()); |
| 307 | bool emit_instructions = true; |
| 308 | for (current_instruction_ = 0; |
| 309 | !is_aborted() && current_instruction_ < instructions_->length(); |
| 310 | current_instruction_++) { |
| 311 | LInstruction* instr = instructions_->at(current_instruction_); |
| 312 | if (instr->IsLabel()) { |
| 313 | LLabel* label = LLabel::cast(instr); |
| 314 | emit_instructions = !label->HasReplacement(); |
| 315 | } |
| 316 | |
| 317 | if (emit_instructions) { |
| 318 | Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); |
| 319 | instr->CompileToNative(this); |
| 320 | } |
| 321 | } |
| 322 | return !is_aborted(); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | LInstruction* LCodeGen::GetNextInstruction() { |
| 327 | if (current_instruction_ < instructions_->length() - 1) { |
| 328 | return instructions_->at(current_instruction_ + 1); |
| 329 | } else { |
| 330 | return NULL; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | |
| 335 | bool LCodeGen::GenerateDeferredCode() { |
| 336 | ASSERT(is_generating()); |
| 337 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 338 | LDeferredCode* code = deferred_[i]; |
| 339 | __ bind(code->entry()); |
| 340 | code->Generate(); |
| 341 | __ jmp(code->exit()); |
| 342 | } |
| 343 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 344 | // Force constant pool emission at the end of deferred code to make |
| 345 | // sure that no constant pools are emitted after the official end of |
| 346 | // the instruction sequence. |
| 347 | masm()->CheckConstPool(true, false); |
| 348 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 349 | // Deferred code is the last part of the instruction sequence. Mark |
| 350 | // the generated code as done unless we bailed out. |
| 351 | if (!is_aborted()) status_ = DONE; |
| 352 | return !is_aborted(); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | bool LCodeGen::GenerateSafepointTable() { |
| 357 | ASSERT(is_done()); |
| 358 | safepoints_.Emit(masm(), StackSlotCount()); |
| 359 | return !is_aborted(); |
| 360 | } |
| 361 | |
| 362 | |
| 363 | Register LCodeGen::ToRegister(int index) const { |
| 364 | return Register::FromAllocationIndex(index); |
| 365 | } |
| 366 | |
| 367 | |
| 368 | DoubleRegister LCodeGen::ToDoubleRegister(int index) const { |
| 369 | return DoubleRegister::FromAllocationIndex(index); |
| 370 | } |
| 371 | |
| 372 | |
| 373 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 374 | ASSERT(op->IsRegister()); |
| 375 | return ToRegister(op->index()); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 380 | if (op->IsRegister()) { |
| 381 | return ToRegister(op->index()); |
| 382 | } else if (op->IsConstantOperand()) { |
| 383 | __ mov(scratch, ToOperand(op)); |
| 384 | return scratch; |
| 385 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 386 | __ ldr(scratch, ToMemOperand(op)); |
| 387 | return scratch; |
| 388 | } |
| 389 | UNREACHABLE(); |
| 390 | return scratch; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 395 | ASSERT(op->IsDoubleRegister()); |
| 396 | return ToDoubleRegister(op->index()); |
| 397 | } |
| 398 | |
| 399 | |
| 400 | DoubleRegister LCodeGen::EmitLoadDoubleRegister(LOperand* op, |
| 401 | SwVfpRegister flt_scratch, |
| 402 | DoubleRegister dbl_scratch) { |
| 403 | if (op->IsDoubleRegister()) { |
| 404 | return ToDoubleRegister(op->index()); |
| 405 | } else if (op->IsConstantOperand()) { |
| 406 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 407 | Handle<Object> literal = chunk_->LookupLiteral(const_op); |
| 408 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 409 | if (r.IsInteger32()) { |
| 410 | ASSERT(literal->IsNumber()); |
| 411 | __ mov(ip, Operand(static_cast<int32_t>(literal->Number()))); |
| 412 | __ vmov(flt_scratch, ip); |
| 413 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
| 414 | return dbl_scratch; |
| 415 | } else if (r.IsDouble()) { |
| 416 | Abort("unsupported double immediate"); |
| 417 | } else if (r.IsTagged()) { |
| 418 | Abort("unsupported tagged immediate"); |
| 419 | } |
| 420 | } else if (op->IsStackSlot() || op->IsArgument()) { |
| 421 | // TODO(regis): Why is vldr not taking a MemOperand? |
| 422 | // __ vldr(dbl_scratch, ToMemOperand(op)); |
| 423 | MemOperand mem_op = ToMemOperand(op); |
| 424 | __ vldr(dbl_scratch, mem_op.rn(), mem_op.offset()); |
| 425 | return dbl_scratch; |
| 426 | } |
| 427 | UNREACHABLE(); |
| 428 | return dbl_scratch; |
| 429 | } |
| 430 | |
| 431 | |
| 432 | int LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 433 | Handle<Object> value = chunk_->LookupLiteral(op); |
| 434 | ASSERT(chunk_->LookupLiteralRepresentation(op).IsInteger32()); |
| 435 | ASSERT(static_cast<double>(static_cast<int32_t>(value->Number())) == |
| 436 | value->Number()); |
| 437 | return static_cast<int32_t>(value->Number()); |
| 438 | } |
| 439 | |
| 440 | |
| 441 | Operand LCodeGen::ToOperand(LOperand* op) { |
| 442 | if (op->IsConstantOperand()) { |
| 443 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 444 | Handle<Object> literal = chunk_->LookupLiteral(const_op); |
| 445 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 446 | if (r.IsInteger32()) { |
| 447 | ASSERT(literal->IsNumber()); |
| 448 | return Operand(static_cast<int32_t>(literal->Number())); |
| 449 | } else if (r.IsDouble()) { |
| 450 | Abort("ToOperand Unsupported double immediate."); |
| 451 | } |
| 452 | ASSERT(r.IsTagged()); |
| 453 | return Operand(literal); |
| 454 | } else if (op->IsRegister()) { |
| 455 | return Operand(ToRegister(op)); |
| 456 | } else if (op->IsDoubleRegister()) { |
| 457 | Abort("ToOperand IsDoubleRegister unimplemented"); |
| 458 | return Operand(0); |
| 459 | } |
| 460 | // Stack slots not implemented, use ToMemOperand instead. |
| 461 | UNREACHABLE(); |
| 462 | return Operand(0); |
| 463 | } |
| 464 | |
| 465 | |
| 466 | MemOperand LCodeGen::ToMemOperand(LOperand* op) const { |
| 467 | // TODO(regis): Revisit. |
| 468 | ASSERT(!op->IsRegister()); |
| 469 | ASSERT(!op->IsDoubleRegister()); |
| 470 | ASSERT(op->IsStackSlot() || op->IsDoubleStackSlot()); |
| 471 | int index = op->index(); |
| 472 | if (index >= 0) { |
| 473 | // Local or spill slot. Skip the frame pointer, function, and |
| 474 | // context in the fixed part of the frame. |
| 475 | return MemOperand(fp, -(index + 3) * kPointerSize); |
| 476 | } else { |
| 477 | // Incoming parameter. Skip the return address. |
| 478 | return MemOperand(fp, -(index - 1) * kPointerSize); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 483 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
| 484 | Translation* translation) { |
| 485 | if (environment == NULL) return; |
| 486 | |
| 487 | // The translation includes one command per value in the environment. |
| 488 | int translation_size = environment->values()->length(); |
| 489 | // The output frame height does not include the parameters. |
| 490 | int height = translation_size - environment->parameter_count(); |
| 491 | |
| 492 | WriteTranslation(environment->outer(), translation); |
| 493 | int closure_id = DefineDeoptimizationLiteral(environment->closure()); |
| 494 | translation->BeginFrame(environment->ast_id(), closure_id, height); |
| 495 | for (int i = 0; i < translation_size; ++i) { |
| 496 | LOperand* value = environment->values()->at(i); |
| 497 | // spilled_registers_ and spilled_double_registers_ are either |
| 498 | // both NULL or both set. |
| 499 | if (environment->spilled_registers() != NULL && value != NULL) { |
| 500 | if (value->IsRegister() && |
| 501 | environment->spilled_registers()[value->index()] != NULL) { |
| 502 | translation->MarkDuplicate(); |
| 503 | AddToTranslation(translation, |
| 504 | environment->spilled_registers()[value->index()], |
| 505 | environment->HasTaggedValueAt(i)); |
| 506 | } else if ( |
| 507 | value->IsDoubleRegister() && |
| 508 | environment->spilled_double_registers()[value->index()] != NULL) { |
| 509 | translation->MarkDuplicate(); |
| 510 | AddToTranslation( |
| 511 | translation, |
| 512 | environment->spilled_double_registers()[value->index()], |
| 513 | false); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | AddToTranslation(translation, value, environment->HasTaggedValueAt(i)); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 522 | void LCodeGen::AddToTranslation(Translation* translation, |
| 523 | LOperand* op, |
| 524 | bool is_tagged) { |
| 525 | if (op == NULL) { |
| 526 | // TODO(twuerthinger): Introduce marker operands to indicate that this value |
| 527 | // is not present and must be reconstructed from the deoptimizer. Currently |
| 528 | // this is only used for the arguments object. |
| 529 | translation->StoreArgumentsObject(); |
| 530 | } else if (op->IsStackSlot()) { |
| 531 | if (is_tagged) { |
| 532 | translation->StoreStackSlot(op->index()); |
| 533 | } else { |
| 534 | translation->StoreInt32StackSlot(op->index()); |
| 535 | } |
| 536 | } else if (op->IsDoubleStackSlot()) { |
| 537 | translation->StoreDoubleStackSlot(op->index()); |
| 538 | } else if (op->IsArgument()) { |
| 539 | ASSERT(is_tagged); |
| 540 | int src_index = StackSlotCount() + op->index(); |
| 541 | translation->StoreStackSlot(src_index); |
| 542 | } else if (op->IsRegister()) { |
| 543 | Register reg = ToRegister(op); |
| 544 | if (is_tagged) { |
| 545 | translation->StoreRegister(reg); |
| 546 | } else { |
| 547 | translation->StoreInt32Register(reg); |
| 548 | } |
| 549 | } else if (op->IsDoubleRegister()) { |
| 550 | DoubleRegister reg = ToDoubleRegister(op); |
| 551 | translation->StoreDoubleRegister(reg); |
| 552 | } else if (op->IsConstantOperand()) { |
| 553 | Handle<Object> literal = chunk()->LookupLiteral(LConstantOperand::cast(op)); |
| 554 | int src_index = DefineDeoptimizationLiteral(literal); |
| 555 | translation->StoreLiteral(src_index); |
| 556 | } else { |
| 557 | UNREACHABLE(); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | |
| 562 | void LCodeGen::CallCode(Handle<Code> code, |
| 563 | RelocInfo::Mode mode, |
| 564 | LInstruction* instr) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 565 | ASSERT(instr != NULL); |
| 566 | LPointerMap* pointers = instr->pointer_map(); |
| 567 | RecordPosition(pointers->position()); |
| 568 | __ Call(code, mode); |
| 569 | RegisterLazyDeoptimization(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
| 573 | void LCodeGen::CallRuntime(Runtime::Function* function, |
| 574 | int num_arguments, |
| 575 | LInstruction* instr) { |
| 576 | ASSERT(instr != NULL); |
| 577 | LPointerMap* pointers = instr->pointer_map(); |
| 578 | ASSERT(pointers != NULL); |
| 579 | RecordPosition(pointers->position()); |
| 580 | |
| 581 | __ CallRuntime(function, num_arguments); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 582 | RegisterLazyDeoptimization(instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | void LCodeGen::RegisterLazyDeoptimization(LInstruction* instr) { |
| 587 | // Create the environment to bailout to. If the call has side effects |
| 588 | // execution has to continue after the call otherwise execution can continue |
| 589 | // from a previous bailout point repeating the call. |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 590 | LEnvironment* deoptimization_environment; |
| 591 | if (instr->HasDeoptimizationEnvironment()) { |
| 592 | deoptimization_environment = instr->deoptimization_environment(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 593 | } else { |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 594 | deoptimization_environment = instr->environment(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 595 | } |
| 596 | |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 597 | RegisterEnvironmentForDeoptimization(deoptimization_environment); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 598 | RecordSafepoint(instr->pointer_map(), |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 599 | deoptimization_environment->deoptimization_index()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
| 603 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment) { |
| 604 | if (!environment->HasBeenRegistered()) { |
| 605 | // Physical stack frame layout: |
| 606 | // -x ............. -4 0 ..................................... y |
| 607 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 608 | |
| 609 | // Layout of the environment: |
| 610 | // 0 ..................................................... size-1 |
| 611 | // [parameters] [locals] [expression stack including arguments] |
| 612 | |
| 613 | // Layout of the translation: |
| 614 | // 0 ........................................................ size - 1 + 4 |
| 615 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 616 | // |>------------ translation_size ------------<| |
| 617 | |
| 618 | int frame_count = 0; |
| 619 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 620 | ++frame_count; |
| 621 | } |
| 622 | Translation translation(&translations_, frame_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 623 | WriteTranslation(environment, &translation); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 624 | int deoptimization_index = deoptimizations_.length(); |
| 625 | environment->Register(deoptimization_index, translation.index()); |
| 626 | deoptimizations_.Add(environment); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | |
| 631 | void LCodeGen::DeoptimizeIf(Condition cc, LEnvironment* environment) { |
| 632 | RegisterEnvironmentForDeoptimization(environment); |
| 633 | ASSERT(environment->HasBeenRegistered()); |
| 634 | int id = environment->deoptimization_index(); |
| 635 | Address entry = Deoptimizer::GetDeoptimizationEntry(id, Deoptimizer::EAGER); |
| 636 | ASSERT(entry != NULL); |
| 637 | if (entry == NULL) { |
| 638 | Abort("bailout was not prepared"); |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | ASSERT(FLAG_deopt_every_n_times < 2); // Other values not supported on ARM. |
| 643 | |
| 644 | if (FLAG_deopt_every_n_times == 1 && |
| 645 | info_->shared_info()->opt_count() == id) { |
| 646 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 647 | return; |
| 648 | } |
| 649 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 650 | if (cc == kNoCondition) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 651 | if (FLAG_trap_on_deopt) __ stop("trap_on_deopt"); |
| 652 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 653 | } else { |
| 654 | if (FLAG_trap_on_deopt) { |
| 655 | Label done; |
| 656 | __ b(&done, NegateCondition(cc)); |
| 657 | __ stop("trap_on_deopt"); |
| 658 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY); |
| 659 | __ bind(&done); |
| 660 | } else { |
| 661 | __ Jump(entry, RelocInfo::RUNTIME_ENTRY, cc); |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | |
| 667 | void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) { |
| 668 | int length = deoptimizations_.length(); |
| 669 | if (length == 0) return; |
| 670 | ASSERT(FLAG_deopt); |
| 671 | Handle<DeoptimizationInputData> data = |
| 672 | Factory::NewDeoptimizationInputData(length, TENURED); |
| 673 | |
| 674 | data->SetTranslationByteArray(*translations_.CreateByteArray()); |
| 675 | data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_)); |
| 676 | |
| 677 | Handle<FixedArray> literals = |
| 678 | Factory::NewFixedArray(deoptimization_literals_.length(), TENURED); |
| 679 | for (int i = 0; i < deoptimization_literals_.length(); i++) { |
| 680 | literals->set(i, *deoptimization_literals_[i]); |
| 681 | } |
| 682 | data->SetLiteralArray(*literals); |
| 683 | |
| 684 | data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id())); |
| 685 | data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
| 686 | |
| 687 | // Populate the deoptimization entries. |
| 688 | for (int i = 0; i < length; i++) { |
| 689 | LEnvironment* env = deoptimizations_[i]; |
| 690 | data->SetAstId(i, Smi::FromInt(env->ast_id())); |
| 691 | data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
| 692 | data->SetArgumentsStackHeight(i, |
| 693 | Smi::FromInt(env->arguments_stack_height())); |
| 694 | } |
| 695 | code->set_deoptimization_data(*data); |
| 696 | } |
| 697 | |
| 698 | |
| 699 | int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
| 700 | int result = deoptimization_literals_.length(); |
| 701 | for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
| 702 | if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
| 703 | } |
| 704 | deoptimization_literals_.Add(literal); |
| 705 | return result; |
| 706 | } |
| 707 | |
| 708 | |
| 709 | void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { |
| 710 | ASSERT(deoptimization_literals_.length() == 0); |
| 711 | |
| 712 | const ZoneList<Handle<JSFunction> >* inlined_closures = |
| 713 | chunk()->inlined_closures(); |
| 714 | |
| 715 | for (int i = 0, length = inlined_closures->length(); |
| 716 | i < length; |
| 717 | i++) { |
| 718 | DefineDeoptimizationLiteral(inlined_closures->at(i)); |
| 719 | } |
| 720 | |
| 721 | inlined_function_count_ = deoptimization_literals_.length(); |
| 722 | } |
| 723 | |
| 724 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 725 | void LCodeGen::RecordSafepoint( |
| 726 | LPointerMap* pointers, |
| 727 | Safepoint::Kind kind, |
| 728 | int arguments, |
| 729 | int deoptimization_index) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 730 | const ZoneList<LOperand*>* operands = pointers->operands(); |
| 731 | Safepoint safepoint = safepoints_.DefineSafepoint(masm(), |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 732 | kind, arguments, deoptimization_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 733 | for (int i = 0; i < operands->length(); i++) { |
| 734 | LOperand* pointer = operands->at(i); |
| 735 | if (pointer->IsStackSlot()) { |
| 736 | safepoint.DefinePointerSlot(pointer->index()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 737 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
| 738 | safepoint.DefinePointerRegister(ToRegister(pointer)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 739 | } |
| 740 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 741 | if (kind & Safepoint::kWithRegisters) { |
| 742 | // Register cp always contains a pointer to the context. |
| 743 | safepoint.DefinePointerRegister(cp); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | |
| 748 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
| 749 | int deoptimization_index) { |
| 750 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deoptimization_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | |
| 754 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 755 | int arguments, |
| 756 | int deoptimization_index) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 757 | RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, |
| 758 | deoptimization_index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 762 | void LCodeGen::RecordSafepointWithRegistersAndDoubles( |
| 763 | LPointerMap* pointers, |
| 764 | int arguments, |
| 765 | int deoptimization_index) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 766 | RecordSafepoint(pointers, Safepoint::kWithRegistersAndDoubles, arguments, |
| 767 | deoptimization_index); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 771 | void LCodeGen::RecordPosition(int position) { |
| 772 | if (!FLAG_debug_info || position == RelocInfo::kNoPosition) return; |
| 773 | masm()->positions_recorder()->RecordPosition(position); |
| 774 | } |
| 775 | |
| 776 | |
| 777 | void LCodeGen::DoLabel(LLabel* label) { |
| 778 | if (label->is_loop_header()) { |
| 779 | Comment(";;; B%d - LOOP entry", label->block_id()); |
| 780 | } else { |
| 781 | Comment(";;; B%d", label->block_id()); |
| 782 | } |
| 783 | __ bind(label->label()); |
| 784 | current_block_ = label->block_id(); |
| 785 | LCodeGen::DoGap(label); |
| 786 | } |
| 787 | |
| 788 | |
| 789 | void LCodeGen::DoParallelMove(LParallelMove* move) { |
| 790 | // d0 must always be a scratch register. |
| 791 | DoubleRegister dbl_scratch = d0; |
| 792 | LUnallocated marker_operand(LUnallocated::NONE); |
| 793 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 794 | Register core_scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 795 | bool destroys_core_scratch = false; |
| 796 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 797 | const ZoneList<LMoveOperands>* moves = |
| 798 | resolver_.Resolve(move->move_operands(), &marker_operand); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 799 | for (int i = moves->length() - 1; i >= 0; --i) { |
| 800 | LMoveOperands move = moves->at(i); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 801 | LOperand* from = move.source(); |
| 802 | LOperand* to = move.destination(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 803 | ASSERT(!from->IsDoubleRegister() || |
| 804 | !ToDoubleRegister(from).is(dbl_scratch)); |
| 805 | ASSERT(!to->IsDoubleRegister() || !ToDoubleRegister(to).is(dbl_scratch)); |
| 806 | ASSERT(!from->IsRegister() || !ToRegister(from).is(core_scratch)); |
| 807 | ASSERT(!to->IsRegister() || !ToRegister(to).is(core_scratch)); |
| 808 | if (from == &marker_operand) { |
| 809 | if (to->IsRegister()) { |
| 810 | __ mov(ToRegister(to), core_scratch); |
| 811 | ASSERT(destroys_core_scratch); |
| 812 | } else if (to->IsStackSlot()) { |
| 813 | __ str(core_scratch, ToMemOperand(to)); |
| 814 | ASSERT(destroys_core_scratch); |
| 815 | } else if (to->IsDoubleRegister()) { |
| 816 | __ vmov(ToDoubleRegister(to), dbl_scratch); |
| 817 | } else { |
| 818 | ASSERT(to->IsDoubleStackSlot()); |
| 819 | // TODO(regis): Why is vstr not taking a MemOperand? |
| 820 | // __ vstr(dbl_scratch, ToMemOperand(to)); |
| 821 | MemOperand to_operand = ToMemOperand(to); |
| 822 | __ vstr(dbl_scratch, to_operand.rn(), to_operand.offset()); |
| 823 | } |
| 824 | } else if (to == &marker_operand) { |
| 825 | if (from->IsRegister() || from->IsConstantOperand()) { |
| 826 | __ mov(core_scratch, ToOperand(from)); |
| 827 | destroys_core_scratch = true; |
| 828 | } else if (from->IsStackSlot()) { |
| 829 | __ ldr(core_scratch, ToMemOperand(from)); |
| 830 | destroys_core_scratch = true; |
| 831 | } else if (from->IsDoubleRegister()) { |
| 832 | __ vmov(dbl_scratch, ToDoubleRegister(from)); |
| 833 | } else { |
| 834 | ASSERT(from->IsDoubleStackSlot()); |
| 835 | // TODO(regis): Why is vldr not taking a MemOperand? |
| 836 | // __ vldr(dbl_scratch, ToMemOperand(from)); |
| 837 | MemOperand from_operand = ToMemOperand(from); |
| 838 | __ vldr(dbl_scratch, from_operand.rn(), from_operand.offset()); |
| 839 | } |
| 840 | } else if (from->IsConstantOperand()) { |
| 841 | if (to->IsRegister()) { |
| 842 | __ mov(ToRegister(to), ToOperand(from)); |
| 843 | } else { |
| 844 | ASSERT(to->IsStackSlot()); |
| 845 | __ mov(ip, ToOperand(from)); |
| 846 | __ str(ip, ToMemOperand(to)); |
| 847 | } |
| 848 | } else if (from->IsRegister()) { |
| 849 | if (to->IsRegister()) { |
| 850 | __ mov(ToRegister(to), ToOperand(from)); |
| 851 | } else { |
| 852 | ASSERT(to->IsStackSlot()); |
| 853 | __ str(ToRegister(from), ToMemOperand(to)); |
| 854 | } |
| 855 | } else if (to->IsRegister()) { |
| 856 | ASSERT(from->IsStackSlot()); |
| 857 | __ ldr(ToRegister(to), ToMemOperand(from)); |
| 858 | } else if (from->IsStackSlot()) { |
| 859 | ASSERT(to->IsStackSlot()); |
| 860 | __ ldr(ip, ToMemOperand(from)); |
| 861 | __ str(ip, ToMemOperand(to)); |
| 862 | } else if (from->IsDoubleRegister()) { |
| 863 | if (to->IsDoubleRegister()) { |
| 864 | __ vmov(ToDoubleRegister(to), ToDoubleRegister(from)); |
| 865 | } else { |
| 866 | ASSERT(to->IsDoubleStackSlot()); |
| 867 | // TODO(regis): Why is vstr not taking a MemOperand? |
| 868 | // __ vstr(dbl_scratch, ToMemOperand(to)); |
| 869 | MemOperand to_operand = ToMemOperand(to); |
| 870 | __ vstr(ToDoubleRegister(from), to_operand.rn(), to_operand.offset()); |
| 871 | } |
| 872 | } else if (to->IsDoubleRegister()) { |
| 873 | ASSERT(from->IsDoubleStackSlot()); |
| 874 | // TODO(regis): Why is vldr not taking a MemOperand? |
| 875 | // __ vldr(ToDoubleRegister(to), ToMemOperand(from)); |
| 876 | MemOperand from_operand = ToMemOperand(from); |
| 877 | __ vldr(ToDoubleRegister(to), from_operand.rn(), from_operand.offset()); |
| 878 | } else { |
| 879 | ASSERT(to->IsDoubleStackSlot() && from->IsDoubleStackSlot()); |
| 880 | // TODO(regis): Why is vldr not taking a MemOperand? |
| 881 | // __ vldr(dbl_scratch, ToMemOperand(from)); |
| 882 | MemOperand from_operand = ToMemOperand(from); |
| 883 | __ vldr(dbl_scratch, from_operand.rn(), from_operand.offset()); |
| 884 | // TODO(regis): Why is vstr not taking a MemOperand? |
| 885 | // __ vstr(dbl_scratch, ToMemOperand(to)); |
| 886 | MemOperand to_operand = ToMemOperand(to); |
| 887 | __ vstr(dbl_scratch, to_operand.rn(), to_operand.offset()); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | if (destroys_core_scratch) { |
| 892 | __ ldr(core_scratch, MemOperand(fp, -kPointerSize)); |
| 893 | } |
| 894 | |
| 895 | LInstruction* next = GetNextInstruction(); |
| 896 | if (next != NULL && next->IsLazyBailout()) { |
| 897 | int pc = masm()->pc_offset(); |
| 898 | safepoints_.SetPcAfterGap(pc); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | |
| 903 | void LCodeGen::DoGap(LGap* gap) { |
| 904 | for (int i = LGap::FIRST_INNER_POSITION; |
| 905 | i <= LGap::LAST_INNER_POSITION; |
| 906 | i++) { |
| 907 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 908 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 909 | if (move != NULL) DoParallelMove(move); |
| 910 | } |
| 911 | |
| 912 | LInstruction* next = GetNextInstruction(); |
| 913 | if (next != NULL && next->IsLazyBailout()) { |
| 914 | int pc = masm()->pc_offset(); |
| 915 | safepoints_.SetPcAfterGap(pc); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | |
| 920 | void LCodeGen::DoParameter(LParameter* instr) { |
| 921 | // Nothing to do. |
| 922 | } |
| 923 | |
| 924 | |
| 925 | void LCodeGen::DoCallStub(LCallStub* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 926 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 927 | switch (instr->hydrogen()->major_key()) { |
| 928 | case CodeStub::RegExpConstructResult: { |
| 929 | RegExpConstructResultStub stub; |
| 930 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 931 | break; |
| 932 | } |
| 933 | case CodeStub::RegExpExec: { |
| 934 | RegExpExecStub stub; |
| 935 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 936 | break; |
| 937 | } |
| 938 | case CodeStub::SubString: { |
| 939 | SubStringStub stub; |
| 940 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 941 | break; |
| 942 | } |
| 943 | case CodeStub::StringCharAt: { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 944 | StringCharAtStub stub; |
| 945 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 946 | break; |
| 947 | } |
| 948 | case CodeStub::MathPow: { |
| 949 | Abort("MathPowStub unimplemented."); |
| 950 | break; |
| 951 | } |
| 952 | case CodeStub::NumberToString: { |
| 953 | NumberToStringStub stub; |
| 954 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 955 | break; |
| 956 | } |
| 957 | case CodeStub::StringAdd: { |
| 958 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 959 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 960 | break; |
| 961 | } |
| 962 | case CodeStub::StringCompare: { |
| 963 | StringCompareStub stub; |
| 964 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 965 | break; |
| 966 | } |
| 967 | case CodeStub::TranscendentalCache: { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 968 | __ ldr(r0, MemOperand(sp, 0)); |
| 969 | TranscendentalCacheStub stub(instr->transcendental_type()); |
| 970 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 971 | break; |
| 972 | } |
| 973 | default: |
| 974 | UNREACHABLE(); |
| 975 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | |
| 979 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 980 | // Nothing to do. |
| 981 | } |
| 982 | |
| 983 | |
| 984 | void LCodeGen::DoModI(LModI* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 985 | class DeferredModI: public LDeferredCode { |
| 986 | public: |
| 987 | DeferredModI(LCodeGen* codegen, LModI* instr) |
| 988 | : LDeferredCode(codegen), instr_(instr) { } |
| 989 | virtual void Generate() { |
| 990 | codegen()->DoDeferredGenericBinaryStub(instr_, Token::MOD); |
| 991 | } |
| 992 | private: |
| 993 | LModI* instr_; |
| 994 | }; |
| 995 | // These registers hold untagged 32 bit values. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 996 | Register left = ToRegister(instr->InputAt(0)); |
| 997 | Register right = ToRegister(instr->InputAt(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 998 | Register result = ToRegister(instr->result()); |
| 999 | Register scratch = scratch0(); |
| 1000 | |
| 1001 | Label deoptimize, done; |
| 1002 | // Check for x % 0. |
| 1003 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1004 | __ tst(right, Operand(right)); |
| 1005 | __ b(eq, &deoptimize); |
| 1006 | } |
| 1007 | |
| 1008 | // Check for (0 % -x) that will produce negative zero. |
| 1009 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1010 | Label ok; |
| 1011 | __ tst(left, Operand(left)); |
| 1012 | __ b(ne, &ok); |
| 1013 | __ tst(right, Operand(right)); |
| 1014 | __ b(pl, &ok); |
| 1015 | __ b(al, &deoptimize); |
| 1016 | __ bind(&ok); |
| 1017 | } |
| 1018 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1019 | // Try a few common cases before using the generic stub. |
| 1020 | Label call_stub; |
| 1021 | const int kUnfolds = 3; |
| 1022 | // Skip if either side is negative. |
| 1023 | __ cmp(left, Operand(0)); |
| 1024 | __ cmp(right, Operand(0), NegateCondition(mi)); |
| 1025 | __ b(mi, &call_stub); |
| 1026 | // If the right hand side is smaller than the (nonnegative) |
| 1027 | // left hand side, it is the result. Else try a few subtractions |
| 1028 | // of the left hand side. |
| 1029 | __ mov(scratch, left); |
| 1030 | for (int i = 0; i < kUnfolds; i++) { |
| 1031 | // Check if the left hand side is less or equal than the |
| 1032 | // the right hand side. |
| 1033 | __ cmp(scratch, right); |
| 1034 | __ mov(result, scratch, LeaveCC, lt); |
| 1035 | __ b(lt, &done); |
| 1036 | // If not, reduce the left hand side by the right hand |
| 1037 | // side and check again. |
| 1038 | if (i < kUnfolds - 1) __ sub(scratch, scratch, right); |
| 1039 | } |
| 1040 | |
| 1041 | // Check for power of two on the right hand side. |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1042 | __ JumpIfNotPowerOfTwoOrZero(right, scratch, &call_stub); |
| 1043 | // Perform modulo operation (scratch contains right - 1). |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1044 | __ and_(result, scratch, Operand(left)); |
| 1045 | |
| 1046 | __ bind(&call_stub); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1047 | // Call the generic stub. The numbers in r0 and r1 have |
| 1048 | // to be tagged to Smis. If that is not possible, deoptimize. |
| 1049 | DeferredModI* deferred = new DeferredModI(this, instr); |
| 1050 | __ TrySmiTag(left, &deoptimize, scratch); |
| 1051 | __ TrySmiTag(right, &deoptimize, scratch); |
| 1052 | |
| 1053 | __ b(al, deferred->entry()); |
| 1054 | __ bind(deferred->exit()); |
| 1055 | |
| 1056 | // 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] | 1057 | __ JumpIfNotSmi(result, &deoptimize); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1058 | __ SmiUntag(result); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1059 | |
| 1060 | __ b(al, &done); |
| 1061 | __ bind(&deoptimize); |
| 1062 | DeoptimizeIf(al, instr->environment()); |
| 1063 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | void LCodeGen::DoDivI(LDivI* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1068 | class DeferredDivI: public LDeferredCode { |
| 1069 | public: |
| 1070 | DeferredDivI(LCodeGen* codegen, LDivI* instr) |
| 1071 | : LDeferredCode(codegen), instr_(instr) { } |
| 1072 | virtual void Generate() { |
| 1073 | codegen()->DoDeferredGenericBinaryStub(instr_, Token::DIV); |
| 1074 | } |
| 1075 | private: |
| 1076 | LDivI* instr_; |
| 1077 | }; |
| 1078 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1079 | const Register left = ToRegister(instr->InputAt(0)); |
| 1080 | const Register right = ToRegister(instr->InputAt(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1081 | const Register scratch = scratch0(); |
| 1082 | const Register result = ToRegister(instr->result()); |
| 1083 | |
| 1084 | // Check for x / 0. |
| 1085 | if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1086 | __ tst(right, right); |
| 1087 | DeoptimizeIf(eq, instr->environment()); |
| 1088 | } |
| 1089 | |
| 1090 | // Check for (0 / -x) that will produce negative zero. |
| 1091 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1092 | Label left_not_zero; |
| 1093 | __ tst(left, Operand(left)); |
| 1094 | __ b(ne, &left_not_zero); |
| 1095 | __ tst(right, Operand(right)); |
| 1096 | DeoptimizeIf(mi, instr->environment()); |
| 1097 | __ bind(&left_not_zero); |
| 1098 | } |
| 1099 | |
| 1100 | // Check for (-kMinInt / -1). |
| 1101 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1102 | Label left_not_min_int; |
| 1103 | __ cmp(left, Operand(kMinInt)); |
| 1104 | __ b(ne, &left_not_min_int); |
| 1105 | __ cmp(right, Operand(-1)); |
| 1106 | DeoptimizeIf(eq, instr->environment()); |
| 1107 | __ bind(&left_not_min_int); |
| 1108 | } |
| 1109 | |
| 1110 | Label done, deoptimize; |
| 1111 | // Test for a few common cases first. |
| 1112 | __ cmp(right, Operand(1)); |
| 1113 | __ mov(result, left, LeaveCC, eq); |
| 1114 | __ b(eq, &done); |
| 1115 | |
| 1116 | __ cmp(right, Operand(2)); |
| 1117 | __ tst(left, Operand(1), eq); |
| 1118 | __ mov(result, Operand(left, ASR, 1), LeaveCC, eq); |
| 1119 | __ b(eq, &done); |
| 1120 | |
| 1121 | __ cmp(right, Operand(4)); |
| 1122 | __ tst(left, Operand(3), eq); |
| 1123 | __ mov(result, Operand(left, ASR, 2), LeaveCC, eq); |
| 1124 | __ b(eq, &done); |
| 1125 | |
| 1126 | // Call the generic stub. The numbers in r0 and r1 have |
| 1127 | // to be tagged to Smis. If that is not possible, deoptimize. |
| 1128 | DeferredDivI* deferred = new DeferredDivI(this, instr); |
| 1129 | |
| 1130 | __ TrySmiTag(left, &deoptimize, scratch); |
| 1131 | __ TrySmiTag(right, &deoptimize, scratch); |
| 1132 | |
| 1133 | __ b(al, deferred->entry()); |
| 1134 | __ bind(deferred->exit()); |
| 1135 | |
| 1136 | // 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] | 1137 | __ JumpIfNotSmi(result, &deoptimize); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1138 | __ SmiUntag(result); |
| 1139 | __ b(&done); |
| 1140 | |
| 1141 | __ bind(&deoptimize); |
| 1142 | DeoptimizeIf(al, instr->environment()); |
| 1143 | __ bind(&done); |
| 1144 | } |
| 1145 | |
| 1146 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1147 | template<int T> |
| 1148 | void LCodeGen::DoDeferredGenericBinaryStub(LTemplateInstruction<1, 2, T>* instr, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1149 | Token::Value op) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1150 | Register left = ToRegister(instr->InputAt(0)); |
| 1151 | Register right = ToRegister(instr->InputAt(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1152 | |
| 1153 | __ PushSafepointRegistersAndDoubles(); |
| 1154 | GenericBinaryOpStub stub(op, OVERWRITE_LEFT, left, right); |
| 1155 | __ CallStub(&stub); |
| 1156 | RecordSafepointWithRegistersAndDoubles(instr->pointer_map(), |
| 1157 | 0, |
| 1158 | Safepoint::kNoDeoptimizationIndex); |
| 1159 | // Overwrite the stored value of r0 with the result of the stub. |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 1160 | __ StoreToSafepointRegistersAndDoublesSlot(r0); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1161 | __ PopSafepointRegistersAndDoubles(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | void LCodeGen::DoMulI(LMulI* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1166 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1167 | Register left = ToRegister(instr->InputAt(0)); |
| 1168 | Register right = EmitLoadRegister(instr->InputAt(1), scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1169 | |
| 1170 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero) && |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1171 | !instr->InputAt(1)->IsConstantOperand()) { |
| 1172 | __ orr(ToRegister(instr->TempAt(0)), left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1176 | // scratch:left = left * right. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 1177 | __ smull(left, scratch, left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1178 | __ mov(ip, Operand(left, ASR, 31)); |
| 1179 | __ cmp(ip, Operand(scratch)); |
| 1180 | DeoptimizeIf(ne, instr->environment()); |
| 1181 | } else { |
| 1182 | __ mul(left, left, right); |
| 1183 | } |
| 1184 | |
| 1185 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1186 | // Bail out if the result is supposed to be negative zero. |
| 1187 | Label done; |
| 1188 | __ tst(left, Operand(left)); |
| 1189 | __ b(ne, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1190 | if (instr->InputAt(1)->IsConstantOperand()) { |
| 1191 | if (ToInteger32(LConstantOperand::cast(instr->InputAt(1))) < 0) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1192 | DeoptimizeIf(kNoCondition, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1193 | } |
| 1194 | } else { |
| 1195 | // Test the non-zero operand for negative sign. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1196 | __ cmp(ToRegister(instr->TempAt(0)), Operand(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1197 | DeoptimizeIf(mi, instr->environment()); |
| 1198 | } |
| 1199 | __ bind(&done); |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | void LCodeGen::DoBitI(LBitI* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1205 | LOperand* left = instr->InputAt(0); |
| 1206 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1207 | ASSERT(left->Equals(instr->result())); |
| 1208 | ASSERT(left->IsRegister()); |
| 1209 | Register result = ToRegister(left); |
| 1210 | Register right_reg = EmitLoadRegister(right, ip); |
| 1211 | switch (instr->op()) { |
| 1212 | case Token::BIT_AND: |
| 1213 | __ and_(result, ToRegister(left), Operand(right_reg)); |
| 1214 | break; |
| 1215 | case Token::BIT_OR: |
| 1216 | __ orr(result, ToRegister(left), Operand(right_reg)); |
| 1217 | break; |
| 1218 | case Token::BIT_XOR: |
| 1219 | __ eor(result, ToRegister(left), Operand(right_reg)); |
| 1220 | break; |
| 1221 | default: |
| 1222 | UNREACHABLE(); |
| 1223 | break; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | void LCodeGen::DoShiftI(LShiftI* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1229 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1230 | LOperand* left = instr->InputAt(0); |
| 1231 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1232 | ASSERT(left->Equals(instr->result())); |
| 1233 | ASSERT(left->IsRegister()); |
| 1234 | Register result = ToRegister(left); |
| 1235 | if (right->IsRegister()) { |
| 1236 | // Mask the right operand. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1237 | __ and_(scratch, ToRegister(right), Operand(0x1F)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1238 | switch (instr->op()) { |
| 1239 | case Token::SAR: |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1240 | __ mov(result, Operand(result, ASR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1241 | break; |
| 1242 | case Token::SHR: |
| 1243 | if (instr->can_deopt()) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1244 | __ mov(result, Operand(result, LSR, scratch), SetCC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1245 | DeoptimizeIf(mi, instr->environment()); |
| 1246 | } else { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1247 | __ mov(result, Operand(result, LSR, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1248 | } |
| 1249 | break; |
| 1250 | case Token::SHL: |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1251 | __ mov(result, Operand(result, LSL, scratch)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1252 | break; |
| 1253 | default: |
| 1254 | UNREACHABLE(); |
| 1255 | break; |
| 1256 | } |
| 1257 | } else { |
| 1258 | int value = ToInteger32(LConstantOperand::cast(right)); |
| 1259 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1260 | switch (instr->op()) { |
| 1261 | case Token::SAR: |
| 1262 | if (shift_count != 0) { |
| 1263 | __ mov(result, Operand(result, ASR, shift_count)); |
| 1264 | } |
| 1265 | break; |
| 1266 | case Token::SHR: |
| 1267 | if (shift_count == 0 && instr->can_deopt()) { |
| 1268 | __ tst(result, Operand(0x80000000)); |
| 1269 | DeoptimizeIf(ne, instr->environment()); |
| 1270 | } else { |
| 1271 | __ mov(result, Operand(result, LSR, shift_count)); |
| 1272 | } |
| 1273 | break; |
| 1274 | case Token::SHL: |
| 1275 | if (shift_count != 0) { |
| 1276 | __ mov(result, Operand(result, LSL, shift_count)); |
| 1277 | } |
| 1278 | break; |
| 1279 | default: |
| 1280 | UNREACHABLE(); |
| 1281 | break; |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | |
| 1287 | void LCodeGen::DoSubI(LSubI* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1288 | Register left = ToRegister(instr->InputAt(0)); |
| 1289 | Register right = EmitLoadRegister(instr->InputAt(1), ip); |
| 1290 | ASSERT(instr->InputAt(0)->Equals(instr->result())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1291 | __ sub(left, left, right, SetCC); |
| 1292 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1293 | DeoptimizeIf(vs, instr->environment()); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | void LCodeGen::DoConstantI(LConstantI* instr) { |
| 1299 | ASSERT(instr->result()->IsRegister()); |
| 1300 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | void LCodeGen::DoConstantD(LConstantD* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1305 | ASSERT(instr->result()->IsDoubleRegister()); |
| 1306 | DwVfpRegister result = ToDoubleRegister(instr->result()); |
| 1307 | double v = instr->value(); |
| 1308 | __ vmov(result, v); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | void LCodeGen::DoConstantT(LConstantT* instr) { |
| 1313 | ASSERT(instr->result()->IsRegister()); |
| 1314 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1315 | } |
| 1316 | |
| 1317 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1318 | void LCodeGen::DoJSArrayLength(LJSArrayLength* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1319 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1320 | Register array = ToRegister(instr->InputAt(0)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1321 | __ ldr(result, FieldMemOperand(array, JSArray::kLengthOffset)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1322 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1323 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1324 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1325 | void LCodeGen::DoFixedArrayLength(LFixedArrayLength* instr) { |
| 1326 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1327 | Register array = ToRegister(instr->InputAt(0)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1328 | __ ldr(result, FieldMemOperand(array, FixedArray::kLengthOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | void LCodeGen::DoValueOf(LValueOf* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1333 | Register input = ToRegister(instr->InputAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1334 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1335 | Register map = ToRegister(instr->TempAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1336 | ASSERT(input.is(result)); |
| 1337 | Label done; |
| 1338 | |
| 1339 | // If the object is a smi return the object. |
| 1340 | __ tst(input, Operand(kSmiTagMask)); |
| 1341 | __ b(eq, &done); |
| 1342 | |
| 1343 | // If the object is not a value type, return the object. |
| 1344 | __ CompareObjectType(input, map, map, JS_VALUE_TYPE); |
| 1345 | __ b(ne, &done); |
| 1346 | __ ldr(result, FieldMemOperand(input, JSValue::kValueOffset)); |
| 1347 | |
| 1348 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | |
| 1352 | void LCodeGen::DoBitNotI(LBitNotI* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1353 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1354 | ASSERT(input->Equals(instr->result())); |
| 1355 | __ mvn(ToRegister(input), Operand(ToRegister(input))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | void LCodeGen::DoThrow(LThrow* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1360 | Register input_reg = EmitLoadRegister(instr->InputAt(0), ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1361 | __ push(input_reg); |
| 1362 | CallRuntime(Runtime::kThrow, 1, instr); |
| 1363 | |
| 1364 | if (FLAG_debug_code) { |
| 1365 | __ stop("Unreachable code."); |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | void LCodeGen::DoAddI(LAddI* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1371 | LOperand* left = instr->InputAt(0); |
| 1372 | LOperand* right = instr->InputAt(1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1373 | ASSERT(left->Equals(instr->result())); |
| 1374 | |
| 1375 | Register right_reg = EmitLoadRegister(right, ip); |
| 1376 | __ add(ToRegister(left), ToRegister(left), Operand(right_reg), SetCC); |
| 1377 | |
| 1378 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1379 | DeoptimizeIf(vs, instr->environment()); |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | |
| 1384 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1385 | DoubleRegister left = ToDoubleRegister(instr->InputAt(0)); |
| 1386 | DoubleRegister right = ToDoubleRegister(instr->InputAt(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1387 | switch (instr->op()) { |
| 1388 | case Token::ADD: |
| 1389 | __ vadd(left, left, right); |
| 1390 | break; |
| 1391 | case Token::SUB: |
| 1392 | __ vsub(left, left, right); |
| 1393 | break; |
| 1394 | case Token::MUL: |
| 1395 | __ vmul(left, left, right); |
| 1396 | break; |
| 1397 | case Token::DIV: |
| 1398 | __ vdiv(left, left, right); |
| 1399 | break; |
| 1400 | case Token::MOD: { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 1401 | // Save r0-r3 on the stack. |
| 1402 | __ stm(db_w, sp, r0.bit() | r1.bit() | r2.bit() | r3.bit()); |
| 1403 | |
| 1404 | __ PrepareCallCFunction(4, scratch0()); |
| 1405 | __ vmov(r0, r1, left); |
| 1406 | __ vmov(r2, r3, right); |
| 1407 | __ CallCFunction(ExternalReference::double_fp_operation(Token::MOD), 4); |
| 1408 | // Move the result in the double result register. |
| 1409 | __ vmov(ToDoubleRegister(instr->result()), r0, r1); |
| 1410 | |
| 1411 | // Restore r0-r3. |
| 1412 | __ 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] | 1413 | break; |
| 1414 | } |
| 1415 | default: |
| 1416 | UNREACHABLE(); |
| 1417 | break; |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1423 | ASSERT(ToRegister(instr->InputAt(0)).is(r1)); |
| 1424 | ASSERT(ToRegister(instr->InputAt(1)).is(r0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1425 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 1426 | |
| 1427 | // TODO(regis): Implement TypeRecordingBinaryOpStub and replace current |
| 1428 | // GenericBinaryOpStub: |
| 1429 | // TypeRecordingBinaryOpStub stub(instr->op(), NO_OVERWRITE); |
| 1430 | GenericBinaryOpStub stub(instr->op(), NO_OVERWRITE, r1, r0); |
| 1431 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 1432 | } |
| 1433 | |
| 1434 | |
| 1435 | int LCodeGen::GetNextEmittedBlock(int block) { |
| 1436 | for (int i = block + 1; i < graph()->blocks()->length(); ++i) { |
| 1437 | LLabel* label = chunk_->GetLabel(i); |
| 1438 | if (!label->HasReplacement()) return i; |
| 1439 | } |
| 1440 | return -1; |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | void LCodeGen::EmitBranch(int left_block, int right_block, Condition cc) { |
| 1445 | int next_block = GetNextEmittedBlock(current_block_); |
| 1446 | right_block = chunk_->LookupDestination(right_block); |
| 1447 | left_block = chunk_->LookupDestination(left_block); |
| 1448 | |
| 1449 | if (right_block == left_block) { |
| 1450 | EmitGoto(left_block); |
| 1451 | } else if (left_block == next_block) { |
| 1452 | __ b(NegateCondition(cc), chunk_->GetAssemblyLabel(right_block)); |
| 1453 | } else if (right_block == next_block) { |
| 1454 | __ b(cc, chunk_->GetAssemblyLabel(left_block)); |
| 1455 | } else { |
| 1456 | __ b(cc, chunk_->GetAssemblyLabel(left_block)); |
| 1457 | __ b(chunk_->GetAssemblyLabel(right_block)); |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | |
| 1462 | void LCodeGen::DoBranch(LBranch* instr) { |
| 1463 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1464 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1465 | |
| 1466 | Representation r = instr->hydrogen()->representation(); |
| 1467 | if (r.IsInteger32()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1468 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1469 | __ cmp(reg, Operand(0)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1470 | EmitBranch(true_block, false_block, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1471 | } else if (r.IsDouble()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1472 | DoubleRegister reg = ToDoubleRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1473 | Register scratch = scratch0(); |
| 1474 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1475 | // Test the double value. Zero and NaN are false. |
| 1476 | __ VFPCompareAndLoadFlags(reg, 0.0, scratch); |
| 1477 | __ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1478 | EmitBranch(true_block, false_block, ne); |
| 1479 | } else { |
| 1480 | ASSERT(r.IsTagged()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1481 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1482 | if (instr->hydrogen()->type().IsBoolean()) { |
| 1483 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 1484 | __ cmp(reg, ip); |
| 1485 | EmitBranch(true_block, false_block, eq); |
| 1486 | } else { |
| 1487 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1488 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1489 | |
| 1490 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 1491 | __ cmp(reg, ip); |
| 1492 | __ b(eq, false_label); |
| 1493 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 1494 | __ cmp(reg, ip); |
| 1495 | __ b(eq, true_label); |
| 1496 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 1497 | __ cmp(reg, ip); |
| 1498 | __ b(eq, false_label); |
| 1499 | __ cmp(reg, Operand(0)); |
| 1500 | __ b(eq, false_label); |
| 1501 | __ tst(reg, Operand(kSmiTagMask)); |
| 1502 | __ b(eq, true_label); |
| 1503 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1504 | // Test double values. Zero and NaN are false. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1505 | Label call_stub; |
| 1506 | DoubleRegister dbl_scratch = d0; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1507 | Register scratch = scratch0(); |
| 1508 | __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1509 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1510 | __ cmp(scratch, Operand(ip)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1511 | __ b(ne, &call_stub); |
| 1512 | __ sub(ip, reg, Operand(kHeapObjectTag)); |
| 1513 | __ vldr(dbl_scratch, ip, HeapNumber::kValueOffset); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1514 | __ VFPCompareAndLoadFlags(dbl_scratch, 0.0, scratch); |
| 1515 | __ tst(scratch, Operand(kVFPZConditionFlagBit | kVFPVConditionFlagBit)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1516 | __ b(ne, false_label); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1517 | __ b(true_label); |
| 1518 | |
| 1519 | // The conversion stub doesn't cause garbage collections so it's |
| 1520 | // safe to not record a safepoint after the call. |
| 1521 | __ bind(&call_stub); |
| 1522 | ToBooleanStub stub(reg); |
| 1523 | RegList saved_regs = kJSCallerSaved | kCalleeSaved; |
| 1524 | __ stm(db_w, sp, saved_regs); |
| 1525 | __ CallStub(&stub); |
| 1526 | __ cmp(reg, Operand(0)); |
| 1527 | __ ldm(ia_w, sp, saved_regs); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1528 | EmitBranch(true_block, false_block, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | |
| 1534 | void LCodeGen::EmitGoto(int block, LDeferredCode* deferred_stack_check) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1535 | block = chunk_->LookupDestination(block); |
| 1536 | int next_block = GetNextEmittedBlock(current_block_); |
| 1537 | if (block != next_block) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1538 | // Perform stack overflow check if this goto needs it before jumping. |
| 1539 | if (deferred_stack_check != NULL) { |
| 1540 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 1541 | __ cmp(sp, Operand(ip)); |
| 1542 | __ b(hs, chunk_->GetAssemblyLabel(block)); |
| 1543 | __ jmp(deferred_stack_check->entry()); |
| 1544 | deferred_stack_check->SetExit(chunk_->GetAssemblyLabel(block)); |
| 1545 | } else { |
| 1546 | __ jmp(chunk_->GetAssemblyLabel(block)); |
| 1547 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | void LCodeGen::DoDeferredStackCheck(LGoto* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1553 | __ PushSafepointRegisters(); |
| 1554 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 1555 | RecordSafepointWithRegisters( |
| 1556 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 1557 | __ PopSafepointRegisters(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | |
| 1561 | void LCodeGen::DoGoto(LGoto* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1562 | class DeferredStackCheck: public LDeferredCode { |
| 1563 | public: |
| 1564 | DeferredStackCheck(LCodeGen* codegen, LGoto* instr) |
| 1565 | : LDeferredCode(codegen), instr_(instr) { } |
| 1566 | virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } |
| 1567 | private: |
| 1568 | LGoto* instr_; |
| 1569 | }; |
| 1570 | |
| 1571 | DeferredStackCheck* deferred = NULL; |
| 1572 | if (instr->include_stack_check()) { |
| 1573 | deferred = new DeferredStackCheck(this, instr); |
| 1574 | } |
| 1575 | EmitGoto(instr->block_id(), deferred); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | |
| 1579 | Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1580 | Condition cond = kNoCondition; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1581 | switch (op) { |
| 1582 | case Token::EQ: |
| 1583 | case Token::EQ_STRICT: |
| 1584 | cond = eq; |
| 1585 | break; |
| 1586 | case Token::LT: |
| 1587 | cond = is_unsigned ? lo : lt; |
| 1588 | break; |
| 1589 | case Token::GT: |
| 1590 | cond = is_unsigned ? hi : gt; |
| 1591 | break; |
| 1592 | case Token::LTE: |
| 1593 | cond = is_unsigned ? ls : le; |
| 1594 | break; |
| 1595 | case Token::GTE: |
| 1596 | cond = is_unsigned ? hs : ge; |
| 1597 | break; |
| 1598 | case Token::IN: |
| 1599 | case Token::INSTANCEOF: |
| 1600 | default: |
| 1601 | UNREACHABLE(); |
| 1602 | } |
| 1603 | return cond; |
| 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | void LCodeGen::EmitCmpI(LOperand* left, LOperand* right) { |
| 1608 | __ cmp(ToRegister(left), ToOperand(right)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | void LCodeGen::DoCmpID(LCmpID* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 1613 | LOperand* left = instr->InputAt(0); |
| 1614 | LOperand* right = instr->InputAt(1); |
| 1615 | LOperand* result = instr->result(); |
| 1616 | Register scratch = scratch0(); |
| 1617 | |
| 1618 | Label unordered, done; |
| 1619 | if (instr->is_double()) { |
| 1620 | // Compare left and right as doubles and load the |
| 1621 | // resulting flags into the normal status register. |
| 1622 | __ vcmp(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1623 | __ vmrs(pc); |
| 1624 | // If a NaN is involved, i.e. the result is unordered (V set), |
| 1625 | // jump to unordered to return false. |
| 1626 | __ b(vs, &unordered); |
| 1627 | } else { |
| 1628 | EmitCmpI(left, right); |
| 1629 | } |
| 1630 | |
| 1631 | Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
| 1632 | __ LoadRoot(ToRegister(result), Heap::kTrueValueRootIndex); |
| 1633 | __ b(cc, &done); |
| 1634 | |
| 1635 | __ bind(&unordered); |
| 1636 | __ LoadRoot(ToRegister(result), Heap::kFalseValueRootIndex); |
| 1637 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | void LCodeGen::DoCmpIDAndBranch(LCmpIDAndBranch* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 1642 | LOperand* left = instr->InputAt(0); |
| 1643 | LOperand* right = instr->InputAt(1); |
| 1644 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1645 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1646 | |
| 1647 | if (instr->is_double()) { |
| 1648 | // Compare left and right as doubles and load the |
| 1649 | // resulting flags into the normal status register. |
| 1650 | __ vcmp(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 1651 | __ vmrs(pc); |
| 1652 | // If a NaN is involved, i.e. the result is unordered (V set), |
| 1653 | // jump to false block label. |
| 1654 | __ b(vs, chunk_->GetAssemblyLabel(false_block)); |
| 1655 | } else { |
| 1656 | EmitCmpI(left, right); |
| 1657 | } |
| 1658 | |
| 1659 | Condition cc = TokenToCondition(instr->op(), instr->is_double()); |
| 1660 | EmitBranch(true_block, false_block, cc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | |
| 1664 | void LCodeGen::DoCmpJSObjectEq(LCmpJSObjectEq* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1665 | Register left = ToRegister(instr->InputAt(0)); |
| 1666 | Register right = ToRegister(instr->InputAt(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1667 | Register result = ToRegister(instr->result()); |
| 1668 | |
| 1669 | __ cmp(left, Operand(right)); |
| 1670 | __ LoadRoot(result, Heap::kTrueValueRootIndex, eq); |
| 1671 | __ LoadRoot(result, Heap::kFalseValueRootIndex, ne); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | |
| 1675 | void LCodeGen::DoCmpJSObjectEqAndBranch(LCmpJSObjectEqAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1676 | Register left = ToRegister(instr->InputAt(0)); |
| 1677 | Register right = ToRegister(instr->InputAt(1)); |
| 1678 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1679 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1680 | |
| 1681 | __ cmp(left, Operand(right)); |
| 1682 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | |
| 1686 | void LCodeGen::DoIsNull(LIsNull* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1687 | Register reg = ToRegister(instr->InputAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1688 | Register result = ToRegister(instr->result()); |
| 1689 | |
| 1690 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1691 | __ cmp(reg, ip); |
| 1692 | if (instr->is_strict()) { |
| 1693 | __ LoadRoot(result, Heap::kTrueValueRootIndex, eq); |
| 1694 | __ LoadRoot(result, Heap::kFalseValueRootIndex, ne); |
| 1695 | } else { |
| 1696 | Label true_value, false_value, done; |
| 1697 | __ b(eq, &true_value); |
| 1698 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 1699 | __ cmp(ip, reg); |
| 1700 | __ b(eq, &true_value); |
| 1701 | __ tst(reg, Operand(kSmiTagMask)); |
| 1702 | __ b(eq, &false_value); |
| 1703 | // Check for undetectable objects by looking in the bit field in |
| 1704 | // the map. The object has already been smi checked. |
| 1705 | Register scratch = result; |
| 1706 | __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 1707 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 1708 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
| 1709 | __ b(ne, &true_value); |
| 1710 | __ bind(&false_value); |
| 1711 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 1712 | __ jmp(&done); |
| 1713 | __ bind(&true_value); |
| 1714 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 1715 | __ bind(&done); |
| 1716 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | |
| 1720 | void LCodeGen::DoIsNullAndBranch(LIsNullAndBranch* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1721 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1722 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1723 | |
| 1724 | // TODO(fsc): If the expression is known to be a smi, then it's |
| 1725 | // definitely not null. Jump to the false block. |
| 1726 | |
| 1727 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1728 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1729 | |
| 1730 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1731 | __ cmp(reg, ip); |
| 1732 | if (instr->is_strict()) { |
| 1733 | EmitBranch(true_block, false_block, eq); |
| 1734 | } else { |
| 1735 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1736 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1737 | __ b(eq, true_label); |
| 1738 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 1739 | __ cmp(reg, ip); |
| 1740 | __ b(eq, true_label); |
| 1741 | __ tst(reg, Operand(kSmiTagMask)); |
| 1742 | __ b(eq, false_label); |
| 1743 | // Check for undetectable objects by looking in the bit field in |
| 1744 | // the map. The object has already been smi checked. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1745 | __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 1746 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 1747 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
| 1748 | EmitBranch(true_block, false_block, ne); |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1753 | Condition LCodeGen::EmitIsObject(Register input, |
| 1754 | Register temp1, |
| 1755 | Register temp2, |
| 1756 | Label* is_not_object, |
| 1757 | Label* is_object) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1758 | __ JumpIfSmi(input, is_not_object); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1759 | |
| 1760 | __ LoadRoot(temp1, Heap::kNullValueRootIndex); |
| 1761 | __ cmp(input, temp1); |
| 1762 | __ b(eq, is_object); |
| 1763 | |
| 1764 | // Load map. |
| 1765 | __ ldr(temp1, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 1766 | // Undetectable objects behave like undefined. |
| 1767 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kBitFieldOffset)); |
| 1768 | __ tst(temp2, Operand(1 << Map::kIsUndetectable)); |
| 1769 | __ b(ne, is_not_object); |
| 1770 | |
| 1771 | // Load instance type and check that it is in object type range. |
| 1772 | __ ldrb(temp2, FieldMemOperand(temp1, Map::kInstanceTypeOffset)); |
| 1773 | __ cmp(temp2, Operand(FIRST_JS_OBJECT_TYPE)); |
| 1774 | __ b(lt, is_not_object); |
| 1775 | __ cmp(temp2, Operand(LAST_JS_OBJECT_TYPE)); |
| 1776 | return le; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | |
| 1780 | void LCodeGen::DoIsObject(LIsObject* instr) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1781 | Register reg = ToRegister(instr->InputAt(0)); |
| 1782 | Register result = ToRegister(instr->result()); |
| 1783 | Register temp = scratch0(); |
| 1784 | Label is_false, is_true, done; |
| 1785 | |
| 1786 | Condition true_cond = EmitIsObject(reg, result, temp, &is_false, &is_true); |
| 1787 | __ b(true_cond, &is_true); |
| 1788 | |
| 1789 | __ bind(&is_false); |
| 1790 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 1791 | __ b(&done); |
| 1792 | |
| 1793 | __ bind(&is_true); |
| 1794 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 1795 | |
| 1796 | __ bind(&done); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | |
| 1800 | void LCodeGen::DoIsObjectAndBranch(LIsObjectAndBranch* instr) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1801 | Register reg = ToRegister(instr->InputAt(0)); |
| 1802 | Register temp1 = ToRegister(instr->TempAt(0)); |
| 1803 | Register temp2 = scratch0(); |
| 1804 | |
| 1805 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1806 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1807 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1808 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1809 | |
| 1810 | Condition true_cond = |
| 1811 | EmitIsObject(reg, temp1, temp2, false_label, true_label); |
| 1812 | |
| 1813 | EmitBranch(true_block, false_block, true_cond); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1817 | void LCodeGen::DoIsSmi(LIsSmi* instr) { |
| 1818 | ASSERT(instr->hydrogen()->value()->representation().IsTagged()); |
| 1819 | Register result = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1820 | Register input_reg = EmitLoadRegister(instr->InputAt(0), ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1821 | __ tst(input_reg, Operand(kSmiTagMask)); |
| 1822 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 1823 | Label done; |
| 1824 | __ b(eq, &done); |
| 1825 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 1826 | __ bind(&done); |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
| 1831 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1832 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1833 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1834 | Register input_reg = EmitLoadRegister(instr->InputAt(0), ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1835 | __ tst(input_reg, Operand(kSmiTagMask)); |
| 1836 | EmitBranch(true_block, false_block, eq); |
| 1837 | } |
| 1838 | |
| 1839 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1840 | static InstanceType TestType(HHasInstanceType* instr) { |
| 1841 | InstanceType from = instr->from(); |
| 1842 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1843 | if (from == FIRST_TYPE) return to; |
| 1844 | ASSERT(from == to || to == LAST_TYPE); |
| 1845 | return from; |
| 1846 | } |
| 1847 | |
| 1848 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1849 | static Condition BranchCondition(HHasInstanceType* instr) { |
| 1850 | InstanceType from = instr->from(); |
| 1851 | InstanceType to = instr->to(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1852 | if (from == to) return eq; |
| 1853 | if (to == LAST_TYPE) return hs; |
| 1854 | if (from == FIRST_TYPE) return ls; |
| 1855 | UNREACHABLE(); |
| 1856 | return eq; |
| 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | void LCodeGen::DoHasInstanceType(LHasInstanceType* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1861 | Register input = ToRegister(instr->InputAt(0)); |
| 1862 | Register result = ToRegister(instr->result()); |
| 1863 | |
| 1864 | ASSERT(instr->hydrogen()->value()->representation().IsTagged()); |
| 1865 | Label done; |
| 1866 | __ tst(input, Operand(kSmiTagMask)); |
| 1867 | __ LoadRoot(result, Heap::kFalseValueRootIndex, eq); |
| 1868 | __ b(eq, &done); |
| 1869 | __ CompareObjectType(input, result, result, TestType(instr->hydrogen())); |
| 1870 | Condition cond = BranchCondition(instr->hydrogen()); |
| 1871 | __ LoadRoot(result, Heap::kTrueValueRootIndex, cond); |
| 1872 | __ LoadRoot(result, Heap::kFalseValueRootIndex, NegateCondition(cond)); |
| 1873 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | |
| 1877 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1878 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1879 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1880 | |
| 1881 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1882 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1883 | |
| 1884 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1885 | |
| 1886 | __ tst(input, Operand(kSmiTagMask)); |
| 1887 | __ b(eq, false_label); |
| 1888 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1889 | __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); |
| 1890 | EmitBranch(true_block, false_block, BranchCondition(instr->hydrogen())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | void LCodeGen::DoHasCachedArrayIndex(LHasCachedArrayIndex* instr) { |
| 1895 | Abort("DoHasCachedArrayIndex unimplemented."); |
| 1896 | } |
| 1897 | |
| 1898 | |
| 1899 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 1900 | LHasCachedArrayIndexAndBranch* instr) { |
| 1901 | Abort("DoHasCachedArrayIndexAndBranch unimplemented."); |
| 1902 | } |
| 1903 | |
| 1904 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1905 | // Branches to a label or falls through with the answer in flags. Trashes |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1906 | // the temp registers, but not the input. Only input and temp2 may alias. |
| 1907 | void LCodeGen::EmitClassOfTest(Label* is_true, |
| 1908 | Label* is_false, |
| 1909 | Handle<String>class_name, |
| 1910 | Register input, |
| 1911 | Register temp, |
| 1912 | Register temp2) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1913 | ASSERT(!input.is(temp)); |
| 1914 | ASSERT(!temp.is(temp2)); // But input and temp2 may be the same register. |
| 1915 | __ tst(input, Operand(kSmiTagMask)); |
| 1916 | __ b(eq, is_false); |
| 1917 | __ CompareObjectType(input, temp, temp2, FIRST_JS_OBJECT_TYPE); |
| 1918 | __ b(lt, is_false); |
| 1919 | |
| 1920 | // Map is now in temp. |
| 1921 | // Functions have class 'Function'. |
| 1922 | __ CompareInstanceType(temp, temp2, JS_FUNCTION_TYPE); |
| 1923 | if (class_name->IsEqualTo(CStrVector("Function"))) { |
| 1924 | __ b(eq, is_true); |
| 1925 | } else { |
| 1926 | __ b(eq, is_false); |
| 1927 | } |
| 1928 | |
| 1929 | // Check if the constructor in the map is a function. |
| 1930 | __ ldr(temp, FieldMemOperand(temp, Map::kConstructorOffset)); |
| 1931 | |
| 1932 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 1933 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 1934 | // LAST_JS_OBJECT_TYPE. |
| 1935 | ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 1936 | ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
| 1937 | |
| 1938 | // Objects with a non-function constructor have class 'Object'. |
| 1939 | __ CompareObjectType(temp, temp2, temp2, JS_FUNCTION_TYPE); |
| 1940 | if (class_name->IsEqualTo(CStrVector("Object"))) { |
| 1941 | __ b(ne, is_true); |
| 1942 | } else { |
| 1943 | __ b(ne, is_false); |
| 1944 | } |
| 1945 | |
| 1946 | // temp now contains the constructor function. Grab the |
| 1947 | // instance class name from there. |
| 1948 | __ ldr(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 1949 | __ ldr(temp, FieldMemOperand(temp, |
| 1950 | SharedFunctionInfo::kInstanceClassNameOffset)); |
| 1951 | // The class name we are testing against is a symbol because it's a literal. |
| 1952 | // The name in the constructor is a symbol because of the way the context is |
| 1953 | // booted. This routine isn't expected to work for random API-created |
| 1954 | // classes and it doesn't have to because you can't access it with natives |
| 1955 | // syntax. Since both sides are symbols it is sufficient to use an identity |
| 1956 | // comparison. |
| 1957 | __ cmp(temp, Operand(class_name)); |
| 1958 | // End with the answer in flags. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | |
| 1962 | void LCodeGen::DoClassOfTest(LClassOfTest* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1963 | Register input = ToRegister(instr->InputAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1964 | Register result = ToRegister(instr->result()); |
| 1965 | ASSERT(input.is(result)); |
| 1966 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 1967 | |
| 1968 | Label done, is_true, is_false; |
| 1969 | |
| 1970 | EmitClassOfTest(&is_true, &is_false, class_name, input, scratch0(), input); |
| 1971 | __ b(ne, &is_false); |
| 1972 | |
| 1973 | __ bind(&is_true); |
| 1974 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 1975 | __ jmp(&done); |
| 1976 | |
| 1977 | __ bind(&is_false); |
| 1978 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 1979 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | |
| 1983 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1984 | Register input = ToRegister(instr->InputAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1985 | Register temp = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1986 | Register temp2 = ToRegister(instr->TempAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1987 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 1988 | |
| 1989 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 1990 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 1991 | |
| 1992 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 1993 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 1994 | |
| 1995 | EmitClassOfTest(true_label, false_label, class_name, input, temp, temp2); |
| 1996 | |
| 1997 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | |
| 2001 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2002 | Register reg = ToRegister(instr->InputAt(0)); |
| 2003 | Register temp = ToRegister(instr->TempAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2004 | int true_block = instr->true_block_id(); |
| 2005 | int false_block = instr->false_block_id(); |
| 2006 | |
| 2007 | __ ldr(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2008 | __ cmp(temp, Operand(instr->map())); |
| 2009 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | |
| 2013 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2014 | ASSERT(ToRegister(instr->InputAt(0)).is(r0)); // Object is in r0. |
| 2015 | ASSERT(ToRegister(instr->InputAt(1)).is(r1)); // Function is in r1. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2016 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2017 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
| 2018 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2019 | |
| 2020 | Label true_value, done; |
| 2021 | __ tst(r0, r0); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2022 | __ mov(r0, Operand(Factory::false_value()), LeaveCC, ne); |
| 2023 | __ mov(r0, Operand(Factory::true_value()), LeaveCC, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | void LCodeGen::DoInstanceOfAndBranch(LInstanceOfAndBranch* instr) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2028 | ASSERT(ToRegister(instr->InputAt(0)).is(r0)); // Object is in r0. |
| 2029 | ASSERT(ToRegister(instr->InputAt(1)).is(r1)); // Function is in r1. |
| 2030 | |
| 2031 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 2032 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 2033 | |
| 2034 | InstanceofStub stub(InstanceofStub::kArgsInRegisters); |
| 2035 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2036 | __ tst(r0, Operand(r0)); |
| 2037 | EmitBranch(true_block, false_block, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2041 | void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2042 | class DeferredInstanceOfKnownGlobal: public LDeferredCode { |
| 2043 | public: |
| 2044 | DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
| 2045 | LInstanceOfKnownGlobal* instr) |
| 2046 | : LDeferredCode(codegen), instr_(instr) { } |
| 2047 | virtual void Generate() { |
| 2048 | codegen()->DoDeferredLInstanceOfKnownGlobal(instr_, &map_check_); |
| 2049 | } |
| 2050 | |
| 2051 | Label* map_check() { return &map_check_; } |
| 2052 | |
| 2053 | private: |
| 2054 | LInstanceOfKnownGlobal* instr_; |
| 2055 | Label map_check_; |
| 2056 | }; |
| 2057 | |
| 2058 | DeferredInstanceOfKnownGlobal* deferred; |
| 2059 | deferred = new DeferredInstanceOfKnownGlobal(this, instr); |
| 2060 | |
| 2061 | Label done, false_result; |
| 2062 | Register object = ToRegister(instr->InputAt(0)); |
| 2063 | Register temp = ToRegister(instr->TempAt(0)); |
| 2064 | Register result = ToRegister(instr->result()); |
| 2065 | |
| 2066 | ASSERT(object.is(r0)); |
| 2067 | ASSERT(result.is(r0)); |
| 2068 | |
| 2069 | // A Smi is not instance of anything. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2070 | __ JumpIfSmi(object, &false_result); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2071 | |
| 2072 | // This is the inlined call site instanceof cache. The two occurences of the |
| 2073 | // hole value will be patched to the last map/result pair generated by the |
| 2074 | // instanceof stub. |
| 2075 | Label cache_miss; |
| 2076 | Register map = temp; |
| 2077 | __ ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2078 | __ bind(deferred->map_check()); // Label for calculating code patching. |
| 2079 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2080 | // root array to force relocation to be able to later patch with |
| 2081 | // the cached map. |
| 2082 | __ mov(ip, Operand(Factory::the_hole_value())); |
| 2083 | __ cmp(map, Operand(ip)); |
| 2084 | __ b(ne, &cache_miss); |
| 2085 | // We use Factory::the_hole_value() on purpose instead of loading from the |
| 2086 | // root array to force relocation to be able to later patch |
| 2087 | // with true or false. |
| 2088 | __ mov(result, Operand(Factory::the_hole_value())); |
| 2089 | __ b(&done); |
| 2090 | |
| 2091 | // The inlined call site cache did not match. Check null and string before |
| 2092 | // calling the deferred code. |
| 2093 | __ bind(&cache_miss); |
| 2094 | // Null is not instance of anything. |
| 2095 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2096 | __ cmp(object, Operand(ip)); |
| 2097 | __ b(eq, &false_result); |
| 2098 | |
| 2099 | // String values is not instance of anything. |
| 2100 | Condition is_string = masm_->IsObjectStringType(object, temp); |
| 2101 | __ b(is_string, &false_result); |
| 2102 | |
| 2103 | // Go to the deferred code. |
| 2104 | __ b(deferred->entry()); |
| 2105 | |
| 2106 | __ bind(&false_result); |
| 2107 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 2108 | |
| 2109 | // Here result has either true or false. Deferred code also produces true or |
| 2110 | // false object. |
| 2111 | __ bind(deferred->exit()); |
| 2112 | __ bind(&done); |
| 2113 | } |
| 2114 | |
| 2115 | |
| 2116 | void LCodeGen::DoDeferredLInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 2117 | Label* map_check) { |
| 2118 | Register result = ToRegister(instr->result()); |
| 2119 | ASSERT(result.is(r0)); |
| 2120 | |
| 2121 | InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
| 2122 | flags = static_cast<InstanceofStub::Flags>( |
| 2123 | flags | InstanceofStub::kArgsInRegisters); |
| 2124 | flags = static_cast<InstanceofStub::Flags>( |
| 2125 | flags | InstanceofStub::kCallSiteInlineCheck); |
| 2126 | flags = static_cast<InstanceofStub::Flags>( |
| 2127 | flags | InstanceofStub::kReturnTrueFalseObject); |
| 2128 | InstanceofStub stub(flags); |
| 2129 | |
| 2130 | __ PushSafepointRegisters(); |
| 2131 | |
| 2132 | // Get the temp register reserved by the instruction. This needs to be r4 as |
| 2133 | // its slot of the pushing of safepoint registers is used to communicate the |
| 2134 | // offset to the location of the map check. |
| 2135 | Register temp = ToRegister(instr->TempAt(0)); |
| 2136 | ASSERT(temp.is(r4)); |
| 2137 | __ mov(InstanceofStub::right(), Operand(instr->function())); |
| 2138 | static const int kAdditionalDelta = 4; |
| 2139 | int delta = masm_->InstructionsGeneratedSince(map_check) + kAdditionalDelta; |
| 2140 | Label before_push_delta; |
| 2141 | __ bind(&before_push_delta); |
| 2142 | __ BlockConstPoolFor(kAdditionalDelta); |
| 2143 | __ mov(temp, Operand(delta * kPointerSize)); |
| 2144 | __ StoreToSafepointRegisterSlot(temp); |
| 2145 | __ Call(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2146 | ASSERT_EQ(kAdditionalDelta, |
| 2147 | masm_->InstructionsGeneratedSince(&before_push_delta)); |
| 2148 | RecordSafepointWithRegisters( |
| 2149 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 2150 | // Put the result value into the result register slot and |
| 2151 | // restore all registers. |
| 2152 | __ StoreToSafepointRegisterSlot(result); |
| 2153 | |
| 2154 | __ PopSafepointRegisters(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2157 | |
| 2158 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2159 | switch (op) { |
| 2160 | case Token::EQ_STRICT: |
| 2161 | case Token::EQ: |
| 2162 | return eq; |
| 2163 | case Token::LT: |
| 2164 | return lt; |
| 2165 | case Token::GT: |
| 2166 | return gt; |
| 2167 | case Token::LTE: |
| 2168 | return le; |
| 2169 | case Token::GTE: |
| 2170 | return ge; |
| 2171 | default: |
| 2172 | UNREACHABLE(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2173 | return kNoCondition; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | |
| 2178 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 2179 | Token::Value op = instr->op(); |
| 2180 | |
| 2181 | Handle<Code> ic = CompareIC::GetUninitialized(op); |
| 2182 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2183 | |
| 2184 | Condition condition = ComputeCompareCondition(op); |
| 2185 | if (op == Token::GT || op == Token::LTE) { |
| 2186 | condition = ReverseCondition(condition); |
| 2187 | } |
| 2188 | __ cmp(r0, Operand(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2189 | __ LoadRoot(ToRegister(instr->result()), |
| 2190 | Heap::kTrueValueRootIndex, |
| 2191 | condition); |
| 2192 | __ LoadRoot(ToRegister(instr->result()), |
| 2193 | Heap::kFalseValueRootIndex, |
| 2194 | NegateCondition(condition)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | void LCodeGen::DoCmpTAndBranch(LCmpTAndBranch* instr) { |
| 2199 | Abort("DoCmpTAndBranch unimplemented."); |
| 2200 | } |
| 2201 | |
| 2202 | |
| 2203 | void LCodeGen::DoReturn(LReturn* instr) { |
| 2204 | if (FLAG_trace) { |
| 2205 | // Push the return value on the stack as the parameter. |
| 2206 | // Runtime::TraceExit returns its parameter in r0. |
| 2207 | __ push(r0); |
| 2208 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 2209 | } |
| 2210 | int32_t sp_delta = (ParameterCount() + 1) * kPointerSize; |
| 2211 | __ mov(sp, fp); |
| 2212 | __ ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 2213 | __ add(sp, sp, Operand(sp_delta)); |
| 2214 | __ Jump(lr); |
| 2215 | } |
| 2216 | |
| 2217 | |
| 2218 | void LCodeGen::DoLoadGlobal(LLoadGlobal* instr) { |
| 2219 | Register result = ToRegister(instr->result()); |
| 2220 | __ mov(ip, Operand(Handle<Object>(instr->hydrogen()->cell()))); |
| 2221 | __ ldr(result, FieldMemOperand(ip, JSGlobalPropertyCell::kValueOffset)); |
| 2222 | if (instr->hydrogen()->check_hole_value()) { |
| 2223 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2224 | __ cmp(result, ip); |
| 2225 | DeoptimizeIf(eq, instr->environment()); |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | |
| 2230 | void LCodeGen::DoStoreGlobal(LStoreGlobal* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2231 | Register value = ToRegister(instr->InputAt(0)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2232 | Register scratch = scratch0(); |
| 2233 | |
| 2234 | // Load the cell. |
| 2235 | __ mov(scratch, Operand(Handle<Object>(instr->hydrogen()->cell()))); |
| 2236 | |
| 2237 | // If the cell we are storing to contains the hole it could have |
| 2238 | // been deleted from the property dictionary. In that case, we need |
| 2239 | // to update the property details in the property dictionary to mark |
| 2240 | // it as no longer deleted. |
| 2241 | if (instr->hydrogen()->check_hole_value()) { |
| 2242 | Register scratch2 = ToRegister(instr->TempAt(0)); |
| 2243 | __ ldr(scratch2, |
| 2244 | FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset)); |
| 2245 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2246 | __ cmp(scratch2, ip); |
| 2247 | DeoptimizeIf(eq, instr->environment()); |
| 2248 | } |
| 2249 | |
| 2250 | // Store the value. |
| 2251 | __ str(value, FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2255 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2256 | Register context = ToRegister(instr->context()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2257 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2258 | __ ldr(result, |
| 2259 | MemOperand(context, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2260 | __ ldr(result, ContextOperand(result, instr->slot_index())); |
| 2261 | } |
| 2262 | |
| 2263 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2264 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 2265 | Register context = ToRegister(instr->context()); |
| 2266 | Register value = ToRegister(instr->value()); |
| 2267 | __ ldr(context, |
| 2268 | MemOperand(context, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2269 | __ str(value, ContextOperand(context, instr->slot_index())); |
| 2270 | if (instr->needs_write_barrier()) { |
| 2271 | int offset = Context::SlotOffset(instr->slot_index()); |
| 2272 | __ RecordWrite(context, Operand(offset), value, scratch0()); |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2277 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2278 | Register object = ToRegister(instr->InputAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2279 | Register result = ToRegister(instr->result()); |
| 2280 | if (instr->hydrogen()->is_in_object()) { |
| 2281 | __ ldr(result, FieldMemOperand(object, instr->hydrogen()->offset())); |
| 2282 | } else { |
| 2283 | __ ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 2284 | __ ldr(result, FieldMemOperand(result, instr->hydrogen()->offset())); |
| 2285 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
| 2290 | ASSERT(ToRegister(instr->object()).is(r0)); |
| 2291 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2292 | |
| 2293 | // Name is always in r2. |
| 2294 | __ mov(r2, Operand(instr->name())); |
| 2295 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 2296 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2297 | } |
| 2298 | |
| 2299 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2300 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2301 | Register scratch = scratch0(); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2302 | Register function = ToRegister(instr->function()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2303 | Register result = ToRegister(instr->result()); |
| 2304 | |
| 2305 | // Check that the function really is a function. Load map into the |
| 2306 | // result register. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2307 | __ CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2308 | DeoptimizeIf(ne, instr->environment()); |
| 2309 | |
| 2310 | // Make sure that the function has an instance prototype. |
| 2311 | Label non_instance; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2312 | __ ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 2313 | __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2314 | __ b(ne, &non_instance); |
| 2315 | |
| 2316 | // Get the prototype or initial map from the function. |
| 2317 | __ ldr(result, |
| 2318 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2319 | |
| 2320 | // Check that the function has a prototype or an initial map. |
| 2321 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2322 | __ cmp(result, ip); |
| 2323 | DeoptimizeIf(eq, instr->environment()); |
| 2324 | |
| 2325 | // If the function does not have an initial map, we're done. |
| 2326 | Label done; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2327 | __ CompareObjectType(result, scratch, scratch, MAP_TYPE); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2328 | __ b(ne, &done); |
| 2329 | |
| 2330 | // Get the prototype from the initial map. |
| 2331 | __ ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 2332 | __ jmp(&done); |
| 2333 | |
| 2334 | // Non-instance prototype: Fetch prototype from constructor field |
| 2335 | // in initial map. |
| 2336 | __ bind(&non_instance); |
| 2337 | __ ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 2338 | |
| 2339 | // All done. |
| 2340 | __ bind(&done); |
| 2341 | } |
| 2342 | |
| 2343 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2344 | void LCodeGen::DoLoadElements(LLoadElements* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2345 | ASSERT(instr->result()->Equals(instr->InputAt(0))); |
| 2346 | Register reg = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2347 | Register scratch = scratch0(); |
| 2348 | |
| 2349 | __ ldr(reg, FieldMemOperand(reg, JSObject::kElementsOffset)); |
| 2350 | if (FLAG_debug_code) { |
| 2351 | Label done; |
| 2352 | __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2353 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 2354 | __ cmp(scratch, ip); |
| 2355 | __ b(eq, &done); |
| 2356 | __ LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 2357 | __ cmp(scratch, ip); |
| 2358 | __ Check(eq, "Check for fast elements failed."); |
| 2359 | __ bind(&done); |
| 2360 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | |
| 2364 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2365 | Register arguments = ToRegister(instr->arguments()); |
| 2366 | Register length = ToRegister(instr->length()); |
| 2367 | Register index = ToRegister(instr->index()); |
| 2368 | Register result = ToRegister(instr->result()); |
| 2369 | |
| 2370 | // Bailout index is not a valid argument index. Use unsigned check to get |
| 2371 | // negative check for free. |
| 2372 | __ sub(length, length, index, SetCC); |
| 2373 | DeoptimizeIf(ls, instr->environment()); |
| 2374 | |
| 2375 | // There are two words between the frame pointer and the last argument. |
| 2376 | // Subtracting from length accounts for one of them add one more. |
| 2377 | __ add(length, length, Operand(1)); |
| 2378 | __ ldr(result, MemOperand(arguments, length, LSL, kPointerSizeLog2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | |
| 2382 | void LCodeGen::DoLoadKeyedFastElement(LLoadKeyedFastElement* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2383 | Register elements = ToRegister(instr->elements()); |
| 2384 | Register key = EmitLoadRegister(instr->key(), scratch0()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2385 | Register result = ToRegister(instr->result()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2386 | Register scratch = scratch0(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2387 | ASSERT(result.is(elements)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2388 | |
| 2389 | // Load the result. |
| 2390 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 2391 | __ ldr(result, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 2392 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2393 | // Check for the hole value. |
| 2394 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 2395 | __ cmp(result, scratch); |
| 2396 | DeoptimizeIf(eq, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | |
| 2400 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
| 2401 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 2402 | ASSERT(ToRegister(instr->key()).is(r0)); |
| 2403 | |
| 2404 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
| 2405 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2406 | } |
| 2407 | |
| 2408 | |
| 2409 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2410 | Register scratch = scratch0(); |
| 2411 | Register result = ToRegister(instr->result()); |
| 2412 | |
| 2413 | // Check if the calling frame is an arguments adaptor frame. |
| 2414 | Label done, adapted; |
| 2415 | __ ldr(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2416 | __ ldr(result, MemOperand(scratch, StandardFrameConstants::kContextOffset)); |
| 2417 | __ cmp(result, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2418 | |
| 2419 | // Result is the frame pointer for the frame if not adapted and for the real |
| 2420 | // frame below the adaptor frame if adapted. |
| 2421 | __ mov(result, fp, LeaveCC, ne); |
| 2422 | __ mov(result, scratch, LeaveCC, eq); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | |
| 2426 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2427 | Register elem = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2428 | Register result = ToRegister(instr->result()); |
| 2429 | |
| 2430 | Label done; |
| 2431 | |
| 2432 | // If no arguments adaptor frame the number of arguments is fixed. |
| 2433 | __ cmp(fp, elem); |
| 2434 | __ mov(result, Operand(scope()->num_parameters())); |
| 2435 | __ b(eq, &done); |
| 2436 | |
| 2437 | // Arguments adaptor frame present. Get argument length from there. |
| 2438 | __ ldr(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2439 | __ ldr(result, |
| 2440 | MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2441 | __ SmiUntag(result); |
| 2442 | |
| 2443 | // Argument length is in result register. |
| 2444 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | |
| 2448 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2449 | Register receiver = ToRegister(instr->receiver()); |
| 2450 | Register function = ToRegister(instr->function()); |
| 2451 | Register scratch = scratch0(); |
| 2452 | |
| 2453 | ASSERT(receiver.is(r0)); |
| 2454 | ASSERT(function.is(r1)); |
| 2455 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2456 | |
| 2457 | // If the receiver is null or undefined, we have to pass the |
| 2458 | // global object as a receiver. |
| 2459 | Label global_receiver, receiver_ok; |
| 2460 | __ LoadRoot(scratch, Heap::kNullValueRootIndex); |
| 2461 | __ cmp(receiver, scratch); |
| 2462 | __ b(eq, &global_receiver); |
| 2463 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 2464 | __ cmp(receiver, scratch); |
| 2465 | __ b(ne, &receiver_ok); |
| 2466 | __ bind(&global_receiver); |
| 2467 | __ ldr(receiver, GlobalObjectOperand()); |
| 2468 | __ bind(&receiver_ok); |
| 2469 | |
| 2470 | Register length = ToRegister(instr->length()); |
| 2471 | Register elements = ToRegister(instr->elements()); |
| 2472 | |
| 2473 | Label invoke; |
| 2474 | |
| 2475 | // Copy the arguments to this function possibly from the |
| 2476 | // adaptor frame below it. |
| 2477 | const uint32_t kArgumentsLimit = 1 * KB; |
| 2478 | __ cmp(length, Operand(kArgumentsLimit)); |
| 2479 | DeoptimizeIf(hi, instr->environment()); |
| 2480 | |
| 2481 | // Push the receiver and use the register to keep the original |
| 2482 | // number of arguments. |
| 2483 | __ push(receiver); |
| 2484 | __ mov(receiver, length); |
| 2485 | // The arguments are at a one pointer size offset from elements. |
| 2486 | __ add(elements, elements, Operand(1 * kPointerSize)); |
| 2487 | |
| 2488 | // Loop through the arguments pushing them onto the execution |
| 2489 | // stack. |
| 2490 | Label loop; |
| 2491 | // length is a small non-negative integer, due to the test above. |
| 2492 | __ tst(length, Operand(length)); |
| 2493 | __ b(eq, &invoke); |
| 2494 | __ bind(&loop); |
| 2495 | __ ldr(scratch, MemOperand(elements, length, LSL, 2)); |
| 2496 | __ push(scratch); |
| 2497 | __ sub(length, length, Operand(1), SetCC); |
| 2498 | __ b(ne, &loop); |
| 2499 | |
| 2500 | __ bind(&invoke); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2501 | ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
| 2502 | LPointerMap* pointers = instr->pointer_map(); |
| 2503 | LEnvironment* env = instr->deoptimization_environment(); |
| 2504 | RecordPosition(pointers->position()); |
| 2505 | RegisterEnvironmentForDeoptimization(env); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2506 | SafepointGenerator safepoint_generator(this, |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2507 | pointers, |
| 2508 | env->deoptimization_index()); |
| 2509 | // The number of arguments is stored in receiver which is r0, as expected |
| 2510 | // by InvokeFunction. |
| 2511 | v8::internal::ParameterCount actual(receiver); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2512 | __ InvokeFunction(function, actual, CALL_FUNCTION, &safepoint_generator); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | |
| 2516 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2517 | LOperand* argument = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2518 | if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
| 2519 | Abort("DoPushArgument not implemented for double type."); |
| 2520 | } else { |
| 2521 | Register argument_reg = EmitLoadRegister(argument, ip); |
| 2522 | __ push(argument_reg); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2527 | void LCodeGen::DoContext(LContext* instr) { |
| 2528 | Register result = ToRegister(instr->result()); |
| 2529 | __ mov(result, cp); |
| 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | void LCodeGen::DoOuterContext(LOuterContext* instr) { |
| 2534 | Register context = ToRegister(instr->context()); |
| 2535 | Register result = ToRegister(instr->result()); |
| 2536 | __ ldr(result, |
| 2537 | MemOperand(context, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2538 | __ ldr(result, FieldMemOperand(result, JSFunction::kContextOffset)); |
| 2539 | } |
| 2540 | |
| 2541 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2542 | void LCodeGen::DoGlobalObject(LGlobalObject* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2543 | Register context = ToRegister(instr->context()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2544 | Register result = ToRegister(instr->result()); |
| 2545 | __ ldr(result, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 2546 | } |
| 2547 | |
| 2548 | |
| 2549 | void LCodeGen::DoGlobalReceiver(LGlobalReceiver* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2550 | Register global = ToRegister(instr->global()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2551 | Register result = ToRegister(instr->result()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2552 | __ ldr(result, FieldMemOperand(global, GlobalObject::kGlobalReceiverOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | |
| 2556 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
| 2557 | int arity, |
| 2558 | LInstruction* instr) { |
| 2559 | // Change context if needed. |
| 2560 | bool change_context = |
| 2561 | (graph()->info()->closure()->context() != function->context()) || |
| 2562 | scope()->contains_with() || |
| 2563 | (scope()->num_heap_slots() > 0); |
| 2564 | if (change_context) { |
| 2565 | __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 2566 | } |
| 2567 | |
| 2568 | // Set r0 to arguments count if adaption is not needed. Assumes that r0 |
| 2569 | // is available to write to at this point. |
| 2570 | if (!function->NeedsArgumentsAdaption()) { |
| 2571 | __ mov(r0, Operand(arity)); |
| 2572 | } |
| 2573 | |
| 2574 | LPointerMap* pointers = instr->pointer_map(); |
| 2575 | RecordPosition(pointers->position()); |
| 2576 | |
| 2577 | // Invoke function. |
| 2578 | __ ldr(ip, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 2579 | __ Call(ip); |
| 2580 | |
| 2581 | // Setup deoptimization. |
| 2582 | RegisterLazyDeoptimization(instr); |
| 2583 | |
| 2584 | // Restore context. |
| 2585 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2586 | } |
| 2587 | |
| 2588 | |
| 2589 | void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2590 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2591 | __ mov(r1, Operand(instr->function())); |
| 2592 | CallKnownFunction(instr->function(), instr->arity(), instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | |
| 2596 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2597 | ASSERT(instr->InputAt(0)->Equals(instr->result())); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2598 | Register input = ToRegister(instr->InputAt(0)); |
| 2599 | Register scratch = scratch0(); |
| 2600 | |
| 2601 | // Deoptimize if not a heap number. |
| 2602 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2603 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 2604 | __ cmp(scratch, Operand(ip)); |
| 2605 | DeoptimizeIf(ne, instr->environment()); |
| 2606 | |
| 2607 | Label done; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2608 | Register exponent = scratch0(); |
| 2609 | scratch = no_reg; |
| 2610 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2611 | // Check the sign of the argument. If the argument is positive, just |
| 2612 | // return it. We do not need to patch the stack since |input| and |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2613 | // |result| are the same register and |input| would be restored |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2614 | // unchanged by popping safepoint registers. |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2615 | __ tst(exponent, Operand(HeapNumber::kSignMask)); |
| 2616 | __ b(eq, &done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2617 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2618 | // Input is negative. Reverse its sign. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2619 | // Preserve the value of all registers. |
| 2620 | __ PushSafepointRegisters(); |
| 2621 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2622 | // Registers were saved at the safepoint, so we can use |
| 2623 | // many scratch registers. |
| 2624 | Register tmp1 = input.is(r1) ? r0 : r1; |
| 2625 | Register tmp2 = input.is(r2) ? r0 : r2; |
| 2626 | Register tmp3 = input.is(r3) ? r0 : r3; |
| 2627 | Register tmp4 = input.is(r4) ? r0 : r4; |
| 2628 | |
| 2629 | // exponent: floating point exponent value. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2630 | |
| 2631 | Label allocated, slow; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2632 | __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 2633 | __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2634 | __ b(&allocated); |
| 2635 | |
| 2636 | // Slow case: Call the runtime system to do the number allocation. |
| 2637 | __ bind(&slow); |
| 2638 | |
| 2639 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 2640 | RecordSafepointWithRegisters( |
| 2641 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 2642 | // Set the pointer to the new heap number in tmp. |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2643 | if (!tmp1.is(r0)) __ mov(tmp1, Operand(r0)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2644 | // Restore input_reg after call to runtime. |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2645 | __ LoadFromSafepointRegisterSlot(input); |
| 2646 | __ ldr(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2647 | |
| 2648 | __ bind(&allocated); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2649 | // exponent: floating point exponent value. |
| 2650 | // tmp1: allocated heap number. |
| 2651 | __ bic(exponent, exponent, Operand(HeapNumber::kSignMask)); |
| 2652 | __ str(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2653 | __ ldr(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2654 | __ str(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2655 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2656 | __ str(tmp1, masm()->SafepointRegisterSlot(input)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2657 | __ PopSafepointRegisters(); |
| 2658 | |
| 2659 | __ bind(&done); |
| 2660 | } |
| 2661 | |
| 2662 | |
| 2663 | void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2664 | Register input = ToRegister(instr->InputAt(0)); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2665 | __ cmp(input, Operand(0)); |
| 2666 | // We can make rsb conditional because the previous cmp instruction |
| 2667 | // will clear the V (overflow) flag and rsb won't set this flag |
| 2668 | // if input is positive. |
| 2669 | __ rsb(input, input, Operand(0), SetCC, mi); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2670 | // Deoptimize on overflow. |
| 2671 | DeoptimizeIf(vs, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | |
| 2675 | void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2676 | // Class for deferred case. |
| 2677 | class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { |
| 2678 | public: |
| 2679 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, |
| 2680 | LUnaryMathOperation* instr) |
| 2681 | : LDeferredCode(codegen), instr_(instr) { } |
| 2682 | virtual void Generate() { |
| 2683 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 2684 | } |
| 2685 | private: |
| 2686 | LUnaryMathOperation* instr_; |
| 2687 | }; |
| 2688 | |
| 2689 | ASSERT(instr->InputAt(0)->Equals(instr->result())); |
| 2690 | Representation r = instr->hydrogen()->value()->representation(); |
| 2691 | if (r.IsDouble()) { |
| 2692 | DwVfpRegister input = ToDoubleRegister(instr->InputAt(0)); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2693 | __ vabs(input, input); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2694 | } else if (r.IsInteger32()) { |
| 2695 | EmitIntegerMathAbs(instr); |
| 2696 | } else { |
| 2697 | // Representation is tagged. |
| 2698 | DeferredMathAbsTaggedHeapNumber* deferred = |
| 2699 | new DeferredMathAbsTaggedHeapNumber(this, instr); |
| 2700 | Register input = ToRegister(instr->InputAt(0)); |
| 2701 | // Smi check. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2702 | __ JumpIfNotSmi(input, deferred->entry()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2703 | // If smi, handle it directly. |
| 2704 | EmitIntegerMathAbs(instr); |
| 2705 | __ bind(deferred->exit()); |
| 2706 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2710 | // Truncates a double using a specific rounding mode. |
| 2711 | // Clears the z flag (ne condition) if an overflow occurs. |
| 2712 | void LCodeGen::EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 2713 | SwVfpRegister result, |
| 2714 | DwVfpRegister double_input, |
| 2715 | Register scratch1, |
| 2716 | Register scratch2) { |
| 2717 | Register prev_fpscr = scratch1; |
| 2718 | Register scratch = scratch2; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2719 | |
| 2720 | // Set custom FPCSR: |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2721 | // - Set rounding mode. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2722 | // - Clear vfp cumulative exception flags. |
| 2723 | // - Make sure Flush-to-zero mode control bit is unset. |
| 2724 | __ vmrs(prev_fpscr); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2725 | __ bic(scratch, prev_fpscr, Operand(kVFPExceptionMask | |
| 2726 | kVFPRoundingModeMask | |
| 2727 | kVFPFlushToZeroMask)); |
| 2728 | __ orr(scratch, scratch, Operand(rounding_mode)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2729 | __ vmsr(scratch); |
| 2730 | |
| 2731 | // Convert the argument to an integer. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2732 | __ vcvt_s32_f64(result, |
| 2733 | double_input, |
| 2734 | kFPSCRRounding); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2735 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2736 | // Retrieve FPSCR. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2737 | __ vmrs(scratch); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2738 | // Restore FPSCR. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2739 | __ vmsr(prev_fpscr); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2740 | // Check for vfp exceptions. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2741 | __ tst(scratch, Operand(kVFPExceptionMask)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2742 | } |
| 2743 | |
| 2744 | |
| 2745 | void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { |
| 2746 | DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
| 2747 | Register result = ToRegister(instr->result()); |
| 2748 | SwVfpRegister single_scratch = double_scratch0().low(); |
| 2749 | Register scratch1 = scratch0(); |
| 2750 | Register scratch2 = ToRegister(instr->TempAt(0)); |
| 2751 | |
| 2752 | EmitVFPTruncate(kRoundToMinusInf, |
| 2753 | single_scratch, |
| 2754 | input, |
| 2755 | scratch1, |
| 2756 | scratch2); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2757 | DeoptimizeIf(ne, instr->environment()); |
| 2758 | |
| 2759 | // Move the result back to general purpose register r0. |
| 2760 | __ vmov(result, single_scratch); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2761 | |
| 2762 | // Test for -0. |
| 2763 | Label done; |
| 2764 | __ cmp(result, Operand(0)); |
| 2765 | __ b(ne, &done); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 2766 | __ vmov(scratch1, input.high()); |
| 2767 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2768 | DeoptimizeIf(ne, instr->environment()); |
| 2769 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | |
| 2773 | void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2774 | DoubleRegister input = ToDoubleRegister(instr->InputAt(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2775 | ASSERT(ToDoubleRegister(instr->result()).is(input)); |
| 2776 | __ vsqrt(input, input); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | |
| 2780 | void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2781 | switch (instr->op()) { |
| 2782 | case kMathAbs: |
| 2783 | DoMathAbs(instr); |
| 2784 | break; |
| 2785 | case kMathFloor: |
| 2786 | DoMathFloor(instr); |
| 2787 | break; |
| 2788 | case kMathSqrt: |
| 2789 | DoMathSqrt(instr); |
| 2790 | break; |
| 2791 | default: |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2792 | Abort("Unimplemented type of LUnaryMathOperation."); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2793 | UNREACHABLE(); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | |
| 2798 | void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2799 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2800 | |
| 2801 | int arity = instr->arity(); |
| 2802 | Handle<Code> ic = StubCache::ComputeKeyedCallInitialize(arity, NOT_IN_LOOP); |
| 2803 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2804 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | |
| 2808 | void LCodeGen::DoCallNamed(LCallNamed* instr) { |
| 2809 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2810 | |
| 2811 | int arity = instr->arity(); |
| 2812 | Handle<Code> ic = StubCache::ComputeCallInitialize(arity, NOT_IN_LOOP); |
| 2813 | __ mov(r2, Operand(instr->name())); |
| 2814 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2815 | // Restore context register. |
| 2816 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2817 | } |
| 2818 | |
| 2819 | |
| 2820 | void LCodeGen::DoCallFunction(LCallFunction* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2821 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2822 | |
| 2823 | int arity = instr->arity(); |
| 2824 | CallFunctionStub stub(arity, NOT_IN_LOOP, RECEIVER_MIGHT_BE_VALUE); |
| 2825 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2826 | __ Drop(1); |
| 2827 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | |
| 2831 | void LCodeGen::DoCallGlobal(LCallGlobal* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2832 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2833 | |
| 2834 | int arity = instr->arity(); |
| 2835 | Handle<Code> ic = StubCache::ComputeCallInitialize(arity, NOT_IN_LOOP); |
| 2836 | __ mov(r2, Operand(instr->name())); |
| 2837 | CallCode(ic, RelocInfo::CODE_TARGET_CONTEXT, instr); |
| 2838 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | |
| 2842 | void LCodeGen::DoCallKnownGlobal(LCallKnownGlobal* instr) { |
| 2843 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2844 | __ mov(r1, Operand(instr->target())); |
| 2845 | CallKnownFunction(instr->target(), instr->arity(), instr); |
| 2846 | } |
| 2847 | |
| 2848 | |
| 2849 | void LCodeGen::DoCallNew(LCallNew* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2850 | ASSERT(ToRegister(instr->InputAt(0)).is(r1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2851 | ASSERT(ToRegister(instr->result()).is(r0)); |
| 2852 | |
| 2853 | Handle<Code> builtin(Builtins::builtin(Builtins::JSConstructCall)); |
| 2854 | __ mov(r0, Operand(instr->arity())); |
| 2855 | CallCode(builtin, RelocInfo::CONSTRUCT_CALL, instr); |
| 2856 | } |
| 2857 | |
| 2858 | |
| 2859 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 2860 | CallRuntime(instr->function(), instr->arity(), instr); |
| 2861 | } |
| 2862 | |
| 2863 | |
| 2864 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2865 | Register object = ToRegister(instr->object()); |
| 2866 | Register value = ToRegister(instr->value()); |
| 2867 | Register scratch = scratch0(); |
| 2868 | int offset = instr->offset(); |
| 2869 | |
| 2870 | ASSERT(!object.is(value)); |
| 2871 | |
| 2872 | if (!instr->transition().is_null()) { |
| 2873 | __ mov(scratch, Operand(instr->transition())); |
| 2874 | __ str(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2875 | } |
| 2876 | |
| 2877 | // Do the store. |
| 2878 | if (instr->is_in_object()) { |
| 2879 | __ str(value, FieldMemOperand(object, offset)); |
| 2880 | if (instr->needs_write_barrier()) { |
| 2881 | // Update the write barrier for the object for in-object properties. |
| 2882 | __ RecordWrite(object, Operand(offset), value, scratch); |
| 2883 | } |
| 2884 | } else { |
| 2885 | __ ldr(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 2886 | __ str(value, FieldMemOperand(scratch, offset)); |
| 2887 | if (instr->needs_write_barrier()) { |
| 2888 | // Update the write barrier for the properties array. |
| 2889 | // object is used as a scratch register. |
| 2890 | __ RecordWrite(scratch, Operand(offset), value, object); |
| 2891 | } |
| 2892 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | |
| 2896 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
| 2897 | ASSERT(ToRegister(instr->object()).is(r1)); |
| 2898 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 2899 | |
| 2900 | // Name is always in r2. |
| 2901 | __ mov(r2, Operand(instr->name())); |
| 2902 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 2903 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2904 | } |
| 2905 | |
| 2906 | |
| 2907 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2908 | __ cmp(ToRegister(instr->index()), ToRegister(instr->length())); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2909 | DeoptimizeIf(hs, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | |
| 2913 | void LCodeGen::DoStoreKeyedFastElement(LStoreKeyedFastElement* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2914 | Register value = ToRegister(instr->value()); |
| 2915 | Register elements = ToRegister(instr->object()); |
| 2916 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
| 2917 | Register scratch = scratch0(); |
| 2918 | |
| 2919 | // Do the store. |
| 2920 | if (instr->key()->IsConstantOperand()) { |
| 2921 | ASSERT(!instr->hydrogen()->NeedsWriteBarrier()); |
| 2922 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 2923 | int offset = |
| 2924 | ToInteger32(const_operand) * kPointerSize + FixedArray::kHeaderSize; |
| 2925 | __ str(value, FieldMemOperand(elements, offset)); |
| 2926 | } else { |
| 2927 | __ add(scratch, elements, Operand(key, LSL, kPointerSizeLog2)); |
| 2928 | __ str(value, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 2929 | } |
| 2930 | |
| 2931 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 2932 | // Compute address of modified element and store it into key register. |
| 2933 | __ add(key, scratch, Operand(FixedArray::kHeaderSize)); |
| 2934 | __ RecordWrite(elements, key, value); |
| 2935 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | |
| 2939 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
| 2940 | ASSERT(ToRegister(instr->object()).is(r2)); |
| 2941 | ASSERT(ToRegister(instr->key()).is(r1)); |
| 2942 | ASSERT(ToRegister(instr->value()).is(r0)); |
| 2943 | |
| 2944 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 2945 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2946 | } |
| 2947 | |
| 2948 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2949 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 2950 | class DeferredStringCharCodeAt: public LDeferredCode { |
| 2951 | public: |
| 2952 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 2953 | : LDeferredCode(codegen), instr_(instr) { } |
| 2954 | virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
| 2955 | private: |
| 2956 | LStringCharCodeAt* instr_; |
| 2957 | }; |
| 2958 | |
| 2959 | Register scratch = scratch0(); |
| 2960 | Register string = ToRegister(instr->string()); |
| 2961 | Register index = no_reg; |
| 2962 | int const_index = -1; |
| 2963 | if (instr->index()->IsConstantOperand()) { |
| 2964 | const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 2965 | STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 2966 | if (!Smi::IsValid(const_index)) { |
| 2967 | // Guaranteed to be out of bounds because of the assert above. |
| 2968 | // So the bounds check that must dominate this instruction must |
| 2969 | // have deoptimized already. |
| 2970 | if (FLAG_debug_code) { |
| 2971 | __ Abort("StringCharCodeAt: out of bounds index."); |
| 2972 | } |
| 2973 | // No code needs to be generated. |
| 2974 | return; |
| 2975 | } |
| 2976 | } else { |
| 2977 | index = ToRegister(instr->index()); |
| 2978 | } |
| 2979 | Register result = ToRegister(instr->result()); |
| 2980 | |
| 2981 | DeferredStringCharCodeAt* deferred = |
| 2982 | new DeferredStringCharCodeAt(this, instr); |
| 2983 | |
| 2984 | Label flat_string, ascii_string, done; |
| 2985 | |
| 2986 | // Fetch the instance type of the receiver into result register. |
| 2987 | __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 2988 | __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); |
| 2989 | |
| 2990 | // We need special handling for non-flat strings. |
| 2991 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2992 | __ tst(result, Operand(kStringRepresentationMask)); |
| 2993 | __ b(eq, &flat_string); |
| 2994 | |
| 2995 | // Handle non-flat strings. |
| 2996 | __ tst(result, Operand(kIsConsStringMask)); |
| 2997 | __ b(eq, deferred->entry()); |
| 2998 | |
| 2999 | // ConsString. |
| 3000 | // Check whether the right hand side is the empty string (i.e. if |
| 3001 | // this is really a flat string in a cons string). If that is not |
| 3002 | // the case we would rather go to the runtime system now to flatten |
| 3003 | // the string. |
| 3004 | __ ldr(scratch, FieldMemOperand(string, ConsString::kSecondOffset)); |
| 3005 | __ LoadRoot(ip, Heap::kEmptyStringRootIndex); |
| 3006 | __ cmp(scratch, ip); |
| 3007 | __ b(ne, deferred->entry()); |
| 3008 | // Get the first of the two strings and load its instance type. |
| 3009 | __ ldr(string, FieldMemOperand(string, ConsString::kFirstOffset)); |
| 3010 | __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 3011 | __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); |
| 3012 | // If the first cons component is also non-flat, then go to runtime. |
| 3013 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3014 | __ tst(result, Operand(kStringRepresentationMask)); |
| 3015 | __ b(ne, deferred->entry()); |
| 3016 | |
| 3017 | // Check for 1-byte or 2-byte string. |
| 3018 | __ bind(&flat_string); |
| 3019 | STATIC_ASSERT(kAsciiStringTag != 0); |
| 3020 | __ tst(result, Operand(kStringEncodingMask)); |
| 3021 | __ b(ne, &ascii_string); |
| 3022 | |
| 3023 | // 2-byte string. |
| 3024 | // Load the 2-byte character code into the result register. |
| 3025 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 3026 | if (instr->index()->IsConstantOperand()) { |
| 3027 | __ ldrh(result, |
| 3028 | FieldMemOperand(string, |
| 3029 | SeqTwoByteString::kHeaderSize + 2 * const_index)); |
| 3030 | } else { |
| 3031 | __ add(scratch, |
| 3032 | string, |
| 3033 | Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3034 | __ ldrh(result, MemOperand(scratch, index, LSL, 1)); |
| 3035 | } |
| 3036 | __ jmp(&done); |
| 3037 | |
| 3038 | // ASCII string. |
| 3039 | // Load the byte into the result register. |
| 3040 | __ bind(&ascii_string); |
| 3041 | if (instr->index()->IsConstantOperand()) { |
| 3042 | __ ldrb(result, FieldMemOperand(string, |
| 3043 | SeqAsciiString::kHeaderSize + const_index)); |
| 3044 | } else { |
| 3045 | __ add(scratch, |
| 3046 | string, |
| 3047 | Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 3048 | __ ldrb(result, MemOperand(scratch, index)); |
| 3049 | } |
| 3050 | __ bind(&done); |
| 3051 | __ bind(deferred->exit()); |
| 3052 | } |
| 3053 | |
| 3054 | |
| 3055 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 3056 | Register string = ToRegister(instr->string()); |
| 3057 | Register result = ToRegister(instr->result()); |
| 3058 | Register scratch = scratch0(); |
| 3059 | |
| 3060 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 3061 | // result register contain a valid pointer because it is already |
| 3062 | // contained in the register pointer map. |
| 3063 | __ mov(result, Operand(0)); |
| 3064 | |
| 3065 | __ PushSafepointRegisters(); |
| 3066 | __ push(string); |
| 3067 | // Push the index as a smi. This is safe because of the checks in |
| 3068 | // DoStringCharCodeAt above. |
| 3069 | if (instr->index()->IsConstantOperand()) { |
| 3070 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3071 | __ mov(scratch, Operand(Smi::FromInt(const_index))); |
| 3072 | __ push(scratch); |
| 3073 | } else { |
| 3074 | Register index = ToRegister(instr->index()); |
| 3075 | __ SmiTag(index); |
| 3076 | __ push(index); |
| 3077 | } |
| 3078 | __ CallRuntimeSaveDoubles(Runtime::kStringCharCodeAt); |
| 3079 | RecordSafepointWithRegisters( |
| 3080 | instr->pointer_map(), 2, Safepoint::kNoDeoptimizationIndex); |
| 3081 | if (FLAG_debug_code) { |
| 3082 | __ AbortIfNotSmi(r0); |
| 3083 | } |
| 3084 | __ SmiUntag(r0); |
| 3085 | MemOperand result_stack_slot = masm()->SafepointRegisterSlot(result); |
| 3086 | __ str(r0, result_stack_slot); |
| 3087 | __ PopSafepointRegisters(); |
| 3088 | } |
| 3089 | |
| 3090 | |
| 3091 | void LCodeGen::DoStringLength(LStringLength* instr) { |
| 3092 | Register string = ToRegister(instr->InputAt(0)); |
| 3093 | Register result = ToRegister(instr->result()); |
| 3094 | __ ldr(result, FieldMemOperand(string, String::kLengthOffset)); |
| 3095 | } |
| 3096 | |
| 3097 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3098 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3099 | LOperand* input = instr->InputAt(0); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3100 | ASSERT(input->IsRegister() || input->IsStackSlot()); |
| 3101 | LOperand* output = instr->result(); |
| 3102 | ASSERT(output->IsDoubleRegister()); |
| 3103 | SwVfpRegister single_scratch = double_scratch0().low(); |
| 3104 | if (input->IsStackSlot()) { |
| 3105 | Register scratch = scratch0(); |
| 3106 | __ ldr(scratch, ToMemOperand(input)); |
| 3107 | __ vmov(single_scratch, scratch); |
| 3108 | } else { |
| 3109 | __ vmov(single_scratch, ToRegister(input)); |
| 3110 | } |
| 3111 | __ vcvt_f64_s32(ToDoubleRegister(output), single_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | |
| 3115 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 3116 | class DeferredNumberTagI: public LDeferredCode { |
| 3117 | public: |
| 3118 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 3119 | : LDeferredCode(codegen), instr_(instr) { } |
| 3120 | virtual void Generate() { codegen()->DoDeferredNumberTagI(instr_); } |
| 3121 | private: |
| 3122 | LNumberTagI* instr_; |
| 3123 | }; |
| 3124 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3125 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3126 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 3127 | Register reg = ToRegister(input); |
| 3128 | |
| 3129 | DeferredNumberTagI* deferred = new DeferredNumberTagI(this, instr); |
| 3130 | __ SmiTag(reg, SetCC); |
| 3131 | __ b(vs, deferred->entry()); |
| 3132 | __ bind(deferred->exit()); |
| 3133 | } |
| 3134 | |
| 3135 | |
| 3136 | void LCodeGen::DoDeferredNumberTagI(LNumberTagI* instr) { |
| 3137 | Label slow; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3138 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3139 | DoubleRegister dbl_scratch = d0; |
| 3140 | SwVfpRegister flt_scratch = s0; |
| 3141 | |
| 3142 | // Preserve the value of all registers. |
| 3143 | __ PushSafepointRegisters(); |
| 3144 | |
| 3145 | // There was overflow, so bits 30 and 31 of the original integer |
| 3146 | // disagree. Try to allocate a heap number in new space and store |
| 3147 | // the value in there. If that fails, call the runtime system. |
| 3148 | Label done; |
| 3149 | __ SmiUntag(reg); |
| 3150 | __ eor(reg, reg, Operand(0x80000000)); |
| 3151 | __ vmov(flt_scratch, reg); |
| 3152 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
| 3153 | if (FLAG_inline_new) { |
| 3154 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 3155 | __ AllocateHeapNumber(r5, r3, r4, r6, &slow); |
| 3156 | if (!reg.is(r5)) __ mov(reg, r5); |
| 3157 | __ b(&done); |
| 3158 | } |
| 3159 | |
| 3160 | // Slow case: Call the runtime system to do the number allocation. |
| 3161 | __ bind(&slow); |
| 3162 | |
| 3163 | // TODO(3095996): Put a valid pointer value in the stack slot where the result |
| 3164 | // register is stored, as this register is in the pointer map, but contains an |
| 3165 | // integer value. |
| 3166 | __ mov(ip, Operand(0)); |
| 3167 | int reg_stack_index = __ SafepointRegisterStackIndex(reg.code()); |
| 3168 | __ str(ip, MemOperand(sp, reg_stack_index * kPointerSize)); |
| 3169 | |
| 3170 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 3171 | RecordSafepointWithRegisters( |
| 3172 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 3173 | if (!reg.is(r0)) __ mov(reg, r0); |
| 3174 | |
| 3175 | // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 3176 | // number. |
| 3177 | __ bind(&done); |
| 3178 | __ sub(ip, reg, Operand(kHeapObjectTag)); |
| 3179 | __ vstr(dbl_scratch, ip, HeapNumber::kValueOffset); |
| 3180 | __ str(reg, MemOperand(sp, reg_stack_index * kPointerSize)); |
| 3181 | __ PopSafepointRegisters(); |
| 3182 | } |
| 3183 | |
| 3184 | |
| 3185 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
| 3186 | class DeferredNumberTagD: public LDeferredCode { |
| 3187 | public: |
| 3188 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 3189 | : LDeferredCode(codegen), instr_(instr) { } |
| 3190 | virtual void Generate() { codegen()->DoDeferredNumberTagD(instr_); } |
| 3191 | private: |
| 3192 | LNumberTagD* instr_; |
| 3193 | }; |
| 3194 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3195 | DoubleRegister input_reg = ToDoubleRegister(instr->InputAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3196 | Register scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3197 | Register reg = ToRegister(instr->result()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3198 | Register temp1 = ToRegister(instr->TempAt(0)); |
| 3199 | Register temp2 = ToRegister(instr->TempAt(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3200 | |
| 3201 | DeferredNumberTagD* deferred = new DeferredNumberTagD(this, instr); |
| 3202 | if (FLAG_inline_new) { |
| 3203 | __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3204 | __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3205 | } else { |
| 3206 | __ jmp(deferred->entry()); |
| 3207 | } |
| 3208 | __ bind(deferred->exit()); |
| 3209 | __ sub(ip, reg, Operand(kHeapObjectTag)); |
| 3210 | __ vstr(input_reg, ip, HeapNumber::kValueOffset); |
| 3211 | } |
| 3212 | |
| 3213 | |
| 3214 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 3215 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 3216 | // result register contain a valid pointer because it is already |
| 3217 | // contained in the register pointer map. |
| 3218 | Register reg = ToRegister(instr->result()); |
| 3219 | __ mov(reg, Operand(0)); |
| 3220 | |
| 3221 | __ PushSafepointRegisters(); |
| 3222 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 3223 | RecordSafepointWithRegisters( |
| 3224 | instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); |
| 3225 | int reg_stack_index = __ SafepointRegisterStackIndex(reg.code()); |
| 3226 | __ str(r0, MemOperand(sp, reg_stack_index * kPointerSize)); |
| 3227 | __ PopSafepointRegisters(); |
| 3228 | } |
| 3229 | |
| 3230 | |
| 3231 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3232 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3233 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 3234 | ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
| 3235 | __ SmiTag(ToRegister(input)); |
| 3236 | } |
| 3237 | |
| 3238 | |
| 3239 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3240 | LOperand* input = instr->InputAt(0); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3241 | ASSERT(input->IsRegister() && input->Equals(instr->result())); |
| 3242 | if (instr->needs_check()) { |
| 3243 | __ tst(ToRegister(input), Operand(kSmiTagMask)); |
| 3244 | DeoptimizeIf(ne, instr->environment()); |
| 3245 | } |
| 3246 | __ SmiUntag(ToRegister(input)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | |
| 3250 | void LCodeGen::EmitNumberUntagD(Register input_reg, |
| 3251 | DoubleRegister result_reg, |
| 3252 | LEnvironment* env) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3253 | Register scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3254 | SwVfpRegister flt_scratch = s0; |
| 3255 | ASSERT(!result_reg.is(d0)); |
| 3256 | |
| 3257 | Label load_smi, heap_number, done; |
| 3258 | |
| 3259 | // Smi check. |
| 3260 | __ tst(input_reg, Operand(kSmiTagMask)); |
| 3261 | __ b(eq, &load_smi); |
| 3262 | |
| 3263 | // Heap number map check. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3264 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3265 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3266 | __ cmp(scratch, Operand(ip)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3267 | __ b(eq, &heap_number); |
| 3268 | |
| 3269 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 3270 | __ cmp(input_reg, Operand(ip)); |
| 3271 | DeoptimizeIf(ne, env); |
| 3272 | |
| 3273 | // Convert undefined to NaN. |
| 3274 | __ LoadRoot(ip, Heap::kNanValueRootIndex); |
| 3275 | __ sub(ip, ip, Operand(kHeapObjectTag)); |
| 3276 | __ vldr(result_reg, ip, HeapNumber::kValueOffset); |
| 3277 | __ jmp(&done); |
| 3278 | |
| 3279 | // Heap number to double register conversion. |
| 3280 | __ bind(&heap_number); |
| 3281 | __ sub(ip, input_reg, Operand(kHeapObjectTag)); |
| 3282 | __ vldr(result_reg, ip, HeapNumber::kValueOffset); |
| 3283 | __ jmp(&done); |
| 3284 | |
| 3285 | // Smi to double register conversion |
| 3286 | __ bind(&load_smi); |
| 3287 | __ SmiUntag(input_reg); // Untag smi before converting to float. |
| 3288 | __ vmov(flt_scratch, input_reg); |
| 3289 | __ vcvt_f64_s32(result_reg, flt_scratch); |
| 3290 | __ SmiTag(input_reg); // Retag smi. |
| 3291 | __ bind(&done); |
| 3292 | } |
| 3293 | |
| 3294 | |
| 3295 | class DeferredTaggedToI: public LDeferredCode { |
| 3296 | public: |
| 3297 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 3298 | : LDeferredCode(codegen), instr_(instr) { } |
| 3299 | virtual void Generate() { codegen()->DoDeferredTaggedToI(instr_); } |
| 3300 | private: |
| 3301 | LTaggedToI* instr_; |
| 3302 | }; |
| 3303 | |
| 3304 | |
| 3305 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
| 3306 | Label done; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3307 | Register input_reg = ToRegister(instr->InputAt(0)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3308 | Register scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3309 | DoubleRegister dbl_scratch = d0; |
| 3310 | SwVfpRegister flt_scratch = s0; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3311 | DoubleRegister dbl_tmp = ToDoubleRegister(instr->TempAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3312 | |
| 3313 | // Heap number map check. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3314 | __ ldr(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3315 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3316 | __ cmp(scratch, Operand(ip)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3317 | |
| 3318 | if (instr->truncating()) { |
| 3319 | Label heap_number; |
| 3320 | __ b(eq, &heap_number); |
| 3321 | // Check for undefined. Undefined is converted to zero for truncating |
| 3322 | // conversions. |
| 3323 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 3324 | __ cmp(input_reg, Operand(ip)); |
| 3325 | DeoptimizeIf(ne, instr->environment()); |
| 3326 | __ mov(input_reg, Operand(0)); |
| 3327 | __ b(&done); |
| 3328 | |
| 3329 | __ bind(&heap_number); |
| 3330 | __ sub(ip, input_reg, Operand(kHeapObjectTag)); |
| 3331 | __ vldr(dbl_tmp, ip, HeapNumber::kValueOffset); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3332 | __ vcmp(dbl_tmp, 0.0); // Sets overflow bit in FPSCR flags if NaN. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3333 | __ vcvt_s32_f64(flt_scratch, dbl_tmp); |
| 3334 | __ vmov(input_reg, flt_scratch); // 32-bit result of conversion. |
| 3335 | __ vmrs(pc); // Move vector status bits to normal status bits. |
| 3336 | // Overflow bit is set if dbl_tmp is Nan. |
| 3337 | __ cmn(input_reg, Operand(1), vc); // 0x7fffffff + 1 -> overflow. |
| 3338 | __ cmp(input_reg, Operand(1), vc); // 0x80000000 - 1 -> overflow. |
| 3339 | DeoptimizeIf(vs, instr->environment()); // Saturation may have occured. |
| 3340 | |
| 3341 | } else { |
| 3342 | // Deoptimize if we don't have a heap number. |
| 3343 | DeoptimizeIf(ne, instr->environment()); |
| 3344 | |
| 3345 | __ sub(ip, input_reg, Operand(kHeapObjectTag)); |
| 3346 | __ vldr(dbl_tmp, ip, HeapNumber::kValueOffset); |
| 3347 | __ vcvt_s32_f64(flt_scratch, dbl_tmp); |
| 3348 | __ vmov(input_reg, flt_scratch); // 32-bit result of conversion. |
| 3349 | // Non-truncating conversion means that we cannot lose bits, so we convert |
| 3350 | // back to check; note that using non-overlapping s and d regs would be |
| 3351 | // slightly faster. |
| 3352 | __ vcvt_f64_s32(dbl_scratch, flt_scratch); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3353 | __ VFPCompareAndSetFlags(dbl_scratch, dbl_tmp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3354 | DeoptimizeIf(ne, instr->environment()); // Not equal or unordered. |
| 3355 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3356 | __ tst(input_reg, Operand(input_reg)); |
| 3357 | __ b(ne, &done); |
| 3358 | __ vmov(lr, ip, dbl_tmp); |
| 3359 | __ tst(ip, Operand(1 << 31)); // Test sign bit. |
| 3360 | DeoptimizeIf(ne, instr->environment()); |
| 3361 | } |
| 3362 | } |
| 3363 | __ bind(&done); |
| 3364 | } |
| 3365 | |
| 3366 | |
| 3367 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3368 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3369 | ASSERT(input->IsRegister()); |
| 3370 | ASSERT(input->Equals(instr->result())); |
| 3371 | |
| 3372 | Register input_reg = ToRegister(input); |
| 3373 | |
| 3374 | DeferredTaggedToI* deferred = new DeferredTaggedToI(this, instr); |
| 3375 | |
| 3376 | // Smi check. |
| 3377 | __ tst(input_reg, Operand(kSmiTagMask)); |
| 3378 | __ b(ne, deferred->entry()); |
| 3379 | |
| 3380 | // Smi to int32 conversion |
| 3381 | __ SmiUntag(input_reg); // Untag smi. |
| 3382 | |
| 3383 | __ bind(deferred->exit()); |
| 3384 | } |
| 3385 | |
| 3386 | |
| 3387 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3388 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3389 | ASSERT(input->IsRegister()); |
| 3390 | LOperand* result = instr->result(); |
| 3391 | ASSERT(result->IsDoubleRegister()); |
| 3392 | |
| 3393 | Register input_reg = ToRegister(input); |
| 3394 | DoubleRegister result_reg = ToDoubleRegister(result); |
| 3395 | |
| 3396 | EmitNumberUntagD(input_reg, result_reg, instr->environment()); |
| 3397 | } |
| 3398 | |
| 3399 | |
| 3400 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 3401 | LOperand* input = instr->InputAt(0); |
| 3402 | ASSERT(input->IsDoubleRegister()); |
| 3403 | LOperand* result = instr->result(); |
| 3404 | ASSERT(result->IsRegister()); |
| 3405 | |
| 3406 | DoubleRegister double_input = ToDoubleRegister(input); |
| 3407 | Register result_reg = ToRegister(result); |
| 3408 | SwVfpRegister single_scratch = double_scratch0().low(); |
| 3409 | Register scratch1 = scratch0(); |
| 3410 | Register scratch2 = ToRegister(instr->TempAt(0)); |
| 3411 | |
| 3412 | VFPRoundingMode rounding_mode = instr->truncating() ? kRoundToMinusInf |
| 3413 | : kRoundToNearest; |
| 3414 | |
| 3415 | EmitVFPTruncate(rounding_mode, |
| 3416 | single_scratch, |
| 3417 | double_input, |
| 3418 | scratch1, |
| 3419 | scratch2); |
| 3420 | // Deoptimize if we had a vfp invalid exception. |
| 3421 | DeoptimizeIf(ne, instr->environment()); |
| 3422 | // Retrieve the result. |
| 3423 | __ vmov(result_reg, single_scratch); |
| 3424 | |
| 3425 | if (instr->truncating() && |
| 3426 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3427 | Label done; |
| 3428 | __ cmp(result_reg, Operand(0)); |
| 3429 | __ b(ne, &done); |
| 3430 | // Check for -0. |
| 3431 | __ vmov(scratch1, double_input.high()); |
| 3432 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
| 3433 | DeoptimizeIf(ne, instr->environment()); |
| 3434 | |
| 3435 | __ bind(&done); |
| 3436 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | |
| 3440 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3441 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3442 | ASSERT(input->IsRegister()); |
| 3443 | __ tst(ToRegister(input), Operand(kSmiTagMask)); |
| 3444 | DeoptimizeIf(instr->condition(), instr->environment()); |
| 3445 | } |
| 3446 | |
| 3447 | |
| 3448 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3449 | Register input = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3450 | Register scratch = scratch0(); |
| 3451 | InstanceType first = instr->hydrogen()->first(); |
| 3452 | InstanceType last = instr->hydrogen()->last(); |
| 3453 | |
| 3454 | __ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3455 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 3456 | __ cmp(scratch, Operand(first)); |
| 3457 | |
| 3458 | // If there is only one type in the interval check for equality. |
| 3459 | if (first == last) { |
| 3460 | DeoptimizeIf(ne, instr->environment()); |
| 3461 | } else { |
| 3462 | DeoptimizeIf(lo, instr->environment()); |
| 3463 | // Omit check for the last type. |
| 3464 | if (last != LAST_TYPE) { |
| 3465 | __ cmp(scratch, Operand(last)); |
| 3466 | DeoptimizeIf(hi, instr->environment()); |
| 3467 | } |
| 3468 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | |
| 3472 | void LCodeGen::DoCheckFunction(LCheckFunction* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3473 | ASSERT(instr->InputAt(0)->IsRegister()); |
| 3474 | Register reg = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3475 | __ cmp(reg, Operand(instr->hydrogen()->target())); |
| 3476 | DeoptimizeIf(ne, instr->environment()); |
| 3477 | } |
| 3478 | |
| 3479 | |
| 3480 | void LCodeGen::DoCheckMap(LCheckMap* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3481 | Register scratch = scratch0(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3482 | LOperand* input = instr->InputAt(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3483 | ASSERT(input->IsRegister()); |
| 3484 | Register reg = ToRegister(input); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3485 | __ ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 3486 | __ cmp(scratch, Operand(instr->hydrogen()->map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3487 | DeoptimizeIf(ne, instr->environment()); |
| 3488 | } |
| 3489 | |
| 3490 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3491 | void LCodeGen::LoadHeapObject(Register result, |
| 3492 | Handle<HeapObject> object) { |
| 3493 | if (Heap::InNewSpace(*object)) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3494 | Handle<JSGlobalPropertyCell> cell = |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3495 | Factory::NewJSGlobalPropertyCell(object); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3496 | __ mov(result, Operand(cell)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3497 | __ ldr(result, FieldMemOperand(result, JSGlobalPropertyCell::kValueOffset)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3498 | } else { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3499 | __ mov(result, Operand(object)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3500 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | |
| 3504 | void LCodeGen::DoCheckPrototypeMaps(LCheckPrototypeMaps* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3505 | Register temp1 = ToRegister(instr->TempAt(0)); |
| 3506 | Register temp2 = ToRegister(instr->TempAt(1)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3507 | |
| 3508 | Handle<JSObject> holder = instr->holder(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3509 | Handle<JSObject> current_prototype = instr->prototype(); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3510 | |
| 3511 | // Load prototype object. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3512 | LoadHeapObject(temp1, current_prototype); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3513 | |
| 3514 | // Check prototype maps up to the holder. |
| 3515 | while (!current_prototype.is_identical_to(holder)) { |
| 3516 | __ ldr(temp2, FieldMemOperand(temp1, HeapObject::kMapOffset)); |
| 3517 | __ cmp(temp2, Operand(Handle<Map>(current_prototype->map()))); |
| 3518 | DeoptimizeIf(ne, instr->environment()); |
| 3519 | current_prototype = |
| 3520 | Handle<JSObject>(JSObject::cast(current_prototype->GetPrototype())); |
| 3521 | // Load next prototype object. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3522 | LoadHeapObject(temp1, current_prototype); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | // Check the holder map. |
| 3526 | __ ldr(temp2, FieldMemOperand(temp1, HeapObject::kMapOffset)); |
| 3527 | __ cmp(temp2, Operand(Handle<Map>(current_prototype->map()))); |
| 3528 | DeoptimizeIf(ne, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | |
| 3532 | void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3533 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3534 | __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 3535 | __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 3536 | __ mov(r1, Operand(instr->hydrogen()->constant_elements())); |
| 3537 | __ Push(r3, r2, r1); |
| 3538 | |
| 3539 | // Pick the right runtime function or stub to call. |
| 3540 | int length = instr->hydrogen()->length(); |
| 3541 | if (instr->hydrogen()->IsCopyOnWrite()) { |
| 3542 | ASSERT(instr->hydrogen()->depth() == 1); |
| 3543 | FastCloneShallowArrayStub::Mode mode = |
| 3544 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; |
| 3545 | FastCloneShallowArrayStub stub(mode, length); |
| 3546 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3547 | } else if (instr->hydrogen()->depth() > 1) { |
| 3548 | CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); |
| 3549 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 3550 | CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); |
| 3551 | } else { |
| 3552 | FastCloneShallowArrayStub::Mode mode = |
| 3553 | FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 3554 | FastCloneShallowArrayStub stub(mode, length); |
| 3555 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3556 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | |
| 3560 | void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3561 | __ ldr(r4, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3562 | __ ldr(r4, FieldMemOperand(r4, JSFunction::kLiteralsOffset)); |
| 3563 | __ mov(r3, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 3564 | __ mov(r2, Operand(instr->hydrogen()->constant_properties())); |
| 3565 | __ mov(r1, Operand(Smi::FromInt(instr->hydrogen()->fast_elements() ? 1 : 0))); |
| 3566 | __ Push(r4, r3, r2, r1); |
| 3567 | |
| 3568 | // Pick the right runtime function to call. |
| 3569 | if (instr->hydrogen()->depth() > 1) { |
| 3570 | CallRuntime(Runtime::kCreateObjectLiteral, 4, instr); |
| 3571 | } else { |
| 3572 | CallRuntime(Runtime::kCreateObjectLiteralShallow, 4, instr); |
| 3573 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | |
| 3577 | void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3578 | Label materialized; |
| 3579 | // Registers will be used as follows: |
| 3580 | // r3 = JS function. |
| 3581 | // r7 = literals array. |
| 3582 | // r1 = regexp literal. |
| 3583 | // r0 = regexp literal clone. |
| 3584 | // r2 and r4-r6 are used as temporaries. |
| 3585 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3586 | __ ldr(r7, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 3587 | int literal_offset = FixedArray::kHeaderSize + |
| 3588 | instr->hydrogen()->literal_index() * kPointerSize; |
| 3589 | __ ldr(r1, FieldMemOperand(r7, literal_offset)); |
| 3590 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 3591 | __ cmp(r1, ip); |
| 3592 | __ b(ne, &materialized); |
| 3593 | |
| 3594 | // Create regexp literal using runtime function |
| 3595 | // Result will be in r0. |
| 3596 | __ mov(r6, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
| 3597 | __ mov(r5, Operand(instr->hydrogen()->pattern())); |
| 3598 | __ mov(r4, Operand(instr->hydrogen()->flags())); |
| 3599 | __ Push(r7, r6, r5, r4); |
| 3600 | CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr); |
| 3601 | __ mov(r1, r0); |
| 3602 | |
| 3603 | __ bind(&materialized); |
| 3604 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 3605 | Label allocated, runtime_allocate; |
| 3606 | |
| 3607 | __ AllocateInNewSpace(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); |
| 3608 | __ jmp(&allocated); |
| 3609 | |
| 3610 | __ bind(&runtime_allocate); |
| 3611 | __ mov(r0, Operand(Smi::FromInt(size))); |
| 3612 | __ Push(r1, r0); |
| 3613 | CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 3614 | __ pop(r1); |
| 3615 | |
| 3616 | __ bind(&allocated); |
| 3617 | // Copy the content into the newly allocated memory. |
| 3618 | // (Unroll copy loop once for better throughput). |
| 3619 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 3620 | __ ldr(r3, FieldMemOperand(r1, i)); |
| 3621 | __ ldr(r2, FieldMemOperand(r1, i + kPointerSize)); |
| 3622 | __ str(r3, FieldMemOperand(r0, i)); |
| 3623 | __ str(r2, FieldMemOperand(r0, i + kPointerSize)); |
| 3624 | } |
| 3625 | if ((size % (2 * kPointerSize)) != 0) { |
| 3626 | __ ldr(r3, FieldMemOperand(r1, size - kPointerSize)); |
| 3627 | __ str(r3, FieldMemOperand(r0, size - kPointerSize)); |
| 3628 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | |
| 3632 | void LCodeGen::DoFunctionLiteral(LFunctionLiteral* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3633 | // Use the fast case closure allocation code that allocates in new |
| 3634 | // space for nested functions that don't need literals cloning. |
| 3635 | Handle<SharedFunctionInfo> shared_info = instr->shared_info(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 3636 | bool pretenure = instr->hydrogen()->pretenure(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3637 | if (shared_info->num_literals() == 0 && !pretenure) { |
| 3638 | FastNewClosureStub stub; |
| 3639 | __ mov(r1, Operand(shared_info)); |
| 3640 | __ push(r1); |
| 3641 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3642 | } else { |
| 3643 | __ mov(r2, Operand(shared_info)); |
| 3644 | __ mov(r1, Operand(pretenure |
| 3645 | ? Factory::true_value() |
| 3646 | : Factory::false_value())); |
| 3647 | __ Push(cp, r2, r1); |
| 3648 | CallRuntime(Runtime::kNewClosure, 3, instr); |
| 3649 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | |
| 3653 | void LCodeGen::DoTypeof(LTypeof* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3654 | Register input = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3655 | __ push(input); |
| 3656 | CallRuntime(Runtime::kTypeof, 1, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | |
| 3660 | void LCodeGen::DoTypeofIs(LTypeofIs* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3661 | Register input = ToRegister(instr->InputAt(0)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3662 | Register result = ToRegister(instr->result()); |
| 3663 | Label true_label; |
| 3664 | Label false_label; |
| 3665 | Label done; |
| 3666 | |
| 3667 | Condition final_branch_condition = EmitTypeofIs(&true_label, |
| 3668 | &false_label, |
| 3669 | input, |
| 3670 | instr->type_literal()); |
| 3671 | __ b(final_branch_condition, &true_label); |
| 3672 | __ bind(&false_label); |
| 3673 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 3674 | __ b(&done); |
| 3675 | |
| 3676 | __ bind(&true_label); |
| 3677 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 3678 | |
| 3679 | __ bind(&done); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | |
| 3683 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3684 | Register input = ToRegister(instr->InputAt(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3685 | int true_block = chunk_->LookupDestination(instr->true_block_id()); |
| 3686 | int false_block = chunk_->LookupDestination(instr->false_block_id()); |
| 3687 | Label* true_label = chunk_->GetAssemblyLabel(true_block); |
| 3688 | Label* false_label = chunk_->GetAssemblyLabel(false_block); |
| 3689 | |
| 3690 | Condition final_branch_condition = EmitTypeofIs(true_label, |
| 3691 | false_label, |
| 3692 | input, |
| 3693 | instr->type_literal()); |
| 3694 | |
| 3695 | EmitBranch(true_block, false_block, final_branch_condition); |
| 3696 | } |
| 3697 | |
| 3698 | |
| 3699 | Condition LCodeGen::EmitTypeofIs(Label* true_label, |
| 3700 | Label* false_label, |
| 3701 | Register input, |
| 3702 | Handle<String> type_name) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3703 | Condition final_branch_condition = kNoCondition; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3704 | Register scratch = scratch0(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3705 | if (type_name->Equals(Heap::number_symbol())) { |
| 3706 | __ tst(input, Operand(kSmiTagMask)); |
| 3707 | __ b(eq, true_label); |
| 3708 | __ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3709 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3710 | __ cmp(input, Operand(ip)); |
| 3711 | final_branch_condition = eq; |
| 3712 | |
| 3713 | } else if (type_name->Equals(Heap::string_symbol())) { |
| 3714 | __ tst(input, Operand(kSmiTagMask)); |
| 3715 | __ b(eq, false_label); |
| 3716 | __ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3717 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 3718 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 3719 | __ b(ne, false_label); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3720 | __ CompareInstanceType(input, scratch, FIRST_NONSTRING_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3721 | final_branch_condition = lo; |
| 3722 | |
| 3723 | } else if (type_name->Equals(Heap::boolean_symbol())) { |
| 3724 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 3725 | __ cmp(input, ip); |
| 3726 | __ b(eq, true_label); |
| 3727 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 3728 | __ cmp(input, ip); |
| 3729 | final_branch_condition = eq; |
| 3730 | |
| 3731 | } else if (type_name->Equals(Heap::undefined_symbol())) { |
| 3732 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 3733 | __ cmp(input, ip); |
| 3734 | __ b(eq, true_label); |
| 3735 | __ tst(input, Operand(kSmiTagMask)); |
| 3736 | __ b(eq, false_label); |
| 3737 | // Check for undetectable objects => true. |
| 3738 | __ ldr(input, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3739 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 3740 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 3741 | final_branch_condition = ne; |
| 3742 | |
| 3743 | } else if (type_name->Equals(Heap::function_symbol())) { |
| 3744 | __ tst(input, Operand(kSmiTagMask)); |
| 3745 | __ b(eq, false_label); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3746 | __ CompareObjectType(input, input, scratch, JS_FUNCTION_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3747 | __ b(eq, true_label); |
| 3748 | // Regular expressions => 'function' (they are callable). |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3749 | __ CompareInstanceType(input, scratch, JS_REGEXP_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3750 | final_branch_condition = eq; |
| 3751 | |
| 3752 | } else if (type_name->Equals(Heap::object_symbol())) { |
| 3753 | __ tst(input, Operand(kSmiTagMask)); |
| 3754 | __ b(eq, false_label); |
| 3755 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 3756 | __ cmp(input, ip); |
| 3757 | __ b(eq, true_label); |
| 3758 | // Regular expressions => 'function', not 'object'. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3759 | __ CompareObjectType(input, input, scratch, JS_REGEXP_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3760 | __ b(eq, false_label); |
| 3761 | // Check for undetectable objects => false. |
| 3762 | __ ldrb(ip, FieldMemOperand(input, Map::kBitFieldOffset)); |
| 3763 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 3764 | __ b(ne, false_label); |
| 3765 | // Check for JS objects => true. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3766 | __ CompareInstanceType(input, scratch, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3767 | __ b(lo, false_label); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 3768 | __ CompareInstanceType(input, scratch, LAST_JS_OBJECT_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3769 | final_branch_condition = ls; |
| 3770 | |
| 3771 | } else { |
| 3772 | final_branch_condition = ne; |
| 3773 | __ b(false_label); |
| 3774 | // A dead branch instruction will be generated after this point. |
| 3775 | } |
| 3776 | |
| 3777 | return final_branch_condition; |
| 3778 | } |
| 3779 | |
| 3780 | |
| 3781 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
| 3782 | // No code for lazy bailout instruction. Used to capture environment after a |
| 3783 | // call for populating the safepoint data with deoptimization data. |
| 3784 | } |
| 3785 | |
| 3786 | |
| 3787 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3788 | DeoptimizeIf(kNoCondition, instr->environment()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | |
| 3792 | void LCodeGen::DoDeleteProperty(LDeleteProperty* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3793 | Register object = ToRegister(instr->object()); |
| 3794 | Register key = ToRegister(instr->key()); |
| 3795 | __ Push(object, key); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3796 | ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
| 3797 | LPointerMap* pointers = instr->pointer_map(); |
| 3798 | LEnvironment* env = instr->deoptimization_environment(); |
| 3799 | RecordPosition(pointers->position()); |
| 3800 | RegisterEnvironmentForDeoptimization(env); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3801 | SafepointGenerator safepoint_generator(this, |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3802 | pointers, |
| 3803 | env->deoptimization_index()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3804 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS, &safepoint_generator); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3805 | } |
| 3806 | |
| 3807 | |
| 3808 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
| 3809 | // Perform stack overflow check. |
| 3810 | Label ok; |
| 3811 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 3812 | __ cmp(sp, Operand(ip)); |
| 3813 | __ b(hs, &ok); |
| 3814 | StackCheckStub stub; |
| 3815 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3816 | __ bind(&ok); |
| 3817 | } |
| 3818 | |
| 3819 | |
| 3820 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 3821 | Abort("DoOsrEntry unimplemented."); |
| 3822 | } |
| 3823 | |
| 3824 | |
| 3825 | #undef __ |
| 3826 | |
| 3827 | } } // namespace v8::internal |