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