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;
class LPlatformChunk;
class LOperand;
class LUnallocated;
class LConstantOperand;
class LGap;
class LParallelMove;
class LPointerMap;
class LStackSlot;
class LRegister;
// This class represents a single point of a LOperand's lifetime.
......
......@@ -114,33 +114,37 @@ void LOperand::PrintTo(StringStream* stream) {
}
}
#define DEFINE_OPERAND_CACHE(name, type) \
L##name* L##name::cache = NULL; \
\
void L##name::SetUpCache() { \
if (cache) return; \
cache = new L##name[kNumCachedOperands]; \
for (int i = 0; i < kNumCachedOperands; i++) { \
cache[i].ConvertTo(type, i); \
} \
} \
\
void L##name::TearDownCache() { \
delete[] cache; \
template<LOperand::Kind kOperandKind, int kNumCachedOperands>
LSubKindOperand<kOperandKind, kNumCachedOperands>*
LSubKindOperand<kOperandKind, kNumCachedOperands>::cache = NULL;
template<LOperand::Kind kOperandKind, int kNumCachedOperands>
void LSubKindOperand<kOperandKind, kNumCachedOperands>::SetUpCache() {
if (cache) return;
cache = new LSubKindOperand[kNumCachedOperands];
for (int i = 0; i < kNumCachedOperands; i++) {
cache[i].ConvertTo(kOperandKind, i);
}
}
template<LOperand::Kind kOperandKind, int kNumCachedOperands>
void LSubKindOperand<kOperandKind, kNumCachedOperands>::TearDownCache() {
delete[] cache;
}
LITHIUM_OPERAND_LIST(DEFINE_OPERAND_CACHE)
#undef DEFINE_OPERAND_CACHE
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)
#undef LITHIUM_OPERAND_SETUP
}
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)
#undef LITHIUM_OPERAND_TEARDOWN
}
......
......@@ -35,12 +35,12 @@
namespace v8 {
namespace internal {
#define LITHIUM_OPERAND_LIST(V) \
V(ConstantOperand, CONSTANT_OPERAND) \
V(StackSlot, STACK_SLOT) \
V(DoubleStackSlot, DOUBLE_STACK_SLOT) \
V(Register, REGISTER) \
V(DoubleRegister, DOUBLE_REGISTER)
#define LITHIUM_OPERAND_LIST(V) \
V(ConstantOperand, CONSTANT_OPERAND, 128) \
V(StackSlot, STACK_SLOT, 128) \
V(DoubleStackSlot, DOUBLE_STACK_SLOT, 128) \
V(Register, REGISTER, 16) \
V(DoubleRegister, DOUBLE_REGISTER, 16)
class LOperand : public ZoneObject {
......@@ -59,11 +59,11 @@ class LOperand : public ZoneObject {
Kind kind() const { return KindField::decode(value_); }
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; }
LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE)
LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED)
LITHIUM_OPERAND_PREDICATE(Ignored, INVALID)
LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED, 0)
LITHIUM_OPERAND_PREDICATE(Ignored, INVALID, 0)
#undef LITHIUM_OPERAND_PREDICATE
bool Equals(LOperand* other) const { return value_ == other->value_; }
......@@ -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:
static LConstantOperand* Create(int index, Zone* zone) {
static LSubKindOperand* Create(int index, Zone* zone) {
ASSERT(index >= 0);
if (index < kNumCachedOperands) return &cache[index];
return new(zone) LConstantOperand(index);
return new(zone) LSubKindOperand(index);
}
static LConstantOperand* cast(LOperand* op) {
ASSERT(op->IsConstantOperand());
return reinterpret_cast<LConstantOperand*>(op);
static LSubKindOperand* cast(LOperand* op) {
ASSERT(op->kind() == kOperandKind);
return reinterpret_cast<LSubKindOperand*>(op);
}
static void SetUpCache();
static void TearDownCache();
private:
static const int kNumCachedOperands = 128;
static LConstantOperand* cache;
static LSubKindOperand* cache;
LConstantOperand() : LOperand() { }
explicit LConstantOperand(int index) : LOperand(CONSTANT_OPERAND, index) { }
LSubKindOperand() : LOperand() { }
explicit LSubKindOperand(int index) : LOperand(kOperandKind, index) { }
};
class LStackSlot V8_FINAL : public LOperand {
public:
static LStackSlot* Create(int index, Zone* zone) {
ASSERT(index >= 0);
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) { }
};
#define LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS(name, type, number) \
typedef LSubKindOperand<LOperand::type, number> L##name;
LITHIUM_OPERAND_LIST(LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS)
#undef LITHIUM_TYPEDEF_SUBKIND_OPERAND_CLASS
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