Commit 557e9b9d authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Fix IfBuilder to use instruction factories. Add missing instruction factories.

This also makes the instruction constructors private and fixes
all uses of the public constructors to use the factory methods
instead.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/23654051

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16808 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent bf192205
...@@ -1351,14 +1351,12 @@ class HUnaryControlInstruction : public HTemplateControlInstruction<2, 1> { ...@@ -1351,14 +1351,12 @@ class HUnaryControlInstruction : public HTemplateControlInstruction<2, 1> {
class HBranch V8_FINAL : public HUnaryControlInstruction { class HBranch V8_FINAL : public HUnaryControlInstruction {
public: public:
HBranch(HValue* value, DECLARE_INSTRUCTION_FACTORY_P1(HBranch, HValue*);
ToBooleanStub::Types expected_input_types = ToBooleanStub::Types(), DECLARE_INSTRUCTION_FACTORY_P2(HBranch, HValue*,
HBasicBlock* true_target = NULL, ToBooleanStub::Types);
HBasicBlock* false_target = NULL) DECLARE_INSTRUCTION_FACTORY_P4(HBranch, HValue*,
: HUnaryControlInstruction(value, true_target, false_target), ToBooleanStub::Types,
expected_input_types_(expected_input_types) { HBasicBlock*, HBasicBlock*);
SetFlag(kAllowUndefinedAsNaN);
}
virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE {
return Representation::None(); return Representation::None();
...@@ -1372,20 +1370,24 @@ class HBranch V8_FINAL : public HUnaryControlInstruction { ...@@ -1372,20 +1370,24 @@ class HBranch V8_FINAL : public HUnaryControlInstruction {
DECLARE_CONCRETE_INSTRUCTION(Branch) DECLARE_CONCRETE_INSTRUCTION(Branch)
private: private:
HBranch(HValue* value,
ToBooleanStub::Types expected_input_types = ToBooleanStub::Types(),
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target),
expected_input_types_(expected_input_types) {
SetFlag(kAllowUndefinedAsNaN);
}
ToBooleanStub::Types expected_input_types_; ToBooleanStub::Types expected_input_types_;
}; };
class HCompareMap V8_FINAL : public HUnaryControlInstruction { class HCompareMap V8_FINAL : public HUnaryControlInstruction {
public: public:
HCompareMap(HValue* value, DECLARE_INSTRUCTION_FACTORY_P2(HCompareMap, HValue*, Handle<Map>);
Handle<Map> map, DECLARE_INSTRUCTION_FACTORY_P4(HCompareMap, HValue*, Handle<Map>,
HBasicBlock* true_target = NULL, HBasicBlock*, HBasicBlock*);
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target),
map_(map) {
ASSERT(!map.is_null());
}
virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE;
...@@ -1401,6 +1403,14 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction { ...@@ -1401,6 +1403,14 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction {
virtual int RedefinedOperandIndex() { return 0; } virtual int RedefinedOperandIndex() { return 0; }
private: private:
HCompareMap(HValue* value,
Handle<Map> map,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target), map_(map) {
ASSERT(!map.is_null());
}
Handle<Map> map_; Handle<Map> map_;
}; };
...@@ -4033,13 +4043,11 @@ class HCompareGeneric V8_FINAL : public HBinaryOperation { ...@@ -4033,13 +4043,11 @@ class HCompareGeneric V8_FINAL : public HBinaryOperation {
class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> { class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> {
public: public:
HCompareNumericAndBranch(HValue* left, HValue* right, Token::Value token) DECLARE_INSTRUCTION_FACTORY_P3(HCompareNumericAndBranch,
: token_(token) { HValue*, HValue*, Token::Value);
SetFlag(kFlexibleRepresentation); DECLARE_INSTRUCTION_FACTORY_P5(HCompareNumericAndBranch,
ASSERT(Token::IsCompareOp(token)); HValue*, HValue*, Token::Value,
SetOperandAt(0, left); HBasicBlock*, HBasicBlock*);
SetOperandAt(1, right);
}
HValue* left() { return OperandAt(0); } HValue* left() { return OperandAt(0); }
HValue* right() { return OperandAt(1); } HValue* right() { return OperandAt(1); }
...@@ -4065,6 +4073,20 @@ class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> { ...@@ -4065,6 +4073,20 @@ class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> {
DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch)
private: private:
HCompareNumericAndBranch(HValue* left,
HValue* right,
Token::Value token,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: token_(token) {
SetFlag(kFlexibleRepresentation);
ASSERT(Token::IsCompareOp(token));
SetOperandAt(0, left);
SetOperandAt(1, right);
SetSuccessorAt(0, true_target);
SetSuccessorAt(1, false_target);
}
Representation observed_input_representation_[2]; Representation observed_input_representation_[2];
Token::Value token_; Token::Value token_;
}; };
...@@ -4072,16 +4094,6 @@ class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> { ...@@ -4072,16 +4094,6 @@ class HCompareNumericAndBranch : public HTemplateControlInstruction<2, 2> {
class HCompareHoleAndBranch V8_FINAL : public HUnaryControlInstruction { class HCompareHoleAndBranch V8_FINAL : public HUnaryControlInstruction {
public: public:
// TODO(danno): make this private when the IfBuilder properly constructs
// control flow instructions.
HCompareHoleAndBranch(HValue* value,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target) {
SetFlag(kFlexibleRepresentation);
SetFlag(kAllowUndefinedAsNaN);
}
DECLARE_INSTRUCTION_FACTORY_P1(HCompareHoleAndBranch, HValue*); DECLARE_INSTRUCTION_FACTORY_P1(HCompareHoleAndBranch, HValue*);
DECLARE_INSTRUCTION_FACTORY_P3(HCompareHoleAndBranch, HValue*, DECLARE_INSTRUCTION_FACTORY_P3(HCompareHoleAndBranch, HValue*,
HBasicBlock*, HBasicBlock*); HBasicBlock*, HBasicBlock*);
...@@ -4094,20 +4106,23 @@ class HCompareHoleAndBranch V8_FINAL : public HUnaryControlInstruction { ...@@ -4094,20 +4106,23 @@ class HCompareHoleAndBranch V8_FINAL : public HUnaryControlInstruction {
} }
DECLARE_CONCRETE_INSTRUCTION(CompareHoleAndBranch) DECLARE_CONCRETE_INSTRUCTION(CompareHoleAndBranch)
private:
HCompareHoleAndBranch(HValue* value,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target) {
SetFlag(kFlexibleRepresentation);
SetFlag(kAllowUndefinedAsNaN);
}
}; };
class HCompareObjectEqAndBranch : public HTemplateControlInstruction<2, 2> { class HCompareObjectEqAndBranch : public HTemplateControlInstruction<2, 2> {
public: public:
// TODO(danno): make this private when the IfBuilder properly constructs
// control flow instructions.
HCompareObjectEqAndBranch(HValue* left,
HValue* right) {
SetOperandAt(0, left);
SetOperandAt(1, right);
}
DECLARE_INSTRUCTION_FACTORY_P2(HCompareObjectEqAndBranch, HValue*, HValue*); DECLARE_INSTRUCTION_FACTORY_P2(HCompareObjectEqAndBranch, HValue*, HValue*);
DECLARE_INSTRUCTION_FACTORY_P4(HCompareObjectEqAndBranch, HValue*, HValue*,
HBasicBlock*, HBasicBlock*);
HValue* left() { return OperandAt(0); } HValue* left() { return OperandAt(0); }
HValue* right() { return OperandAt(1); } HValue* right() { return OperandAt(1); }
...@@ -4123,38 +4138,65 @@ class HCompareObjectEqAndBranch : public HTemplateControlInstruction<2, 2> { ...@@ -4123,38 +4138,65 @@ class HCompareObjectEqAndBranch : public HTemplateControlInstruction<2, 2> {
} }
DECLARE_CONCRETE_INSTRUCTION(CompareObjectEqAndBranch) DECLARE_CONCRETE_INSTRUCTION(CompareObjectEqAndBranch)
private:
HCompareObjectEqAndBranch(HValue* left,
HValue* right,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL) {
SetOperandAt(0, left);
SetOperandAt(1, right);
SetSuccessorAt(0, true_target);
SetSuccessorAt(1, false_target);
}
}; };
class HIsObjectAndBranch V8_FINAL : public HUnaryControlInstruction { class HIsObjectAndBranch V8_FINAL : public HUnaryControlInstruction {
public: public:
explicit HIsObjectAndBranch(HValue* value) DECLARE_INSTRUCTION_FACTORY_P1(HIsObjectAndBranch, HValue*);
: HUnaryControlInstruction(value, NULL, NULL) { } DECLARE_INSTRUCTION_FACTORY_P3(HIsObjectAndBranch, HValue*,
HBasicBlock*, HBasicBlock*);
virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE {
return Representation::Tagged(); return Representation::Tagged();
} }
DECLARE_CONCRETE_INSTRUCTION(IsObjectAndBranch) DECLARE_CONCRETE_INSTRUCTION(IsObjectAndBranch)
private:
HIsObjectAndBranch(HValue* value,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target) {}
}; };
class HIsStringAndBranch V8_FINAL : public HUnaryControlInstruction { class HIsStringAndBranch V8_FINAL : public HUnaryControlInstruction {
public: public:
explicit HIsStringAndBranch(HValue* value) DECLARE_INSTRUCTION_FACTORY_P1(HIsStringAndBranch, HValue*);
: HUnaryControlInstruction(value, NULL, NULL) { } DECLARE_INSTRUCTION_FACTORY_P3(HIsStringAndBranch, HValue*,
HBasicBlock*, HBasicBlock*);
virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE {
return Representation::Tagged(); return Representation::Tagged();
} }
DECLARE_CONCRETE_INSTRUCTION(IsStringAndBranch) DECLARE_CONCRETE_INSTRUCTION(IsStringAndBranch)
private:
HIsStringAndBranch(HValue* value,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target) {}
}; };
class HIsSmiAndBranch V8_FINAL : public HUnaryControlInstruction { class HIsSmiAndBranch V8_FINAL : public HUnaryControlInstruction {
public: public:
explicit HIsSmiAndBranch(HValue* value) DECLARE_INSTRUCTION_FACTORY_P1(HIsSmiAndBranch, HValue*);
: HUnaryControlInstruction(value, NULL, NULL) { } DECLARE_INSTRUCTION_FACTORY_P3(HIsSmiAndBranch, HValue*,
HBasicBlock*, HBasicBlock*);
DECLARE_CONCRETE_INSTRUCTION(IsSmiAndBranch) DECLARE_CONCRETE_INSTRUCTION(IsSmiAndBranch)
...@@ -4164,19 +4206,32 @@ class HIsSmiAndBranch V8_FINAL : public HUnaryControlInstruction { ...@@ -4164,19 +4206,32 @@ class HIsSmiAndBranch V8_FINAL : public HUnaryControlInstruction {
protected: protected:
virtual bool DataEquals(HValue* other) V8_OVERRIDE { return true; } virtual bool DataEquals(HValue* other) V8_OVERRIDE { return true; }
private:
HIsSmiAndBranch(HValue* value,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target) {}
}; };
class HIsUndetectableAndBranch V8_FINAL : public HUnaryControlInstruction { class HIsUndetectableAndBranch V8_FINAL : public HUnaryControlInstruction {
public: public:
explicit HIsUndetectableAndBranch(HValue* value) DECLARE_INSTRUCTION_FACTORY_P1(HIsUndetectableAndBranch, HValue*);
: HUnaryControlInstruction(value, NULL, NULL) { } DECLARE_INSTRUCTION_FACTORY_P3(HIsUndetectableAndBranch, HValue*,
HBasicBlock*, HBasicBlock*);
virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE {
return Representation::Tagged(); return Representation::Tagged();
} }
DECLARE_CONCRETE_INSTRUCTION(IsUndetectableAndBranch) DECLARE_CONCRETE_INSTRUCTION(IsUndetectableAndBranch)
private:
HIsUndetectableAndBranch(HValue* value,
HBasicBlock* true_target = NULL,
HBasicBlock* false_target = NULL)
: HUnaryControlInstruction(value, true_target, false_target) {}
}; };
......
...@@ -63,8 +63,8 @@ HBasicBlock* HOsrBuilder::BuildPossibleOsrLoopEntry( ...@@ -63,8 +63,8 @@ HBasicBlock* HOsrBuilder::BuildPossibleOsrLoopEntry(
HBasicBlock* non_osr_entry = graph->CreateBasicBlock(); HBasicBlock* non_osr_entry = graph->CreateBasicBlock();
osr_entry_ = graph->CreateBasicBlock(); osr_entry_ = graph->CreateBasicBlock();
HValue* true_value = graph->GetConstantTrue(); HValue* true_value = graph->GetConstantTrue();
HBranch* test = new(zone) HBranch(true_value, ToBooleanStub::Types(), HBranch* test = builder_->New<HBranch>(true_value, ToBooleanStub::Types(),
non_osr_entry, osr_entry_); non_osr_entry, osr_entry_);
builder_->current_block()->Finish(test); builder_->current_block()->Finish(test);
HBasicBlock* loop_predecessor = graph->CreateBasicBlock(); HBasicBlock* loop_predecessor = graph->CreateBasicBlock();
......
This diff is collapsed.
...@@ -1285,29 +1285,29 @@ class HGraphBuilder { ...@@ -1285,29 +1285,29 @@ class HGraphBuilder {
} }
template<class Condition> template<class Condition>
HInstruction* If(HValue *p) { Condition* If(HValue *p) {
HControlInstruction* compare = new(zone()) Condition(p); Condition* compare = builder()->New<Condition>(p);
AddCompare(compare); AddCompare(compare);
return compare; return compare;
} }
template<class Condition, class P2> template<class Condition, class P2>
HInstruction* If(HValue* p1, P2 p2) { Condition* If(HValue* p1, P2 p2) {
HControlInstruction* compare = new(zone()) Condition(p1, p2); Condition* compare = builder()->New<Condition>(p1, p2);
AddCompare(compare); AddCompare(compare);
return compare; return compare;
} }
template<class Condition, class P2, class P3> template<class Condition, class P2, class P3>
HInstruction* If(HValue* p1, P2 p2, P3 p3) { Condition* If(HValue* p1, P2 p2, P3 p3) {
HControlInstruction* compare = new(zone()) Condition(p1, p2, p3); Condition* compare = builder()->New<Condition>(p1, p2, p3);
AddCompare(compare); AddCompare(compare);
return compare; return compare;
} }
template<class Condition, class P2> template<class Condition, class P2>
HInstruction* IfNot(HValue* p1, P2 p2) { Condition* IfNot(HValue* p1, P2 p2) {
HControlInstruction* compare = new(zone()) Condition(p1, p2); Condition* compare = builder()->New<Condition>(p1, p2);
AddCompare(compare); AddCompare(compare);
HBasicBlock* block0 = compare->SuccessorAt(0); HBasicBlock* block0 = compare->SuccessorAt(0);
HBasicBlock* block1 = compare->SuccessorAt(1); HBasicBlock* block1 = compare->SuccessorAt(1);
...@@ -1317,8 +1317,8 @@ class HGraphBuilder { ...@@ -1317,8 +1317,8 @@ class HGraphBuilder {
} }
template<class Condition, class P2, class P3> template<class Condition, class P2, class P3>
HInstruction* IfNot(HValue* p1, P2 p2, P3 p3) { Condition* IfNot(HValue* p1, P2 p2, P3 p3) {
HControlInstruction* compare = new(zone()) Condition(p1, p2, p3); Condition* compare = builder()->New<Condition>(p1, p2, p3);
AddCompare(compare); AddCompare(compare);
HBasicBlock* block0 = compare->SuccessorAt(0); HBasicBlock* block0 = compare->SuccessorAt(0);
HBasicBlock* block1 = compare->SuccessorAt(1); HBasicBlock* block1 = compare->SuccessorAt(1);
...@@ -1328,37 +1328,37 @@ class HGraphBuilder { ...@@ -1328,37 +1328,37 @@ class HGraphBuilder {
} }
template<class Condition> template<class Condition>
HInstruction* OrIf(HValue *p) { Condition* OrIf(HValue *p) {
Or(); Or();
return If<Condition>(p); return If<Condition>(p);
} }
template<class Condition, class P2> template<class Condition, class P2>
HInstruction* OrIf(HValue* p1, P2 p2) { Condition* OrIf(HValue* p1, P2 p2) {
Or(); Or();
return If<Condition>(p1, p2); return If<Condition>(p1, p2);
} }
template<class Condition, class P2, class P3> template<class Condition, class P2, class P3>
HInstruction* OrIf(HValue* p1, P2 p2, P3 p3) { Condition* OrIf(HValue* p1, P2 p2, P3 p3) {
Or(); Or();
return If<Condition>(p1, p2, p3); return If<Condition>(p1, p2, p3);
} }
template<class Condition> template<class Condition>
HInstruction* AndIf(HValue *p) { Condition* AndIf(HValue *p) {
And(); And();
return If<Condition>(p); return If<Condition>(p);
} }
template<class Condition, class P2> template<class Condition, class P2>
HInstruction* AndIf(HValue* p1, P2 p2) { Condition* AndIf(HValue* p1, P2 p2) {
And(); And();
return If<Condition>(p1, p2); return If<Condition>(p1, p2);
} }
template<class Condition, class P2, class P3> template<class Condition, class P2, class P3>
HInstruction* AndIf(HValue* p1, P2 p2, P3 p3) { Condition* AndIf(HValue* p1, P2 p2, P3 p3) {
And(); And();
return If<Condition>(p1, p2, p3); return If<Condition>(p1, p2, p3);
} }
...@@ -1383,7 +1383,7 @@ class HGraphBuilder { ...@@ -1383,7 +1383,7 @@ class HGraphBuilder {
private: private:
void AddCompare(HControlInstruction* compare); void AddCompare(HControlInstruction* compare);
Zone* zone() { return builder_->zone(); } HGraphBuilder* builder() const { return builder_; }
HGraphBuilder* builder_; HGraphBuilder* builder_;
int position_; int position_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment