lithium-arm.cc 75 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

28 29
#include "v8.h"

30
#include "lithium-allocator-inl.h"
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#include "arm/lithium-arm.h"
#include "arm/lithium-codegen-arm.h"

namespace v8 {
namespace internal {

#define DEFINE_COMPILE(type)                            \
  void L##type::CompileToNative(LCodeGen* generator) {  \
    generator->Do##type(this);                          \
  }
LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
#undef DEFINE_COMPILE

LOsrEntry::LOsrEntry() {
  for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) {
    register_spills_[i] = NULL;
  }
  for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) {
    double_register_spills_[i] = NULL;
  }
}


void LOsrEntry::MarkSpilledRegister(int allocation_index,
                                    LOperand* spill_operand) {
  ASSERT(spill_operand->IsStackSlot());
  ASSERT(register_spills_[allocation_index] == NULL);
  register_spills_[allocation_index] = spill_operand;
}


62 63
#ifdef DEBUG
void LInstruction::VerifyCall() {
64 65 66 67
  // Call instructions can use only fixed registers as temporaries and
  // outputs because all registers are blocked by the calling convention.
  // Inputs operands must use a fixed register or use-at-start policy or
  // a non-register policy.
68 69 70
  ASSERT(Output() == NULL ||
         LUnallocated::cast(Output())->HasFixedPolicy() ||
         !LUnallocated::cast(Output())->HasRegisterPolicy());
71 72
  for (UseIterator it(this); !it.Done(); it.Advance()) {
    LUnallocated* operand = LUnallocated::cast(it.Current());
73 74
    ASSERT(operand->HasFixedPolicy() ||
           operand->IsUsedAtStart());
75
  }
76 77
  for (TempIterator it(this); !it.Done(); it.Advance()) {
    LUnallocated* operand = LUnallocated::cast(it.Current());
78
    ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
79 80 81 82 83
  }
}
#endif


84 85 86 87 88 89 90 91
void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index,
                                          LOperand* spill_operand) {
  ASSERT(spill_operand->IsDoubleStackSlot());
  ASSERT(double_register_spills_[allocation_index] == NULL);
  double_register_spills_[allocation_index] = spill_operand;
}


92
void LInstruction::PrintTo(StringStream* stream) {
93
  stream->Add("%s ", this->Mnemonic());
94 95

  PrintOutputOperandTo(stream);
96

97 98 99 100 101 102 103 104 105 106 107 108 109 110
  PrintDataTo(stream);

  if (HasEnvironment()) {
    stream->Add(" ");
    environment()->PrintTo(stream);
  }

  if (HasPointerMap()) {
    stream->Add(" ");
    pointer_map()->PrintTo(stream);
  }
}


111
void LInstruction::PrintDataTo(StringStream* stream) {
112
  stream->Add("= ");
113
  for (int i = 0; i < InputCount(); i++) {
114
    if (i > 0) stream->Add(" ");
115
    InputAt(i)->PrintTo(stream);
116
  }
117 118 119
}


120 121
void LInstruction::PrintOutputOperandTo(StringStream* stream) {
  if (HasResult()) result()->PrintTo(stream);
122 123 124 125
}


void LLabel::PrintDataTo(StringStream* stream) {
fschneider@chromium.org's avatar
fschneider@chromium.org committed
126
  LGap::PrintDataTo(stream);
127 128 129 130 131 132 133 134 135 136 137 138 139
  LLabel* rep = replacement();
  if (rep != NULL) {
    stream->Add(" Dead block replaced with B%d", rep->block_id());
  }
}


bool LGap::IsRedundant() const {
  for (int i = 0; i < 4; i++) {
    if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) {
      return false;
    }
  }
fschneider@chromium.org's avatar
fschneider@chromium.org committed
140

141 142 143 144
  return true;
}


145
void LGap::PrintDataTo(StringStream* stream) {
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  for (int i = 0; i < 4; i++) {
    stream->Add("(");
    if (parallel_moves_[i] != NULL) {
      parallel_moves_[i]->PrintDataTo(stream);
    }
    stream->Add(") ");
  }
}


const char* LArithmeticD::Mnemonic() const {
  switch (op()) {
    case Token::ADD: return "add-d";
    case Token::SUB: return "sub-d";
    case Token::MUL: return "mul-d";
    case Token::DIV: return "div-d";
    case Token::MOD: return "mod-d";
    default:
      UNREACHABLE();
      return NULL;
  }
}


const char* LArithmeticT::Mnemonic() const {
  switch (op()) {
    case Token::ADD: return "add-t";
    case Token::SUB: return "sub-t";
    case Token::MUL: return "mul-t";
    case Token::MOD: return "mod-t";
    case Token::DIV: return "div-t";
177 178 179
    case Token::BIT_AND: return "bit-and-t";
    case Token::BIT_OR: return "bit-or-t";
    case Token::BIT_XOR: return "bit-xor-t";
180 181 182
    case Token::SHL: return "shl-t";
    case Token::SAR: return "sar-t";
    case Token::SHR: return "shr-t";
183 184 185 186 187 188 189
    default:
      UNREACHABLE();
      return NULL;
  }
}


190
void LGoto::PrintDataTo(StringStream* stream) {
191 192 193 194
  stream->Add("B%d", block_id());
}


195
void LBranch::PrintDataTo(StringStream* stream) {
196
  stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
197
  InputAt(0)->PrintTo(stream);
198 199 200
}


201
void LCmpIDAndBranch::PrintDataTo(StringStream* stream) {
202
  stream->Add("if ");
203
  InputAt(0)->PrintTo(stream);
204
  stream->Add(" %s ", Token::String(op()));
205
  InputAt(1)->PrintTo(stream);
206 207 208 209
  stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
}


210
void LIsNilAndBranch::PrintDataTo(StringStream* stream) {
211
  stream->Add("if ");
212
  InputAt(0)->PrintTo(stream);
213 214
  stream->Add(kind() == kStrictEquality ? " === " : " == ");
  stream->Add(nil() == kNullValue ? "null" : "undefined");
215 216 217 218
  stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
}


219
void LIsObjectAndBranch::PrintDataTo(StringStream* stream) {
220
  stream->Add("if is_object(");
221
  InputAt(0)->PrintTo(stream);
222 223 224 225
  stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
}


226 227 228 229 230 231 232
void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
  stream->Add("if is_string(");
  InputAt(0)->PrintTo(stream);
  stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
}


233
void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
234
  stream->Add("if is_smi(");
235
  InputAt(0)->PrintTo(stream);
236 237 238 239
  stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
}


240 241 242 243 244 245 246
void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
  stream->Add("if is_undetectable(");
  InputAt(0)->PrintTo(stream);
  stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
}


247 248 249 250 251 252 253 254
void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
  stream->Add("if string_compare(");
  InputAt(0)->PrintTo(stream);
  InputAt(1)->PrintTo(stream);
  stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
}


255
void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
256
  stream->Add("if has_instance_type(");
257
  InputAt(0)->PrintTo(stream);
258 259 260 261
  stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
}


262
void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
263
  stream->Add("if has_cached_array_index(");
264
  InputAt(0)->PrintTo(stream);
265 266 267 268
  stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
}


269
void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
270
  stream->Add("if class_of_test(");
271
  InputAt(0)->PrintTo(stream);
272 273 274 275 276 277 278
  stream->Add(", \"%o\") then B%d else B%d",
              *hydrogen()->class_name(),
              true_block_id(),
              false_block_id());
}


279
void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
280
  stream->Add("if typeof ");
281
  InputAt(0)->PrintTo(stream);
282 283 284 285 286 287
  stream->Add(" == \"%s\" then B%d else B%d",
              *hydrogen()->type_literal()->ToCString(),
              true_block_id(), false_block_id());
}


288
void LCallConstantFunction::PrintDataTo(StringStream* stream) {
289 290 291 292
  stream->Add("#%d / ", arity());
}


293
void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
294
  stream->Add("/%s ", hydrogen()->OpName());
295
  InputAt(0)->PrintTo(stream);
296 297 298
}


299
void LLoadContextSlot::PrintDataTo(StringStream* stream) {
300 301 302 303 304 305 306 307 308
  InputAt(0)->PrintTo(stream);
  stream->Add("[%d]", slot_index());
}


void LStoreContextSlot::PrintDataTo(StringStream* stream) {
  InputAt(0)->PrintTo(stream);
  stream->Add("[%d] <- ", slot_index());
  InputAt(1)->PrintTo(stream);
309 310 311
}


312 313 314 315 316 317 318
void LInvokeFunction::PrintDataTo(StringStream* stream) {
  stream->Add("= ");
  InputAt(0)->PrintTo(stream);
  stream->Add(" #%d / ", arity());
}


319
void LCallKeyed::PrintDataTo(StringStream* stream) {
320 321 322 323
  stream->Add("[r2] #%d / ", arity());
}


324
void LCallNamed::PrintDataTo(StringStream* stream) {
325
  SmartArrayPointer<char> name_string = name()->ToCString();
326 327 328 329
  stream->Add("%s #%d / ", *name_string, arity());
}


330
void LCallGlobal::PrintDataTo(StringStream* stream) {
331
  SmartArrayPointer<char> name_string = name()->ToCString();
332 333 334 335
  stream->Add("%s #%d / ", *name_string, arity());
}


336
void LCallKnownGlobal::PrintDataTo(StringStream* stream) {
337 338 339 340
  stream->Add("#%d / ", arity());
}


341 342 343
void LCallNew::PrintDataTo(StringStream* stream) {
  stream->Add("= ");
  InputAt(0)->PrintTo(stream);
344 345 346 347
  stream->Add(" #%d / ", arity());
}


348
void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
349 350 351 352 353 354 355 356 357 358
  arguments()->PrintTo(stream);

  stream->Add(" length ");
  length()->PrintTo(stream);

  stream->Add(" index ");
  index()->PrintTo(stream);
}


359
void LStoreNamedField::PrintDataTo(StringStream* stream) {
360 361 362 363 364 365 366 367
  object()->PrintTo(stream);
  stream->Add(".");
  stream->Add(*String::cast(*name())->ToCString());
  stream->Add(" <- ");
  value()->PrintTo(stream);
}


368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
  object()->PrintTo(stream);
  stream->Add(".");
  stream->Add(*String::cast(*name())->ToCString());
  stream->Add(" <- ");
  value()->PrintTo(stream);
}


