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