lithium-arm64.h 91.9 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_ARM64_LITHIUM_ARM64_H_
#define V8_ARM64_LITHIUM_ARM64_H_
7

8 9
#include "src/hydrogen.h"
#include "src/lithium.h"
10
#include "src/lithium-allocator.h"
11 12
#include "src/safepoint-table.h"
#include "src/utils.h"
13 14 15 16 17 18 19

namespace v8 {
namespace internal {

// Forward declarations.
class LCodeGen;

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \
  V(AccessArgumentsAt)                       \
  V(AddE)                                    \
  V(AddI)                                    \
  V(AddS)                                    \
  V(Allocate)                                \
  V(AllocateBlockContext)                    \
  V(ApplyArguments)                          \
  V(ArgumentsElements)                       \
  V(ArgumentsLength)                         \
  V(ArithmeticD)                             \
  V(ArithmeticT)                             \
  V(BitI)                                    \
  V(BitS)                                    \
  V(BoundsCheck)                             \
  V(Branch)                                  \
  V(CallFunction)                            \
  V(CallJSFunction)                          \
  V(CallNew)                                 \
  V(CallNewArray)                            \
  V(CallRuntime)                             \
  V(CallStub)                                \
  V(CallWithDescriptor)                      \
43
  V(CheckArrayBufferNotNeutered)             \
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  V(CheckInstanceType)                       \
  V(CheckMapValue)                           \
  V(CheckMaps)                               \
  V(CheckNonSmi)                             \
  V(CheckSmi)                                \
  V(CheckValue)                              \
  V(ClampDToUint8)                           \
  V(ClampIToUint8)                           \
  V(ClampTToUint8)                           \
  V(ClassOfTestAndBranch)                    \
  V(CmpHoleAndBranchD)                       \
  V(CmpHoleAndBranchT)                       \
  V(CmpMapAndBranch)                         \
  V(CmpObjectEqAndBranch)                    \
  V(CmpT)                                    \
  V(CompareMinusZeroAndBranch)               \
  V(CompareNumericAndBranch)                 \
  V(ConstantD)                               \
  V(ConstantE)                               \
  V(ConstantI)                               \
  V(ConstantS)                               \
  V(ConstantT)                               \
  V(ConstructDouble)                         \
  V(Context)                                 \
  V(DateField)                               \
  V(DebugBreak)                              \
  V(DeclareGlobals)                          \
  V(Deoptimize)                              \
  V(DivByConstI)                             \
  V(DivByPowerOf2I)                          \
  V(DivI)                                    \
  V(DoubleBits)                              \
  V(DoubleToIntOrSmi)                        \
  V(Drop)                                    \
  V(Dummy)                                   \
  V(DummyUse)                                \
  V(FlooringDivByConstI)                     \
  V(FlooringDivByPowerOf2I)                  \
  V(FlooringDivI)                            \
  V(ForInCacheArray)                         \
  V(ForInPrepareMap)                         \
  V(FunctionLiteral)                         \
  V(GetCachedArrayIndex)                     \
  V(Goto)                                    \
  V(HasCachedArrayIndexAndBranch)            \
  V(HasInstanceTypeAndBranch)                \
  V(InnerAllocatedObject)                    \
  V(InstanceOf)                              \
  V(InstanceOfKnownGlobal)                   \
  V(InstructionGap)                          \
  V(Integer32ToDouble)                       \
  V(InvokeFunction)                          \
  V(IsConstructCallAndBranch)                \
  V(IsObjectAndBranch)                       \
  V(IsSmiAndBranch)                          \
  V(IsStringAndBranch)                       \
  V(IsUndetectableAndBranch)                 \
  V(Label)                                   \
  V(LazyBailout)                             \
  V(LoadContextSlot)                         \
  V(LoadFieldByIndex)                        \
  V(LoadFunctionPrototype)                   \
  V(LoadGlobalGeneric)                       \
107
  V(LoadGlobalViaContext)                    \
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  V(LoadKeyedExternal)                       \
  V(LoadKeyedFixed)                          \
  V(LoadKeyedFixedDouble)                    \
  V(LoadKeyedGeneric)                        \
  V(LoadNamedField)                          \
  V(LoadNamedGeneric)                        \
  V(LoadRoot)                                \
  V(MapEnumLength)                           \
  V(MathAbs)                                 \
  V(MathAbsTagged)                           \
  V(MathClz32)                               \
  V(MathExp)                                 \
  V(MathFloorD)                              \
  V(MathFloorI)                              \
  V(MathFround)                              \
  V(MathLog)                                 \
  V(MathMinMax)                              \
  V(MathPowHalf)                             \
  V(MathRoundD)                              \
  V(MathRoundI)                              \
  V(MathSqrt)                                \
129
  V(MaybeGrowElements)                       \
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  V(ModByConstI)                             \
  V(ModByPowerOf2I)                          \
  V(ModI)                                    \
  V(MulConstIS)                              \
  V(MulI)                                    \
  V(MulS)                                    \
  V(NumberTagD)                              \
  V(NumberTagU)                              \
  V(NumberUntagD)                            \
  V(OsrEntry)                                \
  V(Parameter)                               \
  V(Power)                                   \
  V(PreparePushArguments)                    \
  V(PushArguments)                           \
  V(RegExpLiteral)                           \
  V(Return)                                  \
  V(SeqStringGetChar)                        \
  V(SeqStringSetChar)                        \
  V(ShiftI)                                  \
  V(ShiftS)                                  \
  V(SmiTag)                                  \
  V(SmiUntag)                                \
  V(StackCheck)                              \
  V(StoreCodeEntry)                          \
  V(StoreContextSlot)                        \
  V(StoreFrameContext)                       \
156
  V(StoreGlobalViaContext)                   \
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
  V(StoreKeyedExternal)                      \
  V(StoreKeyedFixed)                         \
  V(StoreKeyedFixedDouble)                   \
  V(StoreKeyedGeneric)                       \
  V(StoreNamedField)                         \
  V(StoreNamedGeneric)                       \
  V(StringAdd)                               \
  V(StringCharCodeAt)                        \
  V(StringCharFromCode)                      \
  V(StringCompareAndBranch)                  \
  V(SubI)                                    \
  V(SubS)                                    \
  V(TaggedToI)                               \
  V(ThisFunction)                            \
  V(ToFastProperties)                        \
  V(TransitionElementsKind)                  \
  V(TrapAllocationMemento)                   \
  V(TruncateDoubleToIntOrSmi)                \
  V(Typeof)                                  \
  V(TypeofIsAndBranch)                       \
  V(Uint32ToDouble)                          \
  V(UnknownOSRValue)                         \
179 180 181
  V(WrapReceiver)


182
#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic)            \
183 184 185
  Opcode opcode() const final { return LInstruction::k##type; } \
  void CompileToNative(LCodeGen* generator) final;              \
  const char* Mnemonic() const final { return mnemonic; }       \
186 187 188
  static L##type* cast(LInstruction* instr) {                   \
    DCHECK(instr->Is##type());                                  \
    return reinterpret_cast<L##type*>(instr);                   \
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  }


#define DECLARE_HYDROGEN_ACCESSOR(type)           \
  H##type* hydrogen() const {                     \
    return H##type::cast(this->hydrogen_value()); \
  }


class LInstruction : public ZoneObject {
 public:
  LInstruction()
      : environment_(NULL),
        hydrogen_value_(NULL),
        bit_field_(IsCallBits::encode(false)) { }

  virtual ~LInstruction() { }

  virtual void CompileToNative(LCodeGen* generator) = 0;
  virtual const char* Mnemonic() const = 0;
  virtual void PrintTo(StringStream* stream);
  virtual void PrintDataTo(StringStream* stream);
  virtual void PrintOutputOperandTo(StringStream* stream);

  enum Opcode {
    // Declare a unique enum value for each instruction.
#define DECLARE_OPCODE(type) k##type,
    LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE)
    kNumberOfInstructions
#undef DECLARE_OPCODE
  };

  virtual Opcode opcode() const = 0;

  // Declare non-virtual type testers for all leaf IR classes.
#define DECLARE_PREDICATE(type) \
  bool Is##type() const { return opcode() == k##type; }
  LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE)
#undef DECLARE_PREDICATE

  // Declare virtual predicates for instructions that don't have
  // an opcode.
  virtual bool IsGap() const { return false; }

  virtual bool IsControl() const { return false; }

235 236 237
  // Try deleting this instruction if possible.
  virtual bool TryDelete() { return false; }

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
  void set_environment(LEnvironment* env) { environment_ = env; }
  LEnvironment* environment() const { return environment_; }
  bool HasEnvironment() const { return environment_ != NULL; }

  void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); }
  LPointerMap* pointer_map() const { return pointer_map_.get(); }
  bool HasPointerMap() const { return pointer_map_.is_set(); }

  void set_hydrogen_value(HValue* value) { hydrogen_value_ = value; }
  HValue* hydrogen_value() const { return hydrogen_value_; }

  virtual void SetDeferredLazyDeoptimizationEnvironment(LEnvironment* env) { }

  void MarkAsCall() { bit_field_ = IsCallBits::update(bit_field_, true); }
  bool IsCall() const { return IsCallBits::decode(bit_field_); }

  // Interface to the register allocator and iterators.
  bool ClobbersTemps() const { return IsCall(); }
  bool ClobbersRegisters() const { return IsCall(); }
257
  virtual bool ClobbersDoubleRegisters(Isolate* isolate) const {
258 259
    return IsCall();
  }
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
  bool IsMarkedAsCall() const { return IsCall(); }

  virtual bool HasResult() const = 0;
  virtual LOperand* result() const = 0;

  virtual int InputCount() = 0;
  virtual LOperand* InputAt(int i) = 0;
  virtual int TempCount() = 0;
  virtual LOperand* TempAt(int i) = 0;

  LOperand* FirstInput() { return InputAt(0); }
  LOperand* Output() { return HasResult() ? result() : NULL; }

  virtual bool HasInterestingComment(LCodeGen* gen) const { return true; }

#ifdef DEBUG
  void VerifyCall();
#endif

 private:
  class IsCallBits: public BitField<bool, 0, 1> {};

  LEnvironment* environment_;
  SetOncePointer<LPointerMap> pointer_map_;
  HValue* hydrogen_value_;
  int32_t bit_field_;
};


// R = number of result operands (0 or 1).
template<int R>
class LTemplateResultInstruction : public LInstruction {
 public:
  // Allow 0 or 1 output operands.
  STATIC_ASSERT(R == 0 || R == 1);
295
  bool HasResult() const final { return (R != 0) && (result() != NULL); }
296
  void set_result(LOperand* operand) { results_[0] = operand; }
297
  LOperand* result() const override { return results_[0]; }
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314

 protected:
  EmbeddedContainer<LOperand*, R> results_;
};


// R = number of result operands (0 or 1).
// I = number of input operands.
// T = number of temporary operands.
template<int R, int I, int T>
class LTemplateInstruction : public LTemplateResultInstruction<R> {
 protected:
  EmbeddedContainer<LOperand*, I> inputs_;
  EmbeddedContainer<LOperand*, T> temps_;

 private:
  // Iterator support.
315 316
  int InputCount() final { return I; }
  LOperand* InputAt(int i) final { return inputs_[i]; }
317

318 319
  int TempCount() final { return T; }
  LOperand* TempAt(int i) final { return temps_[i]; }
320 321 322
};


323
class LUnknownOSRValue final : public LTemplateInstruction<1, 0, 0> {
324
 public:
325
  bool HasInterestingComment(LCodeGen* gen) const override { return false; }
326 327 328 329 330 331 332 333 334
  DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value")
};


template<int I, int T>
class LControlInstruction : public LTemplateInstruction<0, I, T> {
 public:
  LControlInstruction() : false_label_(NULL), true_label_(NULL) { }

335
  bool IsControl() const final { return true; }
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384

  int SuccessorCount() { return hydrogen()->SuccessorCount(); }
  HBasicBlock* SuccessorAt(int i) { return hydrogen()->SuccessorAt(i); }

  int TrueDestination(LChunk* chunk) {
    return chunk->LookupDestination(true_block_id());
  }

  int FalseDestination(LChunk* chunk) {
    return chunk->LookupDestination(false_block_id());
  }

  Label* TrueLabel(LChunk* chunk) {
    if (true_label_ == NULL) {
      true_label_ = chunk->GetAssemblyLabel(TrueDestination(chunk));
    }
    return true_label_;
  }