void LStoreKeyedFastElement::PrintDataTo(StringStream* stream) {
  object()->PrintTo(stream);
  stream->Add("[");
  key()->PrintTo(stream);
  stream->Add("] <- ");
  value()->PrintTo(stream);
}


386 387 388 389 390 391 392 393 394
void LStoreKeyedFastDoubleElement::PrintDataTo(StringStream* stream) {
  elements()->PrintTo(stream);
  stream->Add("[");
  key()->PrintTo(stream);
  stream->Add("] <- ");
  value()->PrintTo(stream);
}


395
void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
396 397 398 399 400 401 402 403
  object()->PrintTo(stream);
  stream->Add("[");
  key()->PrintTo(stream);
  stream->Add("] <- ");
  value()->PrintTo(stream);
}


404 405 406 407 408 409
void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
  object()->PrintTo(stream);
  stream->Add(" %p -> %p", *original_map(), *transitioned_map());
}


410
int LPlatformChunk::GetNextSpillIndex(bool is_double) {
411 412 413 414 415 416
  // Skip a slot if for a double-width slot.
  if (is_double) spill_slot_count_++;
  return spill_slot_count_++;
}


417
LOperand* LPlatformChunk::GetNextSpillSlot(bool is_double)  {
418 419
  int index = GetNextSpillIndex(is_double);
  if (is_double) {
420
    return LDoubleStackSlot::Create(index, zone());
421
  } else {
422
    return LStackSlot::Create(index, zone());
423 424 425 426
  }
}


427
LPlatformChunk* LChunkBuilder::Build() {
428
  ASSERT(is_unused());
429
  chunk_ = new(zone()) LPlatformChunk(info(), graph());
430
  HPhase phase("L_Building chunk", chunk_);
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
  status_ = BUILDING;
  const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
  for (int i = 0; i < blocks->length(); i++) {
    HBasicBlock* next = NULL;
    if (i < blocks->length() - 1) next = blocks->at(i + 1);
    DoBasicBlock(blocks->at(i), next);
    if (is_aborted()) return NULL;
  }
  status_ = DONE;
  return chunk_;
}


void LChunkBuilder::Abort(const char* format, ...) {
  if (FLAG_trace_bailout) {
446 447
    SmartArrayPointer<char> name(
        info()->shared_info()->DebugName()->ToCString());
448
    PrintF("Aborting LPlatformChunk building in @\"%s\": ", *name);
449 450 451 452 453 454 455 456 457 458 459
    va_list arguments;
    va_start(arguments, format);
    OS::VPrint(format, arguments);
    va_end(arguments);
    PrintF("\n");
  }
  status_ = ABORTED;
}


LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
460 461
  return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
                                  Register::ToAllocationIndex(reg));
462 463 464 465
}


LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
466 467
  return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
                                  DoubleRegister::ToAllocationIndex(reg));
468 469 470 471 472 473 474 475 476 477 478 479 480 481
}


LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
  return Use(value, ToUnallocated(fixed_register));
}


LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) {
  return Use(value, ToUnallocated(reg));
}


LOperand* LChunkBuilder::UseRegister(HValue* value) {
482
  return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
483 484 485 486 487
}


LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
  return Use(value,
488 489
             new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
                                      LUnallocated::USED_AT_START));
490 491 492 493
}


LOperand* LChunkBuilder::UseTempRegister(HValue* value) {
494
  return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
495 496 497 498
}


LOperand* LChunkBuilder::Use(HValue* value) {
499
  return Use(value, new(zone()) LUnallocated(LUnallocated::NONE));
500 501 502 503
}


LOperand* LChunkBuilder::UseAtStart(HValue* value) {
504 505
  return Use(value, new(zone()) LUnallocated(LUnallocated::NONE,
                                             LUnallocated::USED_AT_START));
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
}


LOperand* LChunkBuilder::UseOrConstant(HValue* value) {
  return value->IsConstant()
      ? chunk_->DefineConstantOperand(HConstant::cast(value))
      : Use(value);
}


LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) {
  return value->IsConstant()
      ? chunk_->DefineConstantOperand(HConstant::cast(value))
      : UseAtStart(value);
}


LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
  return value->IsConstant()
      ? chunk_->DefineConstantOperand(HConstant::cast(value))
      : UseRegister(value);
}


LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
  return value->IsConstant()
      ? chunk_->DefineConstantOperand(HConstant::cast(value))
      : UseRegisterAtStart(value);
}


537 538 539
LOperand* LChunkBuilder::UseAny(HValue* value) {
  return value->IsConstant()
      ? chunk_->DefineConstantOperand(HConstant::cast(value))
540
      :  Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
541 542 543
}


544 545 546 547 548
LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
  if (value->EmitAtUses()) {
    HInstruction* instr = HInstruction::cast(value);
    VisitInstruction(instr);
  }
549
  operand->set_virtual_register(value->id());
550 551 552 553
  return operand;
}


554 555 556
template<int I, int T>
LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr,
                                    LUnallocated* result) {
557
  result->set_virtual_register(current_instruction_->id());
558 559 560 561 562 563 564 565
  instr->set_result(result);
  return instr;
}


template<int I, int T>
LInstruction* LChunkBuilder::DefineAsRegister(
    LTemplateInstruction<1, I, T>* instr) {
566 567
  return Define(instr,
                new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
568 569 570
}


571 572 573
template<int I, int T>
LInstruction* LChunkBuilder::DefineAsSpilled(
    LTemplateInstruction<1, I, T>* instr, int index) {
574 575
  return Define(instr,
                new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
576 577 578
}


579 580 581
template<int I, int T>
LInstruction* LChunkBuilder::DefineSameAsFirst(
    LTemplateInstruction<1, I, T>* instr) {
582 583
  return Define(instr,
                new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
584 585 586
}


587 588 589
template<int I, int T>
LInstruction* LChunkBuilder::DefineFixed(
    LTemplateInstruction<1, I, T>* instr, Register reg) {
590 591 592 593
  return Define(instr, ToUnallocated(reg));
}


594 595 596
template<int I, int T>
LInstruction* LChunkBuilder::DefineFixedDouble(
    LTemplateInstruction<1, I, T>* instr, DoubleRegister reg) {
597 598 599 600 601 602
  return Define(instr, ToUnallocated(reg));
}


LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
  HEnvironment* hydrogen_env = current_block_->last_environment();
603 604 605
  int argument_index_accumulator = 0;
  instr->set_environment(CreateEnvironment(hydrogen_env,
                                           &argument_index_accumulator));
606 607 608 609 610 611 612
  return instr;
}


LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
                                        HInstruction* hinstr,
                                        CanDeoptimize can_deoptimize) {
613 614 615 616
#ifdef DEBUG
  instr->VerifyCall();
#endif
  instr->MarkAsCall();
617 618
  instr = AssignPointerMap(instr);

619
  if (hinstr->HasObservableSideEffects()) {
620 621
    ASSERT(hinstr->next()->IsSimulate());
    HSimulate* sim = HSimulate::cast(hinstr->next());
622
    ASSERT(instruction_pending_deoptimization_environment_ == NULL);
623
    ASSERT(pending_deoptimization_ast_id_.IsNone());
624 625
    instruction_pending_deoptimization_environment_ = instr;
    pending_deoptimization_ast_id_ = sim->ast_id();
626 627 628 629 630 631 632
  }

  // If instruction does not have side-effects lazy deoptimization
  // after the call will try to deoptimize to the point before the call.
  // Thus we still need to attach environment to this call even if
  // call sequence can not deoptimize eagerly.
  bool needs_environment =
633 634
      (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
      !hinstr->HasObservableSideEffects();
635 636 637 638 639 640 641 642 643 644
  if (needs_environment && !instr->HasEnvironment()) {
    instr = AssignEnvironment(instr);
  }

  return instr;
}


LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
  ASSERT(!instr->HasPointerMap());
645
  instr->set_pointer_map(new(zone()) LPointerMap(position_, zone()));
646 647 648 649 650
  return instr;
}


LUnallocated* LChunkBuilder::TempRegister() {
651 652
  LUnallocated* operand =
      new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
653 654
  operand->set_virtual_register(allocator_->GetVirtualRegister());
  if (!allocator_->AllocationOk()) Abort("Not enough virtual registers.");
655 656 657 658 659 660
  return operand;
}


LOperand* LChunkBuilder::FixedTemp(Register reg) {
  LUnallocated* operand = ToUnallocated(reg);
661
  ASSERT(operand->HasFixedPolicy());
662 663 664 665 666 667
  return operand;
}


LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
  LUnallocated* operand = ToUnallocated(reg);
668
  ASSERT(operand->HasFixedPolicy());
669 670 671 672 673
  return operand;
}


LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
674
  return new(zone()) LLabel(instr->block());
675 676 677
}


678
LInstruction* LChunkBuilder::DoSoftDeoptimize(HSoftDeoptimize* instr) {
679
  return AssignEnvironment(new(zone()) LDeoptimize);
680 681 682
}


683
LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
684
  return AssignEnvironment(new(zone()) LDeoptimize);
685 686 687 688 689
}


LInstruction* LChunkBuilder::DoShift(Token::Value op,
                                     HBitwiseBinaryOperation* instr) {
690 691 692 693 694 695
  if (instr->representation().IsTagged()) {
    ASSERT(instr->left()->representation().IsTagged());
    ASSERT(instr->right()->representation().IsTagged());

    LOperand* left = UseFixed(instr->left(), r1);
    LOperand* right = UseFixed(instr->right(), r0);
696
    LArithmeticT* result = new(zone()) LArithmeticT(op, left, right);
697 698 699
    return MarkAsCall(DefineFixed(result, r0), instr);
  }

700
  ASSERT(instr->representation().IsInteger32());
701 702 703
  ASSERT(instr->left()->representation().IsInteger32());
  ASSERT(instr->right()->representation().IsInteger32());
  LOperand* left = UseRegisterAtStart(instr->left());
704

705
  HValue* right_value = instr->right();
706 707 708 709 710 711 712
  LOperand* right = NULL;
  int constant_value = 0;
  if (right_value->IsConstant()) {
    HConstant* constant = HConstant::cast(right_value);
    right = chunk_->DefineConstantOperand(constant);
    constant_value = constant->Integer32Value() & 0x1f;
  } else {
713
    right = UseRegisterAtStart(right_value);
714 715 716 717
  }

  // Shift operations can only deoptimize if we do a logical shift
  // by 0 and the result cannot be truncated to int32.
718 719 720 721 722 723
  bool may_deopt = (op == Token::SHR && constant_value == 0);
  bool does_deopt = false;
  if (may_deopt) {
    for (HUseIterator it(instr->uses()); !it.Done(); it.Advance()) {
      if (!it.value()->CheckFlag(HValue::kTruncatingToInt32)) {
        does_deopt = true;
724 725 726 727 728 729
        break;
      }
    }
  }

  LInstruction* result =
730
      DefineAsRegister(new(zone()) LShiftI(op, left, right, does_deopt));
731
  return does_deopt ? AssignEnvironment(result) : result;
732 733 734 735 736 737 738 739
}


LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
                                           HArithmeticBinaryOperation* instr) {
  ASSERT(instr->representation().IsDouble());
  ASSERT(instr->left()->representation().IsDouble());
  ASSERT(instr->right()->representation().IsDouble());
740
  ASSERT(op != Token::MOD);
741 742
  LOperand* left = UseRegisterAtStart(instr->left());
  LOperand* right = UseRegisterAtStart(instr->right());
743
  LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
744
  return DefineAsRegister(result);
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
}


LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
                                           HArithmeticBinaryOperation* instr) {
  ASSERT(op == Token::ADD ||
         op == Token::DIV ||
         op == Token::MOD ||
         op == Token::MUL ||
         op == Token::SUB);
  HValue* left = instr->left();
  HValue* right = instr->right();
  ASSERT(left->representation().IsTagged());
  ASSERT(right->representation().IsTagged());
  LOperand* left_operand = UseFixed(left, r1);
  LOperand* right_operand = UseFixed(right, r0);
761 762
  LArithmeticT* result =
      new(zone()) LArithmeticT(op, left_operand, right_operand);
763 764 765
  return MarkAsCall(DefineFixed(result, r0), instr);
}

766

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) {
  ASSERT(is_building());
  current_block_ = block;
  next_block_ = next_block;
  if (block->IsStartBlock()) {
    block->UpdateEnvironment(graph_->start_environment());
    argument_count_ = 0;
  } else if (block->predecessors()->length() == 1) {
    // We have a single predecessor => copy environment and outgoing
    // argument count from the predecessor.
    ASSERT(block->phis()->length() == 0);
    HBasicBlock* pred = block->predecessors()->at(0);
    HEnvironment* last_environment = pred->last_environment();
    ASSERT(last_environment != NULL);
    // Only copy the environment, if it is later used again.
    if (pred->end()->SecondSuccessor() == NULL) {
      ASSERT(pred->end()->FirstSuccessor() == block);
    } else {
      if (pred->end()->FirstSuccessor()->block_id() > block->block_id() ||
          pred->end()->SecondSuccessor()->block_id() > block->block_id()) {
        last_environment = last_environment->Copy();
      }
    }
    block->UpdateEnvironment(last_environment);
    ASSERT(pred->argument_count() >= 0);
    argument_count_ = pred->argument_count();
  } else {
    // We are at a state join => process phis.
    HBasicBlock* pred = block->predecessors()->at(0);
    // No need to copy the environment, it cannot be used later.
    HEnvironment* last_environment = pred->last_environment();
    for (int i = 0; i < block->phis()->length(); ++i) {
      HPhi* phi = block->phis()->at(i);
      last_environment->SetValueAt(phi->merged_index(), phi);
    }
    for (int i = 0; i < block->deleted_phis()->length(); ++i) {
      last_environment->SetValueAt(block->deleted_phis()->at(i),
                                   graph_->GetConstantUndefined());
    }
    block->UpdateEnvironment(last_environment);
    // Pick up the outgoing argument count of one of the predecessors.
    argument_count_ = pred->argument_count();
  }
  HInstruction* current = block->first();
  int start = chunk_->instructions()->length();
  while (current != NULL && !is_aborted()) {
    // Code for constants in registers is generated lazily.
    if (!current->EmitAtUses()) {
      VisitInstruction(current);
    }
    current = current->next();
  }
  int end = chunk_->instructions()->length() - 1;
  if (end >= start) {
    block->set_first_instruction_index(start);
    block->set_last_instruction_index(end);
  }
  block->set_argument_count(argument_count_);
  next_block_ = NULL;
  current_block_ = NULL;
}


void LChunkBuilder::VisitInstruction(HInstruction* current) {
  HInstruction* old_current = current_instruction_;
  current_instruction_ = current;
  if (current->has_position()) position_ = current->position();
  LInstruction* instr = current->CompileToLithium(this);

  if (instr != NULL) {
    if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
      instr = AssignPointerMap(instr);
    }
    if (FLAG_stress_environments && !instr->HasEnvironment()) {
      instr = AssignEnvironment(instr);
    }
843
    instr->set_hydrogen_value(current);
844
    chunk_->AddInstruction(instr, current_block_);
845 846 847 848 849
  }
  current_instruction_ = old_current;
}


850 851 852
LEnvironment* LChunkBuilder::CreateEnvironment(
    HEnvironment* hydrogen_env,
    int* argument_index_accumulator) {
853 854
  if (hydrogen_env == NULL) return NULL;

855 856
  LEnvironment* outer =
      CreateEnvironment(hydrogen_env->outer(), argument_index_accumulator);
857 858
  BailoutId ast_id = hydrogen_env->ast_id();
  ASSERT(!ast_id.IsNone() ||
859
         hydrogen_env->frame_type() != JS_FUNCTION);
860
  int value_count = hydrogen_env->length();
861 862 863 864 865 866 867
  LEnvironment* result = new(zone()) LEnvironment(
      hydrogen_env->closure(),
      hydrogen_env->frame_type(),
      ast_id,
      hydrogen_env->parameter_count(),
      argument_count_,
      value_count,
868 869
      outer,
      zone());
870
  int argument_index = *argument_index_accumulator;
871
  for (int i = 0; i < value_count; ++i) {
872 873
    if (hydrogen_env->is_special_index(i)) continue;

874 875 876 877 878
    HValue* value = hydrogen_env->values()->at(i);
    LOperand* op = NULL;
    if (value->IsArgumentsObject()) {
      op = NULL;
    } else if (value->IsPushArgument()) {
879
      op = new(zone()) LArgument(argument_index++);
880
    } else {
881
      op = UseAny(value);
882 883 884 885
    }
    result->AddValue(op, value->representation());
  }

886
  if (hydrogen_env->frame_type() == JS_FUNCTION) {
887 888 889
    *argument_index_accumulator = argument_index;
  }

890 891 892 893 894
  return result;
}


LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
895
  return new(zone()) LGoto(instr->FirstSuccessor()->block_id());
896 897 898
}


899
LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
900 901 902
  HValue* value = instr->value();
  if (value->EmitAtUses()) {
    HBasicBlock* successor = HConstant::cast(value)->ToBoolean()
903 904
        ? instr->FirstSuccessor()
        : instr->SecondSuccessor();
905
    return new(zone()) LGoto(successor->block_id());
906
  }
907

908
  LBranch* result = new(zone()) LBranch(UseRegister(value));
909 910 911 912 913 914 915 916
  // Tagged values that are not known smis or booleans require a
  // deoptimization environment.
  Representation rep = value->representation();
  HType type = value->type();
  if (rep.IsTagged() && !type.IsSmi() && !type.IsBoolean()) {
    return AssignEnvironment(result);
  }
  return result;
917 918 919
}


920

921
LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
922 923
  ASSERT(instr->value()->representation().IsTagged());
  LOperand* value = UseRegisterAtStart(instr->value());
924
  LOperand* temp = TempRegister();
925
  return new(zone()) LCmpMapAndBranch(value, temp);
926 927 928
}


929 930 931
LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) {
  LOperand* value = UseRegister(instr->value());
  return DefineAsRegister(new(zone()) LArgumentsLength(value));
932 933 934 935
}


LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) {
936
  return DefineAsRegister(new(zone()) LArgumentsElements);
937 938 939 940
}


LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
941
  LInstanceOf* result =
942
      new(zone()) LInstanceOf(UseFixed(instr->left(), r0),
943
                      UseFixed(instr->right(), r1));
944 945 946 947
  return MarkAsCall(DefineFixed(result, r0), instr);
}


948 949
LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal(
    HInstanceOfKnownGlobal* instr) {
950
  LInstanceOfKnownGlobal* result =
951 952
      new(zone()) LInstanceOfKnownGlobal(UseFixed(instr->left(), r0),
                                         FixedTemp(r4));
953
  return MarkAsCall(DefineFixed(result, r0), instr);
954 955 956
}


957 958 959 960 961 962 963 964
LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
  LOperand* receiver = UseRegisterAtStart(instr->receiver());
  LOperand* function = UseRegisterAtStart(instr->function());
  LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
  return AssignEnvironment(DefineSameAsFirst(result));
}


965 966 967
LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
  LOperand* function = UseFixed(instr->function(), r1);
  LOperand* receiver = UseFixed(instr->receiver(), r0);
968 969
  LOperand* length = UseFixed(instr->length(), r2);
  LOperand* elements = UseFixed(instr->elements(), r3);
970
  LApplyArguments* result = new(zone()) LApplyArguments(function,
971 972 973
                                                receiver,
                                                length,
                                                elements);
974 975 976 977 978 979 980
  return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY);
}


LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) {
  ++argument_count_;
  LOperand* argument = Use(instr->argument());
981
  return new(zone()) LPushArgument(argument);
982 983 984
}


985
LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
986 987 988
  return instr->HasNoUses()
      ? NULL
      : DefineAsRegister(new(zone()) LThisFunction);
989 990 991
}


992
LInstruction* LChunkBuilder::DoContext(HContext* instr) {
993
  return instr->HasNoUses() ? NULL : DefineAsRegister(new(zone()) LContext);
994 995 996 997 998
}


LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) {
  LOperand* context = UseRegisterAtStart(instr->value());
999
  return DefineAsRegister(new(zone()) LOuterContext(context));
1000 1001 1002
}


1003
LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
1004
  return MarkAsCall(new(zone()) LDeclareGlobals, instr);
1005 1006 1007
}


1008
LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) {
1009
  LOperand* context = UseRegisterAtStart(instr->value());
1010
  return DefineAsRegister(new(zone()) LGlobalObject(context));
1011 1012 1013 1014
}


LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) {
1015
  LOperand* global_object = UseRegisterAtStart(instr->value());
1016
  return DefineAsRegister(new(zone()) LGlobalReceiver(global_object));
1017 1018 1019 1020 1021 1022
}


