Chromium Code Reviews| Index: src/hydrogen-instructions.h |
| =================================================================== |
| --- src/hydrogen-instructions.h (revision 8196) |
| +++ src/hydrogen-instructions.h (working copy) |
| @@ -35,6 +35,7 @@ |
| #include "data-flow.h" |
| #include "small-pointer-list.h" |
| #include "string-stream.h" |
| +#include "utils.h" |
| #include "zone.h" |
| namespace v8 { |
| @@ -761,80 +762,69 @@ |
| }; |
| -class HControlInstruction: public HInstruction { |
| +template<int V> |
| +class HTemplateInstruction : public HInstruction { |
| public: |
| - HControlInstruction(HBasicBlock* first, HBasicBlock* second) |
| - : first_successor_(first), second_successor_(second) { |
| - } |
| + int OperandCount() { return V; } |
| + HValue* OperandAt(int i) { return inputs_[i]; } |
| - HBasicBlock* FirstSuccessor() const { return first_successor_; } |
| - HBasicBlock* SecondSuccessor() const { return second_successor_; } |
| + protected: |
| + void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } |
| - virtual void PrintDataTo(StringStream* stream); |
| - |
| - DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction) |
| - |
| private: |
| - HBasicBlock* first_successor_; |
| - HBasicBlock* second_successor_; |
| + EmbeddedContainer<HValue*, V> inputs_; |
| }; |
| -template<int NumElements> |
| -class HOperandContainer { |
| +class HControlInstruction: public HInstruction { |
| public: |
| - HOperandContainer() : elems_() { } |
| + virtual HBasicBlock* SuccessorAt(int i) = 0; |
| + virtual int SuccessorCount() = 0; |
| - int length() { return NumElements; } |
| - HValue*& operator[](int i) { |
| - ASSERT(i < length()); |
| - return elems_[i]; |
| + virtual void PrintDataTo(StringStream* stream); |
| + |
| + HBasicBlock* FirstSuccessor() { |
| + return SuccessorCount() > 0 ? SuccessorAt(0) : NULL; |
| } |
| + HBasicBlock* SecondSuccessor() { |
| + return SuccessorCount() > 1 ? SuccessorAt(1) : NULL; |
| + } |
| - private: |
| - HValue* elems_[NumElements]; |
| + DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction) |
| }; |
| -template<> |
| -class HOperandContainer<0> { |
| +class HSuccessorIterator BASE_EMBEDDED { |
| public: |
| - int length() { return 0; } |
| - HValue*& operator[](int i) { |
| - UNREACHABLE(); |
| - static HValue* t = 0; |
| - return t; |
| - } |
| -}; |
| + explicit HSuccessorIterator(HControlInstruction* instr) |
| + : instr_(instr), next_(0) { } |
| + bool HasNext() { return next_ < instr_->SuccessorCount(); } |
|
Kevin Millikin (Chromium)
2011/06/10 11:39:15
Most of the existing hydrogen/lithium iterators ha
fschneider
2011/06/10 12:09:36
Done.
|
| + HBasicBlock* Next() { return instr_->SuccessorAt(next_); } |
| + void Advance() { next_++; } |
| -template<int V> |
| -class HTemplateInstruction : public HInstruction { |
| - public: |
| - int OperandCount() { return V; } |
| - HValue* OperandAt(int i) { return inputs_[i]; } |
| - |
| - protected: |
| - void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } |
| - |
| private: |
| - HOperandContainer<V> inputs_; |
| + HControlInstruction* instr_; |
| + int next_; |
| }; |
| -template<int V> |
| -class HTemplateControlInstruction : public HControlInstruction { |
| +template<int S, int V> |
| +class HTemplateControlInstruction: public HControlInstruction { |
| public: |
| - HTemplateControlInstruction<V>(HBasicBlock* first, HBasicBlock* second) |
| - : HControlInstruction(first, second) { } |
| + int SuccessorCount() { return S; } |
| + HBasicBlock* SuccessorAt(int i) { return successors_[i]; } |
| + |
| int OperandCount() { return V; } |
| HValue* OperandAt(int i) { return inputs_[i]; } |
| protected: |
| + void SetSuccessorAt(int i, HBasicBlock* block) { successors_[i] = block; } |
| void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } |
| private: |
| - HOperandContainer<V> inputs_; |
| + EmbeddedContainer<HBasicBlock*, S> successors_; |
| + EmbeddedContainer<HValue*, V> inputs_; |
| }; |
| @@ -861,11 +851,9 @@ |
| }; |
| -class HDeoptimize: public HControlInstruction { |
| +class HDeoptimize : public HControlInstruction { |
|
Kevin Millikin (Chromium)
2011/06/10 11:39:15
The rest of this file, with only a coupld of excep
fschneider
2011/06/10 12:09:36
Done.
|
| public: |
| - explicit HDeoptimize(int environment_length) |
| - : HControlInstruction(NULL, NULL), |
| - values_(environment_length) { } |
| + explicit HDeoptimize(int environment_length) : values_(environment_length) { } |
| virtual Representation RequiredInputRepresentation(int index) const { |
| return Representation::None(); |
| @@ -875,6 +863,12 @@ |
| virtual HValue* OperandAt(int index) { return values_[index]; } |
| virtual void PrintDataTo(StringStream* stream); |
| + virtual int SuccessorCount() { return 0; } |
| + virtual HBasicBlock* SuccessorAt(int i) { |
| + UNREACHABLE(); |
| + return NULL; |
| + } |
| + |
| void AddEnvironmentValue(HValue* value) { |
| values_.Add(NULL); |
| SetOperandAt(values_.length() - 1, value); |
| @@ -897,11 +891,12 @@ |
| }; |
| -class HGoto: public HTemplateControlInstruction<0> { |
| +class HGoto: public HTemplateControlInstruction<1, 0> { |
| public: |
| explicit HGoto(HBasicBlock* target) |
| - : HTemplateControlInstruction<0>(target, NULL), |
| - include_stack_check_(false) { } |
| + : include_stack_check_(false) { |
| + SetSuccessorAt(0, target); |
| + } |
| void set_include_stack_check(bool include_stack_check) { |
| include_stack_check_ = include_stack_check; |
| @@ -919,13 +914,14 @@ |
| }; |
| -class HUnaryControlInstruction: public HTemplateControlInstruction<1> { |
| +class HUnaryControlInstruction: public HTemplateControlInstruction<2, 1> { |
| public: |
| - explicit HUnaryControlInstruction(HValue* value, |
| - HBasicBlock* true_target, |
| - HBasicBlock* false_target) |
| - : HTemplateControlInstruction<1>(true_target, false_target) { |
| + HUnaryControlInstruction(HValue* value, |
| + HBasicBlock* true_target, |
| + HBasicBlock* false_target) { |
| SetOperandAt(0, value); |
| + SetSuccessorAt(0, true_target); |
| + SetSuccessorAt(1, false_target); |
| } |
| virtual void PrintDataTo(StringStream* stream); |
| @@ -977,24 +973,26 @@ |
| }; |
| -class HReturn: public HUnaryControlInstruction { |
| +class HReturn: public HTemplateControlInstruction<0, 1> { |
| public: |
| - explicit HReturn(HValue* value) |
| - : HUnaryControlInstruction(value, NULL, NULL) { |
| + explicit HReturn(HValue* value) { |
| + SetOperandAt(0, value); |
| } |
| virtual Representation RequiredInputRepresentation(int index) const { |
| return Representation::Tagged(); |
| } |
| + virtual void PrintDataTo(StringStream* stream); |
| + |
| + HValue* value() { return OperandAt(0); } |
| + |
| DECLARE_CONCRETE_INSTRUCTION(Return) |
| }; |
| -class HAbnormalExit: public HTemplateControlInstruction<0> { |
| +class HAbnormalExit: public HTemplateControlInstruction<0, 0> { |
| public: |
| - HAbnormalExit() : HTemplateControlInstruction<0>(NULL, NULL) { } |
| - |
| virtual Representation RequiredInputRepresentation(int index) const { |
| return Representation::None(); |
| } |