Refactor lithium instructions for constants.

1. Remove unnecessary superlcass LConstant.
2. Use hydrogen accessor instead of duplicating the value.

Review URL: http://codereview.chromium.org/6410120

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6672 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 76cf30d9
...@@ -1644,13 +1644,11 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { ...@@ -1644,13 +1644,11 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation(); Representation r = instr->representation();
if (r.IsInteger32()) { if (r.IsInteger32()) {
int32_t value = instr->Integer32Value(); return DefineAsRegister(new LConstantI);
return DefineAsRegister(new LConstantI(value));
} else if (r.IsDouble()) { } else if (r.IsDouble()) {
double value = instr->DoubleValue(); return DefineAsRegister(new LConstantD);
return DefineAsRegister(new LConstantD(value));
} else if (r.IsTagged()) { } else if (r.IsTagged()) {
return DefineAsRegister(new LConstantT(instr->handle())); return DefineAsRegister(new LConstantT);
} else { } else {
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
......
...@@ -41,7 +41,6 @@ class LCodeGen; ...@@ -41,7 +41,6 @@ class LCodeGen;
#define LITHIUM_ALL_INSTRUCTION_LIST(V) \ #define LITHIUM_ALL_INSTRUCTION_LIST(V) \
V(ControlInstruction) \ V(ControlInstruction) \
V(Constant) \
V(Call) \ V(Call) \
V(StoreKeyed) \ V(StoreKeyed) \
V(StoreNamed) \ V(StoreNamed) \
...@@ -905,44 +904,30 @@ class LSubI: public LTemplateInstruction<1, 2, 0> { ...@@ -905,44 +904,30 @@ class LSubI: public LTemplateInstruction<1, 2, 0> {
}; };
class LConstant: public LTemplateInstruction<1, 0, 0> { class LConstantI: public LTemplateInstruction<1, 0, 0> {
DECLARE_INSTRUCTION(Constant)
};
class LConstantI: public LConstant {
public: public:
explicit LConstantI(int32_t value) : value_(value) { }
int32_t value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i") DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: int32_t value() const { return hydrogen()->Integer32Value(); }
int32_t value_;
}; };
class LConstantD: public LConstant { class LConstantD: public LTemplateInstruction<1, 0, 0> {
public: public:
explicit LConstantD(double value) : value_(value) { }
double value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d") DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: double value() const { return hydrogen()->DoubleValue(); }
double value_;
}; };
class LConstantT: public LConstant { class LConstantT: public LTemplateInstruction<1, 0, 0> {
public: public:
explicit LConstantT(Handle<Object> value) : value_(value) { }
Handle<Object> value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t") DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: Handle<Object> value() const { return hydrogen()->handle(); }
Handle<Object> value_;
}; };
......
...@@ -1674,13 +1674,11 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { ...@@ -1674,13 +1674,11 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation(); Representation r = instr->representation();
if (r.IsInteger32()) { if (r.IsInteger32()) {
int32_t value = instr->Integer32Value(); return DefineAsRegister(new LConstantI);
return DefineAsRegister(new LConstantI(value));
} else if (r.IsDouble()) { } else if (r.IsDouble()) {
double value = instr->DoubleValue(); return DefineAsRegister(new LConstantD);
return DefineAsRegister(new LConstantD(value));
} else if (r.IsTagged()) { } else if (r.IsTagged()) {
return DefineAsRegister(new LConstantT(instr->handle())); return DefineAsRegister(new LConstantT);
} else { } else {
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
......
...@@ -41,7 +41,6 @@ class LCodeGen; ...@@ -41,7 +41,6 @@ class LCodeGen;
#define LITHIUM_ALL_INSTRUCTION_LIST(V) \ #define LITHIUM_ALL_INSTRUCTION_LIST(V) \
V(ControlInstruction) \ V(ControlInstruction) \
V(Constant) \
V(Call) \ V(Call) \
V(StoreKeyed) \ V(StoreKeyed) \
V(StoreNamed) \ V(StoreNamed) \
...@@ -933,44 +932,30 @@ class LSubI: public LTemplateInstruction<1, 2, 0> { ...@@ -933,44 +932,30 @@ class LSubI: public LTemplateInstruction<1, 2, 0> {
}; };
class LConstant: public LTemplateInstruction<1, 0, 0> { class LConstantI: public LTemplateInstruction<1, 0, 0> {
DECLARE_INSTRUCTION(Constant)
};
class LConstantI: public LConstant {
public: public:
explicit LConstantI(int32_t value) : value_(value) { }
int32_t value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i") DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: int32_t value() const { return hydrogen()->Integer32Value(); }
int32_t value_;
}; };
class LConstantD: public LConstant { class LConstantD: public LTemplateInstruction<1, 0, 0> {
public: public:
explicit LConstantD(double value) : value_(value) { }
double value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d") DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: double value() const { return hydrogen()->DoubleValue(); }
double value_;
}; };
class LConstantT: public LConstant { class LConstantT: public LTemplateInstruction<1, 0, 0> {
public: public:
explicit LConstantT(Handle<Object> value) : value_(value) { }
Handle<Object> value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t") DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: Handle<Object> value() const { return hydrogen()->handle(); }
Handle<Object> value_;
}; };
......
...@@ -1554,14 +1554,12 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { ...@@ -1554,14 +1554,12 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation(); Representation r = instr->representation();
if (r.IsInteger32()) { if (r.IsInteger32()) {
int32_t value = instr->Integer32Value(); return DefineAsRegister(new LConstantI);
return DefineAsRegister(new LConstantI(value));
} else if (r.IsDouble()) { } else if (r.IsDouble()) {
double value = instr->DoubleValue();
LOperand* temp = TempRegister(); LOperand* temp = TempRegister();
return DefineAsRegister(new LConstantD(value, temp)); return DefineAsRegister(new LConstantD(temp));
} else if (r.IsTagged()) { } else if (r.IsTagged()) {
return DefineAsRegister(new LConstantT(instr->handle())); return DefineAsRegister(new LConstantT);
} else { } else {
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
......
...@@ -39,119 +39,8 @@ namespace internal { ...@@ -39,119 +39,8 @@ namespace internal {
// Forward declarations. // Forward declarations.
class LCodeGen; class LCodeGen;
// Type hierarchy:
//
// LInstruction
// LTemplateInstruction
// LControlInstruction
// LBranch
// LClassOfTestAndBranch
// LCmpJSObjectEqAndBranch
// LCmpIDAndBranch
// LHasCachedArrayIndexAndBranch
// LHasInstanceTypeAndBranch
// LInstanceOfAndBranch
// LIsNullAndBranch
// LIsObjectAndBranch
// LIsSmiAndBranch
// LTypeofIsAndBranch
// LAccessArgumentsAt
// LArgumentsElements
// LArgumentsLength
// LAddI
// LApplyArguments
// LArithmeticD
// LArithmeticT
// LBitI
// LBoundsCheck
// LCmpID
// LCmpJSObjectEq
// LCmpT
// LDivI
// LInstanceOf
// LInstanceOfKnownGlobal
// LLoadKeyedFastElement
// LLoadKeyedGeneric
// LModI
// LMulI
// LPower
// LShiftI
// LSubI
// LCallConstantFunction
// LCallFunction
// LCallGlobal
// LCallKeyed
// LCallKnownGlobal
// LCallNamed
// LCallRuntime
// LCallStub
// LConstant
// LConstantD
// LConstantI
// LConstantT
// LDeoptimize
// LFunctionLiteral
// LGap
// LLabel
// LGlobalObject
// LGlobalReceiver
// LGoto
// LLazyBailout
// LLoadGlobal
// LCheckPrototypeMaps
// LLoadContextSlot
// LArrayLiteral
// LObjectLiteral
// LRegExpLiteral
// LOsrEntry
// LParameter
// LRegExpConstructResult
// LStackCheck
// LStoreKeyed
// LStoreKeyedFastElement
// LStoreKeyedGeneric
// LStoreNamed
// LStoreNamedField
// LStoreNamedGeneric
// LBitNotI
// LCallNew
// LCheckFunction
// LCheckPrototypeMaps
// LCheckInstanceType
// LCheckMap
// LCheckSmi
// LClassOfTest
// LDeleteProperty
// LDoubleToI
// LFixedArrayLength
// LHasCachedArrayIndex
// LHasInstanceType
// LInteger32ToDouble
// LIsNull
// LIsObject
// LIsSmi
// LJSArrayLength
// LLoadNamedField
// LLoadNamedGeneric
// LLoadFunctionPrototype
// LNumberTagD
// LNumberTagI
// LPushArgument
// LReturn
// LSmiTag
// LStoreGlobal
// LTaggedToI
// LThrow
// LTypeof
// LTypeofIs
// LUnaryMathOperation
// LValueOf
// LUnknownOSRValue
#define LITHIUM_ALL_INSTRUCTION_LIST(V) \ #define LITHIUM_ALL_INSTRUCTION_LIST(V) \
V(ControlInstruction) \ V(ControlInstruction) \
V(Constant) \
V(Call) \ V(Call) \
V(StoreKeyed) \ V(StoreKeyed) \
V(StoreNamed) \ V(StoreNamed) \
...@@ -1015,47 +904,33 @@ class LSubI: public LTemplateInstruction<1, 2, 0> { ...@@ -1015,47 +904,33 @@ class LSubI: public LTemplateInstruction<1, 2, 0> {
}; };
template <int temp_count> class LConstantI: public LTemplateInstruction<1, 0, 0> {
class LConstant: public LTemplateInstruction<1, 0, temp_count> {
DECLARE_INSTRUCTION(Constant)
};
class LConstantI: public LConstant<0> {
public: public:
explicit LConstantI(int32_t value) : value_(value) { }
int32_t value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i") DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: int32_t value() const { return hydrogen()->Integer32Value(); }
int32_t value_;
}; };
class LConstantD: public LConstant<1> { class LConstantD: public LTemplateInstruction<1, 0, 1> {
public: public:
explicit LConstantD(double value, LOperand* temp) : value_(value) { explicit LConstantD(LOperand* temp) {
temps_[0] = temp; temps_[0] = temp;
} }
double value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d") DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: double value() const { return hydrogen()->DoubleValue(); }
double value_;
}; };
class LConstantT: public LConstant<0> { class LConstantT: public LTemplateInstruction<1, 0, 0> {
public: public:
explicit LConstantT(Handle<Object> value) : value_(value) { }
Handle<Object> value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t") DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private: Handle<Object> value() const { return hydrogen()->handle(); }
Handle<Object> value_;
}; };
......
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