LInstruction* LChunkBuilder::DoCallConstantFunction(
    HCallConstantFunction* instr) {
  argument_count_ -= instr->argument_count();
1023
  return MarkAsCall(DefineFixed(new(zone()) LCallConstantFunction, r0), instr);
1024 1025 1026
}


1027 1028 1029
LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
  LOperand* function = UseFixed(instr->function(), r1);
  argument_count_ -= instr->argument_count();
1030
  LInvokeFunction* result = new(zone()) LInvokeFunction(function);
1031 1032 1033 1034
  return MarkAsCall(DefineFixed(result, r0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
}


1035
LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
1036
  BuiltinFunctionId op = instr->op();
1037
  if (op == kMathLog || op == kMathSin || op == kMathCos || op == kMathTan) {
1038
    LOperand* input = UseFixedDouble(instr->value(), d2);
1039
    LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, NULL);
1040
    return MarkAsCall(DefineFixedDouble(result, d2), instr);
yangguo@chromium.org's avatar
yangguo@chromium.org committed
1041
  } else if (op == kMathPowHalf) {
1042 1043
    LOperand* input = UseFixedDouble(instr->value(), d2);
    LOperand* temp = FixedTemp(d3);
1044
    LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp);
1045
    return DefineFixedDouble(result, d2);
1046 1047 1048
  } else {
    LOperand* input = UseRegisterAtStart(instr->value());
    LOperand* temp = (op == kMathFloor) ? TempRegister() : NULL;
1049
    LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp);
1050 1051
    switch (op) {
      case kMathAbs:
1052
        return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1053 1054 1055
      case kMathFloor:
        return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
      case kMathSqrt:
1056
        return DefineAsRegister(result);
1057 1058 1059 1060 1061 1062
      case kMathRound:
        return AssignEnvironment(DefineAsRegister(result));
      default:
        UNREACHABLE();
        return NULL;
    }
1063 1064 1065 1066 1067 1068 1069
  }
}


LInstruction* LChunkBuilder::DoCallKeyed(HCallKeyed* instr) {
  ASSERT(instr->key()->representation().IsTagged());
  argument_count_ -= instr->argument_count();
1070
  LOperand* key = UseFixed(instr->key(), r2);
1071
  return MarkAsCall(DefineFixed(new(zone()) LCallKeyed(key), r0), instr);
1072 1073 1074 1075 1076
}


LInstruction* LChunkBuilder::DoCallNamed(HCallNamed* instr) {
  argument_count_ -= instr->argument_count();
1077
  return MarkAsCall(DefineFixed(new(zone()) LCallNamed, r0), instr);
1078 1079 1080 1081 1082
}


LInstruction* LChunkBuilder::DoCallGlobal(HCallGlobal* instr) {
  argument_count_ -= instr->argument_count();
1083
  return MarkAsCall(DefineFixed(new(zone()) LCallGlobal, r0), instr);
1084 1085 1086 1087 1088
}


LInstruction* LChunkBuilder::DoCallKnownGlobal(HCallKnownGlobal* instr) {
  argument_count_ -= instr->argument_count();
1089
  return MarkAsCall(DefineFixed(new(zone()) LCallKnownGlobal, r0), instr);
1090 1091 1092 1093 1094 1095
}


LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
  LOperand* constructor = UseFixed(instr->constructor(), r1);
  argument_count_ -= instr->argument_count();
1096
  LCallNew* result = new(zone()) LCallNew(constructor);
1097 1098 1099 1100 1101
  return MarkAsCall(DefineFixed(result, r0), instr);
}


LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
1102
  LOperand* function = UseFixed(instr->function(), r1);
1103
  argument_count_ -= instr->argument_count();
1104 1105
  return MarkAsCall(DefineFixed(new(zone()) LCallFunction(function), r0),
                    instr);
1106 1107 1108 1109 1110
}


LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
  argument_count_ -= instr->argument_count();
1111
  return MarkAsCall(DefineFixed(new(zone()) LCallRuntime, r0), instr);
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
}


LInstruction* LChunkBuilder::DoShr(HShr* instr) {
  return DoShift(Token::SHR, instr);
}


LInstruction* LChunkBuilder::DoSar(HSar* instr) {
  return DoShift(Token::SAR, instr);
}


LInstruction* LChunkBuilder::DoShl(HShl* instr) {
  return DoShift(Token::SHL, instr);
}


1130 1131 1132 1133 1134 1135 1136
LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
  if (instr->representation().IsInteger32()) {
    ASSERT(instr->left()->representation().IsInteger32());
    ASSERT(instr->right()->representation().IsInteger32());

    LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
    LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
1137
    return DefineAsRegister(new(zone()) LBitI(left, right));
1138 1139 1140 1141 1142 1143 1144
  } else {
    ASSERT(instr->representation().IsTagged());
    ASSERT(instr->left()->representation().IsTagged());
    ASSERT(instr->right()->representation().IsTagged());

    LOperand* left = UseFixed(instr->left(), r1);
    LOperand* right = UseFixed(instr->right(), r0);
1145
    LArithmeticT* result = new(zone()) LArithmeticT(instr->op(), left, right);
1146 1147
    return MarkAsCall(DefineFixed(result, r0), instr);
  }
1148 1149 1150 1151 1152 1153
}


LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) {
  ASSERT(instr->value()->representation().IsInteger32());
  ASSERT(instr->representation().IsInteger32());
1154
  if (instr->HasNoUses()) return NULL;
1155 1156
  LOperand* value = UseRegisterAtStart(instr->value());
  return DefineAsRegister(new(zone()) LBitNotI(value));
1157 1158 1159 1160 1161 1162 1163
}


LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
  if (instr->representation().IsDouble()) {
    return DoArithmeticD(Token::DIV, instr);
  } else if (instr->representation().IsInteger32()) {
1164
    // TODO(1042) The fixed register allocation
1165
    // is needed because we call TypeRecordingBinaryOpStub from
1166 1167 1168
    // the generated code, which requires registers r0
    // and r1 to be used. We should remove that
    // when we provide a native implementation.
1169
    LOperand* dividend = UseFixed(instr->left(), r0);
1170 1171
    LOperand* divisor = UseFixed(instr->right(), r1);
    return AssignEnvironment(AssignPointerMap(
1172
             DefineFixed(new(zone()) LDivI(dividend, divisor), r0)));
1173 1174 1175 1176 1177 1178
  } else {
    return DoArithmeticT(Token::DIV, instr);
  }
}


1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
bool LChunkBuilder::HasMagicNumberForDivisor(int32_t divisor) {
  uint32_t divisor_abs = abs(divisor);
  // Dividing by 0, 1, and powers of 2 is easy.
  // Note that IsPowerOf2(0) returns true;
  ASSERT(IsPowerOf2(0) == true);
  if (IsPowerOf2(divisor_abs)) return true;

  // We have magic numbers for a few specific divisors.
  // Details and proofs can be found in:
  // - Hacker's Delight, Henry S. Warren, Jr.
  // - The PowerPC Compiler Writer’s Guide
  // and probably many others.
  //
  // We handle
  //   <divisor with magic numbers> * <power of 2>
  // but not
  //   <divisor with magic numbers> * <other divisor with magic numbers>
  int32_t power_of_2_factor =
    CompilerIntrinsics::CountTrailingZeros(divisor_abs);
  DivMagicNumbers magic_numbers =
    DivMagicNumberFor(divisor_abs >> power_of_2_factor);
  if (magic_numbers.M != InvalidDivMagicNumber.M) return true;

  return false;
}


HValue* LChunkBuilder::SimplifiedDividendForMathFloorOfDiv(HValue* dividend) {
  // A value with an integer representation does not need to be transformed.
  if (dividend->representation().IsInteger32()) {
    return dividend;
  // A change from an integer32 can be replaced by the integer32 value.
  } else if (dividend->IsChange() &&
      HChange::cast(dividend)->from().IsInteger32()) {
    return HChange::cast(dividend)->value();
  }
  return NULL;
}


HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) {
  // Only optimize when we have magic numbers for the divisor.
  // The standard integer division routine is usually slower than transitionning
  // to VFP.
  if (divisor->IsConstant() &&
      HConstant::cast(divisor)->HasInteger32Value()) {
    HConstant* constant_val = HConstant::cast(divisor);
    int32_t int32_val = constant_val->Integer32Value();
    if (LChunkBuilder::HasMagicNumberForDivisor(int32_val)) {
1228 1229
      return constant_val->CopyToRepresentation(Representation::Integer32(),
                                                divisor->block()->zone());
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
    }
  }
  return NULL;
}


LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
    HValue* right = instr->right();
    LOperand* dividend = UseRegister(instr->left());
    LOperand* divisor = UseRegisterOrConstant(right);
    LOperand* remainder = TempRegister();
    ASSERT(right->IsConstant() &&
           HConstant::cast(right)->HasInteger32Value() &&
           HasMagicNumberForDivisor(HConstant::cast(right)->Integer32Value()));
    return AssignEnvironment(DefineAsRegister(
1245
          new(zone()) LMathFloorOfDiv(dividend, divisor, remainder)));
1246 1247 1248
}


1249 1250 1251 1252
LInstruction* LChunkBuilder::DoMod(HMod* instr) {
  if (instr->representation().IsInteger32()) {
    ASSERT(instr->left()->representation().IsInteger32());
    ASSERT(instr->right()->representation().IsInteger32());
1253

1254
    LModI* mod;
1255 1256 1257
    if (instr->HasPowerOf2Divisor()) {
      ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero));
      LOperand* value = UseRegisterAtStart(instr->left());
1258
      mod = new(zone()) LModI(value, UseOrConstant(instr->right()));
1259
    } else {
1260
      LOperand* dividend = UseRegister(instr->left());
1261
      LOperand* divisor = UseRegister(instr->right());
1262 1263 1264 1265 1266
      mod = new(zone()) LModI(dividend,
                              divisor,
                              TempRegister(),
                              FixedTemp(d10),
                              FixedTemp(d11));
1267 1268
    }

1269 1270 1271 1272 1273 1274
    if (instr->CheckFlag(HValue::kBailoutOnMinusZero) ||
        instr->CheckFlag(HValue::kCanBeDivByZero)) {
      return AssignEnvironment(DefineAsRegister(mod));
    } else {
      return DefineAsRegister(mod);
    }
