Remove ExternalArray, derived types, and element kinds
[platform/upstream/v8.git] / src / x64 / lithium-x64.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_X64_LITHIUM_X64_H_
6 #define V8_X64_LITHIUM_X64_H_
7
8 #include "src/hydrogen.h"
9 #include "src/lithium.h"
10 #include "src/lithium-allocator.h"
11 #include "src/safepoint-table.h"
12 #include "src/utils.h"
13
14 namespace v8 {
15 namespace internal {
16
17 // Forward declarations.
18 class LCodeGen;
19
20 #define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \
21   V(AccessArgumentsAt)                       \
22   V(AddI)                                    \
23   V(Allocate)                                \
24   V(AllocateBlockContext)                    \
25   V(ApplyArguments)                          \
26   V(ArgumentsElements)                       \
27   V(ArgumentsLength)                         \
28   V(ArithmeticD)                             \
29   V(ArithmeticT)                             \
30   V(BitI)                                    \
31   V(BoundsCheck)                             \
32   V(Branch)                                  \
33   V(CallJSFunction)                          \
34   V(CallWithDescriptor)                      \
35   V(CallFunction)                            \
36   V(CallNew)                                 \
37   V(CallNewArray)                            \
38   V(CallRuntime)                             \
39   V(CallStub)                                \
40   V(CheckArrayBufferNotNeutered)             \
41   V(CheckInstanceType)                       \
42   V(CheckMaps)                               \
43   V(CheckMapValue)                           \
44   V(CheckNonSmi)                             \
45   V(CheckSmi)                                \
46   V(CheckValue)                              \
47   V(ClampDToUint8)                           \
48   V(ClampIToUint8)                           \
49   V(ClampTToUint8)                           \
50   V(ClassOfTestAndBranch)                    \
51   V(CompareMinusZeroAndBranch)               \
52   V(CompareNumericAndBranch)                 \
53   V(CmpObjectEqAndBranch)                    \
54   V(CmpHoleAndBranch)                        \
55   V(CmpMapAndBranch)                         \
56   V(CmpT)                                    \
57   V(ConstantD)                               \
58   V(ConstantE)                               \
59   V(ConstantI)                               \
60   V(ConstantS)                               \
61   V(ConstantT)                               \
62   V(ConstructDouble)                         \
63   V(Context)                                 \
64   V(DateField)                               \
65   V(DebugBreak)                              \
66   V(DeclareGlobals)                          \
67   V(Deoptimize)                              \
68   V(DivByConstI)                             \
69   V(DivByPowerOf2I)                          \
70   V(DivI)                                    \
71   V(DoubleBits)                              \
72   V(DoubleToI)                               \
73   V(DoubleToSmi)                             \
74   V(Drop)                                    \
75   V(DummyUse)                                \
76   V(Dummy)                                   \
77   V(FlooringDivByConstI)                     \
78   V(FlooringDivByPowerOf2I)                  \
79   V(FlooringDivI)                            \
80   V(ForInCacheArray)                         \
81   V(ForInPrepareMap)                         \
82   V(FunctionLiteral)                         \
83   V(GetCachedArrayIndex)                     \
84   V(Goto)                                    \
85   V(HasCachedArrayIndexAndBranch)            \
86   V(HasInstanceTypeAndBranch)                \
87   V(InnerAllocatedObject)                    \
88   V(InstanceOf)                              \
89   V(InstanceOfKnownGlobal)                   \
90   V(InstructionGap)                          \
91   V(Integer32ToDouble)                       \
92   V(InvokeFunction)                          \
93   V(IsConstructCallAndBranch)                \
94   V(IsObjectAndBranch)                       \
95   V(IsStringAndBranch)                       \
96   V(IsSmiAndBranch)                          \
97   V(IsUndetectableAndBranch)                 \
98   V(Label)                                   \
99   V(LazyBailout)                             \
100   V(LoadContextSlot)                         \
101   V(LoadRoot)                                \
102   V(LoadFieldByIndex)                        \
103   V(LoadFunctionPrototype)                   \
104   V(LoadGlobalGeneric)                       \
105   V(LoadGlobalViaContext)                    \
106   V(LoadKeyed)                               \
107   V(LoadKeyedGeneric)                        \
108   V(LoadNamedField)                          \
109   V(LoadNamedGeneric)                        \
110   V(MapEnumLength)                           \
111   V(MathAbs)                                 \
112   V(MathClz32)                               \
113   V(MathExp)                                 \
114   V(MathFloor)                               \
115   V(MathFround)                              \
116   V(MathLog)                                 \
117   V(MathMinMax)                              \
118   V(MathPowHalf)                             \
119   V(MathRound)                               \
120   V(MathSqrt)                                \
121   V(MaybeGrowElements)                       \
122   V(ModByConstI)                             \
123   V(ModByPowerOf2I)                          \
124   V(ModI)                                    \
125   V(MulI)                                    \
126   V(NumberTagD)                              \
127   V(NumberTagI)                              \
128   V(NumberTagU)                              \
129   V(NumberUntagD)                            \
130   V(OsrEntry)                                \
131   V(Parameter)                               \
132   V(Power)                                   \
133   V(PushArgument)                            \
134   V(RegExpLiteral)                           \
135   V(Return)                                  \
136   V(SeqStringGetChar)                        \
137   V(SeqStringSetChar)                        \
138   V(ShiftI)                                  \
139   V(SmiTag)                                  \
140   V(SmiUntag)                                \
141   V(StackCheck)                              \
142   V(StoreCodeEntry)                          \
143   V(StoreContextSlot)                        \
144   V(StoreFrameContext)                       \
145   V(StoreGlobalViaContext)                   \
146   V(StoreKeyed)                              \
147   V(StoreKeyedGeneric)                       \
148   V(StoreNamedField)                         \
149   V(StoreNamedGeneric)                       \
150   V(StringAdd)                               \
151   V(StringCharCodeAt)                        \
152   V(StringCharFromCode)                      \
153   V(StringCompareAndBranch)                  \
154   V(SubI)                                    \
155   V(TaggedToI)                               \
156   V(ThisFunction)                            \
157   V(ToFastProperties)                        \
158   V(TransitionElementsKind)                  \
159   V(TrapAllocationMemento)                   \
160   V(Typeof)                                  \
161   V(TypeofIsAndBranch)                       \
162   V(Uint32ToDouble)                          \
163   V(UnknownOSRValue)                         \
164   V(WrapReceiver)
165
166
167 #define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic)            \
168   Opcode opcode() const final { return LInstruction::k##type; } \
169   void CompileToNative(LCodeGen* generator) final;              \
170   const char* Mnemonic() const final { return mnemonic; }       \
171   static L##type* cast(LInstruction* instr) {                   \
172     DCHECK(instr->Is##type());                                  \
173     return reinterpret_cast<L##type*>(instr);                   \
174   }
175
176
177 #define DECLARE_HYDROGEN_ACCESSOR(type)     \
178   H##type* hydrogen() const {               \
179     return H##type::cast(hydrogen_value()); \
180   }
181
182
183 class LInstruction : public ZoneObject {
184  public:
185   LInstruction()
186       : environment_(NULL),
187         hydrogen_value_(NULL),
188         bit_field_(IsCallBits::encode(false)) {
189   }
190
191   virtual ~LInstruction() {}
192
193   virtual void CompileToNative(LCodeGen* generator) = 0;
194   virtual const char* Mnemonic() const = 0;
195   virtual void PrintTo(StringStream* stream);
196   virtual void PrintDataTo(StringStream* stream);
197   virtual void PrintOutputOperandTo(StringStream* stream);
198
199   enum Opcode {
200     // Declare a unique enum value for each instruction.
201 #define DECLARE_OPCODE(type) k##type,
202     LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE)
203     kNumberOfInstructions
204 #undef DECLARE_OPCODE
205   };
206
207   virtual Opcode opcode() const = 0;
208
209   // Declare non-virtual type testers for all leaf IR classes.
210 #define DECLARE_PREDICATE(type) \
211   bool Is##type() const { return opcode() == k##type; }
212   LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE)
213 #undef DECLARE_PREDICATE
214
215   // Declare virtual predicates for instructions that don't have
216   // an opcode.
217   virtual bool IsGap() const { return false; }
218
219   virtual bool IsControl() const { return false; }
220
221   // Try deleting this instruction if possible.
222   virtual bool TryDelete() { return false; }
223
224   void set_environment(LEnvironment* env) { environment_ = env; }
225   LEnvironment* environment() const { return environment_; }
226   bool HasEnvironment() const { return environment_ != NULL; }
227
228   void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); }
229   LPointerMap* pointer_map() const { return pointer_map_.get(); }
230   bool HasPointerMap() const { return pointer_map_.is_set(); }
231
232   void set_hydrogen_value(HValue* value) { hydrogen_value_ = value; }
233   HValue* hydrogen_value() const { return hydrogen_value_; }
234
235   void MarkAsCall() { bit_field_ = IsCallBits::update(bit_field_, true); }
236   bool IsCall() const { return IsCallBits::decode(bit_field_); }
237
238   // Interface to the register allocator and iterators.
239   bool ClobbersTemps() const { return IsCall(); }
240   bool ClobbersRegisters() const { return IsCall(); }
241   virtual bool ClobbersDoubleRegisters(Isolate* isolate) const {
242     return IsCall();
243   }
244
245   virtual void SetDeferredLazyDeoptimizationEnvironment(LEnvironment* env) { }
246
247   // Interface to the register allocator and iterators.
248   bool IsMarkedAsCall() const { return IsCall(); }
249
250   virtual bool HasResult() const = 0;
251   virtual LOperand* result() const = 0;
252
253   LOperand* FirstInput() { return InputAt(0); }
254   LOperand* Output() { return HasResult() ? result() : NULL; }
255
256   virtual bool HasInterestingComment(LCodeGen* gen) const { return true; }
257
258   virtual bool MustSignExtendResult(LPlatformChunk* chunk) const {
259     return false;
260   }
261
262 #ifdef DEBUG
263   void VerifyCall();
264 #endif
265
266   virtual int InputCount() = 0;
267   virtual LOperand* InputAt(int i) = 0;
268
269  private:
270   // Iterator support.
271   friend class InputIterator;
272
273   friend class TempIterator;
274   virtual int TempCount() = 0;
275   virtual LOperand* TempAt(int i) = 0;
276
277   class IsCallBits: public BitField<bool, 0, 1> {};
278
279   LEnvironment* environment_;
280   SetOncePointer<LPointerMap> pointer_map_;
281   HValue* hydrogen_value_;
282   int bit_field_;
283 };
284
285
286 // R = number of result operands (0 or 1).
287 template<int R>
288 class LTemplateResultInstruction : public LInstruction {
289  public:
290   // Allow 0 or 1 output operands.
291   STATIC_ASSERT(R == 0 || R == 1);
292   bool HasResult() const final { return R != 0 && result() != NULL; }
293   void set_result(LOperand* operand) { results_[0] = operand; }
294   LOperand* result() const override { return results_[0]; }
295
296   bool MustSignExtendResult(LPlatformChunk* chunk) const final;
297
298  protected:
299   EmbeddedContainer<LOperand*, R> results_;
300 };
301
302
303 // R = number of result operands (0 or 1).
304 // I = number of input operands.
305 // T = number of temporary operands.
306 template<int R, int I, int T>
307 class LTemplateInstruction : public LTemplateResultInstruction<R> {
308  protected:
309   EmbeddedContainer<LOperand*, I> inputs_;
310   EmbeddedContainer<LOperand*, T> temps_;
311
312  private:
313   // Iterator support.
314   int InputCount() final { return I; }
315   LOperand* InputAt(int i) final { return inputs_[i]; }
316
317   int TempCount() final { return T; }
318   LOperand* TempAt(int i) final { return temps_[i]; }
319 };
320
321
322 class LGap : public LTemplateInstruction<0, 0, 0> {
323  public:
324   explicit LGap(HBasicBlock* block)
325       : block_(block) {
326     parallel_moves_[BEFORE] = NULL;
327     parallel_moves_[START] = NULL;
328     parallel_moves_[END] = NULL;
329     parallel_moves_[AFTER] = NULL;
330   }
331
332   // Can't use the DECLARE-macro here because of sub-classes.
333   bool IsGap() const final { return true; }
334   void PrintDataTo(StringStream* stream) override;
335   static LGap* cast(LInstruction* instr) {
336     DCHECK(instr->IsGap());
337     return reinterpret_cast<LGap*>(instr);
338   }
339
340   bool IsRedundant() const;
341
342   HBasicBlock* block() const { return block_; }
343
344   enum InnerPosition {
345     BEFORE,
346     START,
347     END,
348     AFTER,
349     FIRST_INNER_POSITION = BEFORE,
350     LAST_INNER_POSITION = AFTER
351   };
352
353   LParallelMove* GetOrCreateParallelMove(InnerPosition pos,
354                                          Zone* zone)  {
355     if (parallel_moves_[pos] == NULL) {
356       parallel_moves_[pos] = new(zone) LParallelMove(zone);
357     }
358     return parallel_moves_[pos];
359   }
360
361   LParallelMove* GetParallelMove(InnerPosition pos)  {
362     return parallel_moves_[pos];
363   }
364
365  private:
366   LParallelMove* parallel_moves_[LAST_INNER_POSITION + 1];
367   HBasicBlock* block_;
368 };
369
370
371 class LInstructionGap final : public LGap {
372  public:
373   explicit LInstructionGap(HBasicBlock* block) : LGap(block) { }
374
375   bool HasInterestingComment(LCodeGen* gen) const override {
376     return !IsRedundant();
377   }
378
379   DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap")
380 };
381
382
383 class LGoto final : public LTemplateInstruction<0, 0, 0> {
384  public:
385   explicit LGoto(HBasicBlock* block) : block_(block) { }
386
387   bool HasInterestingComment(LCodeGen* gen) const override;
388   DECLARE_CONCRETE_INSTRUCTION(Goto, "goto")
389   void PrintDataTo(StringStream* stream) override;
390   bool IsControl() const override { return true; }
391
392   int block_id() const { return block_->block_id(); }
393
394  private:
395   HBasicBlock* block_;
396 };
397
398
399 class LLazyBailout final : public LTemplateInstruction<0, 0, 0> {
400  public:
401   LLazyBailout() : gap_instructions_size_(0) { }
402
403   DECLARE_CONCRETE_INSTRUCTION(LazyBailout, "lazy-bailout")
404
405   void set_gap_instructions_size(int gap_instructions_size) {
406     gap_instructions_size_ = gap_instructions_size;
407   }
408   int gap_instructions_size() { return gap_instructions_size_; }
409
410  private:
411   int gap_instructions_size_;
412 };
413
414
415 class LDummy final : public LTemplateInstruction<1, 0, 0> {
416  public:
417   LDummy() {}
418   DECLARE_CONCRETE_INSTRUCTION(Dummy, "dummy")
419 };
420
421
422 class LDummyUse final : public LTemplateInstruction<1, 1, 0> {
423  public:
424   explicit LDummyUse(LOperand* value) {
425     inputs_[0] = value;
426   }
427   DECLARE_CONCRETE_INSTRUCTION(DummyUse, "dummy-use")
428 };
429
430
431 class LDeoptimize final : public LTemplateInstruction<0, 0, 0> {
432  public:
433   bool IsControl() const override { return true; }
434   DECLARE_CONCRETE_INSTRUCTION(Deoptimize, "deoptimize")
435   DECLARE_HYDROGEN_ACCESSOR(Deoptimize)
436 };
437
438
439 class LLabel final : public LGap {
440  public:
441   explicit LLabel(HBasicBlock* block)
442       : LGap(block), replacement_(NULL) { }
443
444   bool HasInterestingComment(LCodeGen* gen) const override { return false; }
445   DECLARE_CONCRETE_INSTRUCTION(Label, "label")
446
447   void PrintDataTo(StringStream* stream) override;
448
449   int block_id() const { return block()->block_id(); }
450   bool is_loop_header() const { return block()->IsLoopHeader(); }
451   bool is_osr_entry() const { return block()->is_osr_entry(); }
452   Label* label() { return &label_; }
453   LLabel* replacement() const { return replacement_; }
454   void set_replacement(LLabel* label) { replacement_ = label; }
455   bool HasReplacement() const { return replacement_ != NULL; }
456
457  private:
458   Label label_;
459   LLabel* replacement_;
460 };
461
462
463 class LParameter final : public LTemplateInstruction<1, 0, 0> {
464  public:
465   bool HasInterestingComment(LCodeGen* gen) const override { return false; }
466   DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter")
467 };
468
469
470 class LCallStub final : public LTemplateInstruction<1, 1, 0> {
471  public:
472   explicit LCallStub(LOperand* context) {
473     inputs_[0] = context;
474   }
475
476   LOperand* context() { return inputs_[0]; }
477
478   DECLARE_CONCRETE_INSTRUCTION(CallStub, "call-stub")
479   DECLARE_HYDROGEN_ACCESSOR(CallStub)
480 };
481
482
483 class LUnknownOSRValue final : public LTemplateInstruction<1, 0, 0> {
484  public:
485   bool HasInterestingComment(LCodeGen* gen) const override { return false; }
486   DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value")
487 };
488
489
490 template<int I, int T>
491 class LControlInstruction : public LTemplateInstruction<0, I, T> {
492  public:
493   LControlInstruction() : false_label_(NULL), true_label_(NULL) { }
494
495   bool IsControl() const final { return true; }
496
497   int SuccessorCount() { return hydrogen()->SuccessorCount(); }
498   HBasicBlock* SuccessorAt(int i) { return hydrogen()->SuccessorAt(i); }
499
500   int TrueDestination(LChunk* chunk) {
501     return chunk->LookupDestination(true_block_id());
502   }
503   int FalseDestination(LChunk* chunk) {
504     return chunk->LookupDestination(false_block_id());
505   }
506
507   Label* TrueLabel(LChunk* chunk) {
508     if (true_label_ == NULL) {
509       true_label_ = chunk->GetAssemblyLabel(TrueDestination(chunk));
510     }
511     return true_label_;
512   }
513   Label* FalseLabel(LChunk* chunk) {
514     if (false_label_ == NULL) {
515       false_label_ = chunk->GetAssemblyLabel(FalseDestination(chunk));
516     }
517     return false_label_;
518   }
519
520  protected:
521   int true_block_id() { return SuccessorAt(0)->block_id(); }
522   int false_block_id() { return SuccessorAt(1)->block_id(); }
523
524  private:
525   HControlInstruction* hydrogen() {
526     return HControlInstruction::cast(this->hydrogen_value());
527   }
528
529   Label* false_label_;
530   Label* true_label_;
531 };
532
533
534 class LWrapReceiver final : public LTemplateInstruction<1, 2, 0> {
535  public:
536   LWrapReceiver(LOperand* receiver, LOperand* function) {
537     inputs_[0] = receiver;
538     inputs_[1] = function;
539   }
540
541   LOperand* receiver() { return inputs_[0]; }
542   LOperand* function() { return inputs_[1]; }
543
544   DECLARE_CONCRETE_INSTRUCTION(WrapReceiver, "wrap-receiver")
545   DECLARE_HYDROGEN_ACCESSOR(WrapReceiver)
546 };
547
548
549 class LApplyArguments final : public LTemplateInstruction<1, 4, 0> {
550  public:
551   LApplyArguments(LOperand* function,
552                   LOperand* receiver,
553                   LOperand* length,
554                   LOperand* elements) {
555     inputs_[0] = function;
556     inputs_[1] = receiver;
557     inputs_[2] = length;
558     inputs_[3] = elements;
559   }
560
561   LOperand* function() { return inputs_[0]; }
562   LOperand* receiver() { return inputs_[1]; }
563   LOperand* length() { return inputs_[2]; }
564   LOperand* elements() { return inputs_[3]; }
565
566   DECLARE_CONCRETE_INSTRUCTION(ApplyArguments, "apply-arguments")
567 };
568
569
570 class LAccessArgumentsAt final : public LTemplateInstruction<1, 3, 0> {
571  public:
572   LAccessArgumentsAt(LOperand* arguments, LOperand* length, LOperand* index) {
573     inputs_[0] = arguments;
574     inputs_[1] = length;
575     inputs_[2] = index;
576   }
577
578   LOperand* arguments() { return inputs_[0]; }
579   LOperand* length() { return inputs_[1]; }
580   LOperand* index() { return inputs_[2]; }
581
582   DECLARE_CONCRETE_INSTRUCTION(AccessArgumentsAt, "access-arguments-at")
583
584   void PrintDataTo(StringStream* stream) override;
585 };
586
587
588 class LArgumentsLength final : public LTemplateInstruction<1, 1, 0> {
589  public:
590   explicit LArgumentsLength(LOperand* elements) {
591     inputs_[0] = elements;
592   }
593
594   LOperand* elements() { return inputs_[0]; }
595
596   DECLARE_CONCRETE_INSTRUCTION(ArgumentsLength, "arguments-length")
597 };
598
599
600 class LArgumentsElements final : public LTemplateInstruction<1, 0, 0> {
601  public:
602   DECLARE_CONCRETE_INSTRUCTION(ArgumentsElements, "arguments-elements")
603   DECLARE_HYDROGEN_ACCESSOR(ArgumentsElements)
604 };
605
606
607 class LModByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
608  public:
609   LModByPowerOf2I(LOperand* dividend, int32_t divisor) {
610     inputs_[0] = dividend;
611     divisor_ = divisor;
612   }
613
614   LOperand* dividend() { return inputs_[0]; }
615   int32_t divisor() const { return divisor_; }
616
617   DECLARE_CONCRETE_INSTRUCTION(ModByPowerOf2I, "mod-by-power-of-2-i")
618   DECLARE_HYDROGEN_ACCESSOR(Mod)
619
620  private:
621   int32_t divisor_;
622 };
623
624
625 class LModByConstI final : public LTemplateInstruction<1, 1, 2> {
626  public:
627   LModByConstI(LOperand* dividend,
628                int32_t divisor,
629                LOperand* temp1,
630                LOperand* temp2) {
631     inputs_[0] = dividend;
632     divisor_ = divisor;
633     temps_[0] = temp1;
634     temps_[1] = temp2;
635   }
636
637   LOperand* dividend() { return inputs_[0]; }
638   int32_t divisor() const { return divisor_; }
639   LOperand* temp1() { return temps_[0]; }
640   LOperand* temp2() { return temps_[1]; }
641
642   DECLARE_CONCRETE_INSTRUCTION(ModByConstI, "mod-by-const-i")
643   DECLARE_HYDROGEN_ACCESSOR(Mod)
644
645  private:
646   int32_t divisor_;
647 };
648
649
650 class LModI final : public LTemplateInstruction<1, 2, 1> {
651  public:
652   LModI(LOperand* left, LOperand* right, LOperand* temp) {
653     inputs_[0] = left;
654     inputs_[1] = right;
655     temps_[0] = temp;
656   }
657
658   LOperand* left() { return inputs_[0]; }
659   LOperand* right() { return inputs_[1]; }
660   LOperand* temp() { return temps_[0]; }
661
662   DECLARE_CONCRETE_INSTRUCTION(ModI, "mod-i")
663   DECLARE_HYDROGEN_ACCESSOR(Mod)
664 };
665
666
667 class LDivByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
668  public:
669   LDivByPowerOf2I(LOperand* dividend, int32_t divisor) {
670     inputs_[0] = dividend;
671     divisor_ = divisor;
672   }
673
674   LOperand* dividend() { return inputs_[0]; }
675   int32_t divisor() const { return divisor_; }
676
677   DECLARE_CONCRETE_INSTRUCTION(DivByPowerOf2I, "div-by-power-of-2-i")
678   DECLARE_HYDROGEN_ACCESSOR(Div)
679
680  private:
681   int32_t divisor_;
682 };
683
684
685 class LDivByConstI final : public LTemplateInstruction<1, 1, 2> {
686  public:
687   LDivByConstI(LOperand* dividend,
688                int32_t divisor,
689                LOperand* temp1,
690                LOperand* temp2) {
691     inputs_[0] = dividend;
692     divisor_ = divisor;
693     temps_[0] = temp1;
694     temps_[1] = temp2;
695   }
696
697   LOperand* dividend() { return inputs_[0]; }
698   int32_t divisor() const { return divisor_; }
699   LOperand* temp1() { return temps_[0]; }
700   LOperand* temp2() { return temps_[1]; }
701
702   DECLARE_CONCRETE_INSTRUCTION(DivByConstI, "div-by-const-i")
703   DECLARE_HYDROGEN_ACCESSOR(Div)
704
705  private:
706   int32_t divisor_;
707 };
708
709
710 class LDivI final : public LTemplateInstruction<1, 2, 1> {
711  public:
712   LDivI(LOperand* dividend, LOperand* divisor, LOperand* temp) {
713     inputs_[0] = dividend;
714     inputs_[1] = divisor;
715     temps_[0] = temp;
716   }
717
718   LOperand* dividend() { return inputs_[0]; }
719   LOperand* divisor() { return inputs_[1]; }
720   LOperand* temp() { return temps_[0]; }
721
722   DECLARE_CONCRETE_INSTRUCTION(DivI, "div-i")
723   DECLARE_HYDROGEN_ACCESSOR(BinaryOperation)
724 };
725
726
727 class LFlooringDivByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
728  public:
729   LFlooringDivByPowerOf2I(LOperand* dividend, int32_t divisor) {
730     inputs_[0] = dividend;
731     divisor_ = divisor;
732   }
733
734   LOperand* dividend() { return inputs_[0]; }
735   int32_t divisor() const { return divisor_; }
736
737   DECLARE_CONCRETE_INSTRUCTION(FlooringDivByPowerOf2I,
738                                "flooring-div-by-power-of-2-i")
739   DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
740
741  private:
742   int32_t divisor_;
743 };
744
745
746 class LFlooringDivByConstI final : public LTemplateInstruction<1, 1, 3> {
747  public:
748   LFlooringDivByConstI(LOperand* dividend,
749                        int32_t divisor,
750                        LOperand* temp1,
751                        LOperand* temp2,
752                        LOperand* temp3) {
753     inputs_[0] = dividend;
754     divisor_ = divisor;
755     temps_[0] = temp1;
756     temps_[1] = temp2;
757     temps_[2] = temp3;
758   }
759
760   LOperand* dividend() { return inputs_[0]; }
761   int32_t divisor() const { return divisor_; }
762   LOperand* temp1() { return temps_[0]; }
763   LOperand* temp2() { return temps_[1]; }
764   LOperand* temp3() { return temps_[2]; }
765
766   DECLARE_CONCRETE_INSTRUCTION(FlooringDivByConstI, "flooring-div-by-const-i")
767   DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
768
769  private:
770   int32_t divisor_;
771 };
772
773
774 class LFlooringDivI final : public LTemplateInstruction<1, 2, 1> {
775  public:
776   LFlooringDivI(LOperand* dividend, LOperand* divisor, LOperand* temp) {
777     inputs_[0] = dividend;
778     inputs_[1] = divisor;
779     temps_[0] = temp;
780   }
781
782   LOperand* dividend() { return inputs_[0]; }
783   LOperand* divisor() { return inputs_[1]; }
784   LOperand* temp() { return temps_[0]; }
785
786   DECLARE_CONCRETE_INSTRUCTION(FlooringDivI, "flooring-div-i")
787   DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
788 };
789
790
791 class LMulI final : public LTemplateInstruction<1, 2, 0> {
792  public:
793   LMulI(LOperand* left, LOperand* right) {
794     inputs_[0] = left;
795     inputs_[1] = right;
796   }
797
798   LOperand* left() { return inputs_[0]; }
799   LOperand* right() { return inputs_[1]; }
800
801   DECLARE_CONCRETE_INSTRUCTION(MulI, "mul-i")
802   DECLARE_HYDROGEN_ACCESSOR(Mul)
803 };
804
805
806 class LCompareNumericAndBranch final : public LControlInstruction<2, 0> {
807  public:
808   LCompareNumericAndBranch(LOperand* left, LOperand* right) {
809     inputs_[0] = left;
810     inputs_[1] = right;
811   }
812
813   LOperand* left() { return inputs_[0]; }
814   LOperand* right() { return inputs_[1]; }
815
816   DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch,
817                                "compare-numeric-and-branch")
818   DECLARE_HYDROGEN_ACCESSOR(CompareNumericAndBranch)
819
820   Token::Value op() const { return hydrogen()->token(); }
821   bool is_double() const {
822     return hydrogen()->representation().IsDouble();
823   }
824
825   void PrintDataTo(StringStream* stream) override;
826 };
827
828
829 class LMathFloor final : public LTemplateInstruction<1, 1, 0> {
830  public:
831   explicit LMathFloor(LOperand* value) {
832     inputs_[0] = value;
833   }
834
835   LOperand* value() { return inputs_[0]; }
836
837   DECLARE_CONCRETE_INSTRUCTION(MathFloor, "math-floor")
838   DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
839 };
840
841
842 class LMathRound final : public LTemplateInstruction<1, 1, 1> {
843  public:
844   LMathRound(LOperand* value, LOperand* temp) {
845     inputs_[0] = value;
846     temps_[0] = temp;
847   }
848
849   LOperand* value() { return inputs_[0]; }
850   LOperand* temp() { return temps_[0]; }
851
852   DECLARE_CONCRETE_INSTRUCTION(MathRound, "math-round")
853   DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
854 };
855
856
857 class LMathFround final : public LTemplateInstruction<1, 1, 0> {
858  public:
859   explicit LMathFround(LOperand* value) { inputs_[0] = value; }
860
861   LOperand* value() { return inputs_[0]; }
862
863   DECLARE_CONCRETE_INSTRUCTION(MathFround, "math-fround")
864 };
865
866
867 class LMathAbs final : public LTemplateInstruction<1, 2, 0> {
868  public:
869   explicit LMathAbs(LOperand* context, LOperand* value) {
870     inputs_[1] = context;
871     inputs_[0] = value;
872   }
873
874   LOperand* context() { return inputs_[1]; }
875   LOperand* value() { return inputs_[0]; }
876
877   DECLARE_CONCRETE_INSTRUCTION(MathAbs, "math-abs")
878   DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
879 };
880
881
882 class LMathLog final : public LTemplateInstruction<1, 1, 0> {
883  public:
884   explicit LMathLog(LOperand* value) {
885     inputs_[0] = value;
886   }
887
888   LOperand* value() { return inputs_[0]; }
889
890   DECLARE_CONCRETE_INSTRUCTION(MathLog, "math-log")
891 };
892
893
894 class LMathClz32 final : public LTemplateInstruction<1, 1, 0> {
895  public:
896   explicit LMathClz32(LOperand* value) {
897     inputs_[0] = value;
898   }
899
900   LOperand* value() { return inputs_[0]; }
901
902   DECLARE_CONCRETE_INSTRUCTION(MathClz32, "math-clz32")
903 };
904
905
906 class LMathExp final : public LTemplateInstruction<1, 1, 2> {
907  public:
908   LMathExp(LOperand* value, LOperand* temp1, LOperand* temp2) {
909     inputs_[0] = value;
910     temps_[0] = temp1;
911     temps_[1] = temp2;
912     ExternalReference::InitializeMathExpData();
913   }
914
915   LOperand* value() { return inputs_[0]; }
916   LOperand* temp1() { return temps_[0]; }
917   LOperand* temp2() { return temps_[1]; }
918
919   DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
920 };
921
922
923 class LMathSqrt final : public LTemplateInstruction<1, 1, 0> {
924  public:
925   explicit LMathSqrt(LOperand* value) {
926     inputs_[0] = value;
927   }
928
929   LOperand* value() { return inputs_[0]; }
930
931   DECLARE_CONCRETE_INSTRUCTION(MathSqrt, "math-sqrt")
932 };
933
934
935 class LMathPowHalf final : public LTemplateInstruction<1, 1, 0> {
936  public:
937   explicit LMathPowHalf(LOperand* value) {
938     inputs_[0] = value;
939   }
940
941   LOperand* value() { return inputs_[0]; }
942
943   DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half")
944 };
945
946
947 class LCmpObjectEqAndBranch final : public LControlInstruction<2, 0> {
948  public:
949   LCmpObjectEqAndBranch(LOperand* left, LOperand* right) {
950     inputs_[0] = left;
951     inputs_[1] = right;
952   }
953
954   LOperand* left() { return inputs_[0]; }
955   LOperand* right() { return inputs_[1]; }
956
957   DECLARE_CONCRETE_INSTRUCTION(CmpObjectEqAndBranch, "cmp-object-eq-and-branch")
958 };
959
960
961 class LCmpHoleAndBranch final : public LControlInstruction<1, 0> {
962  public:
963   explicit LCmpHoleAndBranch(LOperand* object) {
964     inputs_[0] = object;
965   }
966
967   LOperand* object() { return inputs_[0]; }
968
969   DECLARE_CONCRETE_INSTRUCTION(CmpHoleAndBranch, "cmp-hole-and-branch")
970   DECLARE_HYDROGEN_ACCESSOR(CompareHoleAndBranch)
971 };
972
973
974 class LCompareMinusZeroAndBranch final : public LControlInstruction<1, 0> {
975  public:
976   explicit LCompareMinusZeroAndBranch(LOperand* value) {
977     inputs_[0] = value;
978   }
979
980   LOperand* value() { return inputs_[0]; }
981
982   DECLARE_CONCRETE_INSTRUCTION(CompareMinusZeroAndBranch,
983                                "cmp-minus-zero-and-branch")
984   DECLARE_HYDROGEN_ACCESSOR(CompareMinusZeroAndBranch)
985 };
986
987
988 class LIsObjectAndBranch final : public LControlInstruction<1, 0> {
989  public:
990   explicit LIsObjectAndBranch(LOperand* value) {
991     inputs_[0] = value;
992   }
993
994   LOperand* value() { return inputs_[0]; }
995
996   DECLARE_CONCRETE_INSTRUCTION(IsObjectAndBranch, "is-object-and-branch")
997   DECLARE_HYDROGEN_ACCESSOR(IsObjectAndBranch)
998
999   void PrintDataTo(StringStream* stream) override;
1000 };
1001
1002
1003 class LIsStringAndBranch final : public LControlInstruction<1, 1> {
1004  public:
1005   explicit LIsStringAndBranch(LOperand* value, LOperand* temp) {
1006     inputs_[0] = value;
1007     temps_[0] = temp;
1008   }
1009
1010   LOperand* value() { return inputs_[0]; }
1011   LOperand* temp() { return temps_[0]; }
1012
1013   DECLARE_CONCRETE_INSTRUCTION(IsStringAndBranch, "is-string-and-branch")
1014   DECLARE_HYDROGEN_ACCESSOR(IsStringAndBranch)
1015
1016   void PrintDataTo(StringStream* stream) override;
1017 };
1018
1019
1020 class LIsSmiAndBranch final : public LControlInstruction<1, 0> {
1021  public:
1022   explicit LIsSmiAndBranch(LOperand* value) {
1023     inputs_[0] = value;
1024   }
1025
1026   LOperand* value() { return inputs_[0]; }
1027
1028   DECLARE_CONCRETE_INSTRUCTION(IsSmiAndBranch, "is-smi-and-branch")
1029   DECLARE_HYDROGEN_ACCESSOR(IsSmiAndBranch)
1030
1031   void PrintDataTo(StringStream* stream) override;
1032 };
1033
1034
1035 class LIsUndetectableAndBranch final : public LControlInstruction<1, 1> {
1036  public:
1037   explicit LIsUndetectableAndBranch(LOperand* value, LOperand* temp) {
1038     inputs_[0] = value;
1039     temps_[0] = temp;
1040   }
1041
1042   LOperand* value() { return inputs_[0]; }
1043   LOperand* temp() { return temps_[0]; }
1044
1045   DECLARE_CONCRETE_INSTRUCTION(IsUndetectableAndBranch,
1046                                "is-undetectable-and-branch")
1047   DECLARE_HYDROGEN_ACCESSOR(IsUndetectableAndBranch)
1048
1049   void PrintDataTo(StringStream* stream) override;
1050 };
1051
1052
1053 class LStringCompareAndBranch final : public LControlInstruction<3, 0> {
1054  public:
1055   explicit LStringCompareAndBranch(LOperand* context,
1056                                    LOperand* left,
1057                                    LOperand* right) {
1058     inputs_[0] = context;
1059     inputs_[1] = left;
1060     inputs_[2] = right;
1061   }
1062
1063   LOperand* context() { return inputs_[0]; }
1064   LOperand* left() { return inputs_[1]; }
1065   LOperand* right() { return inputs_[2]; }
1066
1067   DECLARE_CONCRETE_INSTRUCTION(StringCompareAndBranch,
1068                                "string-compare-and-branch")
1069   DECLARE_HYDROGEN_ACCESSOR(StringCompareAndBranch)
1070
1071   void PrintDataTo(StringStream* stream) override;
1072
1073   Token::Value op() const { return hydrogen()->token(); }
1074 };
1075
1076
1077 class LHasInstanceTypeAndBranch final : public LControlInstruction<1, 0> {
1078  public:
1079   explicit LHasInstanceTypeAndBranch(LOperand* value) {
1080     inputs_[0] = value;
1081   }
1082
1083   LOperand* value() { return inputs_[0]; }
1084
1085   DECLARE_CONCRETE_INSTRUCTION(HasInstanceTypeAndBranch,
1086                                "has-instance-type-and-branch")
1087   DECLARE_HYDROGEN_ACCESSOR(HasInstanceTypeAndBranch)
1088
1089   void PrintDataTo(StringStream* stream) override;
1090 };
1091
1092
1093 class LGetCachedArrayIndex final : public LTemplateInstruction<1, 1, 0> {
1094  public:
1095   explicit LGetCachedArrayIndex(LOperand* value) {
1096     inputs_[0] = value;
1097   }
1098
1099   LOperand* value() { return inputs_[0]; }
1100
1101   DECLARE_CONCRETE_INSTRUCTION(GetCachedArrayIndex, "get-cached-array-index")
1102   DECLARE_HYDROGEN_ACCESSOR(GetCachedArrayIndex)
1103 };
1104
1105
1106 class LHasCachedArrayIndexAndBranch final : public LControlInstruction<1, 0> {
1107  public:
1108   explicit LHasCachedArrayIndexAndBranch(LOperand* value) {
1109     inputs_[0] = value;
1110   }
1111
1112   LOperand* value() { return inputs_[0]; }
1113
1114   DECLARE_CONCRETE_INSTRUCTION(HasCachedArrayIndexAndBranch,
1115                                "has-cached-array-index-and-branch")
1116   DECLARE_HYDROGEN_ACCESSOR(HasCachedArrayIndexAndBranch)
1117
1118   void PrintDataTo(StringStream* stream) override;
1119 };
1120
1121
1122 class LClassOfTestAndBranch final : public LControlInstruction<1, 2> {
1123  public:
1124   LClassOfTestAndBranch(LOperand* value, LOperand* temp, LOperand* temp2) {
1125     inputs_[0] = value;
1126     temps_[0] = temp;
1127     temps_[1] = temp2;
1128   }
1129
1130   LOperand* value() { return inputs_[0]; }
1131   LOperand* temp() { return temps_[0]; }
1132   LOperand* temp2() { return temps_[1]; }
1133
1134   DECLARE_CONCRETE_INSTRUCTION(ClassOfTestAndBranch,
1135                                "class-of-test-and-branch")
1136   DECLARE_HYDROGEN_ACCESSOR(ClassOfTestAndBranch)
1137
1138   void PrintDataTo(StringStream* stream) override;
1139 };
1140
1141
1142 class LCmpT final : public LTemplateInstruction<1, 3, 0> {
1143  public:
1144   LCmpT(LOperand* context, LOperand* left, LOperand* right) {
1145     inputs_[0] = context;
1146     inputs_[1] = left;
1147     inputs_[2] = right;
1148   }
1149
1150   LOperand* context() { return inputs_[0]; }
1151   LOperand* left() { return inputs_[1]; }
1152   LOperand* right() { return inputs_[2]; }
1153
1154   DECLARE_CONCRETE_INSTRUCTION(CmpT, "cmp-t")
1155   DECLARE_HYDROGEN_ACCESSOR(CompareGeneric)
1156
1157   Strength strength() { return hydrogen()->strength(); }
1158
1159   Token::Value op() const { return hydrogen()->token(); }
1160 };
1161
1162
1163 class LInstanceOf final : public LTemplateInstruction<1, 3, 0> {
1164  public:
1165   LInstanceOf(LOperand* context, LOperand* left, LOperand* right) {
1166     inputs_[0] = context;
1167     inputs_[1] = left;
1168     inputs_[2] = right;
1169   }
1170
1171   LOperand* context() { return inputs_[0]; }
1172   LOperand* left() { return inputs_[1]; }
1173   LOperand* right() { return inputs_[2]; }
1174
1175   DECLARE_CONCRETE_INSTRUCTION(InstanceOf, "instance-of")
1176 };
1177
1178
1179 class LInstanceOfKnownGlobal final : public LTemplateInstruction<1, 2, 1> {
1180  public:
1181   LInstanceOfKnownGlobal(LOperand* context, LOperand* value, LOperand* temp) {
1182     inputs_[0] = context;
1183     inputs_[1] = value;
1184     temps_[0] = temp;
1185   }
1186
1187   LOperand* context() { return inputs_[0]; }
1188   LOperand* value() { return inputs_[1]; }
1189   LOperand* temp() { return temps_[0]; }
1190
1191   DECLARE_CONCRETE_INSTRUCTION(InstanceOfKnownGlobal,
1192                                "instance-of-known-global")
1193   DECLARE_HYDROGEN_ACCESSOR(InstanceOfKnownGlobal)
1194
1195   Handle<JSFunction> function() const { return hydrogen()->function(); }
1196   LEnvironment* GetDeferredLazyDeoptimizationEnvironment() {
1197     return lazy_deopt_env_;
1198   }
1199   virtual void SetDeferredLazyDeoptimizationEnvironment(
1200       LEnvironment* env) override {
1201     lazy_deopt_env_ = env;
1202   }
1203
1204  private:
1205   LEnvironment* lazy_deopt_env_;
1206 };
1207
1208
1209 class LBoundsCheck final : public LTemplateInstruction<0, 2, 0> {
1210  public:
1211   LBoundsCheck(LOperand* index, LOperand* length) {
1212     inputs_[0] = index;
1213     inputs_[1] = length;
1214   }
1215
1216   LOperand* index() { return inputs_[0]; }
1217   LOperand* length() { return inputs_[1]; }
1218
1219   DECLARE_CONCRETE_INSTRUCTION(BoundsCheck, "bounds-check")
1220   DECLARE_HYDROGEN_ACCESSOR(BoundsCheck)
1221 };
1222
1223
1224 class LBitI final : public LTemplateInstruction<1, 2, 0> {
1225  public:
1226   LBitI(LOperand* left, LOperand* right) {
1227     inputs_[0] = left;
1228     inputs_[1] = right;
1229   }
1230
1231   LOperand* left() { return inputs_[0]; }
1232   LOperand* right() { return inputs_[1]; }
1233
1234   Token::Value op() const { return hydrogen()->op(); }
1235   bool IsInteger32() const {
1236     return hydrogen()->representation().IsInteger32();
1237   }
1238
1239   DECLARE_CONCRETE_INSTRUCTION(BitI, "bit-i")
1240   DECLARE_HYDROGEN_ACCESSOR(Bitwise)
1241 };
1242
1243
1244 class LShiftI final : public LTemplateInstruction<1, 2, 0> {
1245  public:
1246   LShiftI(Token::Value op, LOperand* left, LOperand* right, bool can_deopt)
1247       : op_(op), can_deopt_(can_deopt) {
1248     inputs_[0] = left;
1249     inputs_[1] = right;
1250   }
1251
1252   Token::Value op() const { return op_; }
1253   LOperand* left() { return inputs_[0]; }
1254   LOperand* right() { return inputs_[1]; }
1255   bool can_deopt() const { return can_deopt_; }
1256
1257   DECLARE_CONCRETE_INSTRUCTION(ShiftI, "shift-i")
1258
1259  private:
1260   Token::Value op_;
1261   bool can_deopt_;
1262 };
1263
1264
1265 class LSubI final : public LTemplateInstruction<1, 2, 0> {
1266  public:
1267   LSubI(LOperand* left, LOperand* right) {
1268     inputs_[0] = left;
1269     inputs_[1] = right;
1270   }
1271
1272   LOperand* left() { return inputs_[0]; }
1273   LOperand* right() { return inputs_[1]; }
1274
1275   DECLARE_CONCRETE_INSTRUCTION(SubI, "sub-i")
1276   DECLARE_HYDROGEN_ACCESSOR(Sub)
1277 };
1278
1279
1280 class LConstantI final : public LTemplateInstruction<1, 0, 0> {
1281  public:
1282   DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
1283   DECLARE_HYDROGEN_ACCESSOR(Constant)
1284
1285   int32_t value() const { return hydrogen()->Integer32Value(); }
1286 };
1287
1288
1289 class LConstantS final : public LTemplateInstruction<1, 0, 0> {
1290  public:
1291   DECLARE_CONCRETE_INSTRUCTION(ConstantS, "constant-s")
1292   DECLARE_HYDROGEN_ACCESSOR(Constant)
1293
1294   Smi* value() const { return Smi::FromInt(hydrogen()->Integer32Value()); }
1295 };
1296
1297
1298 class LConstantD final : public LTemplateInstruction<1, 0, 0> {
1299  public:
1300   DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
1301   DECLARE_HYDROGEN_ACCESSOR(Constant)
1302
1303   uint64_t bits() const { return hydrogen()->DoubleValueAsBits(); }
1304 };
1305
1306
1307 class LConstantE final : public LTemplateInstruction<1, 0, 0> {
1308  public:
1309   DECLARE_CONCRETE_INSTRUCTION(ConstantE, "constant-e")
1310   DECLARE_HYDROGEN_ACCESSOR(Constant)
1311
1312   ExternalReference value() const {
1313     return hydrogen()->ExternalReferenceValue();
1314   }
1315 };
1316
1317
1318 class LConstantT final : public LTemplateInstruction<1, 0, 0> {
1319  public:
1320   DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
1321   DECLARE_HYDROGEN_ACCESSOR(Constant)
1322
1323   Handle<Object> value(Isolate* isolate) const {
1324     return hydrogen()->handle(isolate);
1325   }
1326 };
1327
1328
1329 class LBranch final : public LControlInstruction<1, 0> {
1330  public:
1331   explicit LBranch(LOperand* value) {
1332     inputs_[0] = value;
1333   }
1334
1335   LOperand* value() { return inputs_[0]; }
1336
1337   DECLARE_CONCRETE_INSTRUCTION(Branch, "branch")
1338   DECLARE_HYDROGEN_ACCESSOR(Branch)
1339
1340   void PrintDataTo(StringStream* stream) override;
1341 };
1342
1343
1344 class LDebugBreak final : public LTemplateInstruction<0, 0, 0> {
1345  public:
1346   DECLARE_CONCRETE_INSTRUCTION(DebugBreak, "break")
1347 };
1348
1349
1350 class LCmpMapAndBranch final : public LControlInstruction<1, 0> {
1351  public:
1352   explicit LCmpMapAndBranch(LOperand* value) {
1353     inputs_[0] = value;
1354   }
1355
1356   LOperand* value() { return inputs_[0]; }
1357
1358   DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
1359   DECLARE_HYDROGEN_ACCESSOR(CompareMap)
1360
1361   Handle<Map> map() const { return hydrogen()->map().handle(); }
1362 };
1363
1364
1365 class LMapEnumLength final : public LTemplateInstruction<1, 1, 0> {
1366  public:
1367   explicit LMapEnumLength(LOperand* value) {
1368     inputs_[0] = value;
1369   }
1370
1371   LOperand* value() { return inputs_[0]; }
1372
1373   DECLARE_CONCRETE_INSTRUCTION(MapEnumLength, "map-enum-length")
1374 };
1375
1376
1377 class LDateField final : public LTemplateInstruction<1, 1, 0> {
1378  public:
1379   LDateField(LOperand* date, Smi* index) : index_(index) {
1380     inputs_[0] = date;
1381   }
1382
1383   LOperand* date() { return inputs_[0]; }
1384   Smi* index() const { return index_; }
1385
1386   DECLARE_CONCRETE_INSTRUCTION(DateField, "date-field")
1387   DECLARE_HYDROGEN_ACCESSOR(DateField)
1388
1389  private:
1390   Smi* index_;
1391 };
1392
1393
1394 class LSeqStringGetChar final : public LTemplateInstruction<1, 2, 0> {
1395  public:
1396   LSeqStringGetChar(LOperand* string, LOperand* index) {
1397     inputs_[0] = string;
1398     inputs_[1] = index;
1399   }
1400
1401   LOperand* string() const { return inputs_[0]; }
1402   LOperand* index() const { return inputs_[1]; }
1403
1404   DECLARE_CONCRETE_INSTRUCTION(SeqStringGetChar, "seq-string-get-char")
1405   DECLARE_HYDROGEN_ACCESSOR(SeqStringGetChar)
1406 };
1407
1408
1409 class LSeqStringSetChar final : public LTemplateInstruction<1, 4, 0> {
1410  public:
1411   LSeqStringSetChar(LOperand* context,
1412                     LOperand* string,
1413                     LOperand* index,
1414                     LOperand* value) {
1415     inputs_[0] = context;
1416     inputs_[1] = string;
1417     inputs_[2] = index;
1418     inputs_[3] = value;
1419   }
1420
1421   LOperand* string() { return inputs_[1]; }
1422   LOperand* index() { return inputs_[2]; }
1423   LOperand* value() { return inputs_[3]; }
1424
1425   DECLARE_CONCRETE_INSTRUCTION(SeqStringSetChar, "seq-string-set-char")
1426   DECLARE_HYDROGEN_ACCESSOR(SeqStringSetChar)
1427 };
1428
1429
1430 class LAddI final : public LTemplateInstruction<1, 2, 0> {
1431  public:
1432   LAddI(LOperand* left, LOperand* right) {
1433     inputs_[0] = left;
1434     inputs_[1] = right;
1435   }
1436
1437   LOperand* left() { return inputs_[0]; }
1438   LOperand* right() { return inputs_[1]; }
1439
1440   static bool UseLea(HAdd* add) {
1441     return !add->CheckFlag(HValue::kCanOverflow) &&
1442         add->BetterLeftOperand()->UseCount() > 1;
1443   }
1444
1445   DECLARE_CONCRETE_INSTRUCTION(AddI, "add-i")
1446   DECLARE_HYDROGEN_ACCESSOR(Add)
1447 };
1448
1449
1450 class LMathMinMax final : public LTemplateInstruction<1, 2, 0> {
1451  public:
1452   LMathMinMax(LOperand* left, LOperand* right) {
1453     inputs_[0] = left;
1454     inputs_[1] = right;
1455   }
1456
1457   LOperand* left() { return inputs_[0]; }
1458   LOperand* right() { return inputs_[1]; }
1459
1460   DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "math-min-max")
1461   DECLARE_HYDROGEN_ACCESSOR(MathMinMax)
1462 };
1463
1464
1465 class LPower final : public LTemplateInstruction<1, 2, 0> {
1466  public:
1467   LPower(LOperand* left, LOperand* right) {
1468     inputs_[0] = left;
1469     inputs_[1] = right;
1470   }
1471
1472   LOperand* left() { return inputs_[0]; }
1473   LOperand* right() { return inputs_[1]; }
1474
1475   DECLARE_CONCRETE_INSTRUCTION(Power, "power")
1476   DECLARE_HYDROGEN_ACCESSOR(Power)
1477 };
1478
1479
1480 class LArithmeticD final : public LTemplateInstruction<1, 2, 0> {
1481  public:
1482   LArithmeticD(Token::Value op, LOperand* left, LOperand* right)
1483       : op_(op) {
1484     inputs_[0] = left;
1485     inputs_[1] = right;
1486   }
1487
1488   Token::Value op() const { return op_; }
1489   LOperand* left() { return inputs_[0]; }
1490   LOperand* right() { return inputs_[1]; }
1491
1492   Opcode opcode() const override { return LInstruction::kArithmeticD; }
1493   void CompileToNative(LCodeGen* generator) override;
1494   const char* Mnemonic() const override;
1495
1496  private:
1497   Token::Value op_;
1498 };
1499
1500
1501 class LArithmeticT final : public LTemplateInstruction<1, 3, 0> {
1502  public:
1503   LArithmeticT(Token::Value op,
1504                LOperand* context,
1505                LOperand* left,
1506                LOperand* right)
1507       : op_(op) {
1508     inputs_[0] = context;
1509     inputs_[1] = left;
1510     inputs_[2] = right;
1511   }
1512
1513   Token::Value op() const { return op_; }
1514   LOperand* context() { return inputs_[0]; }
1515   LOperand* left() { return inputs_[1]; }
1516   LOperand* right() { return inputs_[2]; }
1517
1518   Opcode opcode() const override { return LInstruction::kArithmeticT; }
1519   void CompileToNative(LCodeGen* generator) override;
1520   const char* Mnemonic() const override;
1521
1522   DECLARE_HYDROGEN_ACCESSOR(BinaryOperation)
1523
1524   Strength strength() { return hydrogen()->strength(); }
1525
1526  private:
1527   Token::Value op_;
1528 };
1529
1530
1531 class LReturn final : public LTemplateInstruction<0, 3, 0> {
1532  public:
1533   explicit LReturn(LOperand* value,
1534                    LOperand* context,
1535                    LOperand* parameter_count) {
1536     inputs_[0] = value;
1537     inputs_[1] = context;
1538     inputs_[2] = parameter_count;
1539   }
1540
1541   LOperand* value() { return inputs_[0]; }
1542   LOperand* context() { return inputs_[1]; }
1543
1544   bool has_constant_parameter_count() {
1545     return parameter_count()->IsConstantOperand();
1546   }
1547   LConstantOperand* constant_parameter_count() {
1548     DCHECK(has_constant_parameter_count());
1549     return LConstantOperand::cast(parameter_count());
1550   }
1551   LOperand* parameter_count() { return inputs_[2]; }
1552
1553   DECLARE_CONCRETE_INSTRUCTION(Return, "return")
1554   DECLARE_HYDROGEN_ACCESSOR(Return)
1555 };
1556
1557
1558 class LLoadNamedField final : public LTemplateInstruction<1, 1, 0> {
1559  public:
1560   explicit LLoadNamedField(LOperand* object) {
1561     inputs_[0] = object;
1562   }
1563
1564   LOperand* object() { return inputs_[0]; }
1565
1566   DECLARE_CONCRETE_INSTRUCTION(LoadNamedField, "load-named-field")
1567   DECLARE_HYDROGEN_ACCESSOR(LoadNamedField)
1568 };
1569
1570
1571 class LLoadNamedGeneric final : public LTemplateInstruction<1, 2, 1> {
1572  public:
1573   explicit LLoadNamedGeneric(LOperand* context, LOperand* object,
1574                              LOperand* vector) {
1575     inputs_[0] = context;
1576     inputs_[1] = object;
1577     temps_[0] = vector;
1578   }
1579
1580   DECLARE_CONCRETE_INSTRUCTION(LoadNamedGeneric, "load-named-generic")
1581   DECLARE_HYDROGEN_ACCESSOR(LoadNamedGeneric)
1582
1583   LOperand* context() { return inputs_[0]; }
1584   LOperand* object() { return inputs_[1]; }
1585   LOperand* temp_vector() { return temps_[0]; }
1586
1587   Handle<Object> name() const { return hydrogen()->name(); }
1588 };
1589
1590
1591 class LLoadFunctionPrototype final : public LTemplateInstruction<1, 1, 0> {
1592  public:
1593   explicit LLoadFunctionPrototype(LOperand* function) {
1594     inputs_[0] = function;
1595   }
1596
1597   DECLARE_CONCRETE_INSTRUCTION(LoadFunctionPrototype, "load-function-prototype")
1598   DECLARE_HYDROGEN_ACCESSOR(LoadFunctionPrototype)
1599
1600   LOperand* function() { return inputs_[0]; }
1601 };
1602
1603
1604 class LLoadRoot final : public LTemplateInstruction<1, 0, 0> {
1605  public:
1606   DECLARE_CONCRETE_INSTRUCTION(LoadRoot, "load-root")
1607   DECLARE_HYDROGEN_ACCESSOR(LoadRoot)
1608
1609   Heap::RootListIndex index() const { return hydrogen()->index(); }
1610 };
1611
1612
1613 inline static bool ExternalArrayOpRequiresTemp(
1614     Representation key_representation,
1615     ElementsKind elements_kind) {
1616   // Operations that require the key to be divided by two to be converted into
1617   // an index cannot fold the scale operation into a load and need an extra
1618   // temp register to do the work.
1619   return SmiValuesAre31Bits() && key_representation.IsSmi() &&
1620          (elements_kind == UINT8_ELEMENTS || elements_kind == INT8_ELEMENTS ||
1621           elements_kind == UINT8_CLAMPED_ELEMENTS);
1622 }
1623
1624
1625 class LLoadKeyed final : public LTemplateInstruction<1, 2, 0> {
1626  public:
1627   LLoadKeyed(LOperand* elements, LOperand* key) {
1628     inputs_[0] = elements;
1629     inputs_[1] = key;
1630   }
1631
1632   DECLARE_CONCRETE_INSTRUCTION(LoadKeyed, "load-keyed")
1633   DECLARE_HYDROGEN_ACCESSOR(LoadKeyed)
1634
1635   bool is_fixed_typed_array() const {
1636     return hydrogen()->is_fixed_typed_array();
1637   }
1638   LOperand* elements() { return inputs_[0]; }
1639   LOperand* key() { return inputs_[1]; }
1640   void PrintDataTo(StringStream* stream) override;
1641   uint32_t base_offset() const { return hydrogen()->base_offset(); }
1642   ElementsKind elements_kind() const {
1643     return hydrogen()->elements_kind();
1644   }
1645 };
1646
1647
1648 class LLoadKeyedGeneric final : public LTemplateInstruction<1, 3, 1> {
1649  public:
1650   LLoadKeyedGeneric(LOperand* context, LOperand* obj, LOperand* key,
1651                     LOperand* vector) {
1652     inputs_[0] = context;
1653     inputs_[1] = obj;
1654     inputs_[2] = key;
1655     temps_[0] = vector;
1656   }
1657
1658   DECLARE_CONCRETE_INSTRUCTION(LoadKeyedGeneric, "load-keyed-generic")
1659   DECLARE_HYDROGEN_ACCESSOR(LoadKeyedGeneric)
1660
1661   LOperand* context() { return inputs_[0]; }
1662   LOperand* object() { return inputs_[1]; }
1663   LOperand* key() { return inputs_[2]; }
1664   LOperand* temp_vector() { return temps_[0]; }
1665 };
1666
1667
1668 class LLoadGlobalGeneric final : public LTemplateInstruction<1, 2, 1> {
1669  public:
1670   explicit LLoadGlobalGeneric(LOperand* context, LOperand* global_object,
1671                               LOperand* vector) {
1672     inputs_[0] = context;
1673     inputs_[1] = global_object;
1674     temps_[0] = vector;
1675   }
1676
1677   DECLARE_CONCRETE_INSTRUCTION(LoadGlobalGeneric, "load-global-generic")
1678   DECLARE_HYDROGEN_ACCESSOR(LoadGlobalGeneric)
1679
1680   LOperand* context() { return inputs_[0]; }
1681   LOperand* global_object() { return inputs_[1]; }
1682   LOperand* temp_vector() { return temps_[0]; }
1683
1684   Handle<Object> name() const { return hydrogen()->name(); }
1685   TypeofMode typeof_mode() const { return hydrogen()->typeof_mode(); }
1686 };
1687
1688
1689 class LLoadGlobalViaContext final : public LTemplateInstruction<1, 1, 1> {
1690  public:
1691   explicit LLoadGlobalViaContext(LOperand* context) { inputs_[0] = context; }
1692
1693   DECLARE_CONCRETE_INSTRUCTION(LoadGlobalViaContext, "load-global-via-context")
1694   DECLARE_HYDROGEN_ACCESSOR(LoadGlobalViaContext)
1695
1696   void PrintDataTo(StringStream* stream) override;
1697
1698   LOperand* context() { return inputs_[0]; }
1699
1700   Handle<Object> name() const { return hydrogen()->name(); }
1701   int depth() const { return hydrogen()->depth(); }
1702   int slot_index() const { return hydrogen()->slot_index(); }
1703 };
1704
1705
1706 class LLoadContextSlot final : public LTemplateInstruction<1, 1, 0> {
1707  public:
1708   explicit LLoadContextSlot(LOperand* context) {
1709     inputs_[0] = context;
1710   }
1711
1712   LOperand* context() { return inputs_[0]; }
1713
1714   DECLARE_CONCRETE_INSTRUCTION(LoadContextSlot, "load-context-slot")
1715   DECLARE_HYDROGEN_ACCESSOR(LoadContextSlot)
1716
1717   int slot_index() { return hydrogen()->slot_index(); }
1718
1719   void PrintDataTo(StringStream* stream) override;
1720 };
1721
1722
1723 class LStoreContextSlot final : public LTemplateInstruction<0, 2, 1> {
1724  public:
1725   LStoreContextSlot(LOperand* context, LOperand* value, LOperand* temp) {
1726     inputs_[0] = context;
1727     inputs_[1] = value;
1728     temps_[0] = temp;
1729   }
1730
1731   LOperand* context() { return inputs_[0]; }
1732   LOperand* value() { return inputs_[1]; }
1733   LOperand* temp() { return temps_[0]; }
1734
1735   DECLARE_CONCRETE_INSTRUCTION(StoreContextSlot, "store-context-slot")
1736   DECLARE_HYDROGEN_ACCESSOR(StoreContextSlot)
1737
1738   int slot_index() { return hydrogen()->slot_index(); }
1739
1740   void PrintDataTo(StringStream* stream) override;
1741 };
1742
1743
1744 class LPushArgument final : public LTemplateInstruction<0, 1, 0> {
1745  public:
1746   explicit LPushArgument(LOperand* value) {
1747     inputs_[0] = value;
1748   }
1749
1750   LOperand* value() { return inputs_[0]; }
1751
1752   DECLARE_CONCRETE_INSTRUCTION(PushArgument, "push-argument")
1753 };
1754
1755
1756 class LDrop final : public LTemplateInstruction<0, 0, 0> {
1757  public:
1758   explicit LDrop(int count) : count_(count) { }
1759
1760   int count() const { return count_; }
1761
1762   DECLARE_CONCRETE_INSTRUCTION(Drop, "drop")
1763
1764  private:
1765   int count_;
1766 };
1767
1768
1769 class LStoreCodeEntry final : public LTemplateInstruction<0, 2, 0> {
1770  public:
1771   LStoreCodeEntry(LOperand* function, LOperand* code_object) {
1772     inputs_[0] = function;
1773     inputs_[1] = code_object;
1774   }
1775
1776   LOperand* function() { return inputs_[0]; }
1777   LOperand* code_object() { return inputs_[1]; }
1778
1779   void PrintDataTo(StringStream* stream) override;
1780
1781   DECLARE_CONCRETE_INSTRUCTION(StoreCodeEntry, "store-code-entry")
1782   DECLARE_HYDROGEN_ACCESSOR(StoreCodeEntry)
1783 };
1784
1785
1786 class LInnerAllocatedObject final : public LTemplateInstruction<1, 2, 0> {
1787  public:
1788   LInnerAllocatedObject(LOperand* base_object, LOperand* offset) {
1789     inputs_[0] = base_object;
1790     inputs_[1] = offset;
1791   }
1792
1793   LOperand* base_object() const { return inputs_[0]; }
1794   LOperand* offset() const { return inputs_[1]; }
1795
1796   void PrintDataTo(StringStream* stream) override;
1797
1798   DECLARE_CONCRETE_INSTRUCTION(InnerAllocatedObject, "inner-allocated-object")
1799 };
1800
1801
1802 class LThisFunction final : public LTemplateInstruction<1, 0, 0> {
1803  public:
1804   DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
1805   DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
1806 };
1807
1808
1809 class LContext final : public LTemplateInstruction<1, 0, 0> {
1810  public:
1811   DECLARE_CONCRETE_INSTRUCTION(Context, "context")
1812   DECLARE_HYDROGEN_ACCESSOR(Context)
1813 };
1814
1815
1816 class LDeclareGlobals final : public LTemplateInstruction<0, 1, 0> {
1817  public:
1818   explicit LDeclareGlobals(LOperand* context) {
1819     inputs_[0] = context;
1820   }
1821
1822   LOperand* context() { return inputs_[0]; }
1823
1824   DECLARE_CONCRETE_INSTRUCTION(DeclareGlobals, "declare-globals")
1825   DECLARE_HYDROGEN_ACCESSOR(DeclareGlobals)
1826 };
1827
1828
1829 class LCallJSFunction final : public LTemplateInstruction<1, 1, 0> {
1830  public:
1831   explicit LCallJSFunction(LOperand* function) {
1832     inputs_[0] = function;
1833   }
1834
1835   LOperand* function() { return inputs_[0]; }
1836
1837   DECLARE_CONCRETE_INSTRUCTION(CallJSFunction, "call-js-function")
1838   DECLARE_HYDROGEN_ACCESSOR(CallJSFunction)
1839
1840   void PrintDataTo(StringStream* stream) override;
1841
1842   int arity() const { return hydrogen()->argument_count() - 1; }
1843 };
1844
1845
1846 class LCallWithDescriptor final : public LTemplateResultInstruction<1> {
1847  public:
1848   LCallWithDescriptor(CallInterfaceDescriptor descriptor,
1849                       const ZoneList<LOperand*>& operands, Zone* zone)
1850       : inputs_(descriptor.GetRegisterParameterCount() +
1851                     kImplicitRegisterParameterCount,
1852                 zone) {
1853     DCHECK(descriptor.GetRegisterParameterCount() +
1854                kImplicitRegisterParameterCount ==
1855            operands.length());
1856     inputs_.AddAll(operands, zone);
1857   }
1858
1859   LOperand* target() const { return inputs_[0]; }
1860
1861   DECLARE_HYDROGEN_ACCESSOR(CallWithDescriptor)
1862
1863   // The target and context are passed as implicit parameters that are not
1864   // explicitly listed in the descriptor.
1865   static const int kImplicitRegisterParameterCount = 2;
1866
1867  private:
1868   DECLARE_CONCRETE_INSTRUCTION(CallWithDescriptor, "call-with-descriptor")
1869
1870   void PrintDataTo(StringStream* stream) override;
1871
1872   int arity() const { return hydrogen()->argument_count() - 1; }
1873
1874   ZoneList<LOperand*> inputs_;
1875
1876   // Iterator support.
1877   int InputCount() final { return inputs_.length(); }
1878   LOperand* InputAt(int i) final { return inputs_[i]; }
1879
1880   int TempCount() final { return 0; }
1881   LOperand* TempAt(int i) final { return NULL; }
1882 };
1883
1884
1885 class LInvokeFunction final : public LTemplateInstruction<1, 2, 0> {
1886  public:
1887   LInvokeFunction(LOperand* context, LOperand* function) {
1888     inputs_[0] = context;
1889     inputs_[1] = function;
1890   }
1891
1892   LOperand* context() { return inputs_[0]; }
1893   LOperand* function() { return inputs_[1]; }
1894
1895   DECLARE_CONCRETE_INSTRUCTION(InvokeFunction, "invoke-function")
1896   DECLARE_HYDROGEN_ACCESSOR(InvokeFunction)
1897
1898   void PrintDataTo(StringStream* stream) override;
1899
1900   int arity() const { return hydrogen()->argument_count() - 1; }
1901 };
1902
1903
1904 class LCallFunction final : public LTemplateInstruction<1, 2, 2> {
1905  public:
1906   LCallFunction(LOperand* context, LOperand* function, LOperand* slot,
1907                 LOperand* vector) {
1908     inputs_[0] = context;
1909     inputs_[1] = function;
1910     temps_[0] = slot;
1911     temps_[1] = vector;
1912   }
1913
1914   DECLARE_CONCRETE_INSTRUCTION(CallFunction, "call-function")
1915   DECLARE_HYDROGEN_ACCESSOR(CallFunction)
1916
1917   LOperand* context() { return inputs_[0]; }
1918   LOperand* function() { return inputs_[1]; }
1919   LOperand* temp_slot() { return temps_[0]; }
1920   LOperand* temp_vector() { return temps_[1]; }
1921   int arity() const { return hydrogen()->argument_count() - 1; }
1922
1923   void PrintDataTo(StringStream* stream) override;
1924 };
1925
1926
1927 class LCallNew final : public LTemplateInstruction<1, 2, 0> {
1928  public:
1929   LCallNew(LOperand* context, LOperand* constructor) {
1930     inputs_[0] = context;
1931     inputs_[1] = constructor;
1932   }
1933
1934   LOperand* context() { return inputs_[0]; }
1935   LOperand* constructor() { return inputs_[1]; }
1936
1937   DECLARE_CONCRETE_INSTRUCTION(CallNew, "call-new")
1938   DECLARE_HYDROGEN_ACCESSOR(CallNew)
1939
1940   void PrintDataTo(StringStream* stream) override;
1941
1942   int arity() const { return hydrogen()->argument_count() - 1; }
1943 };
1944
1945
1946 class LCallNewArray final : public LTemplateInstruction<1, 2, 0> {
1947  public:
1948   LCallNewArray(LOperand* context, LOperand* constructor) {
1949     inputs_[0] = context;
1950     inputs_[1] = constructor;
1951   }
1952
1953   LOperand* context() { return inputs_[0]; }
1954   LOperand* constructor() { return inputs_[1]; }
1955
1956   DECLARE_CONCRETE_INSTRUCTION(CallNewArray, "call-new-array")
1957   DECLARE_HYDROGEN_ACCESSOR(CallNewArray)
1958
1959   void PrintDataTo(StringStream* stream) override;
1960
1961   int arity() const { return hydrogen()->argument_count() - 1; }
1962 };
1963
1964
1965 class LCallRuntime final : public LTemplateInstruction<1, 1, 0> {
1966  public:
1967   explicit LCallRuntime(LOperand* context) {
1968     inputs_[0] = context;
1969   }
1970
1971   LOperand* context() { return inputs_[0]; }
1972
1973   DECLARE_CONCRETE_INSTRUCTION(CallRuntime, "call-runtime")
1974   DECLARE_HYDROGEN_ACCESSOR(CallRuntime)
1975
1976   bool ClobbersDoubleRegisters(Isolate* isolate) const override {
1977     return save_doubles() == kDontSaveFPRegs;
1978   }
1979
1980   const Runtime::Function* function() const { return hydrogen()->function(); }
1981   int arity() const { return hydrogen()->argument_count(); }
1982   SaveFPRegsMode save_doubles() const { return hydrogen()->save_doubles(); }
1983 };
1984
1985
1986 class LInteger32ToDouble final : public LTemplateInstruction<1, 1, 0> {
1987  public:
1988   explicit LInteger32ToDouble(LOperand* value) {
1989     inputs_[0] = value;
1990   }
1991
1992   LOperand* value() { return inputs_[0]; }
1993
1994   DECLARE_CONCRETE_INSTRUCTION(Integer32ToDouble, "int32-to-double")
1995 };
1996
1997
1998 class LUint32ToDouble final : public LTemplateInstruction<1, 1, 0> {
1999  public:
2000   explicit LUint32ToDouble(LOperand* value) {
2001     inputs_[0] = value;
2002   }
2003
2004   LOperand* value() { return inputs_[0]; }
2005
2006   DECLARE_CONCRETE_INSTRUCTION(Uint32ToDouble, "uint32-to-double")
2007 };
2008
2009
2010 class LNumberTagI final : public LTemplateInstruction<1, 1, 2> {
2011  public:
2012   LNumberTagI(LOperand* value, LOperand* temp1, LOperand* temp2) {
2013     inputs_[0] = value;
2014     temps_[0] = temp1;
2015     temps_[1] = temp2;
2016   }
2017
2018   LOperand* value() { return inputs_[0]; }
2019   LOperand* temp1() { return temps_[0]; }
2020   LOperand* temp2() { return temps_[1]; }
2021
2022   DECLARE_CONCRETE_INSTRUCTION(NumberTagI, "number-tag-i")
2023 };
2024
2025
2026 class LNumberTagU final : public LTemplateInstruction<1, 1, 2> {
2027  public:
2028   LNumberTagU(LOperand* value, LOperand* temp1, LOperand* temp2) {
2029     inputs_[0] = value;
2030     temps_[0] = temp1;
2031     temps_[1] = temp2;
2032   }
2033
2034   LOperand* value() { return inputs_[0]; }
2035   LOperand* temp1() { return temps_[0]; }
2036   LOperand* temp2() { return temps_[1]; }
2037
2038   DECLARE_CONCRETE_INSTRUCTION(NumberTagU, "number-tag-u")
2039 };
2040
2041
2042 class LNumberTagD final : public LTemplateInstruction<1, 1, 1> {
2043  public:
2044   explicit LNumberTagD(LOperand* value, LOperand* temp) {
2045     inputs_[0] = value;
2046     temps_[0] = temp;
2047   }
2048
2049   LOperand* value() { return inputs_[0]; }
2050   LOperand* temp() { return temps_[0]; }
2051
2052   DECLARE_CONCRETE_INSTRUCTION(NumberTagD, "number-tag-d")
2053   DECLARE_HYDROGEN_ACCESSOR(Change)
2054 };
2055
2056
2057 // Sometimes truncating conversion from a tagged value to an int32.
2058 class LDoubleToI final : public LTemplateInstruction<1, 1, 0> {
2059  public:
2060   explicit LDoubleToI(LOperand* value) {
2061     inputs_[0] = value;
2062   }
2063
2064   LOperand* value() { return inputs_[0]; }
2065
2066   DECLARE_CONCRETE_INSTRUCTION(DoubleToI, "double-to-i")
2067   DECLARE_HYDROGEN_ACCESSOR(UnaryOperation)
2068
2069   bool truncating() { return hydrogen()->CanTruncateToInt32(); }
2070 };
2071
2072
2073 class LDoubleToSmi final : public LTemplateInstruction<1, 1, 0> {
2074  public:
2075   explicit LDoubleToSmi(LOperand* value) {
2076     inputs_[0] = value;
2077   }
2078
2079   LOperand* value() { return inputs_[0]; }
2080
2081   DECLARE_CONCRETE_INSTRUCTION(DoubleToSmi, "double-to-smi")
2082   DECLARE_HYDROGEN_ACCESSOR(UnaryOperation)
2083 };
2084
2085
2086 // Truncating conversion from a tagged value to an int32.
2087 class LTaggedToI final : public LTemplateInstruction<1, 1, 1> {
2088  public:
2089   LTaggedToI(LOperand* value, LOperand* temp) {
2090     inputs_[0] = value;
2091     temps_[0] = temp;
2092   }
2093
2094   LOperand* value() { return inputs_[0]; }
2095   LOperand* temp() { return temps_[0]; }
2096
2097   DECLARE_CONCRETE_INSTRUCTION(TaggedToI, "tagged-to-i")
2098   DECLARE_HYDROGEN_ACCESSOR(Change)
2099
2100   bool truncating() { return hydrogen()->CanTruncateToInt32(); }
2101 };
2102
2103
2104 class LSmiTag final : public LTemplateInstruction<1, 1, 0> {
2105  public:
2106   explicit LSmiTag(LOperand* value) {
2107     inputs_[0] = value;
2108   }
2109
2110   LOperand* value() { return inputs_[0]; }
2111
2112   DECLARE_CONCRETE_INSTRUCTION(SmiTag, "smi-tag")
2113   DECLARE_HYDROGEN_ACCESSOR(Change)
2114 };
2115
2116
2117 class LNumberUntagD final : public LTemplateInstruction<1, 1, 0> {
2118  public:
2119   explicit LNumberUntagD(LOperand* value) {
2120     inputs_[0] = value;
2121   }
2122
2123   LOperand* value() { return inputs_[0]; }
2124
2125   DECLARE_CONCRETE_INSTRUCTION(NumberUntagD, "double-untag")
2126   DECLARE_HYDROGEN_ACCESSOR(Change);
2127 };
2128
2129
2130 class LSmiUntag final : public LTemplateInstruction<1, 1, 0> {
2131  public:
2132   LSmiUntag(LOperand* value, bool needs_check)
2133       : needs_check_(needs_check) {
2134     inputs_[0] = value;
2135   }
2136
2137   LOperand* value() { return inputs_[0]; }
2138   bool needs_check() const { return needs_check_; }
2139
2140   DECLARE_CONCRETE_INSTRUCTION(SmiUntag, "smi-untag")
2141
2142  private:
2143   bool needs_check_;
2144 };
2145
2146
2147 class LStoreNamedField final : public LTemplateInstruction<0, 2, 1> {
2148  public:
2149   LStoreNamedField(LOperand* object, LOperand* value, LOperand* temp) {
2150     inputs_[0] = object;
2151     inputs_[1] = value;
2152     temps_[0] = temp;
2153   }
2154
2155   LOperand* object() { return inputs_[0]; }
2156   LOperand* value() { return inputs_[1]; }
2157   LOperand* temp() { return temps_[0]; }
2158
2159   DECLARE_CONCRETE_INSTRUCTION(StoreNamedField, "store-named-field")
2160   DECLARE_HYDROGEN_ACCESSOR(StoreNamedField)
2161
2162   void PrintDataTo(StringStream* stream) override;
2163
2164   Representation representation() const {
2165     return hydrogen()->field_representation();
2166   }
2167 };
2168
2169
2170 class LStoreNamedGeneric final : public LTemplateInstruction<0, 3, 2> {
2171  public:
2172   LStoreNamedGeneric(LOperand* context, LOperand* object, LOperand* value,
2173                      LOperand* slot, LOperand* vector) {
2174     inputs_[0] = context;
2175     inputs_[1] = object;
2176     inputs_[2] = value;
2177     temps_[0] = slot;
2178     temps_[1] = vector;
2179   }
2180
2181   LOperand* context() { return inputs_[0]; }
2182   LOperand* object() { return inputs_[1]; }
2183   LOperand* value() { return inputs_[2]; }
2184   LOperand* temp_slot() { return temps_[0]; }
2185   LOperand* temp_vector() { return temps_[1]; }
2186
2187   DECLARE_CONCRETE_INSTRUCTION(StoreNamedGeneric, "store-named-generic")
2188   DECLARE_HYDROGEN_ACCESSOR(StoreNamedGeneric)
2189
2190   void PrintDataTo(StringStream* stream) override;
2191
2192   Handle<Object> name() const { return hydrogen()->name(); }
2193   LanguageMode language_mode() { return hydrogen()->language_mode(); }
2194 };
2195
2196
2197 class LStoreGlobalViaContext final : public LTemplateInstruction<0, 2, 0> {
2198  public:
2199   LStoreGlobalViaContext(LOperand* context, LOperand* value) {
2200     inputs_[0] = context;
2201     inputs_[1] = value;
2202   }
2203
2204   LOperand* context() { return inputs_[0]; }
2205   LOperand* value() { return inputs_[1]; }
2206
2207   DECLARE_CONCRETE_INSTRUCTION(StoreGlobalViaContext,
2208                                "store-global-via-context")
2209   DECLARE_HYDROGEN_ACCESSOR(StoreGlobalViaContext)
2210
2211   void PrintDataTo(StringStream* stream) override;
2212
2213   Handle<Object> name() const { return hydrogen()->name(); }
2214   int depth() { return hydrogen()->depth(); }
2215   int slot_index() { return hydrogen()->slot_index(); }
2216   LanguageMode language_mode() { return hydrogen()->language_mode(); }
2217 };
2218
2219
2220 class LStoreKeyed final : public LTemplateInstruction<0, 3, 0> {
2221  public:
2222   LStoreKeyed(LOperand* object, LOperand* key, LOperand* value) {
2223     inputs_[0] = object;
2224     inputs_[1] = key;
2225     inputs_[2] = value;
2226   }
2227
2228   bool is_fixed_typed_array() const {
2229     return hydrogen()->is_fixed_typed_array();
2230   }
2231   LOperand* elements() { return inputs_[0]; }
2232   LOperand* key() { return inputs_[1]; }
2233   LOperand* value() { return inputs_[2]; }
2234   ElementsKind elements_kind() const { return hydrogen()->elements_kind(); }
2235
2236   DECLARE_CONCRETE_INSTRUCTION(StoreKeyed, "store-keyed")
2237   DECLARE_HYDROGEN_ACCESSOR(StoreKeyed)
2238
2239   void PrintDataTo(StringStream* stream) override;
2240   bool NeedsCanonicalization() { return hydrogen()->NeedsCanonicalization(); }
2241   uint32_t base_offset() const { return hydrogen()->base_offset(); }
2242 };
2243
2244
2245 class LStoreKeyedGeneric final : public LTemplateInstruction<0, 4, 2> {
2246  public:
2247   LStoreKeyedGeneric(LOperand* context, LOperand* object, LOperand* key,
2248                      LOperand* value, LOperand* slot, LOperand* vector) {
2249     inputs_[0] = context;
2250     inputs_[1] = object;
2251     inputs_[2] = key;
2252     inputs_[3] = value;
2253     temps_[0] = slot;
2254     temps_[1] = vector;
2255   }
2256
2257   LOperand* context() { return inputs_[0]; }
2258   LOperand* object() { return inputs_[1]; }
2259   LOperand* key() { return inputs_[2]; }
2260   LOperand* value() { return inputs_[3]; }
2261   LOperand* temp_slot() { return temps_[0]; }
2262   LOperand* temp_vector() { return temps_[1]; }
2263
2264   DECLARE_CONCRETE_INSTRUCTION(StoreKeyedGeneric, "store-keyed-generic")
2265   DECLARE_HYDROGEN_ACCESSOR(StoreKeyedGeneric)
2266
2267   void PrintDataTo(StringStream* stream) override;
2268
2269   LanguageMode language_mode() { return hydrogen()->language_mode(); }
2270 };
2271
2272
2273 class LTransitionElementsKind final : public LTemplateInstruction<0, 2, 2> {
2274  public:
2275   LTransitionElementsKind(LOperand* object,
2276                           LOperand* context,
2277                           LOperand* new_map_temp,
2278                           LOperand* temp) {
2279     inputs_[0] = object;
2280     inputs_[1] = context;
2281     temps_[0] = new_map_temp;
2282     temps_[1] = temp;
2283   }
2284
2285   LOperand* object() { return inputs_[0]; }
2286   LOperand* context() { return inputs_[1]; }
2287   LOperand* new_map_temp() { return temps_[0]; }
2288   LOperand* temp() { return temps_[1]; }
2289
2290   DECLARE_CONCRETE_INSTRUCTION(TransitionElementsKind,
2291                                "transition-elements-kind")
2292   DECLARE_HYDROGEN_ACCESSOR(TransitionElementsKind)
2293
2294   void PrintDataTo(StringStream* stream) override;
2295
2296   Handle<Map> original_map() { return hydrogen()->original_map().handle(); }
2297   Handle<Map> transitioned_map() {
2298     return hydrogen()->transitioned_map().handle();
2299   }
2300   ElementsKind from_kind() { return hydrogen()->from_kind(); }
2301   ElementsKind to_kind() { return hydrogen()->to_kind(); }
2302 };
2303
2304
2305 class LTrapAllocationMemento final : public LTemplateInstruction<0, 1, 1> {
2306  public:
2307   LTrapAllocationMemento(LOperand* object,
2308                          LOperand* temp) {
2309     inputs_[0] = object;
2310     temps_[0] = temp;
2311   }
2312
2313   LOperand* object() { return inputs_[0]; }
2314   LOperand* temp() { return temps_[0]; }
2315
2316   DECLARE_CONCRETE_INSTRUCTION(TrapAllocationMemento,
2317                                "trap-allocation-memento")
2318 };
2319
2320
2321 class LMaybeGrowElements final : public LTemplateInstruction<1, 5, 0> {
2322  public:
2323   LMaybeGrowElements(LOperand* context, LOperand* object, LOperand* elements,
2324                      LOperand* key, LOperand* current_capacity) {
2325     inputs_[0] = context;
2326     inputs_[1] = object;
2327     inputs_[2] = elements;
2328     inputs_[3] = key;
2329     inputs_[4] = current_capacity;
2330   }
2331
2332   LOperand* context() { return inputs_[0]; }
2333   LOperand* object() { return inputs_[1]; }
2334   LOperand* elements() { return inputs_[2]; }
2335   LOperand* key() { return inputs_[3]; }
2336   LOperand* current_capacity() { return inputs_[4]; }
2337
2338   DECLARE_HYDROGEN_ACCESSOR(MaybeGrowElements)
2339   DECLARE_CONCRETE_INSTRUCTION(MaybeGrowElements, "maybe-grow-elements")
2340 };
2341
2342
2343 class LStringAdd final : public LTemplateInstruction<1, 3, 0> {
2344  public:
2345   LStringAdd(LOperand* context, LOperand* left, LOperand* right) {
2346     inputs_[0] = context;
2347     inputs_[1] = left;
2348     inputs_[2] = right;
2349   }
2350
2351   LOperand* context() { return inputs_[0]; }
2352   LOperand* left() { return inputs_[1]; }
2353   LOperand* right() { return inputs_[2]; }
2354
2355   DECLARE_CONCRETE_INSTRUCTION(StringAdd, "string-add")
2356   DECLARE_HYDROGEN_ACCESSOR(StringAdd)
2357 };
2358
2359
2360 class LStringCharCodeAt final : public LTemplateInstruction<1, 3, 0> {
2361  public:
2362   LStringCharCodeAt(LOperand* context, LOperand* string, LOperand* index) {
2363     inputs_[0] = context;
2364     inputs_[1] = string;
2365     inputs_[2] = index;
2366   }
2367
2368   LOperand* context() { return inputs_[0]; }
2369   LOperand* string() { return inputs_[1]; }
2370   LOperand* index() { return inputs_[2]; }
2371
2372   DECLARE_CONCRETE_INSTRUCTION(StringCharCodeAt, "string-char-code-at")
2373   DECLARE_HYDROGEN_ACCESSOR(StringCharCodeAt)
2374 };
2375
2376
2377 class LStringCharFromCode final : public LTemplateInstruction<1, 2, 0> {
2378  public:
2379   explicit LStringCharFromCode(LOperand* context, LOperand* char_code) {
2380     inputs_[0] = context;
2381     inputs_[1] = char_code;
2382   }
2383
2384   LOperand* context() { return inputs_[0]; }
2385   LOperand* char_code() { return inputs_[1]; }
2386
2387   DECLARE_CONCRETE_INSTRUCTION(StringCharFromCode, "string-char-from-code")
2388   DECLARE_HYDROGEN_ACCESSOR(StringCharFromCode)
2389 };
2390
2391
2392 class LCheckValue final : public LTemplateInstruction<0, 1, 0> {
2393  public:
2394   explicit LCheckValue(LOperand* value) {
2395     inputs_[0] = value;
2396   }
2397
2398   LOperand* value() { return inputs_[0]; }
2399
2400   DECLARE_CONCRETE_INSTRUCTION(CheckValue, "check-value")
2401   DECLARE_HYDROGEN_ACCESSOR(CheckValue)
2402 };
2403
2404
2405 class LCheckArrayBufferNotNeutered final
2406     : public LTemplateInstruction<0, 1, 0> {
2407  public:
2408   explicit LCheckArrayBufferNotNeutered(LOperand* view) { inputs_[0] = view; }
2409
2410   LOperand* view() { return inputs_[0]; }
2411
2412   DECLARE_CONCRETE_INSTRUCTION(CheckArrayBufferNotNeutered,
2413                                "check-array-buffer-not-neutered")
2414   DECLARE_HYDROGEN_ACCESSOR(CheckArrayBufferNotNeutered)
2415 };
2416
2417
2418 class LCheckInstanceType final : public LTemplateInstruction<0, 1, 0> {
2419  public:
2420   explicit LCheckInstanceType(LOperand* value) {
2421     inputs_[0] = value;
2422   }
2423
2424   LOperand* value() { return inputs_[0]; }
2425
2426   DECLARE_CONCRETE_INSTRUCTION(CheckInstanceType, "check-instance-type")
2427   DECLARE_HYDROGEN_ACCESSOR(CheckInstanceType)
2428 };
2429
2430
2431 class LCheckMaps final : public LTemplateInstruction<0, 1, 0> {
2432  public:
2433   explicit LCheckMaps(LOperand* value = NULL) {
2434     inputs_[0] = value;
2435   }
2436
2437   LOperand* value() { return inputs_[0]; }
2438
2439   DECLARE_CONCRETE_INSTRUCTION(CheckMaps, "check-maps")
2440   DECLARE_HYDROGEN_ACCESSOR(CheckMaps)
2441 };
2442
2443
2444 class LCheckSmi final : public LTemplateInstruction<1, 1, 0> {
2445  public:
2446   explicit LCheckSmi(LOperand* value) {
2447     inputs_[0] = value;
2448   }
2449
2450   LOperand* value() { return inputs_[0]; }
2451
2452   DECLARE_CONCRETE_INSTRUCTION(CheckSmi, "check-smi")
2453 };
2454
2455
2456 class LClampDToUint8 final : public LTemplateInstruction<1, 1, 0> {
2457  public:
2458   explicit LClampDToUint8(LOperand* unclamped) {
2459     inputs_[0] = unclamped;
2460   }
2461
2462   LOperand* unclamped() { return inputs_[0]; }
2463
2464   DECLARE_CONCRETE_INSTRUCTION(ClampDToUint8, "clamp-d-to-uint8")
2465 };
2466
2467
2468 class LClampIToUint8 final : public LTemplateInstruction<1, 1, 0> {
2469  public:
2470   explicit LClampIToUint8(LOperand* unclamped) {
2471     inputs_[0] = unclamped;
2472   }
2473
2474   LOperand* unclamped() { return inputs_[0]; }
2475
2476   DECLARE_CONCRETE_INSTRUCTION(ClampIToUint8, "clamp-i-to-uint8")
2477 };
2478
2479
2480 class LClampTToUint8 final : public LTemplateInstruction<1, 1, 1> {
2481  public:
2482   LClampTToUint8(LOperand* unclamped,
2483                  LOperand* temp_xmm) {
2484     inputs_[0] = unclamped;
2485     temps_[0] = temp_xmm;
2486   }
2487
2488   LOperand* unclamped() { return inputs_[0]; }
2489   LOperand* temp_xmm() { return temps_[0]; }
2490
2491   DECLARE_CONCRETE_INSTRUCTION(ClampTToUint8, "clamp-t-to-uint8")
2492 };
2493
2494
2495 class LCheckNonSmi final : public LTemplateInstruction<0, 1, 0> {
2496  public:
2497   explicit LCheckNonSmi(LOperand* value) {
2498     inputs_[0] = value;
2499   }
2500
2501   LOperand* value() { return inputs_[0]; }
2502
2503   DECLARE_CONCRETE_INSTRUCTION(CheckNonSmi, "check-non-smi")
2504   DECLARE_HYDROGEN_ACCESSOR(CheckHeapObject)
2505 };
2506
2507
2508 class LDoubleBits final : public LTemplateInstruction<1, 1, 0> {
2509  public:
2510   explicit LDoubleBits(LOperand* value) {
2511     inputs_[0] = value;
2512   }
2513
2514   LOperand* value() { return inputs_[0]; }
2515
2516   DECLARE_CONCRETE_INSTRUCTION(DoubleBits, "double-bits")
2517   DECLARE_HYDROGEN_ACCESSOR(DoubleBits)
2518 };
2519
2520
2521 class LConstructDouble final : public LTemplateInstruction<1, 2, 0> {
2522  public:
2523   LConstructDouble(LOperand* hi, LOperand* lo) {
2524     inputs_[0] = hi;
2525     inputs_[1] = lo;
2526   }
2527
2528   LOperand* hi() { return inputs_[0]; }
2529   LOperand* lo() { return inputs_[1]; }
2530
2531   DECLARE_CONCRETE_INSTRUCTION(ConstructDouble, "construct-double")
2532 };
2533
2534
2535 class LAllocate final : public LTemplateInstruction<1, 2, 1> {
2536  public:
2537   LAllocate(LOperand* context, LOperand* size, LOperand* temp) {
2538     inputs_[0] = context;
2539     inputs_[1] = size;
2540     temps_[0] = temp;
2541   }
2542
2543   LOperand* context() { return inputs_[0]; }
2544   LOperand* size() { return inputs_[1]; }
2545   LOperand* temp() { return temps_[0]; }
2546
2547   DECLARE_CONCRETE_INSTRUCTION(Allocate, "allocate")
2548   DECLARE_HYDROGEN_ACCESSOR(Allocate)
2549 };
2550
2551
2552 class LRegExpLiteral final : public LTemplateInstruction<1, 1, 0> {
2553  public:
2554   explicit LRegExpLiteral(LOperand* context) {
2555     inputs_[0] = context;
2556   }
2557
2558   LOperand* context() { return inputs_[0]; }
2559
2560   DECLARE_CONCRETE_INSTRUCTION(RegExpLiteral, "regexp-literal")
2561   DECLARE_HYDROGEN_ACCESSOR(RegExpLiteral)
2562 };
2563
2564
2565 class LFunctionLiteral final : public LTemplateInstruction<1, 1, 0> {
2566  public:
2567   explicit LFunctionLiteral(LOperand* context) {
2568     inputs_[0] = context;
2569   }
2570
2571   LOperand* context() { return inputs_[0]; }
2572
2573   DECLARE_CONCRETE_INSTRUCTION(FunctionLiteral, "function-literal")
2574   DECLARE_HYDROGEN_ACCESSOR(FunctionLiteral)
2575 };
2576
2577
2578 class LToFastProperties final : public LTemplateInstruction<1, 1, 0> {
2579  public:
2580   explicit LToFastProperties(LOperand* value) {
2581     inputs_[0] = value;
2582   }
2583
2584   LOperand* value() { return inputs_[0]; }
2585
2586   DECLARE_CONCRETE_INSTRUCTION(ToFastProperties, "to-fast-properties")
2587   DECLARE_HYDROGEN_ACCESSOR(ToFastProperties)
2588 };
2589
2590
2591 class LTypeof final : public LTemplateInstruction<1, 2, 0> {
2592  public:
2593   LTypeof(LOperand* context, LOperand* value) {
2594     inputs_[0] = context;
2595     inputs_[1] = value;
2596   }
2597
2598   LOperand* context() { return inputs_[0]; }
2599   LOperand* value() { return inputs_[1]; }
2600
2601   DECLARE_CONCRETE_INSTRUCTION(Typeof, "typeof")
2602 };
2603
2604
2605 class LTypeofIsAndBranch final : public LControlInstruction<1, 0> {
2606  public:
2607   explicit LTypeofIsAndBranch(LOperand* value) {
2608     inputs_[0] = value;
2609   }
2610
2611   LOperand* value() { return inputs_[0]; }
2612
2613   DECLARE_CONCRETE_INSTRUCTION(TypeofIsAndBranch, "typeof-is-and-branch")
2614   DECLARE_HYDROGEN_ACCESSOR(TypeofIsAndBranch)
2615
2616   Handle<String> type_literal() { return hydrogen()->type_literal(); }
2617
2618   void PrintDataTo(StringStream* stream) override;
2619 };
2620
2621
2622 class LIsConstructCallAndBranch final : public LControlInstruction<0, 1> {
2623  public:
2624   explicit LIsConstructCallAndBranch(LOperand* temp) {
2625     temps_[0] = temp;
2626   }
2627
2628   LOperand* temp() { return temps_[0]; }
2629
2630   DECLARE_CONCRETE_INSTRUCTION(IsConstructCallAndBranch,
2631                                "is-construct-call-and-branch")
2632   DECLARE_HYDROGEN_ACCESSOR(IsConstructCallAndBranch)
2633 };
2634
2635
2636 class LOsrEntry final : public LTemplateInstruction<0, 0, 0> {
2637  public:
2638   LOsrEntry() {}
2639
2640   bool HasInterestingComment(LCodeGen* gen) const override { return false; }
2641   DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr-entry")
2642 };
2643
2644
2645 class LStackCheck final : public LTemplateInstruction<0, 1, 0> {
2646  public:
2647   explicit LStackCheck(LOperand* context) {
2648     inputs_[0] = context;
2649   }
2650
2651   LOperand* context() { return inputs_[0]; }
2652
2653   DECLARE_CONCRETE_INSTRUCTION(StackCheck, "stack-check")
2654   DECLARE_HYDROGEN_ACCESSOR(StackCheck)
2655
2656   Label* done_label() { return &done_label_; }
2657
2658  private:
2659   Label done_label_;
2660 };
2661
2662
2663 class LForInPrepareMap final : public LTemplateInstruction<1, 2, 0> {
2664  public:
2665   LForInPrepareMap(LOperand* context, LOperand* object) {
2666     inputs_[0] = context;
2667     inputs_[1] = object;
2668   }
2669
2670   LOperand* context() { return inputs_[0]; }
2671   LOperand* object() { return inputs_[1]; }
2672
2673   DECLARE_CONCRETE_INSTRUCTION(ForInPrepareMap, "for-in-prepare-map")
2674 };
2675
2676
2677 class LForInCacheArray final : public LTemplateInstruction<1, 1, 0> {
2678  public:
2679   explicit LForInCacheArray(LOperand* map) {
2680     inputs_[0] = map;
2681   }
2682
2683   LOperand* map() { return inputs_[0]; }
2684
2685   DECLARE_CONCRETE_INSTRUCTION(ForInCacheArray, "for-in-cache-array")
2686
2687   int idx() {
2688     return HForInCacheArray::cast(this->hydrogen_value())->idx();
2689   }
2690 };
2691
2692
2693 class LCheckMapValue final : public LTemplateInstruction<0, 2, 0> {
2694  public:
2695   LCheckMapValue(LOperand* value, LOperand* map) {
2696     inputs_[0] = value;
2697     inputs_[1] = map;
2698   }
2699
2700   LOperand* value() { return inputs_[0]; }
2701   LOperand* map() { return inputs_[1]; }
2702
2703   DECLARE_CONCRETE_INSTRUCTION(CheckMapValue, "check-map-value")
2704 };
2705
2706
2707 class LLoadFieldByIndex final : public LTemplateInstruction<1, 2, 0> {
2708  public:
2709   LLoadFieldByIndex(LOperand* object, LOperand* index) {
2710     inputs_[0] = object;
2711     inputs_[1] = index;
2712   }
2713
2714   LOperand* object() { return inputs_[0]; }
2715   LOperand* index() { return inputs_[1]; }
2716
2717   DECLARE_CONCRETE_INSTRUCTION(LoadFieldByIndex, "load-field-by-index")
2718 };
2719
2720
2721 class LStoreFrameContext: public LTemplateInstruction<0, 1, 0> {
2722  public:
2723   explicit LStoreFrameContext(LOperand* context) {
2724     inputs_[0] = context;
2725   }
2726
2727   LOperand* context() { return inputs_[0]; }
2728
2729   DECLARE_CONCRETE_INSTRUCTION(StoreFrameContext, "store-frame-context")
2730 };
2731
2732
2733 class LAllocateBlockContext: public LTemplateInstruction<1, 2, 0> {
2734  public:
2735   LAllocateBlockContext(LOperand* context, LOperand* function) {
2736     inputs_[0] = context;
2737     inputs_[1] = function;
2738   }
2739
2740   LOperand* context() { return inputs_[0]; }
2741   LOperand* function() { return inputs_[1]; }
2742
2743   Handle<ScopeInfo> scope_info() { return hydrogen()->scope_info(); }
2744
2745   DECLARE_CONCRETE_INSTRUCTION(AllocateBlockContext, "allocate-block-context")
2746   DECLARE_HYDROGEN_ACCESSOR(AllocateBlockContext)
2747 };
2748
2749
2750 class LChunkBuilder;
2751 class LPlatformChunk final : public LChunk {
2752  public:
2753   LPlatformChunk(CompilationInfo* info, HGraph* graph)
2754       : LChunk(info, graph),
2755         dehoisted_key_ids_(graph->GetMaximumValueID(), graph->zone()) { }
2756
2757   int GetNextSpillIndex(RegisterKind kind);
2758   LOperand* GetNextSpillSlot(RegisterKind kind);
2759   BitVector* GetDehoistedKeyIds() { return &dehoisted_key_ids_; }
2760   bool IsDehoistedKey(HValue* value) {
2761     return dehoisted_key_ids_.Contains(value->id());
2762   }
2763
2764  private:
2765   BitVector dehoisted_key_ids_;
2766 };
2767
2768
2769 class LChunkBuilder final : public LChunkBuilderBase {
2770  public:
2771   LChunkBuilder(CompilationInfo* info, HGraph* graph, LAllocator* allocator)
2772       : LChunkBuilderBase(info, graph),
2773         current_instruction_(NULL),
2774         current_block_(NULL),
2775         next_block_(NULL),
2776         allocator_(allocator) {}
2777
2778   // Build the sequence for the graph.
2779   LPlatformChunk* Build();
2780
2781   // Declare methods that deal with the individual node types.
2782 #define DECLARE_DO(type) LInstruction* Do##type(H##type* node);
2783   HYDROGEN_CONCRETE_INSTRUCTION_LIST(DECLARE_DO)
2784 #undef DECLARE_DO
2785
2786   LInstruction* DoMathFloor(HUnaryMathOperation* instr);
2787   LInstruction* DoMathRound(HUnaryMathOperation* instr);
2788   LInstruction* DoMathFround(HUnaryMathOperation* instr);
2789   LInstruction* DoMathAbs(HUnaryMathOperation* instr);
2790   LInstruction* DoMathLog(HUnaryMathOperation* instr);
2791   LInstruction* DoMathExp(HUnaryMathOperation* instr);
2792   LInstruction* DoMathSqrt(HUnaryMathOperation* instr);
2793   LInstruction* DoMathPowHalf(HUnaryMathOperation* instr);
2794   LInstruction* DoMathClz32(HUnaryMathOperation* instr);
2795   LInstruction* DoDivByPowerOf2I(HDiv* instr);
2796   LInstruction* DoDivByConstI(HDiv* instr);
2797   LInstruction* DoDivI(HDiv* instr);
2798   LInstruction* DoModByPowerOf2I(HMod* instr);
2799   LInstruction* DoModByConstI(HMod* instr);
2800   LInstruction* DoModI(HMod* instr);
2801   LInstruction* DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr);
2802   LInstruction* DoFlooringDivByConstI(HMathFloorOfDiv* instr);
2803   LInstruction* DoFlooringDivI(HMathFloorOfDiv* instr);
2804
2805  private:
2806   // Methods for getting operands for Use / Define / Temp.
2807   LUnallocated* ToUnallocated(Register reg);
2808   LUnallocated* ToUnallocated(XMMRegister reg);
2809
2810   // Methods for setting up define-use relationships.
2811   MUST_USE_RESULT LOperand* Use(HValue* value, LUnallocated* operand);
2812   MUST_USE_RESULT LOperand* UseFixed(HValue* value, Register fixed_register);
2813   MUST_USE_RESULT LOperand* UseFixedDouble(HValue* value,
2814                                            XMMRegister fixed_register);
2815
2816   // A value that is guaranteed to be allocated to a register.
2817   // Operand created by UseRegister is guaranteed to be live until the end of
2818   // instruction. This means that register allocator will not reuse it's
2819   // register for any other operand inside instruction.
2820   // Operand created by UseRegisterAtStart is guaranteed to be live only at
2821   // instruction start. Register allocator is free to assign the same register
2822   // to some other operand used inside instruction (i.e. temporary or
2823   // output).
2824   MUST_USE_RESULT LOperand* UseRegister(HValue* value);
2825   MUST_USE_RESULT LOperand* UseRegisterAtStart(HValue* value);
2826
2827   // An input operand in a register that may be trashed.
2828   MUST_USE_RESULT LOperand* UseTempRegister(HValue* value);
2829
2830   // An input operand in a register that may be trashed or a constant operand.
2831   MUST_USE_RESULT LOperand* UseTempRegisterOrConstant(HValue* value);
2832
2833   // An input operand in a register or stack slot.
2834   MUST_USE_RESULT LOperand* Use(HValue* value);
2835   MUST_USE_RESULT LOperand* UseAtStart(HValue* value);
2836
2837   // An input operand in a register, stack slot or a constant operand.
2838   MUST_USE_RESULT LOperand* UseOrConstant(HValue* value);
2839   MUST_USE_RESULT LOperand* UseOrConstantAtStart(HValue* value);
2840
2841   // An input operand in a register or a constant operand.
2842   MUST_USE_RESULT LOperand* UseRegisterOrConstant(HValue* value);
2843   MUST_USE_RESULT LOperand* UseRegisterOrConstantAtStart(HValue* value);
2844
2845   // An input operand in a constant operand.
2846   MUST_USE_RESULT LOperand* UseConstant(HValue* value);
2847
2848   // An input operand in register, stack slot or a constant operand.
2849   // Will not be moved to a register even if one is freely available.
2850   MUST_USE_RESULT LOperand* UseAny(HValue* value) override;
2851
2852   // Temporary operand that must be in a register.
2853   MUST_USE_RESULT LUnallocated* TempRegister();
2854   MUST_USE_RESULT LOperand* FixedTemp(Register reg);
2855   MUST_USE_RESULT LOperand* FixedTemp(XMMRegister reg);
2856
2857   // Methods for setting up define-use relationships.
2858   // Return the same instruction that they are passed.
2859   LInstruction* Define(LTemplateResultInstruction<1>* instr,
2860                        LUnallocated* result);
2861   LInstruction* DefineAsRegister(LTemplateResultInstruction<1>* instr);
2862   LInstruction* DefineAsSpilled(LTemplateResultInstruction<1>* instr,
2863                                 int index);
2864   LInstruction* DefineSameAsFirst(LTemplateResultInstruction<1>* instr);
2865   LInstruction* DefineFixed(LTemplateResultInstruction<1>* instr,
2866                             Register reg);
2867   LInstruction* DefineFixedDouble(LTemplateResultInstruction<1>* instr,
2868                                   XMMRegister reg);
2869   // Assigns an environment to an instruction.  An instruction which can
2870   // deoptimize must have an environment.
2871   LInstruction* AssignEnvironment(LInstruction* instr);
2872   // Assigns a pointer map to an instruction.  An instruction which can
2873   // trigger a GC or a lazy deoptimization must have a pointer map.
2874   LInstruction* AssignPointerMap(LInstruction* instr);
2875
2876   enum CanDeoptimize { CAN_DEOPTIMIZE_EAGERLY, CANNOT_DEOPTIMIZE_EAGERLY };
2877
2878   // Marks a call for the register allocator.  Assigns a pointer map to
2879   // support GC and lazy deoptimization.  Assigns an environment to support
2880   // eager deoptimization if CAN_DEOPTIMIZE_EAGERLY.
2881   LInstruction* MarkAsCall(
2882       LInstruction* instr,
2883       HInstruction* hinstr,
2884       CanDeoptimize can_deoptimize = CANNOT_DEOPTIMIZE_EAGERLY);
2885
2886   void VisitInstruction(HInstruction* current);
2887   void AddInstruction(LInstruction* instr, HInstruction* current);
2888
2889   void DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block);
2890   LInstruction* DoShift(Token::Value op, HBitwiseBinaryOperation* instr);
2891   LInstruction* DoArithmeticD(Token::Value op,
2892                               HArithmeticBinaryOperation* instr);
2893   LInstruction* DoArithmeticT(Token::Value op,
2894                               HBinaryOperation* instr);
2895   void FindDehoistedKeyDefinitions(HValue* candidate);
2896
2897   HInstruction* current_instruction_;
2898   HBasicBlock* current_block_;
2899   HBasicBlock* next_block_;
2900   LAllocator* allocator_;
2901
2902   DISALLOW_COPY_AND_ASSIGN(LChunkBuilder);
2903 };
2904
2905 #undef DECLARE_HYDROGEN_ACCESSOR
2906 #undef DECLARE_CONCRETE_INSTRUCTION
2907
2908 } }  // namespace v8::int
2909
2910 #endif  // V8_X64_LITHIUM_X64_H_