2014-04-01 11:07:09 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-06-05 15:43:53 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
2014-04-01 11:07:09 +00:00
|
|
|
|
2013-07-10 11:20:00 +00:00
|
|
|
#include "string-stream.h"
|
2014-04-01 11:07:09 +00:00
|
|
|
#include "types-inl.h"
|
2013-06-05 15:43:53 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::NumClasses() {
|
|
|
|
if (this->IsClass()) {
|
2013-06-12 17:20:37 +00:00
|
|
|
return 1;
|
2014-01-10 12:19:01 +00:00
|
|
|
} else if (this->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = this->AsUnion();
|
2013-06-12 17:20:37 +00:00
|
|
|
int result = 0;
|
2014-04-08 10:50:56 +00:00
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
if (Config::struct_get(unioned, i)->IsClass()) ++result;
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::NumConstants() {
|
|
|
|
if (this->IsConstant()) {
|
2013-06-12 17:20:37 +00:00
|
|
|
return 1;
|
2014-01-10 12:19:01 +00:00
|
|
|
} else if (this->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = this->AsUnion();
|
2013-06-12 17:20:37 +00:00
|
|
|
int result = 0;
|
2014-04-08 10:50:56 +00:00
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
if (Config::struct_get(unioned, i)->IsConstant()) ++result;
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config> template<class T>
|
|
|
|
typename TypeImpl<Config>::TypeHandle
|
|
|
|
TypeImpl<Config>::Iterator<T>::get_type() {
|
2013-06-12 17:20:37 +00:00
|
|
|
ASSERT(!Done());
|
2014-04-08 10:50:56 +00:00
|
|
|
return type_->IsUnion()
|
|
|
|
? Config::struct_get(type_->AsUnion(), index_) : type_;
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
// C++ cannot specialise nested templates, so we have to go through this
|
|
|
|
// contortion with an auxiliary template to simulate it.
|
|
|
|
template<class Config, class T>
|
|
|
|
struct TypeImplIteratorAux {
|
|
|
|
static bool matches(typename TypeImpl<Config>::TypeHandle type);
|
|
|
|
static i::Handle<T> current(typename TypeImpl<Config>::TypeHandle type);
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
struct TypeImplIteratorAux<Config, i::Map> {
|
|
|
|
static bool matches(typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->IsClass();
|
|
|
|
}
|
|
|
|
static i::Handle<i::Map> current(typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->AsClass();
|
|
|
|
}
|
|
|
|
};
|
2013-06-12 17:20:37 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
struct TypeImplIteratorAux<Config, i::Object> {
|
|
|
|
static bool matches(typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->IsConstant();
|
|
|
|
}
|
|
|
|
static i::Handle<i::Object> current(
|
|
|
|
typename TypeImpl<Config>::TypeHandle type) {
|
|
|
|
return type->AsConstant();
|
|
|
|
}
|
|
|
|
};
|
2013-06-12 17:20:37 +00:00
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config> template<class T>
|
|
|
|
bool TypeImpl<Config>::Iterator<T>::matches(TypeHandle type) {
|
|
|
|
return TypeImplIteratorAux<Config, T>::matches(type);
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config> template<class T>
|
|
|
|
i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() {
|
|
|
|
return TypeImplIteratorAux<Config, T>::current(get_type());
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config> template<class T>
|
|
|
|
void TypeImpl<Config>::Iterator<T>::Advance() {
|
2013-06-12 17:20:37 +00:00
|
|
|
++index_;
|
2014-01-10 12:19:01 +00:00
|
|
|
if (type_->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = type_->AsUnion();
|
|
|
|
for (; index_ < Config::struct_length(unioned); ++index_) {
|
|
|
|
if (matches(Config::struct_get(unioned, index_))) return;
|
2013-06-12 17:20:37 +00:00
|
|
|
}
|
|
|
|
} else if (index_ == 0 && matches(type_)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
index_ = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
// Get the smallest bitset subsuming this type.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::LubBitset() {
|
|
|
|
if (this->IsBitset()) {
|
|
|
|
return this->AsBitset();
|
|
|
|
} else if (this->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = this->AsUnion();
|
2013-06-05 15:43:53 +00:00
|
|
|
int bitset = kNone;
|
2014-04-08 10:50:56 +00:00
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
bitset |= Config::struct_get(unioned, i)->LubBitset();
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
return bitset;
|
2014-01-10 12:19:01 +00:00
|
|
|
} else if (this->IsClass()) {
|
2014-03-11 10:28:38 +00:00
|
|
|
int bitset = Config::lub_bitset(this);
|
|
|
|
return bitset ? bitset : LubBitset(*this->AsClass());
|
2013-06-05 15:43:53 +00:00
|
|
|
} else {
|
2014-03-11 10:28:38 +00:00
|
|
|
int bitset = Config::lub_bitset(this);
|
|
|
|
return bitset ? bitset : LubBitset(*this->AsConstant());
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::LubBitset(i::Object* value) {
|
2014-03-18 11:50:18 +00:00
|
|
|
if (value->IsSmi()) return kSignedSmall & kTaggedInt;
|
2013-11-15 15:14:09 +00:00
|
|
|
i::Map* map = i::HeapObject::cast(value)->map();
|
|
|
|
if (map->instance_type() == HEAP_NUMBER_TYPE) {
|
|
|
|
int32_t i;
|
|
|
|
uint32_t u;
|
2014-03-18 11:50:18 +00:00
|
|
|
return kTaggedPtr & (
|
|
|
|
value->ToInt32(&i) ? (Smi::IsValid(i) ? kSignedSmall : kOtherSigned32) :
|
|
|
|
value->ToUint32(&u) ? kUnsigned32 : kFloat);
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
return LubBitset(map);
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::LubBitset(i::Map* map) {
|
2013-11-15 15:14:09 +00:00
|
|
|
switch (map->instance_type()) {
|
|
|
|
case STRING_TYPE:
|
|
|
|
case ASCII_STRING_TYPE:
|
|
|
|
case CONS_STRING_TYPE:
|
|
|
|
case CONS_ASCII_STRING_TYPE:
|
|
|
|
case SLICED_STRING_TYPE:
|
|
|
|
case SLICED_ASCII_STRING_TYPE:
|
|
|
|
case EXTERNAL_STRING_TYPE:
|
|
|
|
case EXTERNAL_ASCII_STRING_TYPE:
|
|
|
|
case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
|
|
|
case SHORT_EXTERNAL_STRING_TYPE:
|
|
|
|
case SHORT_EXTERNAL_ASCII_STRING_TYPE:
|
|
|
|
case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
|
|
|
case INTERNALIZED_STRING_TYPE:
|
|
|
|
case ASCII_INTERNALIZED_STRING_TYPE:
|
|
|
|
case EXTERNAL_INTERNALIZED_STRING_TYPE:
|
|
|
|
case EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE:
|
|
|
|
case EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
|
|
|
case SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE:
|
|
|
|
case SHORT_EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE:
|
|
|
|
case SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
|
|
|
return kString;
|
|
|
|
case SYMBOL_TYPE:
|
|
|
|
return kSymbol;
|
2014-04-07 09:41:13 +00:00
|
|
|
case ODDBALL_TYPE: {
|
|
|
|
Heap* heap = map->GetHeap();
|
|
|
|
if (map == heap->undefined_map()) return kUndefined;
|
|
|
|
if (map == heap->the_hole_map()) return kAny; // TODO(rossberg): kNone?
|
|
|
|
if (map == heap->null_map()) return kNull;
|
|
|
|
if (map == heap->boolean_map()) return kBoolean;
|
2014-04-10 11:51:03 +00:00
|
|
|
ASSERT(map == heap->uninitialized_map() ||
|
|
|
|
map == heap->no_interceptor_result_sentinel_map() ||
|
2014-04-07 09:41:13 +00:00
|
|
|
map == heap->termination_exception_map() ||
|
|
|
|
map == heap->arguments_marker_map());
|
|
|
|
return kInternal & kTaggedPtr;
|
|
|
|
}
|
2013-11-15 15:14:09 +00:00
|
|
|
case HEAP_NUMBER_TYPE:
|
2014-03-18 11:50:18 +00:00
|
|
|
return kFloat & kTaggedPtr;
|
2013-11-15 15:14:09 +00:00
|
|
|
case JS_VALUE_TYPE:
|
|
|
|
case JS_DATE_TYPE:
|
|
|
|
case JS_OBJECT_TYPE:
|
|
|
|
case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
|
|
|
|
case JS_GENERATOR_OBJECT_TYPE:
|
|
|
|
case JS_MODULE_TYPE:
|
|
|
|
case JS_GLOBAL_OBJECT_TYPE:
|
|
|
|
case JS_BUILTINS_OBJECT_TYPE:
|
|
|
|
case JS_GLOBAL_PROXY_TYPE:
|
|
|
|
case JS_ARRAY_BUFFER_TYPE:
|
|
|
|
case JS_TYPED_ARRAY_TYPE:
|
|
|
|
case JS_DATA_VIEW_TYPE:
|
|
|
|
case JS_SET_TYPE:
|
|
|
|
case JS_MAP_TYPE:
|
|
|
|
case JS_WEAK_MAP_TYPE:
|
|
|
|
case JS_WEAK_SET_TYPE:
|
|
|
|
if (map->is_undetectable()) return kUndetectable;
|
|
|
|
return kOtherObject;
|
|
|
|
case JS_ARRAY_TYPE:
|
|
|
|
return kArray;
|
|
|
|
case JS_FUNCTION_TYPE:
|
|
|
|
return kFunction;
|
|
|
|
case JS_REGEXP_TYPE:
|
|
|
|
return kRegExp;
|
|
|
|
case JS_PROXY_TYPE:
|
|
|
|
case JS_FUNCTION_PROXY_TYPE:
|
|
|
|
return kProxy;
|
|
|
|
case MAP_TYPE:
|
|
|
|
// When compiling stub templates, the meta map is used as a place holder
|
|
|
|
// for the actual map with which the template is later instantiated.
|
|
|
|
// We treat it as a kind of type variable whose upper bound is Any.
|
|
|
|
// TODO(rossberg): for caching of CompareNilIC stubs to work correctly,
|
|
|
|
// we must exclude Undetectable here. This makes no sense, really,
|
|
|
|
// because it means that the template isn't actually parametric.
|
|
|
|
// Also, it doesn't apply elsewhere. 8-(
|
|
|
|
// We ought to find a cleaner solution for compiling stubs parameterised
|
|
|
|
// over type or class variables, esp ones with bounds...
|
|
|
|
return kDetectable;
|
|
|
|
case DECLARED_ACCESSOR_INFO_TYPE:
|
|
|
|
case EXECUTABLE_ACCESSOR_INFO_TYPE:
|
|
|
|
case ACCESSOR_PAIR_TYPE:
|
|
|
|
case FIXED_ARRAY_TYPE:
|
2014-03-18 11:50:18 +00:00
|
|
|
return kInternal & kTaggedPtr;
|
2013-11-15 15:14:09 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return kNone;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the largest bitset subsumed by this type.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::GlbBitset() {
|
|
|
|
if (this->IsBitset()) {
|
|
|
|
return this->AsBitset();
|
|
|
|
} else if (this->IsUnion()) {
|
2013-06-05 15:43:53 +00:00
|
|
|
// All but the first are non-bitsets and thus would yield kNone anyway.
|
2014-04-08 10:50:56 +00:00
|
|
|
return Config::struct_get(this->AsUnion(), 0)->GlbBitset();
|
2013-06-05 15:43:53 +00:00
|
|
|
} else {
|
|
|
|
return kNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-15 15:14:09 +00:00
|
|
|
// Most precise _current_ type of a value (usually its class).
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-04-01 13:11:12 +00:00
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NowOf(
|
2014-04-02 07:01:43 +00:00
|
|
|
i::Object* value, Region* region) {
|
2014-03-18 11:50:18 +00:00
|
|
|
if (value->IsSmi() ||
|
2014-04-07 09:41:13 +00:00
|
|
|
i::HeapObject::cast(value)->map()->instance_type() == HEAP_NUMBER_TYPE) {
|
2014-01-10 12:19:01 +00:00
|
|
|
return Of(value, region);
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
2014-04-02 07:01:43 +00:00
|
|
|
return Class(i::handle(i::HeapObject::cast(value)->map()), region);
|
2013-11-15 15:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
// Check this <= that.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
|
2013-06-05 15:43:53 +00:00
|
|
|
// Fast path for bitsets.
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsNone()) return true;
|
|
|
|
if (that->IsBitset()) {
|
|
|
|
return (this->LubBitset() | that->AsBitset()) == that->AsBitset();
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
if (that->IsClass()) {
|
|
|
|
return this->IsClass() && *this->AsClass() == *that->AsClass();
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
if (that->IsConstant()) {
|
|
|
|
return this->IsConstant() && *this->AsConstant() == *that->AsConstant();
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T)
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = this->AsUnion();
|
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
TypeHandle this_i = Config::struct_get(unioned, i);
|
2013-06-05 15:43:53 +00:00
|
|
|
if (!this_i->Is(that)) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn)
|
|
|
|
// (iff T is not a union)
|
2014-01-10 12:19:01 +00:00
|
|
|
ASSERT(!this->IsUnion());
|
|
|
|
if (that->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = that->AsUnion();
|
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
TypeHandle that_i = Config::struct_get(unioned, i);
|
2013-06-05 15:43:53 +00:00
|
|
|
if (this->Is(that_i)) return true;
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsBitset()) break; // Fast fail, only first field is a bitset.
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-04-01 13:11:12 +00:00
|
|
|
bool TypeImpl<Config>::NowIs(TypeImpl* that) {
|
2014-04-10 11:49:18 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2014-04-10 08:04:50 +00:00
|
|
|
if (this->IsConstant()) {
|
|
|
|
i::Object* object = *this->AsConstant();
|
|
|
|
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;
|
|
|
|
}
|
2014-04-09 11:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-10 08:04:50 +00:00
|
|
|
return this->Is(that);
|
2013-11-22 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
// Check this overlaps that.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::Maybe(TypeImpl* that) {
|
2013-06-05 15:43:53 +00:00
|
|
|
// (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T)
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = this->AsUnion();
|
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
TypeHandle this_i = Config::struct_get(unioned, i);
|
2013-06-05 15:43:53 +00:00
|
|
|
if (this_i->Maybe(that)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn)
|
2014-01-10 12:19:01 +00:00
|
|
|
if (that->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = that->AsUnion();
|
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
TypeHandle that_i = Config::struct_get(unioned, i);
|
2013-06-05 15:43:53 +00:00
|
|
|
if (this->Maybe(that_i)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
ASSERT(!this->IsUnion() && !that->IsUnion());
|
2014-04-10 08:04:50 +00:00
|
|
|
if (this->IsBitset()) {
|
|
|
|
return IsInhabited(this->AsBitset() & that->LubBitset());
|
|
|
|
}
|
|
|
|
if (that->IsBitset()) {
|
|
|
|
return IsInhabited(this->LubBitset() & that->AsBitset());
|
|
|
|
}
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsClass()) {
|
|
|
|
return that->IsClass() && *this->AsClass() == *that->AsClass();
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsConstant()) {
|
|
|
|
return that->IsConstant() && *this->AsConstant() == *that->AsConstant();
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-01 13:11:12 +00:00
|
|
|
template<class Config>
|
|
|
|
bool TypeImpl<Config>::Contains(i::Object* value) {
|
2014-04-09 11:12:15 +00:00
|
|
|
for (Iterator<i::Object> it = this->Constants(); !it.Done(); it.Advance()) {
|
|
|
|
if (*it.Current() == value) return true;
|
2014-04-01 13:11:12 +00:00
|
|
|
}
|
|
|
|
return Config::from_bitset(LubBitset(value))->Is(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-04-08 10:50:56 +00:00
|
|
|
bool TypeImpl<Config>::InUnion(StructHandle unioned, int current_size) {
|
2014-01-10 12:19:01 +00:00
|
|
|
ASSERT(!this->IsUnion());
|
2013-06-05 15:43:53 +00:00
|
|
|
for (int i = 0; i < current_size; ++i) {
|
2014-04-08 10:50:56 +00:00
|
|
|
TypeHandle type = Config::struct_get(unioned, i);
|
2013-06-20 09:10:10 +00:00
|
|
|
if (this->Is(type)) return true;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2014-04-08 10:50:56 +00:00
|
|
|
// Get non-bitsets from this which are not subsumed by union, store at result,
|
2013-06-05 15:43:53 +00:00
|
|
|
// starting at index. Returns updated index.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
int TypeImpl<Config>::ExtendUnion(
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle result, TypeHandle type, int current_size) {
|
2013-06-05 15:43:53 +00:00
|
|
|
int old_size = current_size;
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
if (type->IsClass() || type->IsConstant()) {
|
|
|
|
if (!type->InUnion(result, old_size)) {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_set(result, current_size++, type);
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
}
|
|
|
|
} else if (type->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = type->AsUnion();
|
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
TypeHandle type = Config::struct_get(unioned, i);
|
2014-01-10 12:19:01 +00:00
|
|
|
ASSERT(i == 0 ||
|
2014-04-08 10:50:56 +00:00
|
|
|
!(type->IsBitset() || type->Is(Config::struct_get(unioned, 0))));
|
2014-01-10 12:19:01 +00:00
|
|
|
if (!type->IsBitset() && !type->InUnion(result, old_size)) {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_set(result, current_size++, type);
|
2014-01-10 12:19:01 +00:00
|
|
|
}
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return current_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Union is O(1) on simple bit unions, but O(n*m) on structured unions.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union(
|
|
|
|
TypeHandle type1, TypeHandle type2, Region* region) {
|
2013-06-05 15:43:53 +00:00
|
|
|
// Fast case: bit sets.
|
2014-01-10 12:19:01 +00:00
|
|
|
if (type1->IsBitset() && type2->IsBitset()) {
|
|
|
|
return Config::from_bitset(type1->AsBitset() | type2->AsBitset(), region);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 11:10:06 +00:00
|
|
|
// Fast case: top or bottom types.
|
2014-03-31 15:53:21 +00:00
|
|
|
if (type1->IsAny() || type2->IsNone()) return type1;
|
|
|
|
if (type2->IsAny() || type1->IsNone()) return type2;
|
2013-06-21 11:10:06 +00:00
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
// Semi-fast case: Unioned objects are neither involved nor produced.
|
2014-01-10 12:19:01 +00:00
|
|
|
if (!(type1->IsUnion() || type2->IsUnion())) {
|
|
|
|
if (type1->Is(type2)) return type2;
|
|
|
|
if (type2->Is(type1)) return type1;
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Slow case: may need to produce a Unioned object.
|
2014-03-31 15:53:21 +00:00
|
|
|
int size = 0;
|
2014-01-10 12:19:01 +00:00
|
|
|
if (!type1->IsBitset()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
size += (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
if (!type2->IsBitset()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
size += (type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
2014-03-31 15:53:21 +00:00
|
|
|
int bitset = type1->GlbBitset() | type2->GlbBitset();
|
2014-04-14 09:46:56 +00:00
|
|
|
if (IsInhabited(bitset)) ++size;
|
2014-03-31 15:53:21 +00:00
|
|
|
ASSERT(size >= 1);
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = Config::struct_create(kUnionTag, size, region);
|
2013-06-05 15:43:53 +00:00
|
|
|
|
2014-03-31 15:53:21 +00:00
|
|
|
size = 0;
|
2014-04-14 09:46:56 +00:00
|
|
|
if (IsInhabited(bitset)) {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_set(unioned, size++, Config::from_bitset(bitset, region));
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
}
|
|
|
|
size = ExtendUnion(unioned, type1, size);
|
|
|
|
size = ExtendUnion(unioned, type2, size);
|
2013-06-05 15:43:53 +00:00
|
|
|
|
|
|
|
if (size == 1) {
|
2014-04-08 10:50:56 +00:00
|
|
|
return Config::struct_get(unioned, 0);
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
} else {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_shrink(unioned, size);
|
|
|
|
return Config::from_struct(unioned);
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-08 10:50:56 +00:00
|
|
|
// Get non-bitsets from type which are also in other, store at result,
|
2013-06-20 09:10:10 +00:00
|
|
|
// starting at index. Returns updated index.
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
int TypeImpl<Config>::ExtendIntersection(
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle result, TypeHandle type, TypeHandle other, int current_size) {
|
2013-06-20 09:10:10 +00:00
|
|
|
int old_size = current_size;
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
if (type->IsClass() || type->IsConstant()) {
|
|
|
|
if (type->Is(other) && !type->InUnion(result, old_size)) {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_set(result, current_size++, type);
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
}
|
|
|
|
} else if (type->IsUnion()) {
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = type->AsUnion();
|
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
TypeHandle type = Config::struct_get(unioned, i);
|
2014-01-10 12:19:01 +00:00
|
|
|
ASSERT(i == 0 ||
|
2014-04-08 10:50:56 +00:00
|
|
|
!(type->IsBitset() || type->Is(Config::struct_get(unioned, 0))));
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
if (!type->IsBitset() && type->Is(other) &&
|
2014-01-10 12:19:01 +00:00
|
|
|
!type->InUnion(result, old_size)) {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_set(result, current_size++, type);
|
2014-01-10 12:19:01 +00:00
|
|
|
}
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return current_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Intersection is O(1) on simple bit unions, but O(n*m) on structured unions.
|
|
|
|
// TODO(rossberg): Should we use object sets somehow? Is it worth it?
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect(
|
|
|
|
TypeHandle type1, TypeHandle type2, Region* region) {
|
2013-06-20 09:10:10 +00:00
|
|
|
// Fast case: bit sets.
|
2014-01-10 12:19:01 +00:00
|
|
|
if (type1->IsBitset() && type2->IsBitset()) {
|
|
|
|
return Config::from_bitset(type1->AsBitset() & type2->AsBitset(), region);
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 11:10:06 +00:00
|
|
|
// Fast case: top or bottom types.
|
2014-03-31 15:53:21 +00:00
|
|
|
if (type1->IsNone() || type2->IsAny()) return type1;
|
|
|
|
if (type2->IsNone() || type1->IsAny()) return type2;
|
2013-06-21 11:10:06 +00:00
|
|
|
|
2013-06-20 09:10:10 +00:00
|
|
|
// Semi-fast case: Unioned objects are neither involved nor produced.
|
2014-01-10 12:19:01 +00:00
|
|
|
if (!(type1->IsUnion() || type2->IsUnion())) {
|
|
|
|
if (type1->Is(type2)) return type1;
|
|
|
|
if (type2->Is(type1)) return type2;
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Slow case: may need to produce a Unioned object.
|
2014-04-14 09:46:56 +00:00
|
|
|
int size = INT_MAX;
|
2014-01-10 12:19:01 +00:00
|
|
|
if (!type1->IsBitset()) {
|
2014-04-14 09:46:56 +00:00
|
|
|
size = (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1);
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
if (!type2->IsBitset()) {
|
2014-04-14 09:46:56 +00:00
|
|
|
size = Min(size,
|
|
|
|
type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1);
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2014-03-31 15:53:21 +00:00
|
|
|
int bitset = type1->GlbBitset() & type2->GlbBitset();
|
2014-04-14 09:46:56 +00:00
|
|
|
if (IsInhabited(bitset)) ++size;
|
2014-03-31 15:53:21 +00:00
|
|
|
ASSERT(size >= 1);
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = Config::struct_create(kUnionTag, size, region);
|
2013-06-20 09:10:10 +00:00
|
|
|
|
2014-03-31 15:53:21 +00:00
|
|
|
size = 0;
|
2014-04-14 09:46:56 +00:00
|
|
|
if (IsInhabited(bitset)) {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_set(unioned, size++, Config::from_bitset(bitset, region));
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
}
|
|
|
|
size = ExtendIntersection(unioned, type1, type2, size);
|
|
|
|
size = ExtendIntersection(unioned, type2, type1, size);
|
2013-06-20 09:10:10 +00:00
|
|
|
|
|
|
|
if (size == 0) {
|
2014-01-10 12:19:01 +00:00
|
|
|
return None(region);
|
2013-06-20 09:10:10 +00:00
|
|
|
} else if (size == 1) {
|
2014-04-08 10:50:56 +00:00
|
|
|
return Config::struct_get(unioned, 0);
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
} else {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_shrink(unioned, size);
|
|
|
|
return Config::from_struct(unioned);
|
2013-06-20 09:10:10 +00:00
|
|
|
}
|
2013-06-05 15:43:53 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:26:22 +00:00
|
|
|
|
2014-01-24 11:47:47 +00:00
|
|
|
template<class Config>
|
|
|
|
template<class OtherType>
|
|
|
|
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert(
|
|
|
|
typename OtherType::TypeHandle type, Region* region) {
|
|
|
|
if (type->IsBitset()) {
|
|
|
|
return Config::from_bitset(type->AsBitset(), region);
|
|
|
|
} else if (type->IsClass()) {
|
2014-03-11 10:28:38 +00:00
|
|
|
return Config::from_class(type->AsClass(), type->LubBitset(), region);
|
2014-01-24 11:47:47 +00:00
|
|
|
} else if (type->IsConstant()) {
|
2014-03-11 10:28:38 +00:00
|
|
|
return Config::from_constant(type->AsConstant(), type->LubBitset(), region);
|
2014-01-24 11:47:47 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(type->IsUnion());
|
2014-04-08 10:50:56 +00:00
|
|
|
typename OtherType::StructHandle unioned = type->AsUnion();
|
|
|
|
int length = OtherType::StructLength(unioned);
|
|
|
|
StructHandle new_unioned = Config::struct_create(kUnionTag, length, region);
|
2014-01-24 11:47:47 +00:00
|
|
|
for (int i = 0; i < length; ++i) {
|
2014-04-08 10:50:56 +00:00
|
|
|
Config::struct_set(new_unioned, i,
|
|
|
|
Convert<OtherType>(OtherType::StructGet(unioned, i), region));
|
2014-01-24 11:47:47 +00:00
|
|
|
}
|
2014-04-08 10:50:56 +00:00
|
|
|
return Config::from_struct(new_unioned);
|
2014-01-24 11:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
// TODO(rossberg): this does not belong here.
|
2014-01-21 16:22:52 +00:00
|
|
|
Representation Representation::FromType(Type* type) {
|
2013-07-05 09:26:22 +00:00
|
|
|
if (type->Is(Type::None())) return Representation::None();
|
2014-03-18 11:50:18 +00:00
|
|
|
if (type->Is(Type::SignedSmall())) return Representation::Smi();
|
2013-07-05 09:26:22 +00:00
|
|
|
if (type->Is(Type::Signed32())) return Representation::Integer32();
|
|
|
|
if (type->Is(Type::Number())) return Representation::Double();
|
|
|
|
return Representation::Tagged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-03-18 11:50:18 +00:00
|
|
|
void TypeImpl<Config>::TypePrint(PrintDimension dim) {
|
|
|
|
TypePrint(stdout, dim);
|
2013-07-10 11:20:00 +00:00
|
|
|
PrintF(stdout, "\n");
|
|
|
|
Flush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
|
|
|
const char* TypeImpl<Config>::bitset_name(int bitset) {
|
2013-11-22 12:38:49 +00:00
|
|
|
switch (bitset) {
|
2014-03-18 11:50:18 +00:00
|
|
|
case kAny & kRepresentation: return "Any";
|
|
|
|
#define PRINT_COMPOSED_TYPE(type, value) \
|
|
|
|
case k##type & kRepresentation: return #type;
|
|
|
|
REPRESENTATION_BITSET_TYPE_LIST(PRINT_COMPOSED_TYPE)
|
2013-11-22 12:38:49 +00:00
|
|
|
#undef PRINT_COMPOSED_TYPE
|
2014-03-18 11:50:18 +00:00
|
|
|
|
|
|
|
#define PRINT_COMPOSED_TYPE(type, value) \
|
|
|
|
case k##type & kSemantic: return #type;
|
|
|
|
SEMANTIC_BITSET_TYPE_LIST(PRINT_COMPOSED_TYPE)
|
|
|
|
#undef PRINT_COMPOSED_TYPE
|
|
|
|
|
2013-11-22 12:38:49 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template<class Config>
|
2014-03-18 11:50:18 +00:00
|
|
|
void TypeImpl<Config>::BitsetTypePrint(FILE* out, int bitset) {
|
|
|
|
const char* name = bitset_name(bitset);
|
|
|
|
if (name != NULL) {
|
|
|
|
PrintF(out, "%s", name);
|
|
|
|
} else {
|
|
|
|
static const int named_bitsets[] = {
|
|
|
|
#define BITSET_CONSTANT(type, value) k##type & kRepresentation,
|
|
|
|
REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT)
|
|
|
|
#undef BITSET_CONSTANT
|
|
|
|
|
|
|
|
#define BITSET_CONSTANT(type, value) k##type & kSemantic,
|
|
|
|
SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT)
|
|
|
|
#undef BITSET_CONSTANT
|
|
|
|
};
|
|
|
|
|
|
|
|
bool is_first = true;
|
|
|
|
PrintF(out, "(");
|
|
|
|
for (int i(ARRAY_SIZE(named_bitsets) - 1); bitset != 0 && i >= 0; --i) {
|
|
|
|
int subset = named_bitsets[i];
|
|
|
|
if ((bitset & subset) == subset) {
|
|
|
|
if (!is_first) PrintF(out, " | ");
|
|
|
|
is_first = false;
|
|
|
|
PrintF(out, "%s", bitset_name(subset));
|
|
|
|
bitset -= subset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(bitset == 0);
|
|
|
|
PrintF(out, ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Config>
|
|
|
|
void TypeImpl<Config>::TypePrint(FILE* out, PrintDimension dim) {
|
2014-01-10 12:19:01 +00:00
|
|
|
if (this->IsBitset()) {
|
|
|
|
int bitset = this->AsBitset();
|
2014-03-18 11:50:18 +00:00
|
|
|
switch (dim) {
|
|
|
|
case BOTH_DIMS:
|
|
|
|
BitsetTypePrint(out, bitset & kSemantic);
|
2014-03-31 15:53:21 +00:00
|
|
|
PrintF(out, "/");
|
2014-03-18 11:50:18 +00:00
|
|
|
BitsetTypePrint(out, bitset & kRepresentation);
|
|
|
|
break;
|
|
|
|
case SEMANTIC_DIM:
|
|
|
|
BitsetTypePrint(out, bitset & kSemantic);
|
|
|
|
break;
|
|
|
|
case REPRESENTATION_DIM:
|
|
|
|
BitsetTypePrint(out, bitset & kRepresentation);
|
|
|
|
break;
|
2013-07-10 11:20:00 +00:00
|
|
|
}
|
2014-01-10 12:19:01 +00:00
|
|
|
} else if (this->IsConstant()) {
|
|
|
|
PrintF(out, "Constant(%p : ", static_cast<void*>(*this->AsConstant()));
|
2014-04-04 09:00:30 +00:00
|
|
|
Config::from_bitset(this->LubBitset())->TypePrint(out, dim);
|
2014-03-31 15:53:21 +00:00
|
|
|
PrintF(out, ")");
|
2014-01-10 12:19:01 +00:00
|
|
|
} else if (this->IsClass()) {
|
|
|
|
PrintF(out, "Class(%p < ", static_cast<void*>(*this->AsClass()));
|
2014-04-04 09:00:30 +00:00
|
|
|
Config::from_bitset(this->LubBitset())->TypePrint(out, dim);
|
2014-03-31 15:53:21 +00:00
|
|
|
PrintF(out, ")");
|
2014-01-10 12:19:01 +00:00
|
|
|
} else if (this->IsUnion()) {
|
2013-11-22 12:38:49 +00:00
|
|
|
PrintF(out, "(");
|
2014-04-08 10:50:56 +00:00
|
|
|
StructHandle unioned = this->AsUnion();
|
|
|
|
for (int i = 0; i < Config::struct_length(unioned); ++i) {
|
|
|
|
TypeHandle type_i = Config::struct_get(unioned, i);
|
2013-11-22 12:38:49 +00:00
|
|
|
if (i > 0) PrintF(out, " | ");
|
2014-03-31 15:53:21 +00:00
|
|
|
type_i->TypePrint(out, dim);
|
2013-07-10 11:20:00 +00:00
|
|
|
}
|
2013-11-22 12:38:49 +00:00
|
|
|
PrintF(out, ")");
|
2013-07-10 11:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Retry landing "Implement zone-allocated types"
Works around apparent scoping bug in VS, the only change to before being a method rename in the test suite:
--- a/test/cctest/test-types.cc
+++ b/test/cctest/test-types.cc
@@ -153,7 +153,7 @@ struct ZoneRep {
return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t));
}
- static Zone* Region(Zone* zone, Isolate* isolate) { return zone; }
+ static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
};
@@ -168,7 +168,7 @@ struct HeapRep {
static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); }
static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); }
- static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; }
+ static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
};
@@ -183,7 +183,7 @@ struct Tests : Rep {
isolate(CcTest::i_isolate()),
scope(isolate),
zone(isolate),
- T(Rep::Region(&zone, isolate), isolate) {
+ T(Rep::ToRegion(&zone, isolate), isolate) {
}
static void CheckEqual(TypeHandle type1, TypeHandle type2) {
R=titzer@chromium.org
BUG=
Review URL: https://codereview.chromium.org/143693003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-21 14:14:12 +00:00
|
|
|
template class TypeImpl<ZoneTypeConfig>;
|
|
|
|
template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>;
|
|
|
|
template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>;
|
|
|
|
|
2014-01-10 12:19:01 +00:00
|
|
|
template class TypeImpl<HeapTypeConfig>;
|
|
|
|
template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>;
|
|
|
|
template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>;
|
|
|
|
|
2014-01-24 11:47:47 +00:00
|
|
|
template TypeImpl<ZoneTypeConfig>::TypeHandle
|
|
|
|
TypeImpl<ZoneTypeConfig>::Convert<HeapType>(
|
|
|
|
TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*);
|
|
|
|
template TypeImpl<HeapTypeConfig>::TypeHandle
|
|
|
|
TypeImpl<HeapTypeConfig>::Convert<Type>(
|
|
|
|
TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*);
|
|
|
|
|
2013-06-05 15:43:53 +00:00
|
|
|
} } // namespace v8::internal
|