Commit 648ac440 authored by mvstanton's avatar mvstanton Committed by Commit bot

[turbofan] Cleanup: Type only has a semantic dimension.

BUG=

Review-Url: https://codereview.chromium.org/2366433003
Cr-Commit-Position: refs/heads/master@{#39666}
parent 01cd881b
......@@ -196,7 +196,7 @@ Node* RepresentationChanger::GetTaggedSignedRepresentationFor(
}
// Select the correct X -> Tagged operator.
const Operator* op;
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->Constant(0);
......@@ -293,7 +293,7 @@ Node* RepresentationChanger::GetTaggedPointerRepresentationFor(
break;
}
// Select the correct X -> Tagged operator.
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->TheHoleConstant();
......@@ -338,7 +338,7 @@ Node* RepresentationChanger::GetTaggedRepresentationFor(
}
// Select the correct X -> Tagged operator.
const Operator* op;
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->TheHoleConstant();
......@@ -420,7 +420,7 @@ Node* RepresentationChanger::GetFloat32RepresentationFor(
}
// Select the correct X -> Float32 operator.
const Operator* op = nullptr;
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->Float32Constant(0.0f);
......@@ -490,7 +490,7 @@ Node* RepresentationChanger::GetFloat64RepresentationFor(
}
// Select the correct X -> Float64 operator.
const Operator* op = nullptr;
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->Float64Constant(0.0);
......@@ -576,7 +576,7 @@ Node* RepresentationChanger::GetWord32RepresentationFor(
// Select the correct X -> Word32 operator.
const Operator* op = nullptr;
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->Int32Constant(0);
......@@ -698,7 +698,7 @@ Node* RepresentationChanger::GetBitRepresentationFor(
}
// Select the correct X -> Bit operator.
const Operator* op;
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->Int32Constant(0);
......@@ -737,7 +737,7 @@ Node* RepresentationChanger::GetBitRepresentationFor(
Node* RepresentationChanger::GetWord64RepresentationFor(
Node* node, MachineRepresentation output_rep, Type* output_type) {
if (Type::Semantic(output_type, jsgraph()->zone())->Is(Type::None())) {
if (output_type->Is(Type::None())) {
// This is an impossible value; it should not be used at runtime.
// We just provide a dummy value here.
return jsgraph()->Int64Constant(0);
......
......@@ -72,7 +72,7 @@ bool Type::Contains(RangeType* range, i::Object* val) {
// Min and Max computation.
double Type::Min() {
DCHECK(this->SemanticIs(Number()));
DCHECK(this->Is(Number()));
if (this->IsBitset()) return BitsetType::Min(this->AsBitset());
if (this->IsUnion()) {
double min = +V8_INFINITY;
......@@ -88,7 +88,7 @@ double Type::Min() {
}
double Type::Max() {
DCHECK(this->SemanticIs(Number()));
DCHECK(this->Is(Number()));
if (this->IsBitset()) return BitsetType::Max(this->AsBitset());
if (this->IsUnion()) {
double max = -V8_INFINITY;
......@@ -115,10 +115,10 @@ Type::bitset BitsetType::Glb(Type* type) {
} else if (type->IsUnion()) {
SLOW_DCHECK(type->AsUnion()->Wellformed());
return type->AsUnion()->Get(0)->BitsetGlb() |
SEMANTIC(type->AsUnion()->Get(1)->BitsetGlb()); // Shortcut.
type->AsUnion()->Get(1)->BitsetGlb(); // Shortcut.
} else if (type->IsRange()) {
bitset glb = SEMANTIC(
BitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max()));
bitset glb =
BitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max());
return glb;
} else {
return kNone;
......@@ -135,7 +135,7 @@ Type::bitset BitsetType::Lub(Type* type) {
int bitset = type->AsUnion()->Get(0)->BitsetLub();
for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
// Other elements only contribute their semantic part.
bitset |= SEMANTIC(type->AsUnion()->Get(i)->BitsetLub());
bitset |= type->AsUnion()->Get(i)->BitsetLub();
}
return bitset;
}
......@@ -315,12 +315,11 @@ size_t BitsetType::BoundariesSize() {
Type::bitset BitsetType::ExpandInternals(Type::bitset bits) {
DisallowHeapAllocation no_allocation;
if (!(bits & SEMANTIC(kPlainNumber))) return bits; // Shortcut.
if (!(bits & kPlainNumber)) return bits; // Shortcut.
const Boundary* boundaries = Boundaries();
for (size_t i = 0; i < BoundariesSize(); ++i) {
DCHECK(BitsetType::Is(boundaries[i].internal, boundaries[i].external));
if (bits & SEMANTIC(boundaries[i].internal))
bits |= SEMANTIC(boundaries[i].external);
if (bits & boundaries[i].internal) bits |= boundaries[i].external;
}
return bits;
}
......@@ -339,9 +338,7 @@ Type::bitset BitsetType::Lub(double min, double max) {
return lub | mins[BoundariesSize() - 1].internal;
}
Type::bitset BitsetType::NumberBits(bitset bits) {
return SEMANTIC(bits & kPlainNumber);
}
Type::bitset BitsetType::NumberBits(bitset bits) { return bits & kPlainNumber; }
Type::bitset BitsetType::Glb(double min, double max) {
DisallowHeapAllocation no_allocation;
......@@ -359,16 +356,16 @@ Type::bitset BitsetType::Glb(double min, double max) {
}
// OtherNumber also contains float numbers, so it can never be
// in the greatest lower bound.
return glb & ~(SEMANTIC(kOtherNumber));
return glb & ~(kOtherNumber);
}
double BitsetType::Min(bitset bits) {
DisallowHeapAllocation no_allocation;
DCHECK(Is(SEMANTIC(bits), kNumber));
DCHECK(Is(bits, kNumber));
const Boundary* mins = Boundaries();
bool mz = SEMANTIC(bits & kMinusZero);
bool mz = bits & kMinusZero;
for (size_t i = 0; i < BoundariesSize(); ++i) {
if (Is(SEMANTIC(mins[i].internal), bits)) {
if (Is(mins[i].internal, bits)) {
return mz ? std::min(0.0, mins[i].min) : mins[i].min;
}
}
......@@ -378,14 +375,14 @@ double BitsetType::Min(bitset bits) {
double BitsetType::Max(bitset bits) {
DisallowHeapAllocation no_allocation;
DCHECK(Is(SEMANTIC(bits), kNumber));
DCHECK(Is(bits, kNumber));
const Boundary* mins = Boundaries();
bool mz = SEMANTIC(bits & kMinusZero);
if (BitsetType::Is(SEMANTIC(mins[BoundariesSize() - 1].internal), bits)) {
bool mz = bits & kMinusZero;
if (BitsetType::Is(mins[BoundariesSize() - 1].internal, bits)) {
return +V8_INFINITY;
}
for (size_t i = BoundariesSize() - 1; i-- > 0;) {
if (Is(SEMANTIC(mins[i].internal), bits)) {
if (Is(mins[i].internal, bits)) {
return mz ? std::max(0.0, mins[i + 1].min - 1) : mins[i + 1].min - 1;
}
}
......@@ -431,28 +428,10 @@ bool Type::SlowIs(Type* that) {
return BitsetType::Is(this->AsBitset(), that->BitsetGlb());
}
// Check the semantic part.
return SemanticIs(that);
}
// Check if SEMANTIC([this]) <= SEMANTIC([that]). The result of the method
// should be independent of the representation axis of the types.
bool Type::SemanticIs(Type* that) {
DisallowHeapAllocation no_allocation;
if (this == that) return true;
if (that->IsBitset()) {
return BitsetType::Is(SEMANTIC(this->BitsetLub()), that->AsBitset());
}
if (this->IsBitset()) {
return BitsetType::Is(SEMANTIC(this->AsBitset()), that->BitsetGlb());
}
// (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T)
if (this->IsUnion()) {
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
if (!this->AsUnion()->Get(i)->SemanticIs(that)) return false;
if (!this->AsUnion()->Get(i)->Is(that)) return false;
}
return true;
}
......@@ -460,7 +439,7 @@ bool Type::SemanticIs(Type* that) {
// T <= (T1 \/ ... \/ Tn) if (T <= T1) \/ ... \/ (T <= Tn)
if (that->IsUnion()) {
for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
if (this->SemanticIs(that->AsUnion()->Get(i))) return true;
if (this->Is(that->AsUnion()->Get(i))) return true;
if (i > 1 && this->IsRange()) return false; // Shortcut.
}
return false;
......@@ -480,21 +459,13 @@ bool Type::SemanticIs(Type* that) {
bool Type::Maybe(Type* that) {
DisallowHeapAllocation no_allocation;
// Take care of the representation part (and also approximate
// the semantic part).
if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub()))
return false;
return SemanticMaybe(that);
}
bool Type::SemanticMaybe(Type* that) {
DisallowHeapAllocation no_allocation;
// (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T)
if (this->IsUnion()) {
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
if (this->AsUnion()->Get(i)->SemanticMaybe(that)) return true;
if (this->AsUnion()->Get(i)->Maybe(that)) return true;
}
return false;
}
......@@ -502,14 +473,11 @@ bool Type::SemanticMaybe(Type* that) {
// T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn)
if (that->IsUnion()) {
for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
if (this->SemanticMaybe(that->AsUnion()->Get(i))) return true;
if (this->Maybe(that->AsUnion()->Get(i))) return true;
}
return false;
}
if (!BitsetType::SemanticIsInhabited(this->BitsetLub() & that->BitsetLub()))
return false;
if (this->IsBitset() && that->IsBitset()) return true;
if (this->IsRange()) {
......@@ -530,7 +498,7 @@ bool Type::SemanticMaybe(Type* that) {
}
}
if (that->IsRange()) {
return that->SemanticMaybe(this); // This case is handled above.
return that->Maybe(this); // This case is handled above.
}
if (this->IsBitset() || that->IsBitset()) return true;
......@@ -578,8 +546,7 @@ bool UnionType::Wellformed() {
if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3)
DCHECK(!this->Get(i)->IsUnion()); // (4)
for (int j = 0; j < this->Length(); ++j) {
if (i != j && i != 0)
DCHECK(!this->Get(i)->SemanticIs(this->Get(j))); // (5)
if (i != j && i != 0) DCHECK(!this->Get(i)->Is(this->Get(j))); // (5)
}
}
DCHECK(!this->Get(1)->IsRange() ||
......@@ -614,13 +581,13 @@ Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) {
// Semantic subtyping check - this is needed for consistency with the
// semi-fast case above.
if (type1->SemanticIs(type2)) {
if (type1->Is(type2)) {
type2 = Any();
} else if (type2->SemanticIs(type1)) {
} else if (type2->Is(type1)) {
type1 = Any();
}
bitset bits = SEMANTIC(type1->BitsetGlb() & type2->BitsetGlb());
bitset bits = type1->BitsetGlb() & type2->BitsetGlb();
int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
if (!AddIsSafe(size1, size2)) return Any();
......@@ -661,7 +628,7 @@ int Type::UpdateRange(Type* range, UnionType* result, int size, Zone* zone) {
// Remove any components that just got subsumed.
for (int i = 2; i < size;) {
if (result->Get(i)->SemanticIs(range)) {
if (result->Get(i)->Is(range)) {
result->Set(i, result->Get(--size));
} else {
++i;
......@@ -705,7 +672,7 @@ int Type::IntersectAux(Type* lhs, Type* rhs, UnionType* result, int size,
return size;
}
if (!BitsetType::SemanticIsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) {
if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) {
return size;
}
......@@ -757,7 +724,7 @@ Type* Type::NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone) {
// If the range is semantically contained within the bitset, return None and
// leave the bitset untouched.
bitset range_lub = SEMANTIC(range->BitsetLub());
bitset range_lub = range->BitsetLub();
if (BitsetType::Is(range_lub, *bits)) {
return None();
}
......@@ -814,7 +781,7 @@ Type* Type::Union(Type* type1, Type* type2, Zone* zone) {
size = 0;
// Compute the new bitset.
bitset new_bitset = SEMANTIC(type1->BitsetGlb() | type2->BitsetGlb());
bitset new_bitset = type1->BitsetGlb() | type2->BitsetGlb();
// Deal with ranges.
Type* range = None();
......@@ -831,7 +798,6 @@ Type* Type::Union(Type* type1, Type* type2, Zone* zone) {
} else if (range2 != NULL) {
range = NormalizeRangeAndBitset(range2, &new_bitset, zone);
}
new_bitset = SEMANTIC(new_bitset);
Type* bits = BitsetType::New(new_bitset);
result->Set(size++, bits);
if (!range->IsNone()) result->Set(size++, range);
......@@ -852,7 +818,7 @@ int Type::AddToUnion(Type* type, UnionType* result, int size, Zone* zone) {
return size;
}
for (int i = 0; i < size; ++i) {
if (type->SemanticIs(result->Get(i))) return size;
if (type->Is(result->Get(i))) return size;
}
result->Set(size++, type);
return size;
......@@ -868,7 +834,7 @@ Type* Type::NormalizeUnion(Type* union_type, int size, Zone* zone) {
}
bitset bits = unioned->Get(0)->AsBitset();
// If the union only consists of a range, we can get rid of the union.
if (size == 2 && SEMANTIC(bits) == BitsetType::kNone) {
if (size == 2 && bits == BitsetType::kNone) {
if (unioned->Get(1)->IsRange()) {
return RangeType::New(unioned->Get(1)->AsRange()->Min(),
unioned->Get(1)->AsRange()->Max(), zone);
......@@ -879,14 +845,6 @@ Type* Type::NormalizeUnion(Type* union_type, int size, Zone* zone) {
return union_type;
}
// -----------------------------------------------------------------------------
// Component extraction
// static
Type* Type::Semantic(Type* t, Zone* zone) {
return Intersect(t, BitsetType::New(BitsetType::kSemantic), zone);
}
// -----------------------------------------------------------------------------
// Iteration.
......@@ -956,12 +914,12 @@ void Type::Iterator<T>::Advance() {
const char* BitsetType::Name(bitset bits) {
switch (bits) {
#define RETURN_NAMED_SEMANTIC_TYPE(type, value) \
case SEMANTIC(k##type): \
#define RETURN_NAMED_TYPE(type, value) \
case k##type: \
return #type;
SEMANTIC_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE)
INTERNAL_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE)
#undef RETURN_NAMED_SEMANTIC_TYPE
PROPER_BITSET_TYPE_LIST(RETURN_NAMED_TYPE)
INTERNAL_BITSET_TYPE_LIST(RETURN_NAMED_TYPE)
#undef RETURN_NAMED_TYPE
default:
return NULL;
......@@ -979,9 +937,9 @@ void BitsetType::Print(std::ostream& os, // NOLINT
// clang-format off
static const bitset named_bitsets[] = {
#define BITSET_CONSTANT(type, value) SEMANTIC(k##type),
#define BITSET_CONSTANT(type, value) k##type,
INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT)
SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT)
PROPER_BITSET_TYPE_LIST(BITSET_CONSTANT)
#undef BITSET_CONSTANT
};
// clang-format on
......@@ -1004,7 +962,7 @@ void BitsetType::Print(std::ostream& os, // NOLINT
void Type::PrintTo(std::ostream& os) {
DisallowHeapAllocation no_allocation;
if (this->IsBitset()) {
BitsetType::Print(os, SEMANTIC(this->AsBitset()));
BitsetType::Print(os, this->AsBitset());
} else if (this->IsConstant()) {
os << "Constant(" << Brief(*this->AsConstant()->Value()) << ")";
} else if (this->IsRange()) {
......
......@@ -22,13 +22,7 @@ namespace compiler {
// can express class types (a.k.a. specific maps) and singleton types (i.e.,
// concrete constants).
//
// Types consist of two dimensions: semantic (value range) and representation.
// Both are related through subtyping.
//
//
// SEMANTIC DIMENSION
//
// The following equations and inequations hold for the semantic axis:
// The following equations and inequations hold:
//
// None <= T
// T <= Any
......@@ -40,7 +34,6 @@ namespace compiler {
// InternalizedString < String
//
// Receiver = Object \/ Proxy
// RegExp < Object
// OtherUndetectable < Object
// DetectableReceiver = Receiver - OtherUndetectable
//
......@@ -103,18 +96,13 @@ namespace compiler {
// clang-format off
#define MASK_BITSET_TYPE_LIST(V) \
V(Semantic, 0xfffffffeu)
#define SEMANTIC(k) ((k) & BitsetType::kSemantic)
#define INTERNAL_BITSET_TYPE_LIST(V) \
V(OtherUnsigned31, 1u << 1) \
V(OtherUnsigned32, 1u << 2) \
V(OtherSigned32, 1u << 3) \
V(OtherNumber, 1u << 4) \
#define SEMANTIC_BITSET_TYPE_LIST(V) \
#define PROPER_BITSET_TYPE_LIST(V) \
V(None, 0u) \
V(Negative31, 1u << 5) \
V(Null, 1u << 6) \
......@@ -193,13 +181,9 @@ namespace compiler {
* occur as part of PlainNumber.
*/
#define PROPER_BITSET_TYPE_LIST(V) \
SEMANTIC_BITSET_TYPE_LIST(V)
#define BITSET_TYPE_LIST(V) \
MASK_BITSET_TYPE_LIST(V) \
INTERNAL_BITSET_TYPE_LIST(V) \
SEMANTIC_BITSET_TYPE_LIST(V)
#define BITSET_TYPE_LIST(V) \
INTERNAL_BITSET_TYPE_LIST(V) \
PROPER_BITSET_TYPE_LIST(V)
class Type;
......@@ -224,11 +208,7 @@ class BitsetType {
return static_cast<bitset>(reinterpret_cast<uintptr_t>(this) ^ 1u);
}
static bool IsInhabited(bitset bits) { return SemanticIsInhabited(bits); }
static bool SemanticIsInhabited(bitset bits) {
return SEMANTIC(bits) != kNone;
}
static bool IsInhabited(bitset bits) { return bits != kNone; }
static bool Is(bitset bits1, bitset bits2) {
return (bits1 | bits2) == bits2;
......@@ -371,7 +351,7 @@ class RangeType : public TypeBase {
static Type* New(Limits lim, Zone* zone) {
DCHECK(IsInteger(lim.min) && IsInteger(lim.max));
DCHECK(lim.min <= lim.max);
BitsetType::bitset bits = SEMANTIC(BitsetType::Lub(lim.min, lim.max));
BitsetType::bitset bits = BitsetType::Lub(lim.min, lim.max);
return AsType(new (zone->New(sizeof(RangeType))) RangeType(bits, lim));
}
......@@ -526,9 +506,6 @@ class Type {
}
static Type* For(i::Handle<i::Map> map) { return For(*map); }
// Extraction of components.
static Type* Semantic(Type* t, Zone* zone);
// Predicates.
bool IsInhabited() { return BitsetType::IsInhabited(this->BitsetLub()); }
......@@ -627,14 +604,10 @@ class Type {
}
UnionType* AsUnion() { return UnionType::cast(this); }
// Auxiliary functions.
bool SemanticMaybe(Type* that);
bitset BitsetGlb() { return BitsetType::Glb(this); }
bitset BitsetLub() { return BitsetType::Lub(this); }
bool SlowIs(Type* that);
bool SemanticIs(Type* that);
static bool Overlap(RangeType* lhs, RangeType* rhs);
static bool Contains(RangeType* lhs, RangeType* rhs);
......
......@@ -108,9 +108,6 @@ class Types {
PROPER_BITSET_TYPE_LIST(DECLARE_TYPE)
#undef DECLARE_TYPE
#define DECLARE_TYPE(name, value) Type* Mask##name##ForTesting;
MASK_BITSET_TYPE_LIST(DECLARE_TYPE)
#undef DECLARE_TYPE
Type* SignedSmall;
Type* UnsignedSmall;
......@@ -142,8 +139,6 @@ class Types {
Type* Intersect(Type* t1, Type* t2) { return Type::Intersect(t1, t2, zone_); }
Type* Semantic(Type* t) { return Type::Semantic(t, zone_); }
Type* Random() {
return types[rng_->NextInt(static_cast<int>(types.size()))];
}
......
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