Commit 7d64ff66 authored by haitao.feng@intel.com's avatar haitao.feng@intel.com

Refactor lithium operand declaration a little bit.

R=verwaest@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19775 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fe909b47
...@@ -50,12 +50,9 @@ class StringStream; ...@@ -50,12 +50,9 @@ class StringStream;
class LPlatformChunk; class LPlatformChunk;
class LOperand; class LOperand;
class LUnallocated; class LUnallocated;
class LConstantOperand;
class LGap; class LGap;
class LParallelMove; class LParallelMove;
class LPointerMap; class LPointerMap;
class LStackSlot;
class LRegister;
// This class represents a single point of a LOperand's lifetime. // This class represents a single point of a LOperand's lifetime.
......
...@@ -114,33 +114,37 @@ void LOperand::PrintTo(StringStream* stream) { ...@@ -114,33 +114,37 @@ void LOperand::PrintTo(StringStream* stream) {
} }
} }
#define DEFINE_OPERAND_CACHE(name, type) \
L##name* L##name::cache = NULL; \ template<LOperand::Kind kOperandKind, int kNumCachedOperands>
\ LSubKindOperand<kOperandKind, kNumCachedOperands>*
void L##name::SetUpCache() { \ LSubKindOperand<kOperandKind, kNumCachedOperands>::cache = NULL;
if (cache) return; \
cache = new L##name[kNumCachedOperands]; \
for (int i = 0; i < kNumCachedOperands; i++) { \ template<LOperand::Kind kOperandKind, int kNumCachedOperands>
cache[i].ConvertTo(type, i); \ void LSubKindOperand<kOperandKind, kNumCachedOperands>::SetUpCache() {
} \ if (cache) return;
} \ cache = new LSubKindOperand[kNumCachedOperands];
\ for (int i = 0; i < kNumCachedOperands; i++) {
void L##name::TearDownCache() { \ cache[i].ConvertTo(kOperandKind, i);
delete[] cache; \ }
} }
LITHIUM_OPERAND_LIST(DEFINE_OPERAND_CACHE)
#undef DEFINE_OPERAND_CACHE template<LOperand::Kind kOperandKind, int kNumCachedOperands>
void LSubKindOperand<kOperandKind, kNumCachedOperands>::TearDownCache() {
delete[] cache;
}
void LOperand::SetUpCaches() { void LOperand::SetUpCaches() {
#define LITHIUM_OPERAND_SETUP(name, type) L##name::SetUpCache(); #define LITHIUM_OPERAND_SETUP(name, type, number) L##name::SetUpCache();
LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_SETUP) LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_SETUP)
#undef LITHIUM_OPERAND_SETUP #undef LITHIUM_OPERAND_SETUP
} }
void LOperand::TearDownCaches() { void LOperand::TearDownCaches() {
#define LITHIUM_OPERAND_TEARDOWN(name, type) L##name::TearDownCache(); #define LITHIUM_OPERAND_TEARDOWN(name, type, number) L##name::TearDownCache();
LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_TEARDOWN) LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_TEARDOWN)
#undef LITHIUM_OPERAND_TEARDOWN #undef LITHIUM_OPERAND_TEARDOWN
} }
......
...@@ -36,11 +36,11 @@ namespace v8 { ...@@ -36,11 +36,11 @@ namespace v8 {
namespace internal { namespace internal {
#define LITHIUM_OPERAND_LIST(V) \ #define LITHIUM_OPERAND_LIST(V) \
V(ConstantOperand, CONSTANT_OPERAND) \ V(ConstantOperand, CONSTANT_OPERAND, 128) \
V(StackSlot, STACK_SLOT) \ V(StackSlot, STACK_SLOT, 128) \
V(DoubleStackSlot, DOUBLE_STACK_SLOT) \ V(DoubleStackSlot, DOUBLE_STACK_SLOT, 128) \
V(Register, REGISTER) \ V(Register, REGISTER, 16) \
V(DoubleRegister, DOUBLE_REGISTER) V(DoubleRegister, DOUBLE_REGISTER, 16)
class LOperand : public ZoneObject { class LOperand : public ZoneObject {
...@@ -59,11 +59,11 @@ class LOperand : public ZoneObject { ...@@ -59,11 +59,11 @@ class LOperand : public ZoneObject {
Kind kind() const { return KindField::decode(value_); } Kind kind() const { return KindField::decode(value_); }
int index() const { return static_cast<int>(value_) >> kKindFieldWidth; } int index() const { return static_cast<int>(value_) >> kKindFieldWidth; }
#define LITHIUM_OPERAND_PREDICATE(name, type) \ #define LITHIUM_OPERAND_PREDICATE(name, type, number) \
bool Is##name() const { return kind() == type; } bool Is##name() const { return kind() == type; }
LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE) LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE)
LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED) LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED, 0)
LITHIUM_OPERAND_PREDICATE(Ignored, INVALID) LITHIUM_OPERAND_PREDICATE(Ignored, INVALID, 0)
#undef LITHIUM_OPERAND_PREDICATE #undef LITHIUM_OPERAND_PREDICATE
bool Equals(LOperand* other) const { return value_ == other->value_; } bool Equals(LOperand* other) const { return value_ == other->value_; }
...@@ -315,129 +315,35 @@ class LMoveOperands V8_FINAL BASE_EMBEDDED { ...@@ -315,129 +315,35 @@ class LMoveOperands V8_FINAL BASE_EMBEDDED {
}; };
class LConstantOperand V8_FINAL : public LOperand { template<LOperand::Kind kOperandKind, int kNumCachedOperands>
class LSubKindOperand V8_FINAL : public LOperand {
public: public:
static LConstantOperand* Create(int index, Zone* zone) { static LSubKindOperand* Create(int index, Zone* zone) {
ASSERT(index >= 0); ASSERT(index >= 0);
if (index < kNumCachedOperands) return &cache[index]; if (index < kNumCachedOperands) return &cache[index];
return new(zone) LConstantOperand(index); return new(zone) LSubKindOperand(index);
} }
static LConstantOperand* cast(LOperand* op) { static LSubKindOperand* cast(LOperand* op) {
ASSERT(op->IsConstantOperand()); ASSERT(op->kind() == kOperandKind);
return reinterpret_cast<LConstantOperand*>(op); return reinterpret_cast<LSubKindOperand*>(op);
} }
static void SetUpCache(); static void SetUpCache();
static void TearDownCache(); static void TearDownCache();
private: private:
static const int kNumCachedOperands = 128; static LSubKindOperand* cache;
static LConstantOperand* cache;
LConstantOperand() : LOperand() { } LSubKindOperand() : LOperand() { }
explicit LConstantOperand(int index) : LOperand(CONSTANT_OPERAND, index) { } explicit LSubKindOperand(int index) : LOperand(kOperandKind, index) { }
}; };
class LStackSlot V8_FINAL : public LOperand { #define LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS(name, type, number) \
public: typedef LSubKindOperand<LOperand::type, number> L##name;
static LStackSlot* Create(int index, Zone* zone) { LITHIUM_OPERAND_LIST(LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS)
ASSERT(index >= 0); #undef LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS
if (index < kNumCachedOperands) return &cache[index];
return new(zone) LStackSlot(index);
}
static LStackSlot* cast(LOperand* op) {
ASSERT(op->IsStackSlot());
return reinterpret_cast<LStackSlot*>(op);
}
static void SetUpCache();
static void TearDownCache();
private:
static const int kNumCachedOperands = 128;
static LStackSlot* cache;
LStackSlot() : LOperand() { }
explicit LStackSlot(int index) : LOperand(STACK_SLOT, index) { }
};
class LDoubleStackSlot V8_FINAL : public LOperand {
public:
static LDoubleStackSlot* Create(int index, Zone* zone) {
ASSERT(index >= 0);
if (index < kNumCachedOperands) return &cache[index];
return new(zone) LDoubleStackSlot(index);
}
static LDoubleStackSlot* cast(LOperand* op) {
ASSERT(op->IsStackSlot());
return reinterpret_cast<LDoubleStackSlot*>(op);
}
static void SetUpCache();
static void TearDownCache();
private:
static const int kNumCachedOperands = 128;
static LDoubleStackSlot* cache;
LDoubleStackSlot() : LOperand() { }
explicit LDoubleStackSlot(int index) : LOperand(DOUBLE_STACK_SLOT, index) { }
};
class LRegister V8_FINAL : public LOperand {
public:
static LRegister* Create(int index, Zone* zone) {
ASSERT(index >= 0);
if (index < kNumCachedOperands) return &cache[index];
return new(zone) LRegister(index);
}
static LRegister* cast(LOperand* op) {
ASSERT(op->IsRegister());
return reinterpret_cast<LRegister*>(op);
}
static void SetUpCache();
static void TearDownCache();
private:
static const int kNumCachedOperands = 16;
static LRegister* cache;
LRegister() : LOperand() { }
explicit LRegister(int index) : LOperand(REGISTER, index) { }
};
class LDoubleRegister V8_FINAL : public LOperand {
public:
static LDoubleRegister* Create(int index, Zone* zone) {
ASSERT(index >= 0);
if (index < kNumCachedOperands) return &cache[index];
return new(zone) LDoubleRegister(index);
}
static LDoubleRegister* cast(LOperand* op) {
ASSERT(op->IsDoubleRegister());
return reinterpret_cast<LDoubleRegister*>(op);
}
static void SetUpCache();
static void TearDownCache();
private:
static const int kNumCachedOperands = 16;
static LDoubleRegister* cache;
LDoubleRegister() : LOperand() { }
explicit LDoubleRegister(int index) : LOperand(DOUBLE_REGISTER, index) { }
};
class LParallelMove V8_FINAL : public ZoneObject { class LParallelMove V8_FINAL : public ZoneObject {
......
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