1275 1276 1277 1278 1279 1280 1281 1282 1283
  } else if (instr->representation().IsTagged()) {
    return DoArithmeticT(Token::MOD, instr);
  } else {
    ASSERT(instr->representation().IsDouble());
    // We call a C function for double modulo. It can't trigger a GC.
    // We need to use fixed result register for the call.
    // TODO(fschneider): Allow any register as input registers.
    LOperand* left = UseFixedDouble(instr->left(), d1);
    LOperand* right = UseFixedDouble(instr->right(), d2);
1284
    LArithmeticD* result = new(zone()) LArithmeticD(Token::MOD, left, right);
1285 1286 1287 1288 1289 1290 1291 1292 1293
    return MarkAsCall(DefineFixedDouble(result, d1), instr);
  }
}


LInstruction* LChunkBuilder::DoMul(HMul* instr) {
  if (instr->representation().IsInteger32()) {
    ASSERT(instr->left()->representation().IsInteger32());
    ASSERT(instr->right()->representation().IsInteger32());
1294
    LOperand* left;
1295 1296
    LOperand* right = UseOrConstant(instr->MostConstantOperand());
    LOperand* temp = NULL;
1297 1298 1299
    if (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
        (instr->CheckFlag(HValue::kCanOverflow) ||
        !right->IsConstantOperand())) {
1300
      left = UseRegister(instr->LeastConstantOperand());
1301
      temp = TempRegister();
1302 1303
    } else {
      left = UseRegisterAtStart(instr->LeastConstantOperand());
1304
    }
1305
    LMulI* mul = new(zone()) LMulI(left, right, temp);
1306 1307 1308 1309 1310
    if (instr->CheckFlag(HValue::kCanOverflow) ||
        instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
      AssignEnvironment(mul);
    }
    return DefineAsRegister(mul);
1311

1312 1313
  } else if (instr->representation().IsDouble()) {
    return DoArithmeticD(Token::MUL, instr);
1314

1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
  } else {
    return DoArithmeticT(Token::MUL, instr);
  }
}


LInstruction* LChunkBuilder::DoSub(HSub* instr) {
  if (instr->representation().IsInteger32()) {
    ASSERT(instr->left()->representation().IsInteger32());
    ASSERT(instr->right()->representation().IsInteger32());
1325 1326
    LOperand* left = UseRegisterAtStart(instr->left());
    LOperand* right = UseOrConstantAtStart(instr->right());
1327
    LSubI* sub = new(zone()) LSubI(left, right);
1328
    LInstruction* result = DefineAsRegister(sub);
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
    if (instr->CheckFlag(HValue::kCanOverflow)) {
      result = AssignEnvironment(result);
    }
    return result;
  } else if (instr->representation().IsDouble()) {
    return DoArithmeticD(Token::SUB, instr);
  } else {
    return DoArithmeticT(Token::SUB, instr);
  }
}


LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
  if (instr->representation().IsInteger32()) {
    ASSERT(instr->left()->representation().IsInteger32());
    ASSERT(instr->right()->representation().IsInteger32());
    LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand());
    LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand());
1347
    LAddI* add = new(zone()) LAddI(left, right);
1348
    LInstruction* result = DefineAsRegister(add);
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
    if (instr->CheckFlag(HValue::kCanOverflow)) {
      result = AssignEnvironment(result);
    }
    return result;
  } else if (instr->representation().IsDouble()) {
    return DoArithmeticD(Token::ADD, instr);
  } else {
    ASSERT(instr->representation().IsTagged());
    return DoArithmeticT(Token::ADD, instr);
  }
}


1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
  LOperand* left = NULL;
  LOperand* right = NULL;
  if (instr->representation().IsInteger32()) {
    ASSERT(instr->left()->representation().IsInteger32());
    ASSERT(instr->right()->representation().IsInteger32());
    left = UseRegisterAtStart(instr->LeastConstantOperand());
    right = UseOrConstantAtStart(instr->MostConstantOperand());
  } else {
    ASSERT(instr->representation().IsDouble());
    ASSERT(instr->left()->representation().IsDouble());
    ASSERT(instr->right()->representation().IsDouble());
    left = UseRegisterAtStart(instr->left());
    right = UseRegisterAtStart(instr->right());
  }
  return DefineAsRegister(new(zone()) LMathMinMax(left, right));
}


1381
LInstruction* LChunkBuilder::DoPower(HPower* instr) {
1382 1383 1384 1385 1386 1387 1388 1389
  ASSERT(instr->representation().IsDouble());
  // We call a C function for double power. It can't trigger a GC.
  // We need to use fixed result register for the call.
  Representation exponent_type = instr->right()->representation();
  ASSERT(instr->left()->representation().IsDouble());
  LOperand* left = UseFixedDouble(instr->left(), d1);
  LOperand* right = exponent_type.IsDouble() ?
      UseFixedDouble(instr->right(), d2) :
1390
      UseFixed(instr->right(), r2);
1391
  LPower* result = new(zone()) LPower(left, right);
1392 1393 1394
  return MarkAsCall(DefineFixedDouble(result, d3),
                    instr,
                    CAN_DEOPTIMIZE_EAGERLY);
1395 1396 1397
}


1398 1399 1400 1401
LInstruction* LChunkBuilder::DoRandom(HRandom* instr) {
  ASSERT(instr->representation().IsDouble());
  ASSERT(instr->global_object()->representation().IsTagged());
  LOperand* global_object = UseFixed(instr->global_object(), r0);
1402
  LRandom* result = new(zone()) LRandom(global_object);
1403 1404 1405 1406
  return MarkAsCall(DefineFixedDouble(result, d7), instr);
}


1407 1408 1409
LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
  ASSERT(instr->left()->representation().IsTagged());
  ASSERT(instr->right()->representation().IsTagged());
1410 1411
  LOperand* left = UseFixed(instr->left(), r1);
  LOperand* right = UseFixed(instr->right(), r0);
1412
  LCmpT* result = new(zone()) LCmpT(left, right);
1413 1414 1415 1416 1417 1418 1419
  return MarkAsCall(DefineFixed(result, r0), instr);
}


LInstruction* LChunkBuilder::DoCompareIDAndBranch(
    HCompareIDAndBranch* instr) {
  Representation r = instr->GetInputRepresentation();
1420 1421
  if (r.IsInteger32()) {
    ASSERT(instr->left()->representation().IsInteger32());
1422
    ASSERT(instr->right()->representation().IsInteger32());
1423 1424
    LOperand* left = UseRegisterOrConstantAtStart(instr->left());
    LOperand* right = UseRegisterOrConstantAtStart(instr->right());
1425
    return new(zone()) LCmpIDAndBranch(left, right);
1426 1427
  } else {
    ASSERT(r.IsDouble());
1428
    ASSERT(instr->left()->representation().IsDouble());
1429 1430 1431
    ASSERT(instr->right()->representation().IsDouble());
    LOperand* left = UseRegisterAtStart(instr->left());
    LOperand* right = UseRegisterAtStart(instr->right());
1432
    return new(zone()) LCmpIDAndBranch(left, right);
1433 1434 1435 1436
  }
}


1437 1438
LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
    HCompareObjectEqAndBranch* instr) {
1439 1440
  LOperand* left = UseRegisterAtStart(instr->left());
  LOperand* right = UseRegisterAtStart(instr->right());
1441
  return new(zone()) LCmpObjectEqAndBranch(left, right);
1442 1443 1444
}


1445 1446
LInstruction* LChunkBuilder::DoCompareConstantEqAndBranch(
    HCompareConstantEqAndBranch* instr) {
1447 1448
  LOperand* value = UseRegisterAtStart(instr->value());
  return new(zone()) LCmpConstantEqAndBranch(value);
1449 1450 1451
}


1452
LInstruction* LChunkBuilder::DoIsNilAndBranch(HIsNilAndBranch* instr) {
1453
  ASSERT(instr->value()->representation().IsTagged());
1454
  return new(zone()) LIsNilAndBranch(UseRegisterAtStart(instr->value()));
1455 1456 1457
}


1458
LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) {
1459
  ASSERT(instr->value()->representation().IsTagged());
1460
  LOperand* value = UseRegisterAtStart(instr->value());
1461
  LOperand* temp = TempRegister();
1462
  return new(zone()) LIsObjectAndBranch(value, temp);
1463 1464 1465
}


1466 1467
LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
  ASSERT(instr->value()->representation().IsTagged());
1468
  LOperand* value = UseRegisterAtStart(instr->value());
1469
  LOperand* temp = TempRegister();
1470
  return new(zone()) LIsStringAndBranch(value, temp);
1471 1472 1473
}


1474
LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
1475
  ASSERT(instr->value()->representation().IsTagged());
1476
  return new(zone()) LIsSmiAndBranch(Use(instr->value()));
1477 1478 1479
}


1480 1481
LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
    HIsUndetectableAndBranch* instr) {
1482
  ASSERT(instr->value()->representation().IsTagged());
1483 1484
  LOperand* value = UseRegisterAtStart(instr->value());
  return new(zone()) LIsUndetectableAndBranch(value, TempRegister());
1485 1486 1487
}


1488 1489 1490 1491 1492 1493
LInstruction* LChunkBuilder::DoStringCompareAndBranch(
    HStringCompareAndBranch* instr) {
  ASSERT(instr->left()->representation().IsTagged());
  ASSERT(instr->right()->representation().IsTagged());
  LOperand* left = UseFixed(instr->left(), r1);
  LOperand* right = UseFixed(instr->right(), r0);
1494 1495
  LStringCompareAndBranch* result =
      new(zone()) LStringCompareAndBranch(left, right);
1496 1497 1498 1499
  return MarkAsCall(result, instr);
}


1500 1501
LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
    HHasInstanceTypeAndBranch* instr) {
1502
  ASSERT(instr->value()->representation().IsTagged());
1503 1504
  LOperand* value = UseRegisterAtStart(instr->value());
  return new(zone()) LHasInstanceTypeAndBranch(value);
1505 1506 1507
}


1508 1509 1510
LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
    HGetCachedArrayIndex* instr)  {
  ASSERT(instr->value()->representation().IsTagged());
1511
  LOperand* value = UseRegisterAtStart(instr->value());
1512

1513
  return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
1514 1515 1516
}


1517 1518
LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
    HHasCachedArrayIndexAndBranch* instr) {
1519
  ASSERT(instr->value()->representation().IsTagged());
1520
  return new(zone()) LHasCachedArrayIndexAndBranch(
1521
      UseRegisterAtStart(instr->value()));
1522 1523 1524
}


1525 1526
LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
    HClassOfTestAndBranch* instr) {
1527
  ASSERT(instr->value()->representation().IsTagged());
1528 1529
  LOperand* value = UseRegister(instr->value());
  return new(zone()) LClassOfTestAndBranch(value, TempRegister());
1530 1531 1532
}


1533 1534
LInstruction* LChunkBuilder::DoJSArrayLength(HJSArrayLength* instr) {
  LOperand* array = UseRegisterAtStart(instr->value());
1535
  return DefineAsRegister(new(zone()) LJSArrayLength(array));
1536
}
1537 1538


1539 1540
LInstruction* LChunkBuilder::DoFixedArrayBaseLength(
    HFixedArrayBaseLength* instr) {
1541
  LOperand* array = UseRegisterAtStart(instr->value());
1542
  return DefineAsRegister(new(zone()) LFixedArrayBaseLength(array));
1543 1544 1545
}


1546 1547
LInstruction* LChunkBuilder::DoElementsKind(HElementsKind* instr) {
  LOperand* object = UseRegisterAtStart(instr->value());
1548
  return DefineAsRegister(new(zone()) LElementsKind(object));
1549 1550 1551
}


1552 1553
LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) {
  LOperand* object = UseRegister(instr->value());
1554
  LValueOf* result = new(zone()) LValueOf(object, TempRegister());
1555
  return DefineAsRegister(result);
1556 1557 1558
}


1559
LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
1560
  LOperand* object = UseFixed(instr->value(), r0);
1561 1562
  LDateField* result =
      new(zone()) LDateField(object, FixedTemp(r1), instr->index());
1563
  return MarkAsCall(DefineFixed(result, r0), instr);
1564 1565 1566
}


1567
LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
1568
  LOperand* value = UseRegisterOrConstantAtStart(instr->index());
1569 1570
  LOperand* length = UseRegister(instr->length());
  return AssignEnvironment(new(zone()) LBoundsCheck(value, length));
1571 1572 1573
}


1574 1575 1576 1577 1578 1579 1580
LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
  // The control instruction marking the end of a block that completed
  // abruptly (e.g., threw an exception).  There is nothing specific to do.
  return NULL;
}


1581 1582
LInstruction* LChunkBuilder::DoThrow(HThrow* instr) {
  LOperand* value = UseFixed(instr->value(), r0);
1583
  return MarkAsCall(new(zone()) LThrow(value), instr);
1584
}
1585 1586 1587 1588 1589


LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
  return NULL;
}
1590 1591


1592 1593 1594 1595 1596 1597 1598 1599
LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) {
  // All HForceRepresentation instructions should be eliminated in the
  // representation change phase of Hydrogen.
  UNREACHABLE();
  return NULL;
}


1600 1601 1602 1603 1604 1605
LInstruction* LChunkBuilder::DoChange(HChange* instr) {
  Representation from = instr->from();
  Representation to = instr->to();
  if (from.IsTagged()) {
    if (to.IsDouble()) {
      LOperand* value = UseRegister(instr->value());
1606
      LNumberUntagD* res = new(zone()) LNumberUntagD(value);
1607 1608 1609
      return AssignEnvironment(DefineAsRegister(res));
    } else {
      ASSERT(to.IsInteger32());
1610
      LOperand* value = UseRegisterAtStart(instr->value());
1611
      LInstruction* res = NULL;
1612 1613
      if (instr->value()->type().IsSmi()) {
        res = DefineAsRegister(new(zone()) LSmiUntag(value, false));
1614 1615 1616 1617
      } else {
        LOperand* temp1 = TempRegister();
        LOperand* temp2 = instr->CanTruncateToInt32() ? TempRegister()
                                                      : NULL;
1618
        LOperand* temp3 = instr->CanTruncateToInt32() ? FixedTemp(d11)
1619
                                                      : NULL;
1620 1621 1622 1623
        res = DefineSameAsFirst(new(zone()) LTaggedToI(value,
                                                       temp1,
                                                       temp2,
                                                       temp3));
1624 1625 1626 1627 1628 1629 1630
        res = AssignEnvironment(res);
      }
      return res;
    }
  } else if (from.IsDouble()) {
    if (to.IsTagged()) {
      LOperand* value = UseRegister(instr->value());
1631 1632
      LOperand* temp1 = TempRegister();
      LOperand* temp2 = TempRegister();
1633

1634 1635
      // Make sure that the temp and result_temp registers are
      // different.
1636
      LUnallocated* result_temp = TempRegister();
1637
      LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2);
1638 1639 1640 1641 1642
      Define(result, result_temp);
      return AssignPointerMap(result);
    } else {
      ASSERT(to.IsInteger32());
      LOperand* value = UseRegister(instr->value());
1643 1644 1645
      LOperand* temp1 = TempRegister();
      LOperand* temp2 = instr->CanTruncateToInt32() ? TempRegister() : NULL;
      LDoubleToI* res = new(zone()) LDoubleToI(value, temp1, temp2);
1646 1647 1648 1649 1650
      return AssignEnvironment(DefineAsRegister(res));
    }
  } else if (from.IsInteger32()) {
    if (to.IsTagged()) {
      HValue* val = instr->value();
1651
      LOperand* value = UseRegisterAtStart(val);
1652
      if (val->HasRange() && val->range()->IsInSmiRange()) {
1653
        return DefineAsRegister(new(zone()) LSmiTag(value));
1654
      } else {
1655
        LNumberTagI* result = new(zone()) LNumberTagI(value);
1656
        return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
1657 1658 1659 1660
      }
    } else {
      ASSERT(to.IsDouble());
      LOperand* value = Use(instr->value());
1661
      return DefineAsRegister(new(zone()) LInteger32ToDouble(value));
1662 1663 1664 1665 1666 1667 1668 1669 1670
    }
  }
  UNREACHABLE();
  return NULL;
}


LInstruction* LChunkBuilder::DoCheckNonSmi(HCheckNonSmi* instr) {
  LOperand* value = UseRegisterAtStart(instr->value());
1671
  return AssignEnvironment(new(zone()) LCheckNonSmi(value));
1672 1673 1674 1675 1676
}


LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
  LOperand* value = UseRegisterAtStart(instr->value());
1677
  LInstruction* result = new(zone()) LCheckInstanceType(value);
1678 1679 1680 1681 1682
  return AssignEnvironment(result);
}


LInstruction* LChunkBuilder::DoCheckPrototypeMaps(HCheckPrototypeMaps* instr) {
1683 1684
  LOperand* temp1 = TempRegister();
  LOperand* temp2 = TempRegister();
1685
  LInstruction* result = new(zone()) LCheckPrototypeMaps(temp1, temp2);
1686 1687 1688 1689 1690 1691
  return AssignEnvironment(result);
}


LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
  LOperand* value = UseRegisterAtStart(instr->value());
1692
  return AssignEnvironment(new(zone()) LCheckSmi(value));
1693 1694 1695 1696 1697
}


LInstruction* LChunkBuilder::DoCheckFunction(HCheckFunction* instr) {
  LOperand* value = UseRegisterAtStart(instr->value());
1698
  return AssignEnvironment(new(zone()) LCheckFunction(value));
1699 1700 1701
}


1702
LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
1703
  LOperand* value = UseRegisterAtStart(instr->value());
1704
  LInstruction* result = new(zone()) LCheckMaps(value);
1705 1706 1707 1708
  return AssignEnvironment(result);
}


1709 1710 1711 1712 1713
LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
  HValue* value = instr->value();
  Representation input_rep = value->representation();
  LOperand* reg = UseRegister(value);
  if (input_rep.IsDouble()) {
1714
    return DefineAsRegister(new(zone()) LClampDToUint8(reg, FixedTemp(d11)));
1715
  } else if (input_rep.IsInteger32()) {
1716
    return DefineAsRegister(new(zone()) LClampIToUint8(reg));
1717 1718 1719 1720
  } else {
    ASSERT(input_rep.IsTagged());
    // Register allocator doesn't (yet) support allocation of double
    // temps. Reserve d1 explicitly.
1721
    LClampTToUint8* result = new(zone()) LClampTToUint8(reg, FixedTemp(d11));
1722 1723 1724 1725 1726
    return AssignEnvironment(DefineAsRegister(result));
  }
}


1727
LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
1728
  return new(zone()) LReturn(UseFixed(instr->value(), r0));
1729 1730 1731 1732 1733 1734
}


LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
  Representation r = instr->representation();
  if (r.IsInteger32()) {
1735
    return DefineAsRegister(new(zone()) LConstantI);
1736
  } else if (r.IsDouble()) {
1737
    return DefineAsRegister(new(zone()) LConstantD);
1738
  } else if (r.IsTagged()) {
1739
    return DefineAsRegister(new(zone()) LConstantT);
1740
  } else {
1741
    UNREACHABLE();
1742 1743 1744 1745 1746
    return NULL;
  }
}


1747
LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) {
1748
  LLoadGlobalCell* result = new(zone()) LLoadGlobalCell;
1749
  return instr->RequiresHoleCheck()
1750 1751 1752 1753 1754
      ? AssignEnvironment(DefineAsRegister(result))
      : DefineAsRegister(result);
}


1755 1756
LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
  LOperand* global_object = UseFixed(instr->global_object(), r0);
1757
  LLoadGlobalGeneric* result = new(zone()) LLoadGlobalGeneric(global_object);
1758 1759 1760 1761
  return MarkAsCall(DefineFixed(result, r0), instr);
}


1762
LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) {
1763 1764 1765 1766
  LOperand* value = UseRegister(instr->value());
  // Use a temp to check the value in the cell in the case where we perform
  // a hole check.
  return instr->RequiresHoleCheck()
1767 1768
      ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister()))
      : new(zone()) LStoreGlobalCell(value, NULL);
1769 1770 1771
}


1772 1773 1774 1775
LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) {
  LOperand* global_object = UseFixed(instr->global_object(), r1);
  LOperand* value = UseFixed(instr->value(), r0);
  LStoreGlobalGeneric* result =
1776
      new(zone()) LStoreGlobalGeneric(global_object, value);
1777 1778 1779 1780
  return MarkAsCall(result, instr);
}


1781
LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
1782
  LOperand* context = UseRegisterAtStart(instr->value());
1783 1784
  LInstruction* result =
      DefineAsRegister(new(zone()) LLoadContextSlot(context));
1785
  return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
1786 1787 1788 1789
}


LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
1790
  LOperand* context;
