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) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation();
if (r.IsInteger32()) {
int32_t value = instr->Integer32Value();
return DefineAsRegister(new LConstantI(value));
return DefineAsRegister(new LConstantI);
} else if (r.IsDouble()) {
double value = instr->DoubleValue();
return DefineAsRegister(new LConstantD(value));
return DefineAsRegister(new LConstantD);
} else if (r.IsTagged()) {
return DefineAsRegister(new LConstantT(instr->handle()));
return DefineAsRegister(new LConstantT);
} else {
UNREACHABLE();
return NULL;
......
......@@ -41,7 +41,6 @@ class LCodeGen;
#define LITHIUM_ALL_INSTRUCTION_LIST(V) \
V(ControlInstruction) \
V(Constant) \
V(Call) \
V(StoreKeyed) \
V(StoreNamed) \
......@@ -905,44 +904,30 @@ class LSubI: public LTemplateInstruction<1, 2, 0> {
};
class LConstant: public LTemplateInstruction<1, 0, 0> {
DECLARE_INSTRUCTION(Constant)
};
class LConstantI: public LConstant {
class LConstantI: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantI(int32_t value) : value_(value) { }
int32_t value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
int32_t value_;
int32_t value() const { return hydrogen()->Integer32Value(); }
};
class LConstantD: public LConstant {
class LConstantD: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantD(double value) : value_(value) { }
double value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
double value_;
double value() const { return hydrogen()->DoubleValue(); }
};
class LConstantT: public LConstant {
class LConstantT: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantT(Handle<Object> value) : value_(value) { }
Handle<Object> value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
Handle<Object> value_;
Handle<Object> value() const { return hydrogen()->handle(); }
};
......
......@@ -1674,13 +1674,11 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation();
if (r.IsInteger32()) {
int32_t value = instr->Integer32Value();
return DefineAsRegister(new LConstantI(value));
return DefineAsRegister(new LConstantI);
} else if (r.IsDouble()) {
double value = instr->DoubleValue();
return DefineAsRegister(new LConstantD(value));
return DefineAsRegister(new LConstantD);
} else if (r.IsTagged()) {
return DefineAsRegister(new LConstantT(instr->handle()));
return DefineAsRegister(new LConstantT);
} else {
UNREACHABLE();
return NULL;
......
......@@ -41,7 +41,6 @@ class LCodeGen;
#define LITHIUM_ALL_INSTRUCTION_LIST(V) \
V(ControlInstruction) \
V(Constant) \
V(Call) \
V(StoreKeyed) \
V(StoreNamed) \
......@@ -933,44 +932,30 @@ class LSubI: public LTemplateInstruction<1, 2, 0> {
};
class LConstant: public LTemplateInstruction<1, 0, 0> {
DECLARE_INSTRUCTION(Constant)
};
class LConstantI: public LConstant {
class LConstantI: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantI(int32_t value) : value_(value) { }
int32_t value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
int32_t value_;
int32_t value() const { return hydrogen()->Integer32Value(); }
};
class LConstantD: public LConstant {
class LConstantD: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantD(double value) : value_(value) { }
double value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
double value_;
double value() const { return hydrogen()->DoubleValue(); }
};
class LConstantT: public LConstant {
class LConstantT: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantT(Handle<Object> value) : value_(value) { }
Handle<Object> value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
Handle<Object> value_;
Handle<Object> value() const { return hydrogen()->handle(); }
};
......
......@@ -1554,14 +1554,12 @@ LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
Representation r = instr->representation();
if (r.IsInteger32()) {
int32_t value = instr->Integer32Value();
return DefineAsRegister(new LConstantI(value));
return DefineAsRegister(new LConstantI);
} else if (r.IsDouble()) {
double value = instr->DoubleValue();
LOperand* temp = TempRegister();
return DefineAsRegister(new LConstantD(value, temp));
return DefineAsRegister(new LConstantD(temp));
} else if (r.IsTagged()) {
return DefineAsRegister(new LConstantT(instr->handle()));
return DefineAsRegister(new LConstantT);
} else {
UNREACHABLE();
return NULL;
......
......@@ -39,119 +39,8 @@ namespace internal {
// Forward declarations.
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) \
V(ControlInstruction) \
V(Constant) \
V(Call) \
V(StoreKeyed) \
V(StoreNamed) \
......@@ -1015,47 +904,33 @@ class LSubI: public LTemplateInstruction<1, 2, 0> {
};
template <int temp_count>
class LConstant: public LTemplateInstruction<1, 0, temp_count> {
DECLARE_INSTRUCTION(Constant)
};
class LConstantI: public LConstant<0> {
class LConstantI: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantI(int32_t value) : value_(value) { }
int32_t value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
int32_t value_;
int32_t value() const { return hydrogen()->Integer32Value(); }
};
class LConstantD: public LConstant<1> {
class LConstantD: public LTemplateInstruction<1, 0, 1> {
public:
explicit LConstantD(double value, LOperand* temp) : value_(value) {
explicit LConstantD(LOperand* temp) {
temps_[0] = temp;
}
double value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
double value_;
double value() const { return hydrogen()->DoubleValue(); }
};
class LConstantT: public LConstant<0> {
class LConstantT: public LTemplateInstruction<1, 0, 0> {
public:
explicit LConstantT(Handle<Object> value) : value_(value) { }
Handle<Object> value() const { return value_; }
DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
DECLARE_HYDROGEN_ACCESSOR(Constant)
private:
Handle<Object> value_;
Handle<Object> value() const { return hydrogen()->handle(); }
};
......
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