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