1791 1792
  LOperand* value;
  if (instr->NeedsWriteBarrier()) {
1793
    context = UseTempRegister(instr->context());
1794 1795
    value = UseTempRegister(instr->value());
  } else {
1796
    context = UseRegister(instr->context());
1797 1798
    value = UseRegister(instr->value());
  }
1799
  LInstruction* result = new(zone()) LStoreContextSlot(context, value);
1800
  return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result;
1801 1802 1803
}


1804 1805
LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
  return DefineAsRegister(
1806
      new(zone()) LLoadNamedField(UseRegisterAtStart(instr->object())));
1807 1808 1809
}


1810 1811 1812 1813 1814
LInstruction* LChunkBuilder::DoLoadNamedFieldPolymorphic(
    HLoadNamedFieldPolymorphic* instr) {
  ASSERT(instr->representation().IsTagged());
  if (instr->need_generic()) {
    LOperand* obj = UseFixed(instr->object(), r0);
1815 1816
    LLoadNamedFieldPolymorphic* result =
        new(zone()) LLoadNamedFieldPolymorphic(obj);
1817 1818 1819
    return MarkAsCall(DefineFixed(result, r0), instr);
  } else {
    LOperand* obj = UseRegisterAtStart(instr->object());
1820 1821
    LLoadNamedFieldPolymorphic* result =
        new(zone()) LLoadNamedFieldPolymorphic(obj);
1822 1823 1824 1825 1826
    return AssignEnvironment(DefineAsRegister(result));
  }
}


1827 1828
LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
  LOperand* object = UseFixed(instr->object(), r0);
1829
  LInstruction* result = DefineFixed(new(zone()) LLoadNamedGeneric(object), r0);
1830 1831 1832 1833
  return MarkAsCall(result, instr);
}


1834 1835 1836
LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
    HLoadFunctionPrototype* instr) {
  return AssignEnvironment(DefineAsRegister(
1837
      new(zone()) LLoadFunctionPrototype(UseRegister(instr->function()))));
1838 1839 1840
}


1841 1842
LInstruction* LChunkBuilder::DoLoadElements(HLoadElements* instr) {
  LOperand* input = UseRegisterAtStart(instr->value());
1843
  return DefineAsRegister(new(zone()) LLoadElements(input));
1844 1845 1846
}


1847 1848
LInstruction* LChunkBuilder::DoLoadExternalArrayPointer(
    HLoadExternalArrayPointer* instr) {
1849
  LOperand* input = UseRegisterAtStart(instr->value());
1850
  return DefineAsRegister(new(zone()) LLoadExternalArrayPointer(input));
1851 1852 1853 1854 1855
}


LInstruction* LChunkBuilder::DoLoadKeyedFastElement(
    HLoadKeyedFastElement* instr) {
1856
  ASSERT(instr->representation().IsTagged());
1857 1858
  ASSERT(instr->key()->representation().IsInteger32() ||
         instr->key()->representation().IsTagged());
1859
  LOperand* obj = UseRegisterAtStart(instr->object());
1860
  LOperand* key = UseRegisterOrConstantAtStart(instr->key());
1861
  LLoadKeyedFastElement* result = new(zone()) LLoadKeyedFastElement(obj, key);
1862 1863
  if (instr->RequiresHoleCheck()) AssignEnvironment(result);
  return DefineAsRegister(result);
1864 1865 1866
}


1867 1868 1869
LInstruction* LChunkBuilder::DoLoadKeyedFastDoubleElement(
    HLoadKeyedFastDoubleElement* instr) {
  ASSERT(instr->representation().IsDouble());
1870 1871
  ASSERT(instr->key()->representation().IsInteger32() ||
         instr->key()->representation().IsTagged());
1872 1873 1874
  LOperand* elements = UseTempRegister(instr->elements());
  LOperand* key = UseRegisterOrConstantAtStart(instr->key());
  LLoadKeyedFastDoubleElement* result =
1875
      new(zone()) LLoadKeyedFastDoubleElement(elements, key);
1876 1877 1878 1879
  return AssignEnvironment(DefineAsRegister(result));
}


1880 1881
LInstruction* LChunkBuilder::DoLoadKeyedSpecializedArrayElement(
    HLoadKeyedSpecializedArrayElement* instr) {
1882
  ElementsKind elements_kind = instr->elements_kind();
1883
  ASSERT(
1884
      (instr->representation().IsInteger32() &&
1885 1886
       (elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
       (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) ||
1887
      (instr->representation().IsDouble() &&
1888 1889
       ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
       (elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
1890 1891
  ASSERT(instr->key()->representation().IsInteger32() ||
         instr->key()->representation().IsTagged());
1892
  LOperand* external_pointer = UseRegister(instr->external_pointer());
1893
  LOperand* key = UseRegisterOrConstant(instr->key());
1894
  LLoadKeyedSpecializedArrayElement* result =
1895
      new(zone()) LLoadKeyedSpecializedArrayElement(external_pointer, key);
1896 1897 1898
  LInstruction* load_instr = DefineAsRegister(result);
  // An unsigned int array load might overflow and cause a deopt, make sure it
  // has an environment.
1899
  return (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) ?
1900
      AssignEnvironment(load_instr) : load_instr;
1901 1902 1903
}


1904 1905 1906 1907 1908
LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
  LOperand* object = UseFixed(instr->object(), r1);
  LOperand* key = UseFixed(instr->key(), r0);

  LInstruction* result =
1909
      DefineFixed(new(zone()) LLoadKeyedGeneric(object, key), r0);
1910 1911 1912 1913 1914 1915 1916 1917 1918
  return MarkAsCall(result, instr);
}


LInstruction* LChunkBuilder::DoStoreKeyedFastElement(
    HStoreKeyedFastElement* instr) {
  bool needs_write_barrier = instr->NeedsWriteBarrier();
  ASSERT(instr->value()->representation().IsTagged());
  ASSERT(instr->object()->representation().IsTagged());
1919 1920
  ASSERT(instr->key()->representation().IsInteger32() ||
         instr->key()->representation().IsTagged());
1921 1922 1923 1924 1925 1926 1927 1928

  LOperand* obj = UseTempRegister(instr->object());
  LOperand* val = needs_write_barrier
      ? UseTempRegister(instr->value())
      : UseRegisterAtStart(instr->value());
  LOperand* key = needs_write_barrier
      ? UseTempRegister(instr->key())
      : UseRegisterOrConstantAtStart(instr->key());
1929
  return new(zone()) LStoreKeyedFastElement(obj, key, val);
1930 1931 1932
}


1933 1934 1935 1936
LInstruction* LChunkBuilder::DoStoreKeyedFastDoubleElement(
    HStoreKeyedFastDoubleElement* instr) {
  ASSERT(instr->value()->representation().IsDouble());
  ASSERT(instr->elements()->representation().IsTagged());
1937 1938
  ASSERT(instr->key()->representation().IsInteger32() ||
         instr->key()->representation().IsTagged());
1939 1940 1941 1942 1943

  LOperand* elements = UseRegisterAtStart(instr->elements());
  LOperand* val = UseTempRegister(instr->value());
  LOperand* key = UseRegisterOrConstantAtStart(instr->key());

1944
  return new(zone()) LStoreKeyedFastDoubleElement(elements, key, val);
1945 1946 1947
}


1948 1949
LInstruction* LChunkBuilder::DoStoreKeyedSpecializedArrayElement(
    HStoreKeyedSpecializedArrayElement* instr) {
1950
  ElementsKind elements_kind = instr->elements_kind();
1951
  ASSERT(
1952
      (instr->value()->representation().IsInteger32() &&
1953 1954
       (elements_kind != EXTERNAL_FLOAT_ELEMENTS) &&
       (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) ||
1955
      (instr->value()->representation().IsDouble() &&
1956 1957
       ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) ||
       (elements_kind == EXTERNAL_DOUBLE_ELEMENTS))));
1958
  ASSERT(instr->external_pointer()->representation().IsExternal());
1959 1960
  ASSERT(instr->key()->representation().IsInteger32() ||
         instr->key()->representation().IsTagged());
1961 1962

  LOperand* external_pointer = UseRegister(instr->external_pointer());
1963
  bool val_is_temp_register =
1964 1965
      elements_kind == EXTERNAL_PIXEL_ELEMENTS ||
      elements_kind == EXTERNAL_FLOAT_ELEMENTS;
1966 1967 1968
  LOperand* val = val_is_temp_register
      ? UseTempRegister(instr->value())
      : UseRegister(instr->value());
1969
  LOperand* key = UseRegisterOrConstant(instr->key());
1970

1971 1972 1973
  return new(zone()) LStoreKeyedSpecializedArrayElement(external_pointer,
                                                        key,
                                                        val);
1974 1975 1976
}


1977 1978 1979 1980 1981 1982 1983 1984 1985
LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
  LOperand* obj = UseFixed(instr->object(), r2);
  LOperand* key = UseFixed(instr->key(), r1);
  LOperand* val = UseFixed(instr->value(), r0);

  ASSERT(instr->object()->representation().IsTagged());
  ASSERT(instr->key()->representation().IsTagged());
  ASSERT(instr->value()->representation().IsTagged());

1986
  return MarkAsCall(new(zone()) LStoreKeyedGeneric(obj, key, val), instr);
1987 1988 1989
}


1990 1991
LInstruction* LChunkBuilder::DoTransitionElementsKind(
    HTransitionElementsKind* instr) {
1992 1993 1994
  ElementsKind from_kind = instr->original_map()->elements_kind();
  ElementsKind to_kind = instr->transitioned_map()->elements_kind();
  if (IsSimpleMapChangeTransition(from_kind, to_kind)) {
1995 1996 1997
    LOperand* object = UseRegister(instr->object());
    LOperand* new_map_reg = TempRegister();
    LTransitionElementsKind* result =
1998
        new(zone()) LTransitionElementsKind(object, new_map_reg, NULL);
1999 2000 2001 2002 2003 2004
    return DefineSameAsFirst(result);
  } else {
    LOperand* object = UseFixed(instr->object(), r0);
    LOperand* fixed_object_reg = FixedTemp(r2);
    LOperand* new_map_reg = FixedTemp(r3);
    LTransitionElementsKind* result =
2005 2006 2007
        new(zone()) LTransitionElementsKind(object,
                                            new_map_reg,
                                            fixed_object_reg);
2008 2009 2010 2011 2012
    return MarkAsCall(DefineFixed(result, r0), instr);
  }
}


2013
LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
2014
  bool needs_write_barrier = instr->NeedsWriteBarrier();
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
  bool needs_write_barrier_for_map = !instr->transition().is_null() &&
      instr->NeedsWriteBarrierForMap();

  LOperand* obj;
  if (needs_write_barrier) {
    obj = instr->is_in_object()
        ? UseRegister(instr->object())
        : UseTempRegister(instr->object());
  } else {
    obj = needs_write_barrier_for_map
        ? UseRegister(instr->object())
        : UseRegisterAtStart(instr->object());
  }
2028 2029 2030 2031 2032

  LOperand* val = needs_write_barrier
      ? UseTempRegister(instr->value())
      : UseRegister(instr->value());

2033 2034 2035 2036
  // We need a temporary register for write barrier of the map field.
  LOperand* temp = needs_write_barrier_for_map ? TempRegister() : NULL;

  return new(zone()) LStoreNamedField(obj, val, temp);
2037 2038 2039 2040 2041 2042 2043
}


LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
  LOperand* obj = UseFixed(instr->object(), r1);
  LOperand* val = UseFixed(instr->value(), r0);

2044
  LInstruction* result = new(zone()) LStoreNamedGeneric(obj, val);
2045 2046 2047 2048
  return MarkAsCall(result, instr);
}


