Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Unified Diff: src/hydrogen-instructions.h

Issue 7008011: First step in refactoring hydrogen control instructions. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen.cc ('k') | src/lithium-allocator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen-instructions.h
===================================================================
--- src/hydrogen-instructions.h (revision 8054)
+++ src/hydrogen-instructions.h (working copy)
@@ -759,46 +759,60 @@
class HControlInstruction: public HInstruction {
public:
- HControlInstruction(HBasicBlock* first, HBasicBlock* second)
- : first_successor_(first), second_successor_(second) {
- }
+ virtual HBasicBlock* SuccessorAt(int i) = 0;
+ virtual int SuccessorCount() = 0;
- HBasicBlock* FirstSuccessor() const { return first_successor_; }
- HBasicBlock* SecondSuccessor() const { return second_successor_; }
-
virtual void PrintDataTo(StringStream* stream);
+ HBasicBlock* FirstSuccessor() {
+ return SuccessorCount() > 0 ? SuccessorAt(0) : NULL;
+ }
+ HBasicBlock* SecondSuccessor() {
+ return SuccessorCount() > 1 ? SuccessorAt(1) : NULL;
+ }
+
DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction)
+};
+
+class HSuccessorIterator BASE_EMBEDDED {
+ public:
+ explicit HSuccessorIterator(HControlInstruction* instr)
+ : instr_(instr), next_(0) { }
+
+ bool HasNext() { return next_ < instr_->SuccessorCount(); }
+ HBasicBlock* Next() { return instr_->SuccessorAt(next_); }
+ void Advance() { next_++; }
+
private:
- HBasicBlock* first_successor_;
- HBasicBlock* second_successor_;
+ HControlInstruction* instr_;
+ int next_;
};
-template<int NumElements>
-class HOperandContainer {
+template<typename T, int NumElements>
Kevin Millikin (Chromium) 2011/05/25 15:50:28 We have more or less this class "OperandContainer"
+class Container {
public:
- HOperandContainer() : elems_() { }
+ Container() : elems_() { }
int length() { return NumElements; }
- HValue*& operator[](int i) {
+ T& operator[](int i) {
ASSERT(i < length());
return elems_[i];
}
private:
- HValue* elems_[NumElements];
+ T elems_[NumElements];
};
-template<>
-class HOperandContainer<0> {
+template<typename T>
+class Container<T, 0> {
public:
int length() { return 0; }
- HValue*& operator[](int i) {
+ T& operator[](int i) {
UNREACHABLE();
- static HValue* t = 0;
+ static T t = 0;
return t;
}
};
@@ -814,23 +828,26 @@
void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; }
private:
- HOperandContainer<V> inputs_;
+ Container<HValue*, V> inputs_;
};
-template<int V>
+template<int S, int V>
class HTemplateControlInstruction : public HControlInstruction {
public:
- HTemplateControlInstruction<V>(HBasicBlock* first, HBasicBlock* second)
- : HControlInstruction(first, second) { }
int OperandCount() { return V; }
HValue* OperandAt(int i) { return inputs_[i]; }
+ int SuccessorCount() { return S; }
+ HBasicBlock* SuccessorAt(int i) { return successors_[i]; }
+
protected:
void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; }
+ void SetSuccessorAt(int i, HBasicBlock* block) { successors_[i] = block; }
private:
- HOperandContainer<V> inputs_;
+ Container<HBasicBlock*, S> successors_;
+ Container<HValue*, V> inputs_;
};
@@ -846,9 +863,7 @@
class HDeoptimize: public HControlInstruction {
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();
@@ -857,6 +872,12 @@
virtual int OperandCount() { return values_.length(); }
virtual HValue* OperandAt(int index) { return values_[index]; }
+ 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);
@@ -879,11 +900,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;
@@ -901,13 +923,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) {
+ HBasicBlock* false_target) {
SetOperandAt(0, value);
+ SetSuccessorAt(0, true_target);
+ SetSuccessorAt(1, false_target);
}
virtual void PrintDataTo(StringStream* stream);
@@ -959,24 +982,24 @@
};
-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();
}
+ 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();
}
« no previous file with comments | « src/hydrogen.cc ('k') | src/lithium-allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698