  Label* FalseLabel(LChunk* chunk) {
    if (false_label_ == NULL) {
      false_label_ = chunk->GetAssemblyLabel(FalseDestination(chunk));
    }
    return false_label_;
  }

 protected:
  int true_block_id() { return SuccessorAt(0)->block_id(); }
  int false_block_id() { return SuccessorAt(1)->block_id(); }

 private:
  DECLARE_HYDROGEN_ACCESSOR(ControlInstruction);

  Label* false_label_;
  Label* true_label_;
};


class LGap : public LTemplateInstruction<0, 0, 0> {
 public:
  explicit LGap(HBasicBlock* block)
      : block_(block) {
    parallel_moves_[BEFORE] = NULL;
    parallel_moves_[START] = NULL;
    parallel_moves_[END] = NULL;
    parallel_moves_[AFTER] = NULL;
  }

  // Can't use the DECLARE-macro here because of sub-classes.
385 386
  bool IsGap() const override { return true; }
  void PrintDataTo(StringStream* stream) override;
387
  static LGap* cast(LInstruction* instr) {
388
    DCHECK(instr->IsGap());
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    return reinterpret_cast<LGap*>(instr);
  }

  bool IsRedundant() const;

  HBasicBlock* block() const { return block_; }

  enum InnerPosition {
    BEFORE,
    START,
    END,
    AFTER,
    FIRST_INNER_POSITION = BEFORE,
    LAST_INNER_POSITION = AFTER
  };

  LParallelMove* GetOrCreateParallelMove(InnerPosition pos, Zone* zone)  {
    if (parallel_moves_[pos] == NULL) {
      parallel_moves_[pos] = new(zone) LParallelMove(zone);
    }
    return parallel_moves_[pos];
  }

  LParallelMove* GetParallelMove(InnerPosition pos)  {
    return parallel_moves_[pos];
  }

 private:
  LParallelMove* parallel_moves_[LAST_INNER_POSITION + 1];
  HBasicBlock* block_;
};


422
class LInstructionGap final : public LGap {
423 424 425
 public:
  explicit LInstructionGap(HBasicBlock* block) : LGap(block) { }

426
  bool HasInterestingComment(LCodeGen* gen) const override {
427 428 429 430 431 432 433
    return !IsRedundant();
  }

  DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap")
};


434
class LDrop final : public LTemplateInstruction<0, 0, 0> {
435 436 437 438 439 440 441 442 443 444 445 446
 public:
  explicit LDrop(int count) : count_(count) { }

  int count() const { return count_; }

  DECLARE_CONCRETE_INSTRUCTION(Drop, "drop")

 private:
  int count_;
};


447
class LDummy final : public LTemplateInstruction<1, 0, 0> {
448
 public:
449
  LDummy() {}
450 451 452 453
  DECLARE_CONCRETE_INSTRUCTION(Dummy, "dummy")
};


454
class LDummyUse final : public LTemplateInstruction<1, 1, 0> {
455 456 457 458 459 460 461 462
 public:
  explicit LDummyUse(LOperand* value) {
    inputs_[0] = value;
  }
  DECLARE_CONCRETE_INSTRUCTION(DummyUse, "dummy-use")
};


463
class LGoto final : public LTemplateInstruction<0, 0, 0> {
464 465 466
 public:
  explicit LGoto(HBasicBlock* block) : block_(block) { }

467
  bool HasInterestingComment(LCodeGen* gen) const override;
468
  DECLARE_CONCRETE_INSTRUCTION(Goto, "goto")
469 470
  void PrintDataTo(StringStream* stream) override;
  bool IsControl() const override { return true; }
471 472 473 474 475 476 477 478

  int block_id() const { return block_->block_id(); }

 private:
  HBasicBlock* block_;
};


479
class LLazyBailout final : public LTemplateInstruction<0, 0, 0> {
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
 public:
  LLazyBailout() : gap_instructions_size_(0) { }

  DECLARE_CONCRETE_INSTRUCTION(LazyBailout, "lazy-bailout")

  void set_gap_instructions_size(int gap_instructions_size) {
    gap_instructions_size_ = gap_instructions_size;
  }
  int gap_instructions_size() { return gap_instructions_size_; }

 private:
  int gap_instructions_size_;
};


495
class LLabel final : public LGap {
496 497 498 499
 public:
  explicit LLabel(HBasicBlock* block)
      : LGap(block), replacement_(NULL) { }

500
  bool HasInterestingComment(LCodeGen* gen) const override { return false; }
501 502
  DECLARE_CONCRETE_INSTRUCTION(Label, "label")

503
  void PrintDataTo(StringStream* stream) override;
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518

  int block_id() const { return block()->block_id(); }
  bool is_loop_header() const { return block()->IsLoopHeader(); }
  bool is_osr_entry() const { return block()->is_osr_entry(); }
  Label* label() { return &label_; }
  LLabel* replacement() const { return replacement_; }
  void set_replacement(LLabel* label) { replacement_ = label; }
  bool HasReplacement() const { return replacement_ != NULL; }

 private:
  Label label_;
  LLabel* replacement_;
};


519
class LOsrEntry final : public LTemplateInstruction<0, 0, 0> {
520 521 522
 public:
  LOsrEntry() {}

523
  bool HasInterestingComment(LCodeGen* gen) const override { return false; }
524 525 526 527
  DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr-entry")
};


528
class LAccessArgumentsAt final : public LTemplateInstruction<1, 3, 0> {
529 530 531
 public:
  LAccessArgumentsAt(LOperand* arguments,
                     LOperand* length,
532
                     LOperand* index) {
533 534 535 536 537 538 539 540 541 542 543
    inputs_[0] = arguments;
    inputs_[1] = length;
    inputs_[2] = index;
  }

  DECLARE_CONCRETE_INSTRUCTION(AccessArgumentsAt, "access-arguments-at")

  LOperand* arguments() { return inputs_[0]; }
  LOperand* length() { return inputs_[1]; }
  LOperand* index() { return inputs_[2]; }

544
  void PrintDataTo(StringStream* stream) override;
545 546 547
};