2049 2050 2051
LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
  LOperand* left = UseRegisterAtStart(instr->left());
  LOperand* right = UseRegisterAtStart(instr->right());
2052 2053
  return MarkAsCall(DefineFixed(new(zone()) LStringAdd(left, right), r0),
                    instr);
2054 2055 2056
}


2057
LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
2058 2059
  LOperand* string = UseTempRegister(instr->string());
  LOperand* index = UseTempRegister(instr->index());
2060
  LStringCharCodeAt* result = new(zone()) LStringCharCodeAt(string, index);
2061
  return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
2062 2063 2064
}


2065 2066
LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
  LOperand* char_code = UseRegister(instr->value());
2067
  LStringCharFromCode* result = new(zone()) LStringCharFromCode(char_code);
2068 2069 2070 2071
  return AssignPointerMap(DefineAsRegister(result));
}


2072
LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) {
2073
  LOperand* string = UseRegisterAtStart(instr->value());
2074
  return DefineAsRegister(new(zone()) LStringLength(string));
2075 2076 2077
}


2078
LInstruction* LChunkBuilder::DoAllocateObject(HAllocateObject* instr) {
2079 2080
  LAllocateObject* result =
      new(zone()) LAllocateObject(TempRegister(), TempRegister());
2081 2082 2083 2084
  return AssignPointerMap(DefineAsRegister(result));
}


2085
LInstruction* LChunkBuilder::DoFastLiteral(HFastLiteral* instr) {
2086
  return MarkAsCall(DefineFixed(new(zone()) LFastLiteral, r0), instr);
2087 2088 2089
}


2090
LInstruction* LChunkBuilder::DoArrayLiteral(HArrayLiteral* instr) {
2091
  return MarkAsCall(DefineFixed(new(zone()) LArrayLiteral, r0), instr);
2092 2093 2094
}


2095
LInstruction* LChunkBuilder::DoObjectLiteral(HObjectLiteral* instr) {
2096
  return MarkAsCall(DefineFixed(new(zone()) LObjectLiteral, r0), instr);
2097 2098 2099 2100
}


LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
2101
  return MarkAsCall(DefineFixed(new(zone()) LRegExpLiteral, r0), instr);
2102 2103 2104 2105
}


LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) {
2106
  return MarkAsCall(DefineFixed(new(zone()) LFunctionLiteral, r0), instr);
2107 2108 2109 2110
}


LInstruction* LChunkBuilder::DoDeleteProperty(HDeleteProperty* instr) {
2111 2112
  LOperand* object = UseFixed(instr->object(), r0);
  LOperand* key = UseFixed(instr->key(), r1);
2113
  LDeleteProperty* result = new(zone()) LDeleteProperty(object, key);
2114 2115 2116 2117 2118 2119 2120
  return MarkAsCall(DefineFixed(result, r0), instr);
}


LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
  allocator_->MarkAsOsrEntry();
  current_block_->last_environment()->set_ast_id(instr->ast_id());
2121
  return AssignEnvironment(new(zone()) LOsrEntry);
2122 2123 2124 2125 2126
}


LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
  int spill_index = chunk()->GetParameterStackSlot(instr->index());
2127
  return DefineAsSpilled(new(zone()) LParameter, spill_index);
2128 2129 2130 2131 2132
}


LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
  int spill_index = chunk()->GetNextSpillIndex(false);  // Not double-width.
2133 2134
  if (spill_index > LUnallocated::kMaxFixedIndex) {
    Abort("Too many spill slots needed for OSR");
2135
    spill_index = 0;
2136
  }
2137
  return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
2138 2139 2140 2141 2142
}


LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
  argument_count_ -= instr->argument_count();
2143
  return MarkAsCall(DefineFixed(new(zone()) LCallStub, r0), instr);
2144 2145 2146 2147
}


LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
2148 2149 2150 2151
  // There are no real uses of the arguments object.
  // arguments.length and element access are supported directly on
  // stack arguments, and any real arguments object use causes a bailout.
  // So this value is never used.
2152 2153 2154 2155 2156 2157 2158
  return NULL;
}


LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
  LOperand* arguments = UseRegister(instr->arguments());
  LOperand* length = UseTempRegister(instr->length());
2159
  LOperand* index = UseRegister(instr->index());
2160 2161
  LAccessArgumentsAt* result =
      new(zone()) LAccessArgumentsAt(arguments, length, index);
2162
  return AssignEnvironment(DefineAsRegister(result));
2163 2164 2165
}


2166 2167
LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
  LOperand* object = UseFixed(instr->value(), r0);
2168
  LToFastProperties* result = new(zone()) LToFastProperties(object);
2169 2170 2171 2172
  return MarkAsCall(DefineFixed(result, r0), instr);
}


2173
LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
2174
  LTypeof* result = new(zone()) LTypeof(UseFixed(instr->value(), r0));
2175 2176 2177 2178
  return MarkAsCall(DefineFixed(result, r0), instr);
}


2179
LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
2180
  return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value()));
2181 2182
}

2183

2184 2185
LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
    HIsConstructCallAndBranch* instr) {
2186
  return new(zone()) LIsConstructCallAndBranch(TempRegister());
2187 2188 2189
}


2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207
LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
  HEnvironment* env = current_block_->last_environment();
  ASSERT(env != NULL);

  env->set_ast_id(instr->ast_id());

  env->Drop(instr->pop_count());
  for (int i = 0; i < instr->values()->length(); ++i) {
    HValue* value = instr->values()->at(i);
    if (instr->HasAssignedIndexAt(i)) {
      env->Bind(instr->GetAssignedIndexAt(i), value);
    } else {
      env->Push(value);
    }
  }

  // If there is an instruction pending deoptimization environment create a
  // lazy bailout instruction to capture the environment.
2208
  if (pending_deoptimization_ast_id_ == instr->ast_id()) {
2209
    LInstruction* result = new(zone()) LLazyBailout;
2210
    result = AssignEnvironment(result);
2211 2212
    // Store the lazy deopt environment with the instruction if needed. Right
    // now it is only used for LInstanceOfKnownGlobal.
2213
    instruction_pending_deoptimization_environment_->
2214 2215
        SetDeferredLazyDeoptimizationEnvironment(result->environment());
    instruction_pending_deoptimization_environment_ = NULL;
2216
    pending_deoptimization_ast_id_ = BailoutId::None();
2217 2218 2219 2220 2221 2222 2223 2224
    return result;
  }

  return NULL;
}


LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
2225
  if (instr->is_function_entry()) {
2226
    return MarkAsCall(new(zone()) LStackCheck, instr);
2227 2228
  } else {
    ASSERT(instr->is_backwards_branch());
2229
    return AssignEnvironment(AssignPointerMap(new(zone()) LStackCheck));
2230
  }
2231 2232 2233 2234 2235 2236 2237
}


LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
  HEnvironment* outer = current_block_->last_environment();
  HConstant* undefined = graph()->GetConstantUndefined();
  HEnvironment* inner = outer->CopyForInlining(instr->closure(),
2238
                                               instr->arguments_count(),
2239
                                               instr->function(),
2240
                                               undefined,
2241
                                               instr->call_kind(),
2242
                                               instr->inlining_kind());
2243 2244
  if (instr->arguments_var() != NULL) {
    inner->Bind(instr->arguments_var(), graph()->GetArgumentsObject());
2245
  }
2246 2247 2248 2249 2250 2251 2252
  current_block_->UpdateEnvironment(inner);
  chunk_->AddInlinedClosure(instr->closure());
  return NULL;
}


LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
  LInstruction* pop = NULL;

  HEnvironment* env = current_block_->last_environment();

  if (instr->arguments_pushed()) {
    int argument_count = env->arguments_environment()->parameter_count();
    pop = new(zone()) LDrop(argument_count);
    argument_count_ -= argument_count;
  }

2263 2264
  HEnvironment* outer = current_block_->last_environment()->
      DiscardInlined(false);
2265
  current_block_->UpdateEnvironment(outer);
2266 2267

  return pop;
2268 2269 2270
}


2271 2272 2273
LInstruction* LChunkBuilder::DoIn(HIn* instr) {
  LOperand* key = UseRegisterAtStart(instr->key());
  LOperand* object = UseRegisterAtStart(instr->object());
2274
  LIn* result = new(zone()) LIn(key, object);
2275 2276 2277 2278
  return MarkAsCall(DefineFixed(result, r0), instr);
}


2279 2280
LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
  LOperand* object = UseFixed(instr->enumerable(), r0);
2281
  LForInPrepareMap* result = new(zone()) LForInPrepareMap(object);
2282 2283 2284 2285 2286 2287
  return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY);
}


LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
  LOperand* map = UseRegister(instr->map());
2288
  LOperand* scratch = TempRegister();
2289
  return AssignEnvironment(DefineAsRegister(
2290
      new(zone()) LForInCacheArray(map, scratch)));
2291 2292 2293 2294 2295 2296
}


LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
  LOperand* value = UseRegisterAtStart(instr->value());
  LOperand* map = UseRegisterAtStart(instr->map());
2297
  return AssignEnvironment(new(zone()) LCheckMapValue(value, map));
2298 2299 2300 2301 2302 2303
}


LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
  LOperand* object = UseRegister(instr->object());
  LOperand* index = UseRegister(instr->index());
2304
  return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index));
2305 2306 2307
}


2308
} }  // namespace v8::internal