Commit 7e95e206 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Nuke class types.

There are no users of class types left inside TurboFan, so we can nuke
them and thereby simplify the type system quite a bit.

R=mvstanton@chromium.org
BUG=v8:5267,v8:5270

Review-Url: https://codereview.chromium.org/2309753002
Cr-Commit-Position: refs/heads/master@{#39152}
parent 776a5c10
......@@ -144,7 +144,6 @@ Type::bitset BitsetType::Lub(Type* type) {
}
return bitset;
}
if (type->IsClass()) return type->AsClass()->Lub();
if (type->IsConstant()) return type->AsConstant()->Lub();
if (type->IsRange()) return type->AsRange()->Lub();
if (type->IsContext()) return kOtherInternal & kTaggedPointer;
......@@ -409,10 +408,6 @@ double BitsetType::Max(bitset bits) {
bool Type::SimplyEquals(Type* that) {
DisallowHeapAllocation no_allocation;
if (this->IsClass()) {
return that->IsClass()
&& *this->AsClass()->Map() == *that->AsClass()->Map();
}
if (this->IsConstant()) {
return that->IsConstant()
&& *this->AsConstant()->Value() == *that->AsConstant()->Value();
......@@ -524,52 +519,6 @@ bool Type::SemanticIs(Type* that) {
return this->SimplyEquals(that);
}
// Most precise _current_ type of a value (usually its class).
Type* Type::NowOf(i::Object* value, Zone* zone) {
if (value->IsSmi() ||
i::HeapObject::cast(value)->map()->instance_type() == HEAP_NUMBER_TYPE) {
return Of(value, zone);
}
return Class(i::handle(i::HeapObject::cast(value)->map()), zone);
}
bool Type::NowContains(i::Object* value) {
DisallowHeapAllocation no_allocation;
if (this->IsAny()) return true;
if (value->IsHeapObject()) {
i::Map* map = i::HeapObject::cast(value)->map();
for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) {
if (*it.Current() == map) return true;
}
}
return this->Contains(value);
}
bool Type::NowIs(Type* that) {
DisallowHeapAllocation no_allocation;
// TODO(rossberg): this is incorrect for
// Union(Constant(V), T)->NowIs(Class(M))
// but fuzzing does not cover that!
if (this->IsConstant()) {
i::Object* object = *this->AsConstant()->Value();
if (object->IsHeapObject()) {
i::Map* map = i::HeapObject::cast(object)->map();
for (Iterator<i::Map> it = that->Classes(); !it.Done(); it.Advance()) {
if (*it.Current() == map) return true;
}
}
}
return this->Is(that);
}
// Check if [this] contains only (currently) stable classes.
bool Type::NowStable() {
DisallowHeapAllocation no_allocation;
return !this->IsClass() || this->AsClass()->Map()->is_stable();
}
// Check if [this] and [that] overlap.
bool Type::Maybe(Type* that) {
......@@ -607,8 +556,6 @@ bool Type::SemanticMaybe(Type* that) {
if (this->IsBitset() && that->IsBitset()) return true;
if (this->IsClass() != that->IsClass()) return true;
if (this->IsRange()) {
if (that->IsConstant()) {
return Contains(this->AsRange(), that->AsConstant());
......@@ -830,10 +777,6 @@ int Type::IntersectAux(Type* lhs, Type* rhs, UnionType* result, int size,
}
return size;
}
if (rhs->IsClass()) {
*lims =
RangeType::Limits::Union(RangeType::Limits(lhs->AsRange()), *lims);
}
if (rhs->IsConstant() && Contains(lhs->AsRange(), rhs->AsConstant())) {
return AddToUnion(rhs, result, size, zone);
}
......@@ -853,9 +796,6 @@ int Type::IntersectAux(Type* lhs, Type* rhs, UnionType* result, int size,
if (lhs->IsBitset() || rhs->IsBitset()) {
return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, zone);
}
if (lhs->IsClass() != rhs->IsClass()) {
return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, zone);
}
if (lhs->SimplyEquals(rhs)) {
return AddToUnion(lhs, result, size, zone);
}
......@@ -1031,21 +971,6 @@ Type* Type::Semantic(Type* t, Zone* zone) {
// -----------------------------------------------------------------------------
// Iteration.
int Type::NumClasses() {
DisallowHeapAllocation no_allocation;
if (this->IsClass()) {
return 1;
} else if (this->IsUnion()) {
int result = 0;
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
if (this->AsUnion()->Get(i)->IsClass()) ++result;
}
return result;
} else {
return 0;
}
}
int Type::NumConstants() {
DisallowHeapAllocation no_allocation;
if (this->IsConstant()) {
......@@ -1076,14 +1001,6 @@ struct TypeImplIteratorAux {
static i::Handle<T> current(Type* type);
};
template <>
struct TypeImplIteratorAux<i::Map> {
static bool matches(Type* type) { return type->IsClass(); }
static i::Handle<i::Map> current(Type* type) {
return type->AsClass()->Map();
}
};
template <>
struct TypeImplIteratorAux<i::Object> {
static bool matches(Type* type) { return type->IsConstant(); }
......@@ -1181,10 +1098,6 @@ void Type::PrintTo(std::ostream& os, PrintDimension dim) {
if (dim != REPRESENTATION_DIM) {
if (this->IsBitset()) {
BitsetType::Print(os, SEMANTIC(this->AsBitset()));
} else if (this->IsClass()) {
os << "Class(" << static_cast<void*>(*this->AsClass()->Map()) << " < ";
BitsetType::New(BitsetType::Lub(this))->PrintTo(os, dim);
os << ")";
} else if (this->IsConstant()) {
os << "Constant(" << Brief(*this->AsConstant()->Value()) << ")";
} else if (this->IsRange()) {
......@@ -1262,17 +1175,9 @@ BitsetType::bitset BitsetType::UnsignedSmall() {
return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31;
}
#define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \
Type* Type::Name(Isolate* isolate, Zone* zone) { \
return Class(i::handle(isolate->heap()->name##_map()), zone); \
}
SIMD128_TYPES(CONSTRUCT_SIMD_TYPE)
#undef CONSTRUCT_SIMD_TYPE
// -----------------------------------------------------------------------------
// Instantiations.
template class Type::Iterator<i::Map>;
template class Type::Iterator<i::Object>;
} // namespace internal
......
......@@ -45,7 +45,6 @@ namespace internal {
// OtherUndetectable < Object
// DetectableReceiver = Receiver - OtherUndetectable
//
// Class(map) < T iff instance_type(map) < T
// Constant(x) < T iff instance_type(map(x)) < T
// Array(T) < Array
// Function(R, S, T0, T1, ...) < Function
......@@ -56,12 +55,6 @@ namespace internal {
// There is no subtyping relation between Array, Function, or Context types
// and respective Constant types, since these types cannot be reconstructed
// for arbitrary heap values.
// Note also that Constant(x) < Class(map(x)) does _not_ hold, since x's map can
// change! (Its instance type cannot, however.)
// TODO(rossberg): the latter is not currently true for proxies, because of fix,
// but will hold once we implement direct proxies.
// However, we also define a 'temporal' variant of the subtyping relation that
// considers the _current_ state only, i.e., Constant(x) <_now Class(map(x)).
//
//
// REPRESENTATIONAL DIMENSION
......@@ -140,11 +133,10 @@ namespace internal {
// IMPLEMENTATION
//
// Internally, all 'primitive' types, and their unions, are represented as
// bitsets. Bit 0 is reserved for tagging. Class is a heap pointer to the
// respective map. Only structured types require allocation.
// bitsets. Bit 0 is reserved for tagging. Only structured types require
// allocation.
// Note that the bitset representation is closed under both Union and Intersect.
// -----------------------------------------------------------------------------
// Values for bitset types
......@@ -356,7 +348,6 @@ class TypeBase {
friend class Type;
enum Kind {
kClass,
kConstant,
kContext,
kArray,
......@@ -385,36 +376,6 @@ class TypeBase {
Kind kind_;
};
// -----------------------------------------------------------------------------
// Class types.
class ClassType : public TypeBase {
public:
i::Handle<i::Map> Map() { return map_; }
private:
friend class Type;
friend class BitsetType;
static Type* New(i::Handle<i::Map> map, Zone* zone) {
return AsType(new (zone->New(sizeof(ClassType)))
ClassType(BitsetType::Lub(*map), map));
}
static ClassType* cast(Type* type) {
DCHECK(IsKind(type, kClass));
return static_cast<ClassType*>(FromType(type));
}
ClassType(BitsetType::bitset bitset, i::Handle<i::Map> map)
: TypeBase(kClass), bitset_(bitset), map_(map) {}
BitsetType::bitset Lub() { return bitset_; }
BitsetType::bitset bitset_;
Handle<i::Map> map_;
};
// -----------------------------------------------------------------------------
// Constant types.
......@@ -689,9 +650,6 @@ class Type {
return BitsetType::New(BitsetType::UnsignedSmall());
}
static Type* Class(i::Handle<i::Map> map, Zone* zone) {
return ClassType::New(map, zone);
}
static Type* Constant(i::Handle<i::Object> value, Zone* zone) {
return ConstantType::New(value, zone);
}
......@@ -746,11 +704,6 @@ class Type {
return tuple;
}
#define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \
static Type* Name(Isolate* isolate, Zone* zone);
SIMD128_TYPES(CONSTRUCT_SIMD_TYPE)
#undef CONSTRUCT_SIMD_TYPE
static Type* Union(Type* type1, Type* type2, Zone* zone);
static Type* Intersect(Type* type1, Type* type2, Zone* zone);
......@@ -784,28 +737,14 @@ class Type {
bool Contains(i::Object* val);
bool Contains(i::Handle<i::Object> val) { return this->Contains(*val); }
// State-dependent versions of the above that consider subtyping between
// a constant and its map class.
static Type* NowOf(i::Object* value, Zone* zone);
static Type* NowOf(i::Handle<i::Object> value, Zone* zone) {
return NowOf(*value, zone);
}
bool NowIs(Type* that);
bool NowContains(i::Object* val);
bool NowContains(i::Handle<i::Object> val) { return this->NowContains(*val); }
bool NowStable();
// Inspection.
bool IsRange() { return IsKind(TypeBase::kRange); }
bool IsClass() { return IsKind(TypeBase::kClass); }
bool IsConstant() { return IsKind(TypeBase::kConstant); }
bool IsContext() { return IsKind(TypeBase::kContext); }
bool IsArray() { return IsKind(TypeBase::kArray); }
bool IsFunction() { return IsKind(TypeBase::kFunction); }
bool IsTuple() { return IsKind(TypeBase::kTuple); }
ClassType* AsClass() { return ClassType::cast(this); }
ConstantType* AsConstant() { return ConstantType::cast(this); }
RangeType* AsRange() { return RangeType::cast(this); }
ContextType* AsContext() { return ContextType::cast(this); }
......@@ -829,7 +768,6 @@ class Type {
return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities.
}
int NumClasses();
int NumConstants();
template <class T>
......@@ -852,10 +790,6 @@ class Type {
int index_;
};
Iterator<i::Map> Classes() {
if (this->IsBitset()) return Iterator<i::Map>();
return Iterator<i::Map>(this);
}
Iterator<i::Object> Constants() {
if (this->IsBitset()) return Iterator<i::Object>();
return Iterator<i::Object>(this);
......
......@@ -36,9 +36,9 @@
namespace v8 {
namespace internal {
class Types {
class AstTypes {
public:
Types(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng)
AstTypes(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng)
: zone_(zone), isolate_(isolate), rng_(rng) {
#define DECLARE_TYPE(name, value) \
name = AstType::name(); \
......
......@@ -21,6 +21,8 @@
using namespace v8::internal;
namespace {
// Testing auxiliaries (breaking the Type abstraction).
static bool IsInteger(double x) {
......@@ -34,14 +36,14 @@ static bool IsInteger(i::Object* x) {
typedef uint32_t bitset;
struct Tests {
typedef Types::TypeVector::iterator TypeIterator;
typedef Types::MapVector::iterator MapIterator;
typedef Types::ValueVector::iterator ValueIterator;
typedef AstTypes::TypeVector::iterator TypeIterator;
typedef AstTypes::MapVector::iterator MapIterator;
typedef AstTypes::ValueVector::iterator ValueIterator;
Isolate* isolate;
HandleScope scope;
Zone zone;
Types T;
AstTypes T;
Tests()
: isolate(CcTest::InitIsolateOnce()),
......@@ -1845,6 +1847,8 @@ struct Tests {
}
};
} // namespace
TEST(AstIsSomeType_zone) { Tests().IsSomeType(); }
TEST(AstPointwiseRepresentation_zone) { Tests().PointwiseRepresentation(); }
......
This diff is collapsed.
......@@ -36,11 +36,10 @@
namespace v8 {
namespace internal {
class Types {
public:
Types(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng)
: zone_(zone), isolate_(isolate), rng_(rng) {
: zone_(zone), rng_(rng) {
#define DECLARE_TYPE(name, value) \
name = Type::name(); \
types.push_back(name);
......@@ -52,22 +51,6 @@ class Types {
object_map = isolate->factory()->NewMap(
JS_OBJECT_TYPE, JSObject::kHeaderSize);
array_map = isolate->factory()->NewMap(
JS_ARRAY_TYPE, JSArray::kSize);
number_map = isolate->factory()->NewMap(
HEAP_NUMBER_TYPE, HeapNumber::kSize);
uninitialized_map = isolate->factory()->uninitialized_map();
ObjectClass = Type::Class(object_map, zone);
ArrayClass = Type::Class(array_map, zone);
NumberClass = Type::Class(number_map, zone);
UninitializedClass = Type::Class(uninitialized_map, zone);
maps.push_back(object_map);
maps.push_back(array_map);
maps.push_back(uninitialized_map);
for (MapVector::iterator it = maps.begin(); it != maps.end(); ++it) {
types.push_back(Type::Class(*it, zone));
}
smi = handle(Smi::FromInt(666), isolate);
signed32 = isolate->factory()->NewHeapNumber(0x40000000);
......@@ -121,9 +104,6 @@ class Types {
}
Handle<i::Map> object_map;
Handle<i::Map> array_map;
Handle<i::Map> number_map;
Handle<i::Map> uninitialized_map;
Handle<i::Smi> smi;
Handle<i::HeapNumber> signed32;
......@@ -142,11 +122,6 @@ class Types {
Type* SignedSmall;
Type* UnsignedSmall;
Type* ObjectClass;
Type* ArrayClass;
Type* NumberClass;
Type* UninitializedClass;
Type* SmiConstant;
Type* Signed32Constant;
Type* ObjectConstant1;
......@@ -166,20 +141,14 @@ class Types {
Type* MethodFunction;
typedef std::vector<Type*> TypeVector;
typedef std::vector<Handle<i::Map> > MapVector;
typedef std::vector<Handle<i::Object> > ValueVector;
TypeVector types;
MapVector maps;
ValueVector values;
ValueVector integers; // "Integer" values used for range limits.
Type* Of(Handle<i::Object> value) { return Type::Of(value, zone_); }
Type* NowOf(Handle<i::Object> value) { return Type::NowOf(value, zone_); }
Type* Class(Handle<i::Map> map) { return Type::Class(map, zone_); }
Type* Constant(Handle<i::Object> value) {
return Type::Constant(value, zone_);
}
......@@ -241,15 +210,11 @@ class Types {
}
return result;
}
case 1: { // class
int i = rng_->NextInt(static_cast<int>(maps.size()));
return Type::Class(maps[i], zone_);
}
case 2: { // constant
case 1: { // constant
int i = rng_->NextInt(static_cast<int>(values.size()));
return Type::Constant(values[i], zone_);
}
case 3: { // range
case 2: { // range
int i = rng_->NextInt(static_cast<int>(integers.size()));
int j = rng_->NextInt(static_cast<int>(integers.size()));
double min = integers[i]->Number();
......@@ -257,18 +222,18 @@ class Types {
if (min > max) std::swap(min, max);
return Type::Range(min, max, zone_);
}
case 4: { // context
case 3: { // context
int depth = rng_->NextInt(3);
Type* type = Type::Internal();
for (int i = 0; i < depth; ++i) type = Type::Context(type, zone_);
return type;
}
case 5: { // array
case 4: { // array
Type* element = Fuzz(depth / 2);
return Type::Array(element, zone_);
}
case 6:
case 7: { // function
case 5:
case 6: { // function
Type* result = Fuzz(depth / 2);
Type* receiver = Fuzz(depth / 2);
int arity = rng_->NextInt(3);
......@@ -279,20 +244,6 @@ class Types {
}
return type;
}
case 8: { // simd
static const int num_simd_types =
#define COUNT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) +1
SIMD128_TYPES(COUNT_SIMD_TYPE);
#undef COUNT_SIMD_TYPE
Type* (*simd_constructors[num_simd_types])(Isolate*, Zone*) = {
#define COUNT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \
&Type::Name,
SIMD128_TYPES(COUNT_SIMD_TYPE)
#undef COUNT_SIMD_TYPE
};
return simd_constructors[rng_->NextInt(num_simd_types)](isolate_,
zone_);
}
default: { // union
int n = rng_->NextInt(10);
Type* type = None;
......@@ -310,7 +261,6 @@ class Types {
private:
Zone* zone_;
Isolate* isolate_;
v8::base::RandomNumberGenerator* rng_;
};
......
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