Commit 5950acf2 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] Push layout descriptors to InstructionOperand subclasses.

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

Cr-Commit-Position: refs/heads/master@{#27701}
parent 8157b6c9
...@@ -35,8 +35,7 @@ class InstructionOperand { ...@@ -35,8 +35,7 @@ class InstructionOperand {
// kInvalidVirtualRegister and some DCHECKS. // kInvalidVirtualRegister and some DCHECKS.
enum Kind { INVALID, UNALLOCATED, CONSTANT, IMMEDIATE, ALLOCATED }; enum Kind { INVALID, UNALLOCATED, CONSTANT, IMMEDIATE, ALLOCATED };
InstructionOperand() InstructionOperand() : InstructionOperand(INVALID) {}
: InstructionOperand(INVALID, 0, kInvalidVirtualRegister) {}
Kind kind() const { return KindField::decode(value_); } Kind kind() const { return KindField::decode(value_); }
...@@ -75,19 +74,9 @@ class InstructionOperand { ...@@ -75,19 +74,9 @@ class InstructionOperand {
} }
protected: protected:
InstructionOperand(Kind kind, int index, int virtual_register) { explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {}
if (kind != UNALLOCATED && kind != CONSTANT) {
DCHECK(virtual_register == kInvalidVirtualRegister);
}
value_ = KindField::encode(kind);
value_ |=
VirtualRegisterField::encode(static_cast<uint32_t>(virtual_register));
value_ |= static_cast<int64_t>(index) << IndexField::kShift;
}
typedef BitField64<Kind, 0, 3> KindField; class KindField : public BitField64<Kind, 0, 3> {};
typedef BitField64<uint32_t, 3, 32> VirtualRegisterField;
typedef BitField64<int32_t, 35, 29> IndexField;
uint64_t value_; uint64_t value_;
}; };
...@@ -146,14 +135,14 @@ class UnallocatedOperand : public InstructionOperand { ...@@ -146,14 +135,14 @@ class UnallocatedOperand : public InstructionOperand {
}; };
UnallocatedOperand(ExtendedPolicy policy, int virtual_register) UnallocatedOperand(ExtendedPolicy policy, int virtual_register)
: InstructionOperand(UNALLOCATED, 0, virtual_register) { : UnallocatedOperand(virtual_register) {
value_ |= BasicPolicyField::encode(EXTENDED_POLICY); value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
value_ |= ExtendedPolicyField::encode(policy); value_ |= ExtendedPolicyField::encode(policy);
value_ |= LifetimeField::encode(USED_AT_END); value_ |= LifetimeField::encode(USED_AT_END);
} }
UnallocatedOperand(BasicPolicy policy, int index, int virtual_register) UnallocatedOperand(BasicPolicy policy, int index, int virtual_register)
: InstructionOperand(UNALLOCATED, 0, virtual_register) { : UnallocatedOperand(virtual_register) {
DCHECK(policy == FIXED_SLOT); DCHECK(policy == FIXED_SLOT);
value_ |= BasicPolicyField::encode(policy); value_ |= BasicPolicyField::encode(policy);
value_ |= static_cast<int64_t>(index) << FixedSlotIndexField::kShift; value_ |= static_cast<int64_t>(index) << FixedSlotIndexField::kShift;
...@@ -161,7 +150,7 @@ class UnallocatedOperand : public InstructionOperand { ...@@ -161,7 +150,7 @@ class UnallocatedOperand : public InstructionOperand {
} }
UnallocatedOperand(ExtendedPolicy policy, int index, int virtual_register) UnallocatedOperand(ExtendedPolicy policy, int index, int virtual_register)
: InstructionOperand(UNALLOCATED, 0, virtual_register) { : UnallocatedOperand(virtual_register) {
DCHECK(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER); DCHECK(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER);
value_ |= BasicPolicyField::encode(EXTENDED_POLICY); value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
value_ |= ExtendedPolicyField::encode(policy); value_ |= ExtendedPolicyField::encode(policy);
...@@ -171,7 +160,7 @@ class UnallocatedOperand : public InstructionOperand { ...@@ -171,7 +160,7 @@ class UnallocatedOperand : public InstructionOperand {
UnallocatedOperand(ExtendedPolicy policy, Lifetime lifetime, UnallocatedOperand(ExtendedPolicy policy, Lifetime lifetime,
int virtual_register) int virtual_register)
: InstructionOperand(UNALLOCATED, 0, virtual_register) { : UnallocatedOperand(virtual_register) {
value_ |= BasicPolicyField::encode(EXTENDED_POLICY); value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
value_ |= ExtendedPolicyField::encode(policy); value_ |= ExtendedPolicyField::encode(policy);
value_ |= LifetimeField::encode(lifetime); value_ |= LifetimeField::encode(lifetime);
...@@ -183,40 +172,6 @@ class UnallocatedOperand : public InstructionOperand { ...@@ -183,40 +172,6 @@ class UnallocatedOperand : public InstructionOperand {
return New(zone, UnallocatedOperand(ANY, virtual_register())); return New(zone, UnallocatedOperand(ANY, virtual_register()));
} }
// The encoding used for UnallocatedOperand operands depends on the policy
// that is
// stored within the operand. The FIXED_SLOT policy uses a compact encoding
// because it accommodates a larger pay-load.
//
// For FIXED_SLOT policy:
// +------------------------------------------------+
// | slot_index | 0 | virtual_register | 001 |
// +------------------------------------------------+
//
// For all other (extended) policies:
// +-----------------------------------------------------+
// | reg_index | L | PPP | 1 | virtual_register | 001 |
// +-----------------------------------------------------+
// L ... Lifetime
// P ... Policy
//
// The slot index is a signed value which requires us to decode it manually
// instead of using the BitField utility class.
// All bits fit into the index field.
STATIC_ASSERT(IndexField::kShift == 35);
// BitFields for all unallocated operands.
class BasicPolicyField : public BitField64<BasicPolicy, 35, 1> {};
// BitFields specific to BasicPolicy::FIXED_SLOT.
class FixedSlotIndexField : public BitField64<int, 36, 28> {};
// BitFields specific to BasicPolicy::EXTENDED_POLICY.
class ExtendedPolicyField : public BitField64<ExtendedPolicy, 36, 3> {};
class LifetimeField : public BitField64<Lifetime, 39, 1> {};
class FixedRegisterField : public BitField64<int, 40, 6> {};
// Predicates for the operand policy. // Predicates for the operand policy.
bool HasAnyPolicy() const { bool HasAnyPolicy() const {
return basic_policy() == EXTENDED_POLICY && extended_policy() == ANY; return basic_policy() == EXTENDED_POLICY && extended_policy() == ANY;
...@@ -292,13 +247,58 @@ class UnallocatedOperand : public InstructionOperand { ...@@ -292,13 +247,58 @@ class UnallocatedOperand : public InstructionOperand {
} }
INSTRUCTION_OPERAND_CASTS(UnallocatedOperand, UNALLOCATED); INSTRUCTION_OPERAND_CASTS(UnallocatedOperand, UNALLOCATED);
// The encoding used for UnallocatedOperand operands depends on the policy
// that is
// stored within the operand. The FIXED_SLOT policy uses a compact encoding
// because it accommodates a larger pay-load.
//
// For FIXED_SLOT policy:
// +------------------------------------------------+
// | slot_index | 0 | virtual_register | 001 |
// +------------------------------------------------+
//
// For all other (extended) policies:
// +-----------------------------------------------------+
// | reg_index | L | PPP | 1 | virtual_register | 001 |
// +-----------------------------------------------------+
// L ... Lifetime
// P ... Policy
//
// The slot index is a signed value which requires us to decode it manually
// instead of using the BitField utility class.
STATIC_ASSERT(KindField::kSize == 3);
class VirtualRegisterField : public BitField64<uint32_t, 3, 32> {};
// BitFields for all unallocated operands.
class BasicPolicyField : public BitField64<BasicPolicy, 35, 1> {};
// BitFields specific to BasicPolicy::FIXED_SLOT.
class FixedSlotIndexField : public BitField64<int, 36, 28> {};
// BitFields specific to BasicPolicy::EXTENDED_POLICY.
class ExtendedPolicyField : public BitField64<ExtendedPolicy, 36, 3> {};
class LifetimeField : public BitField64<Lifetime, 39, 1> {};
class FixedRegisterField : public BitField64<int, 40, 6> {};
private:
explicit UnallocatedOperand(int virtual_register)
: InstructionOperand(UNALLOCATED) {
value_ |=
VirtualRegisterField::encode(static_cast<uint32_t>(virtual_register));
}
}; };
class ConstantOperand : public InstructionOperand { class ConstantOperand : public InstructionOperand {
public: public:
explicit ConstantOperand(int virtual_register) explicit ConstantOperand(int virtual_register)
: InstructionOperand(CONSTANT, 0, virtual_register) {} : InstructionOperand(CONSTANT) {
value_ |=
VirtualRegisterField::encode(static_cast<uint32_t>(virtual_register));
}
int32_t virtual_register() const { int32_t virtual_register() const {
return static_cast<int32_t>(VirtualRegisterField::decode(value_)); return static_cast<int32_t>(VirtualRegisterField::decode(value_));
...@@ -309,13 +309,17 @@ class ConstantOperand : public InstructionOperand { ...@@ -309,13 +309,17 @@ class ConstantOperand : public InstructionOperand {
} }
INSTRUCTION_OPERAND_CASTS(ConstantOperand, CONSTANT); INSTRUCTION_OPERAND_CASTS(ConstantOperand, CONSTANT);
STATIC_ASSERT(KindField::kSize == 3);
class VirtualRegisterField : public BitField64<uint32_t, 3, 32> {};
}; };
class ImmediateOperand : public InstructionOperand { class ImmediateOperand : public InstructionOperand {
public: public:
explicit ImmediateOperand(int index) explicit ImmediateOperand(int index) : InstructionOperand(IMMEDIATE) {
: InstructionOperand(IMMEDIATE, index, kInvalidVirtualRegister) {} value_ |= static_cast<int64_t>(index) << IndexField::kShift;
}
int index() const { int index() const {
return static_cast<int64_t>(value_) >> IndexField::kShift; return static_cast<int64_t>(value_) >> IndexField::kShift;
...@@ -326,6 +330,9 @@ class ImmediateOperand : public InstructionOperand { ...@@ -326,6 +330,9 @@ class ImmediateOperand : public InstructionOperand {
} }
INSTRUCTION_OPERAND_CASTS(ImmediateOperand, IMMEDIATE); INSTRUCTION_OPERAND_CASTS(ImmediateOperand, IMMEDIATE);
STATIC_ASSERT(KindField::kSize == 3);
class IndexField : public BitField64<int32_t, 35, 29> {};
}; };
...@@ -339,9 +346,10 @@ class AllocatedOperand : public InstructionOperand { ...@@ -339,9 +346,10 @@ class AllocatedOperand : public InstructionOperand {
}; };
AllocatedOperand(AllocatedKind kind, int index) AllocatedOperand(AllocatedKind kind, int index)
: InstructionOperand(ALLOCATED, index, kInvalidVirtualRegister) { : InstructionOperand(ALLOCATED) {
if (kind == REGISTER || kind == DOUBLE_REGISTER) DCHECK(index >= 0); DCHECK_IMPLIES(kind == REGISTER || kind == DOUBLE_REGISTER, index >= 0);
value_ = AllocatedKindField::update(value_, kind); value_ |= AllocatedKindField::encode(kind);
value_ |= static_cast<int64_t>(index) << IndexField::kShift;
} }
int index() const { int index() const {
...@@ -358,8 +366,9 @@ class AllocatedOperand : public InstructionOperand { ...@@ -358,8 +366,9 @@ class AllocatedOperand : public InstructionOperand {
INSTRUCTION_OPERAND_CASTS(AllocatedOperand, ALLOCATED); INSTRUCTION_OPERAND_CASTS(AllocatedOperand, ALLOCATED);
private: STATIC_ASSERT(KindField::kSize == 3);
typedef BitField64<AllocatedKind, 3, 2> AllocatedKindField; class AllocatedKindField : public BitField64<AllocatedKind, 3, 2> {};
class IndexField : public BitField64<int32_t, 35, 29> {};
}; };
......
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