548
class LAddE final : public LTemplateInstruction<1, 2, 0> {
549 550 551 552 553 554 555 556 557 558 559 560 561 562
 public:
  LAddE(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(AddE, "add-e")
  DECLARE_HYDROGEN_ACCESSOR(Add)
};


563
class LAddI final : public LTemplateInstruction<1, 2, 0> {
564
 public:
565 566 567 568 569 570 571 572
  LAddI(LOperand* left, LOperand* right)
      : shift_(NO_SHIFT), shift_amount_(0)  {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LAddI(LOperand* left, LOperand* right, Shift shift, LOperand* shift_amount)
      : shift_(shift), shift_amount_(shift_amount)  {
573 574 575 576 577 578 579
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

580 581 582
  Shift shift() const { return shift_; }
  LOperand* shift_amount() const { return shift_amount_; }

583 584
  DECLARE_CONCRETE_INSTRUCTION(AddI, "add-i")
  DECLARE_HYDROGEN_ACCESSOR(Add)
585 586 587 588

 protected:
  Shift shift_;
  LOperand* shift_amount_;
589 590 591
};


592
class LAddS final : public LTemplateInstruction<1, 2, 0> {
593 594 595 596 597 598 599 600 601 602 603 604 605 606
 public:
  LAddS(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(AddS, "add-s")
  DECLARE_HYDROGEN_ACCESSOR(Add)
};


607
class LAllocate final : public LTemplateInstruction<1, 2, 3> {
608 609 610 611
 public:
  LAllocate(LOperand* context,
            LOperand* size,
            LOperand* temp1,
612 613
            LOperand* temp2,
            LOperand* temp3) {
614 615 616 617
    inputs_[0] = context;
    inputs_[1] = size;
    temps_[0] = temp1;
    temps_[1] = temp2;
618
    temps_[2] = temp3;
619 620 621 622 623 624
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* size() { return inputs_[1]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }
625
  LOperand* temp3() { return temps_[2]; }
626 627 628 629 630 631

  DECLARE_CONCRETE_INSTRUCTION(Allocate, "allocate")
  DECLARE_HYDROGEN_ACCESSOR(Allocate)
};


632
class LApplyArguments final : public LTemplateInstruction<1, 4, 0> {
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
 public:
  LApplyArguments(LOperand* function,
                  LOperand* receiver,
                  LOperand* length,
                  LOperand* elements) {
    inputs_[0] = function;
    inputs_[1] = receiver;
    inputs_[2] = length;
    inputs_[3] = elements;
  }

  DECLARE_CONCRETE_INSTRUCTION(ApplyArguments, "apply-arguments")

  LOperand* function() { return inputs_[0]; }
  LOperand* receiver() { return inputs_[1]; }
  LOperand* length() { return inputs_[2]; }
  LOperand* elements() { return inputs_[3]; }
};


653
class LArgumentsElements final : public LTemplateInstruction<1, 0, 1> {
654 655 656 657 658 659 660 661 662 663 664 665
 public:
  explicit LArgumentsElements(LOperand* temp) {
    temps_[0] = temp;
  }

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ArgumentsElements, "arguments-elements")
  DECLARE_HYDROGEN_ACCESSOR(ArgumentsElements)
};


666
class LArgumentsLength final : public LTemplateInstruction<1, 1, 0> {
667 668 669 670 671 672 673 674 675 676 677
 public:
  explicit LArgumentsLength(LOperand* elements) {
    inputs_[0] = elements;
  }

  LOperand* elements() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ArgumentsLength, "arguments-length")
};


678
class LArithmeticD final : public LTemplateInstruction<1, 2, 0> {
679 680 681 682 683 684 685 686 687 688 689 690 691
 public:
  LArithmeticD(Token::Value op,
               LOperand* left,
               LOperand* right)
      : op_(op) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  Token::Value op() const { return op_; }
  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

692 693 694
  Opcode opcode() const override { return LInstruction::kArithmeticD; }
  void CompileToNative(LCodeGen* generator) override;
  const char* Mnemonic() const override;
695 696 697 698 699 700

 private:
  Token::Value op_;
};


701
class LArithmeticT final : public LTemplateInstruction<1, 3, 0> {
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
 public:
  LArithmeticT(Token::Value op,
               LOperand* context,
               LOperand* left,
               LOperand* right)
      : op_(op) {
    inputs_[0] = context;
    inputs_[1] = left;
    inputs_[2] = right;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* left() { return inputs_[1]; }
  LOperand* right() { return inputs_[2]; }
  Token::Value op() const { return op_; }

718 719 720
  Opcode opcode() const override { return LInstruction::kArithmeticT; }
  void CompileToNative(LCodeGen* generator) override;
  const char* Mnemonic() const override;
721

conradw's avatar
conradw committed
722 723
  DECLARE_HYDROGEN_ACCESSOR(BinaryOperation)

724
  Strength strength() { return hydrogen()->strength(); }
conradw's avatar
conradw committed
725

726 727 728 729 730
 private:
  Token::Value op_;
};


731
class LBoundsCheck final : public LTemplateInstruction<0, 2, 0> {
732 733 734 735 736 737 738 739 740 741 742 743 744 745
 public:
  explicit LBoundsCheck(LOperand* index, LOperand* length) {
    inputs_[0] = index;
    inputs_[1] = length;
  }

  LOperand* index() { return inputs_[0]; }
  LOperand* length() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(BoundsCheck, "bounds-check")
  DECLARE_HYDROGEN_ACCESSOR(BoundsCheck)
};


746
class LBitI final : public LTemplateInstruction<1, 2, 0> {
747
 public:
748 749 750 751 752 753 754 755
  LBitI(LOperand* left, LOperand* right)
      : shift_(NO_SHIFT), shift_amount_(0)  {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LBitI(LOperand* left, LOperand* right, Shift shift, LOperand* shift_amount)
      : shift_(shift), shift_amount_(shift_amount)  {
756 757 758 759 760 761 762
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

763 764 765
  Shift shift() const { return shift_; }
  LOperand* shift_amount() const { return shift_amount_; }

766 767 768 769
  Token::Value op() const { return hydrogen()->op(); }

  DECLARE_CONCRETE_INSTRUCTION(BitI, "bit-i")
  DECLARE_HYDROGEN_ACCESSOR(Bitwise)
770 771 772 773

 protected:
  Shift shift_;
  LOperand* shift_amount_;
774 775 776
};


777
class LBitS final : public LTemplateInstruction<1, 2, 0> {
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
 public:
  LBitS(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  Token::Value op() const { return hydrogen()->op(); }

  DECLARE_CONCRETE_INSTRUCTION(BitS, "bit-s")
  DECLARE_HYDROGEN_ACCESSOR(Bitwise)
};


794
class LBranch final : public LControlInstruction<1, 2> {
795 796 797 798 799 800 801 802 803 804 805 806 807 808
 public:
  explicit LBranch(LOperand* value, LOperand *temp1, LOperand *temp2) {
    inputs_[0] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(Branch, "branch")
  DECLARE_HYDROGEN_ACCESSOR(Branch)

809
  void PrintDataTo(StringStream* stream) override;
810 811 812
};


813
class LCallJSFunction final : public LTemplateInstruction<1, 1, 0> {
814 815 816 817 818 819 820 821 822 823
 public:
  explicit LCallJSFunction(LOperand* function) {
    inputs_[0] = function;
  }

  LOperand* function() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CallJSFunction, "call-js-function")
  DECLARE_HYDROGEN_ACCESSOR(CallJSFunction)

824
  void PrintDataTo(StringStream* stream) override;
825 826 827 828 829

  int arity() const { return hydrogen()->argument_count() - 1; }
};


830
class LCallFunction final : public LTemplateInstruction<1, 2, 2> {
831
 public:
832 833
  LCallFunction(LOperand* context, LOperand* function, LOperand* slot,
                LOperand* vector) {
834 835
    inputs_[0] = context;
    inputs_[1] = function;
836 837
    temps_[0] = slot;
    temps_[1] = vector;
838 839 840 841
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* function() { return inputs_[1]; }
842 843
  LOperand* temp_slot() { return temps_[0]; }
  LOperand* temp_vector() { return temps_[1]; }
844 845 846 847 848

  DECLARE_CONCRETE_INSTRUCTION(CallFunction, "call-function")
  DECLARE_HYDROGEN_ACCESSOR(CallFunction)

  int arity() const { return hydrogen()->argument_count() - 1; }
849
  void PrintDataTo(StringStream* stream) override;
850 851 852
};


853
class LCallNew final : public LTemplateInstruction<1, 2, 0> {
854 855 856 857 858 859 860 861 862 863 864 865
 public:
  LCallNew(LOperand* context, LOperand* constructor) {
    inputs_[0] = context;
    inputs_[1] = constructor;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* constructor() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(CallNew, "call-new")
  DECLARE_HYDROGEN_ACCESSOR(CallNew)

866
  void PrintDataTo(StringStream* stream) override;
867 868 869 870 871

  int arity() const { return hydrogen()->argument_count() - 1; }
};


872
class LCallNewArray final : public LTemplateInstruction<1, 2, 0> {
873 874 875 876 877 878 879 880 881 882 883 884
 public:
  LCallNewArray(LOperand* context, LOperand* constructor) {
    inputs_[0] = context;
    inputs_[1] = constructor;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* constructor() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(CallNewArray, "call-new-array")
  DECLARE_HYDROGEN_ACCESSOR(CallNewArray)

885
  void PrintDataTo(StringStream* stream) override;
886 887 888 889 890

  int arity() const { return hydrogen()->argument_count() - 1; }
};


891
class LCallRuntime final : public LTemplateInstruction<1, 1, 0> {
892 893 894 895 896 897 898 899 900 901
 public:
  explicit LCallRuntime(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CallRuntime, "call-runtime")
  DECLARE_HYDROGEN_ACCESSOR(CallRuntime)

902
  bool ClobbersDoubleRegisters(Isolate* isolate) const override {
903 904 905 906 907 908 909 910 911
    return save_doubles() == kDontSaveFPRegs;
  }

  const Runtime::Function* function() const { return hydrogen()->function(); }
  int arity() const { return hydrogen()->argument_count(); }
  SaveFPRegsMode save_doubles() const { return hydrogen()->save_doubles(); }
};


912
class LCallStub final : public LTemplateInstruction<1, 1, 0> {
913 914 915 916 917 918 919 920 921 922 923 924
 public:
  explicit LCallStub(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CallStub, "call-stub")
  DECLARE_HYDROGEN_ACCESSOR(CallStub)
};


925 926 927 928 929 930 931 932 933 934 935 936 937
class LCheckArrayBufferNotNeutered final
    : public LTemplateInstruction<0, 1, 0> {
 public:
  explicit LCheckArrayBufferNotNeutered(LOperand* view) { inputs_[0] = view; }

  LOperand* view() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CheckArrayBufferNotNeutered,
                               "check-array-buffer-not-neutered")
  DECLARE_HYDROGEN_ACCESSOR(CheckArrayBufferNotNeutered)
};


938
class LCheckInstanceType final : public LTemplateInstruction<0, 1, 1> {
939 940 941 942 943 944 945 946 947 948 949 950 951 952
 public:
  explicit LCheckInstanceType(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CheckInstanceType, "check-instance-type")
  DECLARE_HYDROGEN_ACCESSOR(CheckInstanceType)
};


953
class LCheckMaps final : public LTemplateInstruction<0, 1, 1> {
954
 public:
955
  explicit LCheckMaps(LOperand* value = NULL, LOperand* temp = NULL) {
956 957 958 959 960 961 962 963 964 965 966 967
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CheckMaps, "check-maps")
  DECLARE_HYDROGEN_ACCESSOR(CheckMaps)
};


968
class LCheckNonSmi final : public LTemplateInstruction<0, 1, 0> {
969 970 971 972 973 974 975 976 977 978 979 980
 public:
  explicit LCheckNonSmi(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CheckNonSmi, "check-non-smi")
  DECLARE_HYDROGEN_ACCESSOR(CheckHeapObject)
};


981
class LCheckSmi final : public LTemplateInstruction<1, 1, 0> {
982 983 984 985 986 987 988 989 990 991 992
 public:
  explicit LCheckSmi(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CheckSmi, "check-smi")
};


993
class LCheckValue final : public LTemplateInstruction<0, 1, 0> {
994
 public:
995
  explicit LCheckValue(LOperand* value) {
996 997 998 999 1000 1001 1002 1003 1004 1005
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CheckValue, "check-value")
  DECLARE_HYDROGEN_ACCESSOR(CheckValue)
};


1006
class LClampDToUint8 final : public LTemplateInstruction<1, 1, 0> {
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
 public:
  explicit LClampDToUint8(LOperand* unclamped) {
    inputs_[0] = unclamped;
  }

  LOperand* unclamped() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ClampDToUint8, "clamp-d-to-uint8")
};


1018
class LClampIToUint8 final : public LTemplateInstruction<1, 1, 0> {
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
 public:
  explicit LClampIToUint8(LOperand* unclamped) {
    inputs_[0] = unclamped;
  }

  LOperand* unclamped() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ClampIToUint8, "clamp-i-to-uint8")
};


1030
class LClampTToUint8 final : public LTemplateInstruction<1, 1, 1> {
1031
 public:
1032
  LClampTToUint8(LOperand* unclamped, LOperand* temp1) {
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
    inputs_[0] = unclamped;
    temps_[0] = temp1;
  }

  LOperand* unclamped() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ClampTToUint8, "clamp-t-to-uint8")
};


1044
class LDoubleBits final : public LTemplateInstruction<1, 1, 0> {
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
 public:
  explicit LDoubleBits(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(DoubleBits, "double-bits")
  DECLARE_HYDROGEN_ACCESSOR(DoubleBits)
};


1057
class LConstructDouble final : public LTemplateInstruction<1, 2, 0> {
1058
 public:
1059
  LConstructDouble(LOperand* hi, LOperand* lo) {
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
    inputs_[0] = hi;
    inputs_[1] = lo;
  }

  LOperand* hi() { return inputs_[0]; }
  LOperand* lo() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(ConstructDouble, "construct-double")
};


1071
class LClassOfTestAndBranch final : public LControlInstruction<1, 2> {
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
 public:
  LClassOfTestAndBranch(LOperand* value, LOperand* temp1, LOperand* temp2) {
    inputs_[0] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(ClassOfTestAndBranch,
                               "class-of-test-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(ClassOfTestAndBranch)

1087
  void PrintDataTo(StringStream* stream) override;
1088 1089 1090
};


1091
class LCmpHoleAndBranchD final : public LControlInstruction<1, 1> {
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
 public:
  explicit LCmpHoleAndBranchD(LOperand* object, LOperand* temp) {
    inputs_[0] = object;
    temps_[0] = temp;
  }

  LOperand* object() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CmpHoleAndBranchD, "cmp-hole-and-branch-d")
  DECLARE_HYDROGEN_ACCESSOR(CompareHoleAndBranch)
};


1106
class LCmpHoleAndBranchT final : public LControlInstruction<1, 0> {
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
 public:
  explicit LCmpHoleAndBranchT(LOperand* object) {
    inputs_[0] = object;
  }

  LOperand* object() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CmpHoleAndBranchT, "cmp-hole-and-branch-t")
  DECLARE_HYDROGEN_ACCESSOR(CompareHoleAndBranch)
};


1119
class LCmpMapAndBranch final : public LControlInstruction<1, 1> {
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
 public:
  LCmpMapAndBranch(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(CompareMap)

  Handle<Map> map() const { return hydrogen()->map().handle(); }
};


1136
class LCmpObjectEqAndBranch final : public LControlInstruction<2, 0> {
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
 public:
  LCmpObjectEqAndBranch(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(CmpObjectEqAndBranch, "cmp-object-eq-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(CompareObjectEqAndBranch)
};


1151
class LCmpT final : public LTemplateInstruction<1, 3, 0> {
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
 public:
  LCmpT(LOperand* context, LOperand* left, LOperand* right) {
    inputs_[0] = context;
    inputs_[1] = left;
    inputs_[2] = right;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* left() { return inputs_[1]; }
  LOperand* right() { return inputs_[2]; }

  DECLARE_CONCRETE_INSTRUCTION(CmpT, "cmp-t")
  DECLARE_HYDROGEN_ACCESSOR(CompareGeneric)

1166
  Strength strength() { return hydrogen()->strength(); }
1167

1168 1169 1170 1171
  Token::Value op() const { return hydrogen()->token(); }
};


1172
class LCompareMinusZeroAndBranch final : public LControlInstruction<1, 1> {
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
 public:
  LCompareMinusZeroAndBranch(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CompareMinusZeroAndBranch,
                               "cmp-minus-zero-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(CompareMinusZeroAndBranch)
};


1188
class LCompareNumericAndBranch final : public LControlInstruction<2, 0> {
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
 public:
  LCompareNumericAndBranch(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch,
                               "compare-numeric-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(CompareNumericAndBranch)

  Token::Value op() const { return hydrogen()->token(); }
  bool is_double() const {
    return hydrogen()->representation().IsDouble();
  }

1207
  void PrintDataTo(StringStream* stream) override;
1208 1209 1210
};


1211
class LConstantD final : public LTemplateInstruction<1, 0, 0> {
1212 1213 1214 1215 1216 1217 1218 1219
 public:
  DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
  DECLARE_HYDROGEN_ACCESSOR(Constant)

  double value() const { return hydrogen()->DoubleValue(); }
};


1220
class LConstantE final : public LTemplateInstruction<1, 0, 0> {
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
 public:
  DECLARE_CONCRETE_INSTRUCTION(ConstantE, "constant-e")
  DECLARE_HYDROGEN_ACCESSOR(Constant)

  ExternalReference value() const {
    return hydrogen()->ExternalReferenceValue();
  }
};


1231
class LConstantI final : public LTemplateInstruction<1, 0, 0> {
1232 1233 1234 1235 1236 1237 1238 1239
 public:
  DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
  DECLARE_HYDROGEN_ACCESSOR(Constant)

  int32_t value() const { return hydrogen()->Integer32Value(); }
};


1240
class LConstantS final : public LTemplateInstruction<1, 0, 0> {
1241 1242 1243 1244 1245 1246 1247 1248
 public:
  DECLARE_CONCRETE_INSTRUCTION(ConstantS, "constant-s")
  DECLARE_HYDROGEN_ACCESSOR(Constant)

  Smi* value() const { return Smi::FromInt(hydrogen()->Integer32Value()); }
};


1249
class LConstantT final : public LTemplateInstruction<1, 0, 0> {
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
 public:
  DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
  DECLARE_HYDROGEN_ACCESSOR(Constant)

  Handle<Object> value(Isolate* isolate) const {
    return hydrogen()->handle(isolate);
  }
};


1260
class LContext final : public LTemplateInstruction<1, 0, 0> {
1261 1262 1263 1264 1265 1266
 public:
  DECLARE_CONCRETE_INSTRUCTION(Context, "context")
  DECLARE_HYDROGEN_ACCESSOR(Context)
};


1267
class LDateField final : public LTemplateInstruction<1, 1, 0> {
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
 public:
  LDateField(LOperand* date, Smi* index) : index_(index) {
    inputs_[0] = date;
  }

  LOperand* date() { return inputs_[0]; }
  Smi* index() const { return index_; }

  DECLARE_CONCRETE_INSTRUCTION(DateField, "date-field")
  DECLARE_HYDROGEN_ACCESSOR(DateField)

 private:
  Smi* index_;
};


1284
class LDebugBreak final : public LTemplateInstruction<0, 0, 0> {
1285 1286 1287 1288 1289
 public:
  DECLARE_CONCRETE_INSTRUCTION(DebugBreak, "break")
};


1290
class LDeclareGlobals final : public LTemplateInstruction<0, 1, 0> {
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
 public:
  explicit LDeclareGlobals(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(DeclareGlobals, "declare-globals")
  DECLARE_HYDROGEN_ACCESSOR(DeclareGlobals)
};


1303
class LDeoptimize final : public LTemplateInstruction<0, 0, 0> {
1304
 public:
1305
  bool IsControl() const override { return true; }
1306 1307 1308 1309 1310
  DECLARE_CONCRETE_INSTRUCTION(Deoptimize, "deoptimize")
  DECLARE_HYDROGEN_ACCESSOR(Deoptimize)
};


1311
class LDivByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
 public:
  LDivByPowerOf2I(LOperand* dividend, int32_t divisor) {
    inputs_[0] = dividend;
    divisor_ = divisor;
  }

  LOperand* dividend() { return inputs_[0]; }
  int32_t divisor() const { return divisor_; }

  DECLARE_CONCRETE_INSTRUCTION(DivByPowerOf2I, "div-by-power-of-2-i")
  DECLARE_HYDROGEN_ACCESSOR(Div)

 private:
  int32_t divisor_;
};


1329
class LDivByConstI final : public LTemplateInstruction<1, 1, 1> {
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
 public:
  LDivByConstI(LOperand* dividend, int32_t divisor, LOperand* temp) {
    inputs_[0] = dividend;
    divisor_ = divisor;
    temps_[0] = temp;
  }

  LOperand* dividend() { return inputs_[0]; }
  int32_t divisor() const { return divisor_; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(DivByConstI, "div-by-const-i")
  DECLARE_HYDROGEN_ACCESSOR(Div)

 private:
  int32_t divisor_;
};


1349
class LDivI final : public LTemplateInstruction<1, 2, 1> {
1350
 public:
1351 1352 1353
  LDivI(LOperand* dividend, LOperand* divisor, LOperand* temp) {
    inputs_[0] = dividend;
    inputs_[1] = divisor;
1354 1355 1356
    temps_[0] = temp;
  }

1357 1358
  LOperand* dividend() { return inputs_[0]; }
  LOperand* divisor() { return inputs_[1]; }
1359 1360 1361
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(DivI, "div-i")
1362
  DECLARE_HYDROGEN_ACCESSOR(BinaryOperation)
1363 1364 1365
};


1366
class LDoubleToIntOrSmi final : public LTemplateInstruction<1, 1, 0> {
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
 public:
  explicit LDoubleToIntOrSmi(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(DoubleToIntOrSmi, "double-to-int-or-smi")
  DECLARE_HYDROGEN_ACCESSOR(UnaryOperation)

  bool tag_result() { return hydrogen()->representation().IsSmi(); }
};


1381
class LForInCacheArray final : public LTemplateInstruction<1, 1, 0> {
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
 public:
  explicit LForInCacheArray(LOperand* map) {
    inputs_[0] = map;
  }

  LOperand* map() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ForInCacheArray, "for-in-cache-array")

  int idx() {
    return HForInCacheArray::cast(this->hydrogen_value())->idx();
  }
};


1397
class LForInPrepareMap final : public LTemplateInstruction<1, 2, 0> {
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410
 public:
  LForInPrepareMap(LOperand* context, LOperand* object) {
    inputs_[0] = context;
    inputs_[1] = object;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* object() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(ForInPrepareMap, "for-in-prepare-map")
};


1411
class LGetCachedArrayIndex final : public LTemplateInstruction<1, 1, 0> {
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
 public:
  explicit LGetCachedArrayIndex(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(GetCachedArrayIndex, "get-cached-array-index")
  DECLARE_HYDROGEN_ACCESSOR(GetCachedArrayIndex)
};


1424
class LHasCachedArrayIndexAndBranch final : public LControlInstruction<1, 1> {
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
 public:
  LHasCachedArrayIndexAndBranch(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(HasCachedArrayIndexAndBranch,
                               "has-cached-array-index-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(HasCachedArrayIndexAndBranch)

1438
  void PrintDataTo(StringStream* stream) override;
1439 1440 1441
};


1442
class LHasInstanceTypeAndBranch final : public LControlInstruction<1, 1> {
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
 public:
  LHasInstanceTypeAndBranch(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(HasInstanceTypeAndBranch,
                               "has-instance-type-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(HasInstanceTypeAndBranch)

1456
  void PrintDataTo(StringStream* stream) override;
1457 1458 1459
};


1460
class LInnerAllocatedObject final : public LTemplateInstruction<1, 2, 0> {
1461 1462 1463 1464 1465 1466 1467 1468 1469
 public:
  LInnerAllocatedObject(LOperand* base_object, LOperand* offset) {
    inputs_[0] = base_object;
    inputs_[1] = offset;
  }

  LOperand* base_object() const { return inputs_[0]; }
  LOperand* offset() const { return inputs_[1]; }

1470
  void PrintDataTo(StringStream* stream) override;
1471 1472 1473 1474 1475

  DECLARE_CONCRETE_INSTRUCTION(InnerAllocatedObject, "inner-allocated-object")
};


1476
class LInstanceOf final : public LTemplateInstruction<1, 3, 0> {
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
 public:
  LInstanceOf(LOperand* context, LOperand* left, LOperand* right) {
    inputs_[0] = context;
    inputs_[1] = left;
    inputs_[2] = right;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* left() { return inputs_[1]; }
  LOperand* right() { return inputs_[2]; }

  DECLARE_CONCRETE_INSTRUCTION(InstanceOf, "instance-of")
};


1492
class LInstanceOfKnownGlobal final : public LTemplateInstruction<1, 2, 0> {
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
 public:
  LInstanceOfKnownGlobal(LOperand* context, LOperand* value) {
    inputs_[0] = context;
    inputs_[1] = value;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* value() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(InstanceOfKnownGlobal,
                               "instance-of-known-global")
  DECLARE_HYDROGEN_ACCESSOR(InstanceOfKnownGlobal)

  Handle<JSFunction> function() const { return hydrogen()->function(); }
  LEnvironment* GetDeferredLazyDeoptimizationEnvironment() {
    return lazy_deopt_env_;
  }
  virtual void SetDeferredLazyDeoptimizationEnvironment(
1511
      LEnvironment* env) override {
1512 1513 1514 1515 1516 1517 1518 1519
    lazy_deopt_env_ = env;
  }

 private:
  LEnvironment* lazy_deopt_env_;
};


1520
class LInteger32ToDouble final : public LTemplateInstruction<1, 1, 0> {
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
 public:
  explicit LInteger32ToDouble(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(Integer32ToDouble, "int32-to-double")
};


1532
class LCallWithDescriptor final : public LTemplateResultInstruction<1> {
1533
 public:
1534
  LCallWithDescriptor(CallInterfaceDescriptor descriptor,
1535 1536
                      const ZoneList<LOperand*>& operands, Zone* zone)
      : descriptor_(descriptor),
1537 1538 1539 1540 1541 1542
        inputs_(descriptor.GetRegisterParameterCount() +
                    kImplicitRegisterParameterCount,
                zone) {
    DCHECK(descriptor.GetRegisterParameterCount() +
               kImplicitRegisterParameterCount ==
           operands.length());
1543 1544 1545 1546 1547
    inputs_.AddAll(operands, zone);
  }

  LOperand* target() const { return inputs_[0]; }

1548
  CallInterfaceDescriptor descriptor() { return descriptor_; }
1549

1550 1551
  DECLARE_HYDROGEN_ACCESSOR(CallWithDescriptor)

1552 1553 1554 1555
  // The target and context are passed as implicit parameters that are not
  // explicitly listed in the descriptor.
  static const int kImplicitRegisterParameterCount = 2;

1556 1557 1558
 private:
  DECLARE_CONCRETE_INSTRUCTION(CallWithDescriptor, "call-with-descriptor")

1559
  void PrintDataTo(StringStream* stream) override;
1560 1561 1562

  int arity() const { return hydrogen()->argument_count() - 1; }

1563
  CallInterfaceDescriptor descriptor_;
1564 1565 1566
  ZoneList<LOperand*> inputs_;

  // Iterator support.
1567 1568
  int InputCount() final { return inputs_.length(); }
  LOperand* InputAt(int i) final { return inputs_[i]; }
1569

1570 1571
  int TempCount() final { return 0; }
  LOperand* TempAt(int i) final { return NULL; }
1572 1573 1574
};


1575
class LInvokeFunction final : public LTemplateInstruction<1, 2, 0> {
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
 public:
  LInvokeFunction(LOperand* context, LOperand* function) {
    inputs_[0] = context;
    inputs_[1] = function;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* function() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(InvokeFunction, "invoke-function")
  DECLARE_HYDROGEN_ACCESSOR(InvokeFunction)

1588
  void PrintDataTo(StringStream* stream) override;
1589 1590 1591 1592 1593

  int arity() const { return hydrogen()->argument_count() - 1; }
};


1594
class LIsConstructCallAndBranch final : public LControlInstruction<0, 2> {
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
 public:
  LIsConstructCallAndBranch(LOperand* temp1, LOperand* temp2) {
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(IsConstructCallAndBranch,
                               "is-construct-call-and-branch")
};


1609
class LIsObjectAndBranch final : public LControlInstruction<1, 2> {
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623
 public:
  LIsObjectAndBranch(LOperand* value, LOperand* temp1, LOperand* temp2) {
    inputs_[0] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(IsObjectAndBranch, "is-object-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(IsObjectAndBranch)

1624
  void PrintDataTo(StringStream* stream) override;
1625 1626 1627
};


1628
class LIsStringAndBranch final : public LControlInstruction<1, 1> {
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
 public:
  LIsStringAndBranch(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(IsStringAndBranch, "is-string-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(IsStringAndBranch)

1641
  void PrintDataTo(StringStream* stream) override;
1642 1643 1644
};


1645
class LIsSmiAndBranch final : public LControlInstruction<1, 0> {
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
 public:
  explicit LIsSmiAndBranch(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(IsSmiAndBranch, "is-smi-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(IsSmiAndBranch)

1656
  void PrintDataTo(StringStream* stream) override;
1657 1658 1659
};


1660
class LIsUndetectableAndBranch final : public LControlInstruction<1, 1> {
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
 public:
  explicit LIsUndetectableAndBranch(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(IsUndetectableAndBranch,
                               "is-undetectable-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(IsUndetectableAndBranch)

1674
  void PrintDataTo(StringStream* stream) override;
1675 1676 1677
};


1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
class LLoadGlobalViaContext final : public LTemplateInstruction<1, 1, 1> {
 public:
  explicit LLoadGlobalViaContext(LOperand* context) { inputs_[0] = context; }

  DECLARE_CONCRETE_INSTRUCTION(LoadGlobalViaContext, "load-global-via-context")
  DECLARE_HYDROGEN_ACCESSOR(LoadGlobalViaContext)

  void PrintDataTo(StringStream* stream) override;

  LOperand* context() { return inputs_[0]; }

  int depth() const { return hydrogen()->depth(); }
  int slot_index() const { return hydrogen()->slot_index(); }
};


1694
class LLoadContextSlot final : public LTemplateInstruction<1, 1, 0> {
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706
 public:
  explicit LLoadContextSlot(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(LoadContextSlot, "load-context-slot")
  DECLARE_HYDROGEN_ACCESSOR(LoadContextSlot)

  int slot_index() const { return hydrogen()->slot_index(); }

1707
  void PrintDataTo(StringStream* stream) override;
1708 1709 1710
};


1711
class LLoadNamedField final : public LTemplateInstruction<1, 1, 0> {
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
 public:
  explicit LLoadNamedField(LOperand* object) {
    inputs_[0] = object;
  }

  LOperand* object() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(LoadNamedField, "load-named-field")
  DECLARE_HYDROGEN_ACCESSOR(LoadNamedField)
};


1724
class LFunctionLiteral final : public LTemplateInstruction<1, 1, 0> {
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736
 public:
  explicit LFunctionLiteral(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(FunctionLiteral, "function-literal")
  DECLARE_HYDROGEN_ACCESSOR(FunctionLiteral)
};


1737
class LLoadFunctionPrototype final : public LTemplateInstruction<1, 1, 1> {
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
 public:
  LLoadFunctionPrototype(LOperand* function, LOperand* temp) {
    inputs_[0] = function;
    temps_[0] = temp;
  }

  LOperand* function() { return inputs_[0]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(LoadFunctionPrototype, "load-function-prototype")
  DECLARE_HYDROGEN_ACCESSOR(LoadFunctionPrototype)
};


1752
class LLoadGlobalGeneric final : public LTemplateInstruction<1, 2, 1> {
1753
 public:
1754 1755
  LLoadGlobalGeneric(LOperand* context, LOperand* global_object,
                     LOperand* vector) {
1756 1757
    inputs_[0] = context;
    inputs_[1] = global_object;
1758
    temps_[0] = vector;
1759 1760 1761 1762
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* global_object() { return inputs_[1]; }
1763
  LOperand* temp_vector() { return temps_[0]; }
1764 1765 1766 1767 1768

  DECLARE_CONCRETE_INSTRUCTION(LoadGlobalGeneric, "load-global-generic")
  DECLARE_HYDROGEN_ACCESSOR(LoadGlobalGeneric)

  Handle<Object> name() const { return hydrogen()->name(); }
1769
  TypeofMode typeof_mode() const { return hydrogen()->typeof_mode(); }
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
};


template<int T>
class LLoadKeyed : public LTemplateInstruction<1, 2, T> {
 public:
  LLoadKeyed(LOperand* elements, LOperand* key) {
    this->inputs_[0] = elements;
    this->inputs_[1] = key;
  }

  LOperand* elements() { return this->inputs_[0]; }
  LOperand* key() { return this->inputs_[1]; }
  ElementsKind elements_kind() const {
    return this->hydrogen()->elements_kind();
  }
  bool is_external() const {
    return this->hydrogen()->is_external();
  }
  bool is_fixed_typed_array() const {
    return hydrogen()->is_fixed_typed_array();
  }
  bool is_typed_elements() const {
    return is_external() || is_fixed_typed_array();
  }
1795 1796
  uint32_t base_offset() const {
    return this->hydrogen()->base_offset();
1797
  }
1798
  void PrintDataTo(StringStream* stream) override {
1799 1800 1801
    this->elements()->PrintTo(stream);
    stream->Add("[");
    this->key()->PrintTo(stream);
1802 1803
    if (this->base_offset() != 0) {
      stream->Add(" + %d]", this->base_offset());
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
    } else {
      stream->Add("]");
    }
  }

  DECLARE_HYDROGEN_ACCESSOR(LoadKeyed)
};


class LLoadKeyedExternal: public LLoadKeyed<1> {
 public:
  LLoadKeyedExternal(LOperand* elements, LOperand* key, LOperand* temp) :
      LLoadKeyed<1>(elements, key) {
    temps_[0] = temp;
  }

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(LoadKeyedExternal, "load-keyed-external");
};


class LLoadKeyedFixed: public LLoadKeyed<1> {
 public:
  LLoadKeyedFixed(LOperand* elements, LOperand* key, LOperand* temp) :
      LLoadKeyed<1>(elements, key) {
    temps_[0] = temp;
  }

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(LoadKeyedFixed, "load-keyed-fixed");
};


class LLoadKeyedFixedDouble: public LLoadKeyed<1> {
 public:
  LLoadKeyedFixedDouble(LOperand* elements, LOperand* key, LOperand* temp) :
      LLoadKeyed<1>(elements, key) {
    temps_[0] = temp;
  }

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(LoadKeyedFixedDouble, "load-keyed-fixed-double");
};


1852
class LLoadKeyedGeneric final : public LTemplateInstruction<1, 3, 1> {
1853
 public:
1854 1855
  LLoadKeyedGeneric(LOperand* context, LOperand* object, LOperand* key,
                    LOperand* vector) {
1856 1857 1858
    inputs_[0] = context;
    inputs_[1] = object;
    inputs_[2] = key;
1859
    temps_[0] = vector;
1860 1861 1862 1863 1864
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* object() { return inputs_[1]; }
  LOperand* key() { return inputs_[2]; }
1865
  LOperand* temp_vector() { return temps_[0]; }
1866 1867

  DECLARE_CONCRETE_INSTRUCTION(LoadKeyedGeneric, "load-keyed-generic")
1868
  DECLARE_HYDROGEN_ACCESSOR(LoadKeyedGeneric)
1869 1870 1871
};


1872
class LLoadNamedGeneric final : public LTemplateInstruction<1, 2, 1> {
1873
 public:
1874
  LLoadNamedGeneric(LOperand* context, LOperand* object, LOperand* vector) {
1875 1876
    inputs_[0] = context;
    inputs_[1] = object;
1877
    temps_[0] = vector;
1878 1879 1880 1881
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* object() { return inputs_[1]; }
1882
  LOperand* temp_vector() { return temps_[0]; }
1883 1884 1885 1886 1887 1888 1889 1890

  DECLARE_CONCRETE_INSTRUCTION(LoadNamedGeneric, "load-named-generic")
  DECLARE_HYDROGEN_ACCESSOR(LoadNamedGeneric)

  Handle<Object> name() const { return hydrogen()->name(); }
};


1891
class LLoadRoot final : public LTemplateInstruction<1, 0, 0> {
1892 1893 1894 1895 1896 1897 1898 1899
 public:
  DECLARE_CONCRETE_INSTRUCTION(LoadRoot, "load-root")
  DECLARE_HYDROGEN_ACCESSOR(LoadRoot)

  Heap::RootListIndex index() const { return hydrogen()->index(); }
};


1900
class LMapEnumLength final : public LTemplateInstruction<1, 1, 0> {
1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
 public:
  explicit LMapEnumLength(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(MapEnumLength, "map-enum-length")
};


template<int T>
class LUnaryMathOperation : public LTemplateInstruction<1, 1, T> {
 public:
  explicit LUnaryMathOperation(LOperand* value) {
    this->inputs_[0] = value;
  }

  LOperand* value() { return this->inputs_[0]; }
  BuiltinFunctionId op() const { return this->hydrogen()->op(); }

1922
  void PrintDataTo(StringStream* stream) override;
1923 1924 1925 1926 1927

  DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};


1928
class LMathAbs final : public LUnaryMathOperation<0> {
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957
 public:
  explicit LMathAbs(LOperand* value) : LUnaryMathOperation<0>(value) {}

  DECLARE_CONCRETE_INSTRUCTION(MathAbs, "math-abs")
};


class LMathAbsTagged: public LTemplateInstruction<1, 2, 3> {
 public:
  LMathAbsTagged(LOperand* context, LOperand* value,
                 LOperand* temp1, LOperand* temp2, LOperand* temp3) {
    inputs_[0] = context;
    inputs_[1] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
    temps_[2] = temp3;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* value() { return inputs_[1]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }
  LOperand* temp3() { return temps_[2]; }

  DECLARE_CONCRETE_INSTRUCTION(MathAbsTagged, "math-abs-tagged")
  DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};


1958
class LMathExp final : public LUnaryMathOperation<4> {
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981
 public:
  LMathExp(LOperand* value,
                LOperand* double_temp1,
                LOperand* temp1,
                LOperand* temp2,
                LOperand* temp3)
      : LUnaryMathOperation<4>(value) {
    temps_[0] = double_temp1;
    temps_[1] = temp1;
    temps_[2] = temp2;
    temps_[3] = temp3;
    ExternalReference::InitializeMathExpData();
  }

  LOperand* double_temp1() { return temps_[0]; }
  LOperand* temp1() { return temps_[1]; }
  LOperand* temp2() { return temps_[2]; }
  LOperand* temp3() { return temps_[3]; }

  DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
};


1982
// Math.floor with a double result.
1983
class LMathFloorD final : public LUnaryMathOperation<0> {
1984
 public:
1985 1986 1987 1988 1989 1990
  explicit LMathFloorD(LOperand* value) : LUnaryMathOperation<0>(value) { }
  DECLARE_CONCRETE_INSTRUCTION(MathFloorD, "math-floor-d")
};


// Math.floor with an integer result.
1991
class LMathFloorI final : public LUnaryMathOperation<0> {
1992 1993 1994
 public:
  explicit LMathFloorI(LOperand* value) : LUnaryMathOperation<0>(value) { }
  DECLARE_CONCRETE_INSTRUCTION(MathFloorI, "math-floor-i")
1995 1996 1997
};


1998
class LFlooringDivByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
1999
 public:
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
  LFlooringDivByPowerOf2I(LOperand* dividend, int32_t divisor) {
    inputs_[0] = dividend;
    divisor_ = divisor;
  }

  LOperand* dividend() { return inputs_[0]; }
  int32_t divisor() const { return divisor_; }

  DECLARE_CONCRETE_INSTRUCTION(FlooringDivByPowerOf2I,
                               "flooring-div-by-power-of-2-i")
  DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)

 private:
  int32_t divisor_;
};


2017
class LFlooringDivByConstI final : public LTemplateInstruction<1, 1, 2> {
2018
 public:
2019
  LFlooringDivByConstI(LOperand* dividend, int32_t divisor, LOperand* temp) {
2020 2021
    inputs_[0] = dividend;
    divisor_ = divisor;
2022
    temps_[0] = temp;
2023 2024 2025 2026
  }

  LOperand* dividend() { return inputs_[0]; }
  int32_t divisor() const { return divisor_; }
2027
  LOperand* temp() { return temps_[0]; }
2028 2029 2030 2031 2032 2033 2034 2035 2036

  DECLARE_CONCRETE_INSTRUCTION(FlooringDivByConstI, "flooring-div-by-const-i")
  DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)

 private:
  int32_t divisor_;
};


2037
class LFlooringDivI final : public LTemplateInstruction<1, 2, 1> {
2038 2039 2040 2041
 public:
  LFlooringDivI(LOperand* dividend, LOperand* divisor, LOperand* temp) {
    inputs_[0] = dividend;
    inputs_[1] = divisor;
2042 2043 2044
    temps_[0] = temp;
  }

2045 2046
  LOperand* dividend() { return inputs_[0]; }
  LOperand* divisor() { return inputs_[1]; }
2047 2048
  LOperand* temp() { return temps_[0]; }

2049
  DECLARE_CONCRETE_INSTRUCTION(FlooringDivI, "flooring-div-i")
2050 2051 2052 2053
  DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
};


2054
class LMathLog final : public LUnaryMathOperation<0> {
2055 2056 2057 2058 2059 2060
 public:
  explicit LMathLog(LOperand* value) : LUnaryMathOperation<0>(value) { }
  DECLARE_CONCRETE_INSTRUCTION(MathLog, "math-log")
};


2061
class LMathClz32 final : public LUnaryMathOperation<0> {
2062 2063 2064 2065 2066 2067
 public:
  explicit LMathClz32(LOperand* value) : LUnaryMathOperation<0>(value) { }
  DECLARE_CONCRETE_INSTRUCTION(MathClz32, "math-clz32")
};


2068
class LMathMinMax final : public LTemplateInstruction<1, 2, 0> {
2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082
 public:
  LMathMinMax(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "math-min-max")
  DECLARE_HYDROGEN_ACCESSOR(MathMinMax)
};


2083
class LMathPowHalf final : public LUnaryMathOperation<0> {
2084 2085 2086 2087 2088 2089
 public:
  explicit LMathPowHalf(LOperand* value) : LUnaryMathOperation<0>(value) { }
  DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half")
};


2090
// Math.round with an integer result.
2091
class LMathRoundD final : public LUnaryMathOperation<0> {
2092 2093 2094 2095 2096 2097 2098 2099 2100 2101
 public:
  explicit LMathRoundD(LOperand* value)
      : LUnaryMathOperation<0>(value) {
  }

  DECLARE_CONCRETE_INSTRUCTION(MathRoundD, "math-round-d")
};


// Math.round with an integer result.
2102
class LMathRoundI final : public LUnaryMathOperation<1> {
2103
 public:
2104
  LMathRoundI(LOperand* value, LOperand* temp1)
2105 2106 2107 2108 2109 2110
      : LUnaryMathOperation<1>(value) {
    temps_[0] = temp1;
  }

  LOperand* temp1() { return temps_[0]; }

2111
  DECLARE_CONCRETE_INSTRUCTION(MathRoundI, "math-round-i")
2112 2113 2114
};


2115
class LMathFround final : public LUnaryMathOperation<0> {
2116 2117 2118 2119 2120 2121 2122
 public:
  explicit LMathFround(LOperand* value) : LUnaryMathOperation<0>(value) {}

  DECLARE_CONCRETE_INSTRUCTION(MathFround, "math-fround")
};


2123
class LMathSqrt final : public LUnaryMathOperation<0> {
2124 2125 2126 2127 2128 2129
 public:
  explicit LMathSqrt(LOperand* value) : LUnaryMathOperation<0>(value) { }
  DECLARE_CONCRETE_INSTRUCTION(MathSqrt, "math-sqrt")
};


2130
class LModByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147
 public:
  LModByPowerOf2I(LOperand* dividend, int32_t divisor) {
    inputs_[0] = dividend;
    divisor_ = divisor;
  }

  LOperand* dividend() { return inputs_[0]; }
  int32_t divisor() const { return divisor_; }

  DECLARE_CONCRETE_INSTRUCTION(ModByPowerOf2I, "mod-by-power-of-2-i")
  DECLARE_HYDROGEN_ACCESSOR(Mod)

 private:
  int32_t divisor_;
};


2148
class LModByConstI final : public LTemplateInstruction<1, 1, 1> {
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
 public:
  LModByConstI(LOperand* dividend, int32_t divisor, LOperand* temp) {
    inputs_[0] = dividend;
    divisor_ = divisor;
    temps_[0] = temp;
  }

  LOperand* dividend() { return inputs_[0]; }
  int32_t divisor() const { return divisor_; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ModByConstI, "mod-by-const-i")
  DECLARE_HYDROGEN_ACCESSOR(Mod)

 private:
  int32_t divisor_;
};


2168
class LModI final : public LTemplateInstruction<1, 2, 0> {
2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182
 public:
  LModI(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(ModI, "mod-i")
  DECLARE_HYDROGEN_ACCESSOR(Mod)
};


2183
class LMulConstIS final : public LTemplateInstruction<1, 2, 0> {
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
 public:
  LMulConstIS(LOperand* left, LConstantOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LConstantOperand* right() { return LConstantOperand::cast(inputs_[1]); }

  DECLARE_CONCRETE_INSTRUCTION(MulConstIS, "mul-const-i-s")
  DECLARE_HYDROGEN_ACCESSOR(Mul)
};


2198
class LMulI final : public LTemplateInstruction<1, 2, 0> {
2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212
 public:
  LMulI(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(MulI, "mul-i")
  DECLARE_HYDROGEN_ACCESSOR(Mul)
};


2213
class LMulS final : public LTemplateInstruction<1, 2, 0> {
2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
 public:
  LMulS(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(MulI, "mul-s")
  DECLARE_HYDROGEN_ACCESSOR(Mul)
};


2228
class LNumberTagD final : public LTemplateInstruction<1, 1, 2> {
2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244
 public:
  LNumberTagD(LOperand* value, LOperand* temp1, LOperand* temp2) {
    inputs_[0] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(NumberTagD, "number-tag-d")
  DECLARE_HYDROGEN_ACCESSOR(Change)
};


2245
class LNumberTagU final : public LTemplateInstruction<1, 1, 2> {
2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
 public:
  explicit LNumberTagU(LOperand* value,
                       LOperand* temp1,
                       LOperand* temp2) {
    inputs_[0] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(NumberTagU, "number-tag-u")
};


2263
class LNumberUntagD final : public LTemplateInstruction<1, 1, 1> {
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278
 public:
  LNumberUntagD(LOperand* value, LOperand* temp) {
    inputs_[0] = value;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(NumberUntagD, "double-untag")
  DECLARE_HYDROGEN_ACCESSOR(Change)
};


2279
class LParameter final : public LTemplateInstruction<1, 0, 0> {
2280
 public:
2281
  bool HasInterestingComment(LCodeGen* gen) const override { return false; }
2282 2283 2284 2285
  DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter")
};


2286
class LPower final : public LTemplateInstruction<1, 2, 0> {
2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
 public:
  LPower(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(Power, "power")
  DECLARE_HYDROGEN_ACCESSOR(Power)
};


2301
class LPreparePushArguments final : public LTemplateInstruction<0, 0, 0> {
2302
 public:
2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
  explicit LPreparePushArguments(int argc) : argc_(argc) {}

  inline int argc() const { return argc_; }

  DECLARE_CONCRETE_INSTRUCTION(PreparePushArguments, "prepare-push-arguments")

 protected:
  int argc_;
};


2314
class LPushArguments final : public LTemplateResultInstruction<0> {
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331
 public:
  explicit LPushArguments(Zone* zone,
                          int capacity = kRecommendedMaxPushedArgs)
      : zone_(zone), inputs_(capacity, zone) {}

  LOperand* argument(int i) { return inputs_[i]; }
  int ArgumentCount() const { return inputs_.length(); }

  void AddArgument(LOperand* arg) { inputs_.Add(arg, zone_); }

  DECLARE_CONCRETE_INSTRUCTION(PushArguments, "push-arguments")

  // It is better to limit the number of arguments pushed simultaneously to
  // avoid pressure on the register allocator.
  static const int kRecommendedMaxPushedArgs = 4;
  bool ShouldSplitPush() const {
    return inputs_.length() >= kRecommendedMaxPushedArgs;
2332 2333
  }

2334 2335 2336
 protected:
  Zone* zone_;
  ZoneList<LOperand*> inputs_;
2337

2338 2339
 private:
  // Iterator support.
2340 2341
  int InputCount() final { return inputs_.length(); }
  LOperand* InputAt(int i) final { return inputs_[i]; }
2342

2343 2344
  int TempCount() final { return 0; }
  LOperand* TempAt(int i) final { return NULL; }
2345 2346 2347
};


2348
class LRegExpLiteral final : public LTemplateInstruction<1, 1, 0> {
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360
 public:
  explicit LRegExpLiteral(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(RegExpLiteral, "regexp-literal")
  DECLARE_HYDROGEN_ACCESSOR(RegExpLiteral)
};


2361
class LReturn final : public LTemplateInstruction<0, 3, 0> {
2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375
 public:
  LReturn(LOperand* value, LOperand* context, LOperand* parameter_count) {
    inputs_[0] = value;
    inputs_[1] = context;
    inputs_[2] = parameter_count;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* parameter_count() { return inputs_[2]; }

  bool has_constant_parameter_count() {
    return parameter_count()->IsConstantOperand();
  }
  LConstantOperand* constant_parameter_count() {
2376
    DCHECK(has_constant_parameter_count());
2377 2378 2379 2380 2381 2382 2383
    return LConstantOperand::cast(parameter_count());
  }

  DECLARE_CONCRETE_INSTRUCTION(Return, "return")
};


2384
class LSeqStringGetChar final : public LTemplateInstruction<1, 2, 1> {
2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402
 public:
  LSeqStringGetChar(LOperand* string,
                    LOperand* index,
                    LOperand* temp) {
    inputs_[0] = string;
    inputs_[1] = index;
    temps_[0] = temp;
  }

  LOperand* string() { return inputs_[0]; }
  LOperand* index() { return inputs_[1]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(SeqStringGetChar, "seq-string-get-char")
  DECLARE_HYDROGEN_ACCESSOR(SeqStringGetChar)
};


2403
class LSeqStringSetChar final : public LTemplateInstruction<1, 4, 1> {
2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427
 public:
  LSeqStringSetChar(LOperand* context,
                    LOperand* string,
                    LOperand* index,
                    LOperand* value,
                    LOperand* temp) {
    inputs_[0] = context;
    inputs_[1] = string;
    inputs_[2] = index;
    inputs_[3] = value;
    temps_[0] = temp;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* string() { return inputs_[1]; }
  LOperand* index() { return inputs_[2]; }
  LOperand* value() { return inputs_[3]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(SeqStringSetChar, "seq-string-set-char")
  DECLARE_HYDROGEN_ACCESSOR(SeqStringSetChar)
};


2428
class LSmiTag final : public LTemplateInstruction<1, 1, 0> {
2429 2430 2431 2432 2433 2434 2435 2436
 public:
  explicit LSmiTag(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(SmiTag, "smi-tag")
2437
  DECLARE_HYDROGEN_ACCESSOR(Change)
2438 2439 2440
};


2441
class LSmiUntag final : public LTemplateInstruction<1, 1, 0> {
2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457
 public:
  LSmiUntag(LOperand* value, bool needs_check)
      : needs_check_(needs_check) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }
  bool needs_check() const { return needs_check_; }

  DECLARE_CONCRETE_INSTRUCTION(SmiUntag, "smi-untag")

 private:
  bool needs_check_;
};


2458
class LStackCheck final : public LTemplateInstruction<0, 1, 0> {
2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475
 public:
  explicit LStackCheck(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(StackCheck, "stack-check")
  DECLARE_HYDROGEN_ACCESSOR(StackCheck)

  Label* done_label() { return &done_label_; }

 private:
  Label done_label_;
};


2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497
class LStoreGlobalViaContext final : public LTemplateInstruction<0, 2, 0> {
 public:
  LStoreGlobalViaContext(LOperand* context, LOperand* value) {
    inputs_[0] = context;
    inputs_[1] = value;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* value() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(StoreGlobalViaContext,
                               "store-global-via-context")
  DECLARE_HYDROGEN_ACCESSOR(StoreGlobalViaContext)

  void PrintDataTo(StringStream* stream) override;

  int depth() { return hydrogen()->depth(); }
  int slot_index() { return hydrogen()->slot_index(); }
  LanguageMode language_mode() { return hydrogen()->language_mode(); }
};


2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521
template<int T>
class LStoreKeyed : public LTemplateInstruction<0, 3, T> {
 public:
  LStoreKeyed(LOperand* elements, LOperand* key, LOperand* value) {
    this->inputs_[0] = elements;
    this->inputs_[1] = key;
    this->inputs_[2] = value;
  }

  bool is_external() const { return this->hydrogen()->is_external(); }
  bool is_fixed_typed_array() const {
    return hydrogen()->is_fixed_typed_array();
  }
  bool is_typed_elements() const {
    return is_external() || is_fixed_typed_array();
  }
  LOperand* elements() { return this->inputs_[0]; }
  LOperand* key() { return this->inputs_[1]; }
  LOperand* value() { return this->inputs_[2]; }
  ElementsKind elements_kind() const {
    return this->hydrogen()->elements_kind();
  }

  bool NeedsCanonicalization() {
2522 2523 2524 2525
    if (hydrogen()->value()->IsAdd() || hydrogen()->value()->IsSub() ||
        hydrogen()->value()->IsMul() || hydrogen()->value()->IsDiv()) {
      return false;
    }
2526 2527
    return this->hydrogen()->NeedsCanonicalization();
  }
2528
  uint32_t base_offset() const { return this->hydrogen()->base_offset(); }
2529

2530
  void PrintDataTo(StringStream* stream) override {
2531 2532 2533
    this->elements()->PrintTo(stream);
    stream->Add("[");
    this->key()->PrintTo(stream);
2534 2535
    if (this->base_offset() != 0) {
      stream->Add(" + %d] <-", this->base_offset());
2536 2537 2538 2539 2540
    } else {
      stream->Add("] <- ");
    }

    if (this->value() == NULL) {
2541
      DCHECK(hydrogen()->IsConstantHoleStore() &&
2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552
             hydrogen()->value()->representation().IsDouble());
      stream->Add("<the hole(nan)>");
    } else {
      this->value()->PrintTo(stream);
    }
  }

  DECLARE_HYDROGEN_ACCESSOR(StoreKeyed)
};


2553
class LStoreKeyedExternal final : public LStoreKeyed<1> {
2554 2555 2556 2557 2558
 public:
  LStoreKeyedExternal(LOperand* elements, LOperand* key, LOperand* value,
                      LOperand* temp) :
      LStoreKeyed<1>(elements, key, value) {
    temps_[0] = temp;
2559
  }
2560 2561 2562 2563 2564 2565 2566

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(StoreKeyedExternal, "store-keyed-external")
};


2567
class LStoreKeyedFixed final : public LStoreKeyed<1> {
2568 2569 2570 2571 2572
 public:
  LStoreKeyedFixed(LOperand* elements, LOperand* key, LOperand* value,
                   LOperand* temp) :
      LStoreKeyed<1>(elements, key, value) {
    temps_[0] = temp;
2573
  }
2574 2575 2576 2577 2578 2579 2580

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(StoreKeyedFixed, "store-keyed-fixed")
};


2581
class LStoreKeyedFixedDouble final : public LStoreKeyed<1> {
2582 2583 2584 2585 2586
 public:
  LStoreKeyedFixedDouble(LOperand* elements, LOperand* key, LOperand* value,
                         LOperand* temp) :
      LStoreKeyed<1>(elements, key, value) {
    temps_[0] = temp;
2587
  }
2588 2589 2590 2591 2592 2593 2594 2595

  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(StoreKeyedFixedDouble,
                               "store-keyed-fixed-double")
};


2596
class LStoreKeyedGeneric final : public LTemplateInstruction<0, 4, 2> {
2597
 public:
2598 2599
  LStoreKeyedGeneric(LOperand* context, LOperand* object, LOperand* key,
                     LOperand* value, LOperand* slot, LOperand* vector) {
2600
    inputs_[0] = context;
2601
    inputs_[1] = object;
2602 2603
    inputs_[2] = key;
    inputs_[3] = value;
2604 2605
    temps_[0] = slot;
    temps_[1] = vector;
2606 2607 2608 2609 2610 2611
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* object() { return inputs_[1]; }
  LOperand* key() { return inputs_[2]; }
  LOperand* value() { return inputs_[3]; }
2612 2613
  LOperand* temp_slot() { return temps_[0]; }
  LOperand* temp_vector() { return temps_[1]; }
2614 2615 2616 2617

  DECLARE_CONCRETE_INSTRUCTION(StoreKeyedGeneric, "store-keyed-generic")
  DECLARE_HYDROGEN_ACCESSOR(StoreKeyedGeneric)

2618
  void PrintDataTo(StringStream* stream) override;
2619

2620
  LanguageMode language_mode() { return hydrogen()->language_mode(); }
2621 2622 2623
};


2624
class LStoreNamedField final : public LTemplateInstruction<0, 2, 2> {
2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641
 public:
  LStoreNamedField(LOperand* object, LOperand* value,
                   LOperand* temp0, LOperand* temp1) {
    inputs_[0] = object;
    inputs_[1] = value;
    temps_[0] = temp0;
    temps_[1] = temp1;
  }

  LOperand* object() { return inputs_[0]; }
  LOperand* value() { return inputs_[1]; }
  LOperand* temp0() { return temps_[0]; }
  LOperand* temp1() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(StoreNamedField, "store-named-field")
  DECLARE_HYDROGEN_ACCESSOR(StoreNamedField)

2642
  void PrintDataTo(StringStream* stream) override;
2643 2644 2645 2646 2647 2648 2649

  Representation representation() const {
    return hydrogen()->field_representation();
  }
};


2650
class LStoreNamedGeneric final : public LTemplateInstruction<0, 3, 2> {
2651
 public:
2652 2653
  LStoreNamedGeneric(LOperand* context, LOperand* object, LOperand* value,
                     LOperand* slot, LOperand* vector) {
2654 2655 2656
    inputs_[0] = context;
    inputs_[1] = object;
    inputs_[2] = value;
2657 2658
    temps_[0] = slot;
    temps_[1] = vector;
2659 2660 2661 2662 2663
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* object() { return inputs_[1]; }
  LOperand* value() { return inputs_[2]; }
2664 2665
  LOperand* temp_slot() { return temps_[0]; }
  LOperand* temp_vector() { return temps_[1]; }
2666 2667 2668 2669

  DECLARE_CONCRETE_INSTRUCTION(StoreNamedGeneric, "store-named-generic")
  DECLARE_HYDROGEN_ACCESSOR(StoreNamedGeneric)

2670
  void PrintDataTo(StringStream* stream) override;
2671 2672

  Handle<Object> name() const { return hydrogen()->name(); }
2673
  LanguageMode language_mode() { return hydrogen()->language_mode(); }
2674 2675 2676
};


2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698
class LMaybeGrowElements final : public LTemplateInstruction<1, 5, 0> {
 public:
  LMaybeGrowElements(LOperand* context, LOperand* object, LOperand* elements,
                     LOperand* key, LOperand* current_capacity) {
    inputs_[0] = context;
    inputs_[1] = object;
    inputs_[2] = elements;
    inputs_[3] = key;
    inputs_[4] = current_capacity;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* object() { return inputs_[1]; }
  LOperand* elements() { return inputs_[2]; }
  LOperand* key() { return inputs_[3]; }
  LOperand* current_capacity() { return inputs_[4]; }

  DECLARE_HYDROGEN_ACCESSOR(MaybeGrowElements)
  DECLARE_CONCRETE_INSTRUCTION(MaybeGrowElements, "maybe-grow-elements")
};


2699
class LStringAdd final : public LTemplateInstruction<1, 3, 0> {
2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715
 public:
  LStringAdd(LOperand* context, LOperand* left, LOperand* right) {
    inputs_[0] = context;
    inputs_[1] = left;
    inputs_[2] = right;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* left() { return inputs_[1]; }
  LOperand* right() { return inputs_[2]; }

  DECLARE_CONCRETE_INSTRUCTION(StringAdd, "string-add")
  DECLARE_HYDROGEN_ACCESSOR(StringAdd)
};


2716
class LStringCharCodeAt final : public LTemplateInstruction<1, 3, 0> {
2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732
 public:
  LStringCharCodeAt(LOperand* context, LOperand* string, LOperand* index) {
    inputs_[0] = context;
    inputs_[1] = string;
    inputs_[2] = index;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* string() { return inputs_[1]; }
  LOperand* index() { return inputs_[2]; }

  DECLARE_CONCRETE_INSTRUCTION(StringCharCodeAt, "string-char-code-at")
  DECLARE_HYDROGEN_ACCESSOR(StringCharCodeAt)
};


2733
class LStringCharFromCode final : public LTemplateInstruction<1, 2, 0> {
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747
 public:
  LStringCharFromCode(LOperand* context, LOperand* char_code) {
    inputs_[0] = context;
    inputs_[1] = char_code;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* char_code() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(StringCharFromCode, "string-char-from-code")
  DECLARE_HYDROGEN_ACCESSOR(StringCharFromCode)
};


2748
class LStringCompareAndBranch final : public LControlInstruction<3, 0> {
2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765
 public:
  LStringCompareAndBranch(LOperand* context, LOperand* left, LOperand* right) {
    inputs_[0] = context;
    inputs_[1] = left;
    inputs_[2] = right;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* left() { return inputs_[1]; }
  LOperand* right() { return inputs_[2]; }

  DECLARE_CONCRETE_INSTRUCTION(StringCompareAndBranch,
                               "string-compare-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(StringCompareAndBranch)

  Token::Value op() const { return hydrogen()->token(); }

2766
  void PrintDataTo(StringStream* stream) override;
2767 2768 2769 2770
};


// Truncating conversion from a tagged value to an int32.
2771
class LTaggedToI final : public LTemplateInstruction<1, 1, 2> {
2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789
 public:
  explicit LTaggedToI(LOperand* value, LOperand* temp1, LOperand* temp2) {
    inputs_[0] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(TaggedToI, "tagged-to-i")
  DECLARE_HYDROGEN_ACCESSOR(Change)

  bool truncating() { return hydrogen()->CanTruncateToInt32(); }
};


2790
class LShiftI final : public LTemplateInstruction<1, 2, 0> {
2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810
 public:
  LShiftI(Token::Value op, LOperand* left, LOperand* right, bool can_deopt)
      : op_(op), can_deopt_(can_deopt) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  Token::Value op() const { return op_; }
  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }
  bool can_deopt() const { return can_deopt_; }

  DECLARE_CONCRETE_INSTRUCTION(ShiftI, "shift-i")

 private:
  Token::Value op_;
  bool can_deopt_;
};


2811
class LShiftS final : public LTemplateInstruction<1, 2, 0> {
2812
 public:
2813 2814
  LShiftS(Token::Value op, LOperand* left, LOperand* right, bool can_deopt)
      : op_(op), can_deopt_(can_deopt) {
2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
    inputs_[0] = left;
    inputs_[1] = right;
  }

  Token::Value op() const { return op_; }
  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }
  bool can_deopt() const { return can_deopt_; }

  DECLARE_CONCRETE_INSTRUCTION(ShiftS, "shift-s")

 private:
  Token::Value op_;
  bool can_deopt_;
};


2832
class LStoreCodeEntry final : public LTemplateInstruction<0, 2, 1> {
2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844
 public:
  LStoreCodeEntry(LOperand* function, LOperand* code_object,
                  LOperand* temp) {
    inputs_[0] = function;
    inputs_[1] = code_object;
    temps_[0] = temp;
  }

  LOperand* function() { return inputs_[0]; }
  LOperand* code_object() { return inputs_[1]; }
  LOperand* temp() { return temps_[0]; }

2845
  void PrintDataTo(StringStream* stream) override;
2846 2847 2848 2849 2850 2851

  DECLARE_CONCRETE_INSTRUCTION(StoreCodeEntry, "store-code-entry")
  DECLARE_HYDROGEN_ACCESSOR(StoreCodeEntry)
};


2852
class LStoreContextSlot final : public LTemplateInstruction<0, 2, 1> {
2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868
 public:
  LStoreContextSlot(LOperand* context, LOperand* value, LOperand* temp) {
    inputs_[0] = context;
    inputs_[1] = value;
    temps_[0] = temp;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* value() { return inputs_[1]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(StoreContextSlot, "store-context-slot")
  DECLARE_HYDROGEN_ACCESSOR(StoreContextSlot)

  int slot_index() { return hydrogen()->slot_index(); }

2869
  void PrintDataTo(StringStream* stream) override;
2870 2871 2872
};


2873
class LSubI final : public LTemplateInstruction<1, 2, 0> {
2874
 public:
2875 2876 2877 2878 2879 2880 2881 2882
  LSubI(LOperand* left, LOperand* right)
      : shift_(NO_SHIFT), shift_amount_(0)  {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LSubI(LOperand* left, LOperand* right, Shift shift, LOperand* shift_amount)
      : shift_(shift), shift_amount_(shift_amount)  {
2883 2884 2885 2886 2887 2888 2889
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

2890 2891 2892
  Shift shift() const { return shift_; }
  LOperand* shift_amount() const { return shift_amount_; }

2893 2894
  DECLARE_CONCRETE_INSTRUCTION(SubI, "sub-i")
  DECLARE_HYDROGEN_ACCESSOR(Sub)
2895 2896 2897 2898

 protected:
  Shift shift_;
  LOperand* shift_amount_;
2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916
};


class LSubS: public LTemplateInstruction<1, 2, 0> {
 public:
  LSubS(LOperand* left, LOperand* right) {
    inputs_[0] = left;
    inputs_[1] = right;
  }

  LOperand* left() { return inputs_[0]; }
  LOperand* right() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(SubS, "sub-s")
  DECLARE_HYDROGEN_ACCESSOR(Sub)
};


2917
class LThisFunction final : public LTemplateInstruction<1, 0, 0> {
2918 2919 2920 2921 2922 2923
 public:
  DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
  DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
};


2924
class LToFastProperties final : public LTemplateInstruction<1, 1, 0> {
2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936
 public:
  explicit LToFastProperties(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(ToFastProperties, "to-fast-properties")
  DECLARE_HYDROGEN_ACCESSOR(ToFastProperties)
};


2937
class LTransitionElementsKind final : public LTemplateInstruction<0, 2, 2> {
2938 2939 2940 2941
 public:
  LTransitionElementsKind(LOperand* object,
                          LOperand* context,
                          LOperand* temp1,
2942
                          LOperand* temp2) {
2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957
    inputs_[0] = object;
    inputs_[1] = context;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* object() { return inputs_[0]; }
  LOperand* context() { return inputs_[1]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(TransitionElementsKind,
                               "transition-elements-kind")
  DECLARE_HYDROGEN_ACCESSOR(TransitionElementsKind)

2958
  void PrintDataTo(StringStream* stream) override;
2959 2960 2961 2962 2963 2964 2965 2966 2967 2968

  Handle<Map> original_map() { return hydrogen()->original_map().handle(); }
  Handle<Map> transitioned_map() {
    return hydrogen()->transitioned_map().handle();
  }
  ElementsKind from_kind() const { return hydrogen()->from_kind(); }
  ElementsKind to_kind() const { return hydrogen()->to_kind(); }
};


2969
class LTrapAllocationMemento final : public LTemplateInstruction<0, 1, 2> {
2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984
 public:
  LTrapAllocationMemento(LOperand* object, LOperand* temp1, LOperand* temp2) {
    inputs_[0] = object;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* object() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(TrapAllocationMemento, "trap-allocation-memento")
};


2985
class LTruncateDoubleToIntOrSmi final : public LTemplateInstruction<1, 1, 0> {
2986
 public:
2987
  explicit LTruncateDoubleToIntOrSmi(LOperand* value) {
2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(TruncateDoubleToIntOrSmi,
                               "truncate-double-to-int-or-smi")
  DECLARE_HYDROGEN_ACCESSOR(UnaryOperation)

  bool tag_result() { return hydrogen()->representation().IsSmi(); }
};


3001
class LTypeof final : public LTemplateInstruction<1, 2, 0> {
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014
 public:
  LTypeof(LOperand* context, LOperand* value) {
    inputs_[0] = context;
    inputs_[1] = value;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* value() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(Typeof, "typeof")
};


3015
class LTypeofIsAndBranch final : public LControlInstruction<1, 2> {
3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031
 public:
  LTypeofIsAndBranch(LOperand* value, LOperand* temp1, LOperand* temp2) {
    inputs_[0] = value;
    temps_[0] = temp1;
    temps_[1] = temp2;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* temp1() { return temps_[0]; }
  LOperand* temp2() { return temps_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(TypeofIsAndBranch, "typeof-is-and-branch")
  DECLARE_HYDROGEN_ACCESSOR(TypeofIsAndBranch)

  Handle<String> type_literal() const { return hydrogen()->type_literal(); }

3032
  void PrintDataTo(StringStream* stream) override;
3033 3034 3035
};


3036
class LUint32ToDouble final : public LTemplateInstruction<1, 1, 0> {
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047
 public:
  explicit LUint32ToDouble(LOperand* value) {
    inputs_[0] = value;
  }

  LOperand* value() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(Uint32ToDouble, "uint32-to-double")
};


3048
class LCheckMapValue final : public LTemplateInstruction<0, 2, 1> {
3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063
 public:
  LCheckMapValue(LOperand* value, LOperand* map, LOperand* temp) {
    inputs_[0] = value;
    inputs_[1] = map;
    temps_[0] = temp;
  }

  LOperand* value() { return inputs_[0]; }
  LOperand* map() { return inputs_[1]; }
  LOperand* temp() { return temps_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(CheckMapValue, "check-map-value")
};


3064
class LLoadFieldByIndex final : public LTemplateInstruction<1, 2, 0> {
3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077
 public:
  LLoadFieldByIndex(LOperand* object, LOperand* index) {
    inputs_[0] = object;
    inputs_[1] = index;
  }

  LOperand* object() { return inputs_[0]; }
  LOperand* index() { return inputs_[1]; }

  DECLARE_CONCRETE_INSTRUCTION(LoadFieldByIndex, "load-field-by-index")
};


3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106
class LStoreFrameContext: public LTemplateInstruction<0, 1, 0> {
 public:
  explicit LStoreFrameContext(LOperand* context) {
    inputs_[0] = context;
  }

  LOperand* context() { return inputs_[0]; }

  DECLARE_CONCRETE_INSTRUCTION(StoreFrameContext, "store-frame-context")
};


class LAllocateBlockContext: public LTemplateInstruction<1, 2, 0> {
 public:
  LAllocateBlockContext(LOperand* context, LOperand* function) {
    inputs_[0] = context;
    inputs_[1] = function;
  }

  LOperand* context() { return inputs_[0]; }
  LOperand* function() { return inputs_[1]; }

  Handle<ScopeInfo> scope_info() { return hydrogen()->scope_info(); }

  DECLARE_CONCRETE_INSTRUCTION(AllocateBlockContext, "allocate-block-context")
  DECLARE_HYDROGEN_ACCESSOR(AllocateBlockContext)
};


3107
class LWrapReceiver final : public LTemplateInstruction<1, 2, 0> {
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122
 public:
  LWrapReceiver(LOperand* receiver, LOperand* function) {
    inputs_[0] = receiver;
    inputs_[1] = function;
  }

  DECLARE_CONCRETE_INSTRUCTION(WrapReceiver, "wrap-receiver")
  DECLARE_HYDROGEN_ACCESSOR(WrapReceiver)

  LOperand* receiver() { return inputs_[0]; }
  LOperand* function() { return inputs_[1]; }
};


class LChunkBuilder;
3123
class LPlatformChunk final : public LChunk {
3124 3125 3126 3127 3128 3129 3130 3131 3132
 public:
  LPlatformChunk(CompilationInfo* info, HGraph* graph)
      : LChunk(info, graph) { }

  int GetNextSpillIndex();
  LOperand* GetNextSpillSlot(RegisterKind kind);
};


3133
class LChunkBuilder final : public LChunkBuilderBase {
3134 3135
 public:
  LChunkBuilder(CompilationInfo* info, HGraph* graph, LAllocator* allocator)
3136
      : LChunkBuilderBase(info, graph),
3137 3138
        current_instruction_(NULL),
        current_block_(NULL),
3139
        allocator_(allocator) {}
3140 3141 3142 3143 3144 3145 3146 3147 3148

  // Build the sequence for the graph.
  LPlatformChunk* Build();

  // Declare methods that deal with the individual node types.
#define DECLARE_DO(type) LInstruction* Do##type(H##type* node);
  HYDROGEN_CONCRETE_INSTRUCTION_LIST(DECLARE_DO)
#undef DECLARE_DO

3149
  LInstruction* DoDivByPowerOf2I(HDiv* instr);
3150
  LInstruction* DoDivByConstI(HDiv* instr);
3151 3152
  LInstruction* DoDivI(HBinaryOperation* instr);
  LInstruction* DoModByPowerOf2I(HMod* instr);
3153
  LInstruction* DoModByConstI(HMod* instr);
3154 3155
  LInstruction* DoModI(HMod* instr);
  LInstruction* DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr);
3156
  LInstruction* DoFlooringDivByConstI(HMathFloorOfDiv* instr);
3157 3158
  LInstruction* DoFlooringDivI(HMathFloorOfDiv* instr);

3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182
  static bool HasMagicNumberForDivision(int32_t divisor);

 private:
  // Methods for getting operands for Use / Define / Temp.
  LUnallocated* ToUnallocated(Register reg);
  LUnallocated* ToUnallocated(DoubleRegister reg);

  // Methods for setting up define-use relationships.
  MUST_USE_RESULT LOperand* Use(HValue* value, LUnallocated* operand);
  MUST_USE_RESULT LOperand* UseFixed(HValue* value, Register fixed_register);
  MUST_USE_RESULT LOperand* UseFixedDouble(HValue* value,
                                           DoubleRegister fixed_register);

  // A value that is guaranteed to be allocated to a register.
  // The operand created by UseRegister is guaranteed to be live until the end
  // of the instruction. This means that register allocator will not reuse its
  // register for any other operand inside instruction.
  MUST_USE_RESULT LOperand* UseRegister(HValue* value);

  // The operand created by UseRegisterAndClobber is guaranteed to be live until
  // the end of the end of the instruction, and it may also be used as a scratch
  // register by the instruction implementation.
  //
  // This behaves identically to ARM's UseTempRegister. However, it is renamed
3183 3184
  // to discourage its use in ARM64, since in most cases it is better to
  // allocate a temporary register for the Lithium instruction.
3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206
  MUST_USE_RESULT LOperand* UseRegisterAndClobber(HValue* value);

  // The operand created by UseRegisterAtStart is guaranteed to be live only at
  // instruction start. The register allocator is free to assign the same
  // register to some other operand used inside instruction (i.e. temporary or
  // output).
  MUST_USE_RESULT LOperand* UseRegisterAtStart(HValue* value);

  // An input operand in a register or a constant operand.
  MUST_USE_RESULT LOperand* UseRegisterOrConstant(HValue* value);
  MUST_USE_RESULT LOperand* UseRegisterOrConstantAtStart(HValue* value);

  // A constant operand.
  MUST_USE_RESULT LConstantOperand* UseConstant(HValue* value);

  // An input operand in register, stack slot or a constant operand.
  // Will not be moved to a register even if one is freely available.
  virtual MUST_USE_RESULT LOperand* UseAny(HValue* value);

  // Temporary operand that must be in a register.
  MUST_USE_RESULT LUnallocated* TempRegister();

3207 3208 3209
  // Temporary operand that must be in a double register.
  MUST_USE_RESULT LUnallocated* TempDoubleRegister();

3210 3211
  MUST_USE_RESULT LOperand* FixedTemp(Register reg);

3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242
  // Temporary operand that must be in a fixed double register.
  MUST_USE_RESULT LOperand* FixedTemp(DoubleRegister reg);

  // Methods for setting up define-use relationships.
  // Return the same instruction that they are passed.
  LInstruction* Define(LTemplateResultInstruction<1>* instr,
                       LUnallocated* result);
  LInstruction* DefineAsRegister(LTemplateResultInstruction<1>* instr);
  LInstruction* DefineAsSpilled(LTemplateResultInstruction<1>* instr,
                                int index);

  LInstruction* DefineSameAsFirst(LTemplateResultInstruction<1>* instr);
  LInstruction* DefineFixed(LTemplateResultInstruction<1>* instr,
                            Register reg);
  LInstruction* DefineFixedDouble(LTemplateResultInstruction<1>* instr,
                                  DoubleRegister reg);

  enum CanDeoptimize { CAN_DEOPTIMIZE_EAGERLY, CANNOT_DEOPTIMIZE_EAGERLY };

  // By default we assume that instruction sequences generated for calls
  // cannot deoptimize eagerly and we do not attach environment to this
  // instruction.
  LInstruction* MarkAsCall(
      LInstruction* instr,
      HInstruction* hinstr,
      CanDeoptimize can_deoptimize = CANNOT_DEOPTIMIZE_EAGERLY);

  LInstruction* AssignPointerMap(LInstruction* instr);
  LInstruction* AssignEnvironment(LInstruction* instr);

  void VisitInstruction(HInstruction* current);
3243
  void AddInstruction(LInstruction* instr, HInstruction* current);
3244 3245
  void DoBasicBlock(HBasicBlock* block);

3246 3247 3248 3249 3250 3251 3252
  int JSShiftAmountFromHConstant(HValue* constant) {
    return HConstant::cast(constant)->Integer32Value() & 0x1f;
  }
  bool LikelyFitsImmField(HInstruction* instr, int imm) {
    if (instr->IsAdd() || instr->IsSub()) {
      return Assembler::IsImmAddSub(imm) || Assembler::IsImmAddSub(-imm);
    } else {
3253
      DCHECK(instr->IsBitwise());
3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278
      unsigned unused_n, unused_imm_s, unused_imm_r;
      return Assembler::IsImmLogical(imm, kWRegSizeInBits,
                                     &unused_n, &unused_imm_s, &unused_imm_r);
    }
  }

  // Indicates if a sequence of the form
  //   lsl x8, x9, #imm
  //   add x0, x1, x8
  // can be replaced with:
  //   add x0, x1, x9 LSL #imm
  // If this is not possible, the function returns NULL. Otherwise it returns a
  // pointer to the shift instruction that would be optimized away.
  HBitwiseBinaryOperation* CanTransformToShiftedOp(HValue* val,
                                                   HValue** left = NULL);
  // Checks if all uses of the shift operation can optimize it away.
  bool ShiftCanBeOptimizedAway(HBitwiseBinaryOperation* shift);
  // Attempts to merge the binary operation and an eventual previous shift
  // operation into a single operation. Returns the merged instruction on
  // success, and NULL otherwise.
  LInstruction* TryDoOpWithShiftedRightOperand(HBinaryOperation* op);
  LInstruction* DoShiftedBinaryOp(HBinaryOperation* instr,
                                  HValue* left,
                                  HBitwiseBinaryOperation* shift);

3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296
  LInstruction* DoShift(Token::Value op, HBitwiseBinaryOperation* instr);
  LInstruction* DoArithmeticD(Token::Value op,
                              HArithmeticBinaryOperation* instr);
  LInstruction* DoArithmeticT(Token::Value op,
                              HBinaryOperation* instr);

  HInstruction* current_instruction_;
  HBasicBlock* current_block_;
  LAllocator* allocator_;

  DISALLOW_COPY_AND_ASSIGN(LChunkBuilder);
};

#undef DECLARE_HYDROGEN_ACCESSOR
#undef DECLARE_CONCRETE_INSTRUCTION

} }  // namespace v8::internal

3297
#endif  // V8_ARM64_LITHIUM_ARM64_H_