Commit b5c9e31c authored by bbudge's avatar bbudge Committed by Commit bot

[Turbofan] Streamline InstructionOperand predicate methods.

- Orders machine representations so it's easier to check for floating
point.
- Orders operand types so it's easier to check for LocationOperands.
- Adds IsLocation, IsFPLocation predicates.

LOG=N
BUG=v8:4124

Review-Url: https://codereview.chromium.org/2382013003
Cr-Commit-Position: refs/heads/master@{#39941}
parent 60ab52e7
...@@ -33,7 +33,17 @@ class InstructionOperand { ...@@ -33,7 +33,17 @@ class InstructionOperand {
// TODO(dcarney): recover bit. INVALID can be represented as UNALLOCATED with // TODO(dcarney): recover bit. INVALID can be represented as UNALLOCATED with
// kInvalidVirtualRegister and some DCHECKS. // kInvalidVirtualRegister and some DCHECKS.
enum Kind { INVALID, UNALLOCATED, CONSTANT, IMMEDIATE, EXPLICIT, ALLOCATED }; enum Kind {
INVALID,
UNALLOCATED,
CONSTANT,
IMMEDIATE,
// Location operand kinds.
EXPLICIT,
ALLOCATED,
FIRST_LOCATION_OPERAND_KIND = EXPLICIT
// Location operand kinds must be last.
};
InstructionOperand() : InstructionOperand(INVALID) {} InstructionOperand() : InstructionOperand(INVALID) {}
...@@ -64,12 +74,16 @@ class InstructionOperand { ...@@ -64,12 +74,16 @@ class InstructionOperand {
INSTRUCTION_OPERAND_PREDICATE(Allocated, ALLOCATED) INSTRUCTION_OPERAND_PREDICATE(Allocated, ALLOCATED)
#undef INSTRUCTION_OPERAND_PREDICATE #undef INSTRUCTION_OPERAND_PREDICATE
inline bool IsAnyLocationOperand() const;
inline bool IsLocationOperand() const;
inline bool IsFPLocationOperand() const;
inline bool IsAnyRegister() const; inline bool IsAnyRegister() const;
inline bool IsRegister() const; inline bool IsRegister() const;
inline bool IsFPRegister() const; inline bool IsFPRegister() const;
inline bool IsFloatRegister() const; inline bool IsFloatRegister() const;
inline bool IsDoubleRegister() const; inline bool IsDoubleRegister() const;
inline bool IsSimd128Register() const; inline bool IsSimd128Register() const;
inline bool IsAnyStackSlot() const;
inline bool IsStackSlot() const; inline bool IsStackSlot() const;
inline bool IsFPStackSlot() const; inline bool IsFPStackSlot() const;
inline bool IsFloatStackSlot() const; inline bool IsFloatStackSlot() const;
...@@ -482,17 +496,17 @@ class LocationOperand : public InstructionOperand { ...@@ -482,17 +496,17 @@ class LocationOperand : public InstructionOperand {
} }
static LocationOperand* cast(InstructionOperand* op) { static LocationOperand* cast(InstructionOperand* op) {
DCHECK(ALLOCATED == op->kind() || EXPLICIT == op->kind()); DCHECK(op->IsAnyLocationOperand());
return static_cast<LocationOperand*>(op); return static_cast<LocationOperand*>(op);
} }
static const LocationOperand* cast(const InstructionOperand* op) { static const LocationOperand* cast(const InstructionOperand* op) {
DCHECK(ALLOCATED == op->kind() || EXPLICIT == op->kind()); DCHECK(op->IsAnyLocationOperand());
return static_cast<const LocationOperand*>(op); return static_cast<const LocationOperand*>(op);
} }
static LocationOperand cast(const InstructionOperand& op) { static LocationOperand cast(const InstructionOperand& op) {
DCHECK(ALLOCATED == op.kind() || EXPLICIT == op.kind()); DCHECK(op.IsAnyLocationOperand());
return *static_cast<const LocationOperand*>(&op); return *static_cast<const LocationOperand*>(&op);
} }
...@@ -532,9 +546,22 @@ class AllocatedOperand : public LocationOperand { ...@@ -532,9 +546,22 @@ class AllocatedOperand : public LocationOperand {
#undef INSTRUCTION_OPERAND_CASTS #undef INSTRUCTION_OPERAND_CASTS
bool InstructionOperand::IsAnyLocationOperand() const {
return this->kind() >= FIRST_LOCATION_OPERAND_KIND;
}
bool InstructionOperand::IsLocationOperand() const {
return IsAnyLocationOperand() &&
!IsFloatingPoint(LocationOperand::cast(this)->representation());
}
bool InstructionOperand::IsFPLocationOperand() const {
return IsAnyLocationOperand() &&
IsFloatingPoint(LocationOperand::cast(this)->representation());
}
bool InstructionOperand::IsAnyRegister() const { bool InstructionOperand::IsAnyRegister() const {
return (IsAllocated() || IsExplicit()) && return IsAnyLocationOperand() &&
LocationOperand::cast(this)->location_kind() == LocationOperand::cast(this)->location_kind() ==
LocationOperand::REGISTER; LocationOperand::REGISTER;
} }
...@@ -568,22 +595,24 @@ bool InstructionOperand::IsSimd128Register() const { ...@@ -568,22 +595,24 @@ bool InstructionOperand::IsSimd128Register() const {
MachineRepresentation::kSimd128; MachineRepresentation::kSimd128;
} }
bool InstructionOperand::IsStackSlot() const { bool InstructionOperand::IsAnyStackSlot() const {
return (IsAllocated() || IsExplicit()) && return IsAnyLocationOperand() &&
LocationOperand::cast(this)->location_kind() == LocationOperand::cast(this)->location_kind() ==
LocationOperand::STACK_SLOT && LocationOperand::STACK_SLOT;
}
bool InstructionOperand::IsStackSlot() const {
return IsAnyStackSlot() &&
!IsFloatingPoint(LocationOperand::cast(this)->representation()); !IsFloatingPoint(LocationOperand::cast(this)->representation());
} }
bool InstructionOperand::IsFPStackSlot() const { bool InstructionOperand::IsFPStackSlot() const {
return (IsAllocated() || IsExplicit()) && return IsAnyStackSlot() &&
LocationOperand::cast(this)->location_kind() ==
LocationOperand::STACK_SLOT &&
IsFloatingPoint(LocationOperand::cast(this)->representation()); IsFloatingPoint(LocationOperand::cast(this)->representation());
} }
bool InstructionOperand::IsFloatStackSlot() const { bool InstructionOperand::IsFloatStackSlot() const {
return (IsAllocated() || IsExplicit()) && return IsAnyLocationOperand() &&
LocationOperand::cast(this)->location_kind() == LocationOperand::cast(this)->location_kind() ==
LocationOperand::STACK_SLOT && LocationOperand::STACK_SLOT &&
LocationOperand::cast(this)->representation() == LocationOperand::cast(this)->representation() ==
...@@ -591,7 +620,7 @@ bool InstructionOperand::IsFloatStackSlot() const { ...@@ -591,7 +620,7 @@ bool InstructionOperand::IsFloatStackSlot() const {
} }
bool InstructionOperand::IsDoubleStackSlot() const { bool InstructionOperand::IsDoubleStackSlot() const {
return (IsAllocated() || IsExplicit()) && return IsAnyLocationOperand() &&
LocationOperand::cast(this)->location_kind() == LocationOperand::cast(this)->location_kind() ==
LocationOperand::STACK_SLOT && LocationOperand::STACK_SLOT &&
LocationOperand::cast(this)->representation() == LocationOperand::cast(this)->representation() ==
...@@ -599,7 +628,7 @@ bool InstructionOperand::IsDoubleStackSlot() const { ...@@ -599,7 +628,7 @@ bool InstructionOperand::IsDoubleStackSlot() const {
} }
bool InstructionOperand::IsSimd128StackSlot() const { bool InstructionOperand::IsSimd128StackSlot() const {
return (IsAllocated() || IsExplicit()) && return IsAnyLocationOperand() &&
LocationOperand::cast(this)->location_kind() == LocationOperand::cast(this)->location_kind() ==
LocationOperand::STACK_SLOT && LocationOperand::STACK_SLOT &&
LocationOperand::cast(this)->representation() == LocationOperand::cast(this)->representation() ==
...@@ -607,7 +636,7 @@ bool InstructionOperand::IsSimd128StackSlot() const { ...@@ -607,7 +636,7 @@ bool InstructionOperand::IsSimd128StackSlot() const {
} }
uint64_t InstructionOperand::GetCanonicalizedValue() const { uint64_t InstructionOperand::GetCanonicalizedValue() const {
if (IsAllocated() || IsExplicit()) { if (IsAnyLocationOperand()) {
MachineRepresentation canonical = MachineRepresentation::kNone; MachineRepresentation canonical = MachineRepresentation::kNone;
if (IsFPRegister()) { if (IsFPRegister()) {
// We treat all FP register operands the same for simple aliasing. // We treat all FP register operands the same for simple aliasing.
......
...@@ -22,12 +22,14 @@ enum class MachineRepresentation : uint8_t { ...@@ -22,12 +22,14 @@ enum class MachineRepresentation : uint8_t {
kWord16, kWord16,
kWord32, kWord32,
kWord64, kWord64,
kFloat32,
kFloat64, // must follow kFloat32
kSimd128, // must follow kFloat64
kTaggedSigned, kTaggedSigned,
kTaggedPointer, kTaggedPointer,
kTagged kTagged,
// FP representations must be last, and in order of increasing size.
kFloat32,
kFloat64,
kSimd128,
kFirstFPRepresentation = kFloat32
}; };
const char* MachineReprToString(MachineRepresentation); const char* MachineReprToString(MachineRepresentation);
...@@ -224,9 +226,7 @@ std::ostream& operator<<(std::ostream& os, MachineSemantic type); ...@@ -224,9 +226,7 @@ std::ostream& operator<<(std::ostream& os, MachineSemantic type);
std::ostream& operator<<(std::ostream& os, MachineType type); std::ostream& operator<<(std::ostream& os, MachineType type);
inline bool IsFloatingPoint(MachineRepresentation rep) { inline bool IsFloatingPoint(MachineRepresentation rep) {
return rep == MachineRepresentation::kFloat32 || return rep >= MachineRepresentation::kFirstFPRepresentation;
rep == MachineRepresentation::kFloat64 ||
rep == MachineRepresentation::kSimd128;
} }
inline bool CanBeTaggedPointer(MachineRepresentation rep) { inline bool CanBeTaggedPointer(MachineRepresentation rep) {
......
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