Commit 549a3143 authored by Jaroslav Sevcik's avatar Jaroslav Sevcik Committed by Commit Bot

[turbofan] Prepare the Type class for UB treatment.

This is just code reshuffling to enable changing Type* to Type.

Bug: v8:3770
Change-Id: I8ed4ff41b480cab377d115c57c49d6f6c0c46d6d
Reviewed-on: https://chromium-review.googlesource.com/1025897Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52772}
parent 2aa995bf
...@@ -106,43 +106,43 @@ double Type::Max() { ...@@ -106,43 +106,43 @@ double Type::Max() {
// Glb and lub computation. // Glb and lub computation.
// The largest bitset subsumed by this type. // The largest bitset subsumed by this type.
Type::bitset BitsetType::Glb(Type* type) { Type::bitset Type::BitsetGlb() {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
// Fast case. // Fast case.
if (IsBitset(type)) { if (IsBitset()) {
return type->AsBitset(); return AsBitset();
} else if (type->IsUnion()) { } else if (IsUnion()) {
SLOW_DCHECK(type->AsUnion()->Wellformed()); SLOW_DCHECK(AsUnion()->Wellformed());
return type->AsUnion()->Get(0)->BitsetGlb() | return AsUnion()->Get(0)->BitsetGlb() |
type->AsUnion()->Get(1)->BitsetGlb(); // Shortcut. AsUnion()->Get(1)->BitsetGlb(); // Shortcut.
} else if (type->IsRange()) { } else if (IsRange()) {
bitset glb = bitset glb = BitsetType::Glb(AsRange()->Min(), AsRange()->Max());
BitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max());
return glb; return glb;
} else { } else {
return kNone; return BitsetType::kNone;
} }
} }
// The smallest bitset subsuming this type, possibly not a proper one. // The smallest bitset subsuming this type, possibly not a proper one.
Type::bitset BitsetType::Lub(Type* type) { Type::bitset Type::BitsetLub() {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
if (IsBitset(type)) return type->AsBitset(); if (IsBitset()) return AsBitset();
if (type->IsUnion()) { if (IsUnion()) {
// Take the representation from the first element, which is always // Take the representation from the first element, which is always
// a bitset. // a bitset.
int bitset = type->AsUnion()->Get(0)->BitsetLub(); int bitset = AsUnion()->Get(0)->BitsetLub();
for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { for (int i = 0, n = AsUnion()->Length(); i < n; ++i) {
// Other elements only contribute their semantic part. // Other elements only contribute their semantic part.
bitset |= type->AsUnion()->Get(i)->BitsetLub(); bitset |= AsUnion()->Get(i)->BitsetLub();
} }
return bitset; return bitset;
} }
if (type->IsHeapConstant()) return type->AsHeapConstant()->Lub(); if (IsHeapConstant()) return AsHeapConstant()->Lub();
if (type->IsOtherNumberConstant()) if (IsOtherNumberConstant()) {
return type->AsOtherNumberConstant()->Lub(); return AsOtherNumberConstant()->Lub();
if (type->IsRange()) return type->AsRange()->Lub(); }
if (type->IsTuple()) return kOtherInternal; if (IsRange()) return AsRange()->Lub();
if (IsTuple()) return BitsetType::kOtherInternal;
UNREACHABLE(); UNREACHABLE();
} }
...@@ -635,7 +635,7 @@ bool UnionType::Wellformed() { ...@@ -635,7 +635,7 @@ bool UnionType::Wellformed() {
Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) { Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) {
// Fast case: bit sets. // Fast case: bit sets.
if (type1->IsBitset() && type2->IsBitset()) { if (type1->IsBitset() && type2->IsBitset()) {
return BitsetType::New(type1->AsBitset() & type2->AsBitset()); return NewBitset(type1->AsBitset() & type2->AsBitset());
} }
// Fast case: top or bottom types. // Fast case: top or bottom types.
...@@ -662,12 +662,12 @@ Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) { ...@@ -662,12 +662,12 @@ Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) {
int size; int size;
if (base::bits::SignedAddOverflow32(size1, size2, &size)) return Any(); if (base::bits::SignedAddOverflow32(size1, size2, &size)) return Any();
if (base::bits::SignedAddOverflow32(size, 2, &size)) return Any(); if (base::bits::SignedAddOverflow32(size, 2, &size)) return Any();
Type* result_type = UnionType::New(size, zone); Type* result_type = Type::Union(size, zone);
UnionType* result = result_type->AsUnion(); UnionType* result = result_type->AsUnion();
size = 0; size = 0;
// Deal with bitsets. // Deal with bitsets.
result->Set(size++, BitsetType::New(bits)); result->Set(size++, NewBitset(bits));
RangeType::Limits lims = RangeType::Limits::Empty(); RangeType::Limits lims = RangeType::Limits::Empty();
size = IntersectAux(type1, type2, result, size, &lims, zone); size = IntersectAux(type1, type2, result, size, &lims, zone);
...@@ -675,12 +675,12 @@ Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) { ...@@ -675,12 +675,12 @@ Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) {
// If the range is not empty, then insert it into the union and // If the range is not empty, then insert it into the union and
// remove the number bits from the bitset. // remove the number bits from the bitset.
if (!lims.IsEmpty()) { if (!lims.IsEmpty()) {
size = UpdateRange(RangeType::New(lims, zone), result, size, zone); size = UpdateRange(Type::Range(lims, zone), result, size, zone);
// Remove the number bits. // Remove the number bits.
bitset number_bits = BitsetType::NumberBits(bits); bitset number_bits = BitsetType::NumberBits(bits);
bits &= ~number_bits; bits &= ~number_bits;
result->Set(0, BitsetType::New(bits)); result->Set(0, NewBitset(bits));
} }
return NormalizeUnion(result_type, size, zone); return NormalizeUnion(result_type, size, zone);
} }
...@@ -815,7 +815,7 @@ Type* Type::NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone) { ...@@ -815,7 +815,7 @@ Type* Type::NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone) {
if (bitset_max > range_max) { if (bitset_max > range_max) {
range_max = bitset_max; range_max = bitset_max;
} }
return RangeType::New(range_min, range_max, zone); return Type::Range(range_min, range_max, zone);
} }
Type* Type::NewConstant(double value, Zone* zone) { Type* Type::NewConstant(double value, Zone* zone) {
...@@ -846,7 +846,7 @@ Type* Type::NewConstant(i::Handle<i::Object> value, Zone* zone) { ...@@ -846,7 +846,7 @@ Type* Type::NewConstant(i::Handle<i::Object> value, Zone* zone) {
Type* Type::Union(Type* type1, Type* type2, Zone* zone) { Type* Type::Union(Type* type1, Type* type2, Zone* zone) {
// Fast case: bit sets. // Fast case: bit sets.
if (type1->IsBitset() && type2->IsBitset()) { if (type1->IsBitset() && type2->IsBitset()) {
return BitsetType::New(type1->AsBitset() | type2->AsBitset()); return NewBitset(type1->AsBitset() | type2->AsBitset());
} }
// Fast case: top or bottom types. // Fast case: top or bottom types.
...@@ -863,7 +863,7 @@ Type* Type::Union(Type* type1, Type* type2, Zone* zone) { ...@@ -863,7 +863,7 @@ Type* Type::Union(Type* type1, Type* type2, Zone* zone) {
int size; int size;
if (base::bits::SignedAddOverflow32(size1, size2, &size)) return Any(); if (base::bits::SignedAddOverflow32(size1, size2, &size)) return Any();
if (base::bits::SignedAddOverflow32(size, 2, &size)) return Any(); if (base::bits::SignedAddOverflow32(size, 2, &size)) return Any();
Type* result_type = UnionType::New(size, zone); Type* result_type = Type::Union(size, zone);
UnionType* result = result_type->AsUnion(); UnionType* result = result_type->AsUnion();
size = 0; size = 0;
...@@ -878,14 +878,14 @@ Type* Type::Union(Type* type1, Type* type2, Zone* zone) { ...@@ -878,14 +878,14 @@ Type* Type::Union(Type* type1, Type* type2, Zone* zone) {
RangeType::Limits lims = RangeType::Limits lims =
RangeType::Limits::Union(RangeType::Limits(range1->AsRange()), RangeType::Limits::Union(RangeType::Limits(range1->AsRange()),
RangeType::Limits(range2->AsRange())); RangeType::Limits(range2->AsRange()));
Type* union_range = RangeType::New(lims, zone); Type* union_range = Type::Range(lims, zone);
range = NormalizeRangeAndBitset(union_range, &new_bitset, zone); range = NormalizeRangeAndBitset(union_range, &new_bitset, zone);
} else if (range1 != nullptr) { } else if (range1 != nullptr) {
range = NormalizeRangeAndBitset(range1, &new_bitset, zone); range = NormalizeRangeAndBitset(range1, &new_bitset, zone);
} else if (range2 != nullptr) { } else if (range2 != nullptr) {
range = NormalizeRangeAndBitset(range2, &new_bitset, zone); range = NormalizeRangeAndBitset(range2, &new_bitset, zone);
} }
Type* bits = BitsetType::New(new_bitset); Type* bits = NewBitset(new_bitset);
result->Set(size++, bits); result->Set(size++, bits);
if (!range->IsNone()) result->Set(size++, range); if (!range->IsNone()) result->Set(size++, range);
...@@ -923,7 +923,7 @@ Type* Type::NormalizeUnion(Type* union_type, int size, Zone* zone) { ...@@ -923,7 +923,7 @@ Type* Type::NormalizeUnion(Type* union_type, int size, Zone* zone) {
// If the union only consists of a range, we can get rid of the union. // If the union only consists of a range, we can get rid of the union.
if (size == 2 && bits == BitsetType::kNone) { if (size == 2 && bits == BitsetType::kNone) {
if (unioned->Get(1)->IsRange()) { if (unioned->Get(1)->IsRange()) {
return RangeType::New(unioned->Get(1)->AsRange()->Min(), return Type::Range(unioned->Get(1)->AsRange()->Min(),
unioned->Get(1)->AsRange()->Max(), zone); unioned->Get(1)->AsRange()->Max(), zone);
} }
} }
...@@ -1055,6 +1055,65 @@ BitsetType::bitset BitsetType::UnsignedSmall() { ...@@ -1055,6 +1055,65 @@ BitsetType::bitset BitsetType::UnsignedSmall() {
return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31; return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31;
} }
// static
Type* Type::Tuple(Type* first, Type* second, Type* third, Zone* zone) {
TupleType* tuple = TupleType::New(3, zone);
tuple->InitElement(0, first);
tuple->InitElement(1, second);
tuple->InitElement(2, third);
return FromTypeBase(tuple);
}
// static
Type* Type::OtherNumberConstant(double value, Zone* zone) {
return FromTypeBase(OtherNumberConstantType::New(value, zone));
}
// static
Type* Type::HeapConstant(i::Handle<i::HeapObject> value, Zone* zone) {
return FromTypeBase(HeapConstantType::New(value, zone));
}
// static
Type* Type::Range(double min, double max, Zone* zone) {
return FromTypeBase(RangeType::New(min, max, zone));
}
// static
Type* Type::Range(RangeType::Limits lims, Zone* zone) {
return FromTypeBase(RangeType::New(lims, zone));
}
// static
Type* Type::Union(int length, Zone* zone) {
return FromTypeBase(UnionType::New(length, zone));
}
HeapConstantType* Type::AsHeapConstant() {
DCHECK(IsKind(TypeBase::kHeapConstant));
return static_cast<HeapConstantType*>(ToTypeBase());
}
OtherNumberConstantType* Type::AsOtherNumberConstant() {
DCHECK(IsKind(TypeBase::kOtherNumberConstant));
return static_cast<OtherNumberConstantType*>(ToTypeBase());
}
RangeType* Type::AsRange() {
DCHECK(IsKind(TypeBase::kRange));
return static_cast<RangeType*>(ToTypeBase());
}
TupleType* Type::AsTuple() {
DCHECK(IsKind(TypeBase::kTuple));
return static_cast<TupleType*>(ToTypeBase());
}
UnionType* Type::AsUnion() {
DCHECK(IsKind(TypeBase::kUnion));
return static_cast<UnionType*>(ToTypeBase());
}
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
This diff is collapsed.
...@@ -42,7 +42,7 @@ struct Tests { ...@@ -42,7 +42,7 @@ struct Tests {
zone(isolate->allocator(), ZONE_NAME), zone(isolate->allocator(), ZONE_NAME),
T(&zone, isolate, isolate->random_number_generator()) {} T(&zone, isolate, isolate->random_number_generator()) {}
bool IsBitset(Type* type) { return type->IsBitsetForTesting(); } bool IsBitset(Type* type) { return type->IsBitset(); }
bool IsUnion(Type* type) { return type->IsUnionForTesting(); } bool IsUnion(Type* type) { return type->IsUnionForTesting(); }
BitsetType::bitset AsBitset(Type* type) { return type->AsBitsetForTesting(); } BitsetType::bitset AsBitset(Type* type) { return type->AsBitsetForTesting(); }
UnionType* AsUnion(Type* type) { return type->AsUnionForTesting(); } UnionType* AsUnion(Type* type) { return type->AsUnionForTesting(); }
...@@ -404,7 +404,7 @@ struct Tests { ...@@ -404,7 +404,7 @@ struct Tests {
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
Type* type = *it; Type* type = *it;
if (type->IsRange()) { if (type->IsRange()) {
Type* lub = BitsetType::NewForTesting(BitsetType::Lub(type)); Type* lub = type->BitsetLubForTesting();
CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max()); CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max());
} }
} }
...@@ -422,7 +422,7 @@ struct Tests { ...@@ -422,7 +422,7 @@ struct Tests {
// Lower: (T->BitsetGlb())->Is(T) // Lower: (T->BitsetGlb())->Is(T)
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
Type* type = *it; Type* type = *it;
Type* glb = BitsetType::NewForTesting(BitsetType::Glb(type)); Type* glb = type->BitsetGlbForTesting();
CHECK(glb->Is(type)); CHECK(glb->Is(type));
} }
...@@ -431,7 +431,7 @@ struct Tests { ...@@ -431,7 +431,7 @@ struct Tests {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
Type* type1 = *it1; Type* type1 = *it1;
Type* type2 = *it2; Type* type2 = *it2;
Type* glb2 = BitsetType::NewForTesting(BitsetType::Glb(type2)); Type* glb2 = type2->BitsetGlbForTesting();
CHECK(!this->IsBitset(type1) || !type1->Is(type2) || type1->Is(glb2)); CHECK(!this->IsBitset(type1) || !type1->Is(type2) || type1->Is(glb2));
} }
} }
...@@ -441,8 +441,8 @@ struct Tests { ...@@ -441,8 +441,8 @@ struct Tests {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
Type* type1 = *it1; Type* type1 = *it1;
Type* type2 = *it2; Type* type2 = *it2;
Type* glb1 = BitsetType::NewForTesting(BitsetType::Glb(type1)); Type* glb1 = type1->BitsetGlbForTesting();
Type* glb2 = BitsetType::NewForTesting(BitsetType::Glb(type2)); Type* glb2 = type2->BitsetGlbForTesting();
CHECK(!type1->Is(type2) || glb1->Is(glb2)); CHECK(!type1->Is(type2) || glb1->Is(glb2));
} }
} }
...@@ -452,7 +452,7 @@ struct Tests { ...@@ -452,7 +452,7 @@ struct Tests {
// Upper: T->Is(T->BitsetLub()) // Upper: T->Is(T->BitsetLub())
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
Type* type = *it; Type* type = *it;
Type* lub = BitsetType::NewForTesting(BitsetType::Lub(type)); Type* lub = type->BitsetLubForTesting();
CHECK(type->Is(lub)); CHECK(type->Is(lub));
} }
...@@ -461,7 +461,7 @@ struct Tests { ...@@ -461,7 +461,7 @@ struct Tests {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
Type* type1 = *it1; Type* type1 = *it1;
Type* type2 = *it2; Type* type2 = *it2;
Type* lub1 = BitsetType::NewForTesting(BitsetType::Lub(type1)); Type* lub1 = type1->BitsetLubForTesting();
CHECK(!this->IsBitset(type2) || !type1->Is(type2) || lub1->Is(type2)); CHECK(!this->IsBitset(type2) || !type1->Is(type2) || lub1->Is(type2));
} }
} }
...@@ -471,8 +471,8 @@ struct Tests { ...@@ -471,8 +471,8 @@ struct Tests {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
Type* type1 = *it1; Type* type1 = *it1;
Type* type2 = *it2; Type* type2 = *it2;
Type* lub1 = BitsetType::NewForTesting(BitsetType::Lub(type1)); Type* lub1 = type1->BitsetLubForTesting();
Type* lub2 = BitsetType::NewForTesting(BitsetType::Lub(type2)); Type* lub2 = type2->BitsetLubForTesting();
CHECK(!type1->Is(type2) || lub1->Is(lub2)); CHECK(!type1->Is(type2) || lub1->Is(lub2));
} }
} }
...@@ -601,7 +601,7 @@ struct Tests { ...@@ -601,7 +601,7 @@ struct Tests {
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
Type* type = *it; Type* type = *it;
if (type->IsRange()) { if (type->IsRange()) {
Type* lub = BitsetType::NewForTesting(BitsetType::Lub(type)); Type* lub = type->BitsetLubForTesting();
CHECK(lub->Is(T.PlainNumber)); CHECK(lub->Is(T.PlainNumber));
} }
} }
......
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