Commit 54536f4f authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm][formatting] Split ValueType class into regions

Additional change: Add ValueType::is_bottom()

Change-Id: I8e294c6318b6e51efac0a07ac0ec059ea9dc5654
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2440515
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70243}
parent 0763e924
...@@ -178,38 +178,7 @@ class ValueType { ...@@ -178,38 +178,7 @@ class ValueType {
#undef DEF_ENUM #undef DEF_ENUM
}; };
constexpr bool is_reference_type() const { /******************************* Constructors *******************************/
return kind() == kRef || kind() == kOptRef || kind() == kRtt;
}
constexpr bool is_object_reference_type() const {
return kind() == kRef || kind() == kOptRef;
}
constexpr bool is_packed() const { return kind() == kI8 || kind() == kI16; }
constexpr bool is_nullable() const { return kind() == kOptRef; }
constexpr bool is_reference_to(uint32_t htype) const {
return (kind() == kRef || kind() == kOptRef) &&
heap_representation() == htype;
}
constexpr bool is_defaultable() const {
CONSTEXPR_DCHECK(kind() != kBottom && kind() != kStmt);
return kind() != kRef && kind() != kRtt;
}
constexpr ValueType Unpacked() const {
return is_packed() ? Primitive(kI32) : *this;
}
constexpr bool has_index() const {
return is_reference_type() && heap_type().is_index();
}
constexpr bool is_rtt() const { return kind() == kRtt; }
constexpr bool has_depth() const { return is_rtt(); }
constexpr ValueType() : bit_field_(KindField::encode(kStmt)) {} constexpr ValueType() : bit_field_(KindField::encode(kStmt)) {}
static constexpr ValueType Primitive(Kind kind) { static constexpr ValueType Primitive(Kind kind) {
CONSTEXPR_DCHECK(kind == kBottom || kind <= kI16); CONSTEXPR_DCHECK(kind == kBottom || kind <= kI16);
...@@ -242,6 +211,43 @@ class ValueType { ...@@ -242,6 +211,43 @@ class ValueType {
return ValueType(bit_field); return ValueType(bit_field);
} }
/******************************** Type checks *******************************/
constexpr bool is_reference_type() const {
return kind() == kRef || kind() == kOptRef || kind() == kRtt;
}
constexpr bool is_object_reference_type() const {
return kind() == kRef || kind() == kOptRef;
}
constexpr bool is_nullable() const { return kind() == kOptRef; }
constexpr bool is_reference_to(uint32_t htype) const {
return (kind() == kRef || kind() == kOptRef) &&
heap_representation() == htype;
}
constexpr bool is_rtt() const { return kind() == kRtt; }
constexpr bool has_depth() const { return is_rtt(); }
constexpr bool has_index() const {
return is_reference_type() && heap_type().is_index();
}
constexpr bool is_defaultable() const {
CONSTEXPR_DCHECK(kind() != kBottom && kind() != kStmt);
return kind() != kRef && kind() != kRtt;
}
constexpr bool is_bottom() const { return kind() == kBottom; }
constexpr bool is_packed() const { return kind() == kI8 || kind() == kI16; }
constexpr ValueType Unpacked() const {
return is_packed() ? Primitive(kI32) : *this;
}
/***************************** Field Accessors ******************************/
constexpr Kind kind() const { return KindField::decode(bit_field_); } constexpr Kind kind() const { return KindField::decode(bit_field_); }
constexpr HeapType::Representation heap_representation() const { constexpr HeapType::Representation heap_representation() const {
CONSTEXPR_DCHECK(is_reference_type()); CONSTEXPR_DCHECK(is_reference_type());
...@@ -263,6 +269,14 @@ class ValueType { ...@@ -263,6 +269,14 @@ class ValueType {
// Useful when serializing this type to store it into a runtime object. // Useful when serializing this type to store it into a runtime object.
constexpr uint32_t raw_bit_field() const { return bit_field_; } constexpr uint32_t raw_bit_field() const { return bit_field_; }
/*************************** Other utility methods **************************/
constexpr bool operator==(ValueType other) const {
return bit_field_ == other.bit_field_;
}
constexpr bool operator!=(ValueType other) const {
return bit_field_ != other.bit_field_;
}
static constexpr size_t bit_field_offset() { static constexpr size_t bit_field_offset() {
return offsetof(ValueType, bit_field_); return offsetof(ValueType, bit_field_);
} }
...@@ -292,13 +306,7 @@ class ValueType { ...@@ -292,13 +306,7 @@ class ValueType {
return size; return size;
} }
constexpr bool operator==(ValueType other) const { /*************************** Machine-type related ***************************/
return bit_field_ == other.bit_field_;
}
constexpr bool operator!=(ValueType other) const {
return bit_field_ != other.bit_field_;
}
constexpr MachineType machine_type() const { constexpr MachineType machine_type() const {
CONSTEXPR_DCHECK(kBottom != kind()); CONSTEXPR_DCHECK(kBottom != kind());
...@@ -316,6 +324,29 @@ class ValueType { ...@@ -316,6 +324,29 @@ class ValueType {
return machine_type().representation(); return machine_type().representation();
} }
static ValueType For(MachineType type) {
switch (type.representation()) {
case MachineRepresentation::kWord8:
case MachineRepresentation::kWord16:
case MachineRepresentation::kWord32:
return Primitive(kI32);
case MachineRepresentation::kWord64:
return Primitive(kI64);
case MachineRepresentation::kFloat32:
return Primitive(kF32);
case MachineRepresentation::kFloat64:
return Primitive(kF64);
case MachineRepresentation::kTaggedPointer:
return Ref(HeapType::kExtern, kNullable);
case MachineRepresentation::kSimd128:
return Primitive(kS128);
default:
UNREACHABLE();
}
}
/********************************* Encoding *********************************/
// Returns the first byte of this type's representation in the wasm binary // Returns the first byte of this type's representation in the wasm binary
// format. // format.
// For compatibility with the reftypes and exception-handling proposals, this // For compatibility with the reftypes and exception-handling proposals, this
...@@ -365,27 +396,9 @@ class ValueType { ...@@ -365,27 +396,9 @@ class ValueType {
heap_representation() == HeapType::kI31)); heap_representation() == HeapType::kI31));
} }
static ValueType For(MachineType type) { static constexpr int kLastUsedBit = 30;
switch (type.representation()) {
case MachineRepresentation::kWord8:
case MachineRepresentation::kWord16:
case MachineRepresentation::kWord32:
return Primitive(kI32);
case MachineRepresentation::kWord64:
return Primitive(kI64);
case MachineRepresentation::kFloat32:
return Primitive(kF32);
case MachineRepresentation::kFloat64:
return Primitive(kF64);
case MachineRepresentation::kTaggedPointer:
return Ref(HeapType::kExtern, kNullable);
case MachineRepresentation::kSimd128:
return Primitive(kS128);
default:
UNREACHABLE();
}
}
/****************************** Pretty-printing *****************************/
constexpr char short_name() const { constexpr char short_name() const {
constexpr char kShortName[] = { constexpr char kShortName[] = {
#define SHORT_NAME(kind, log2Size, code, machineType, shortName, ...) shortName, #define SHORT_NAME(kind, log2Size, code, machineType, shortName, ...) shortName,
...@@ -425,8 +438,6 @@ class ValueType { ...@@ -425,8 +438,6 @@ class ValueType {
return buf.str(); return buf.str();
} }
static constexpr int kLastUsedBit = 30;
private: private:
// We only use 31 bits so ValueType fits in a Smi. This can be changed if // We only use 31 bits so ValueType fits in a Smi. This can be changed if
// needed. // needed.
......
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