5 #ifndef V8_COMPILER_TYPES_H_ 6 #define V8_COMPILER_TYPES_H_ 8 #include "src/base/compiler-specific.h" 9 #include "src/compiler/js-heap-broker.h" 10 #include "src/conversions.h" 11 #include "src/globals.h" 12 #include "src/handles.h" 13 #include "src/objects.h" 14 #include "src/ostreams.h" 102 #define INTERNAL_BITSET_TYPE_LIST(V) \ 103 V(OtherUnsigned31, 1u << 1) \ 104 V(OtherUnsigned32, 1u << 2) \ 105 V(OtherSigned32, 1u << 3) \ 106 V(OtherNumber, 1u << 4) \ 107 V(OtherString, 1u << 5) \ 109 #define PROPER_BITSET_TYPE_LIST(V) \ 111 V(Negative31, 1u << 6) \ 113 V(Undefined, 1u << 8) \ 114 V(Boolean, 1u << 9) \ 115 V(Unsigned30, 1u << 10) \ 116 V(MinusZero, 1u << 11) \ 118 V(Symbol, 1u << 13) \ 119 V(InternalizedString, 1u << 14) \ 120 V(OtherCallable, 1u << 16) \ 121 V(OtherObject, 1u << 17) \ 122 V(OtherUndetectable, 1u << 18) \ 123 V(CallableProxy, 1u << 19) \ 124 V(OtherProxy, 1u << 20) \ 125 V(Function, 1u << 21) \ 126 V(BoundFunction, 1u << 22) \ 128 V(OtherInternal, 1u << 24) \ 129 V(ExternalPointer, 1u << 25) \ 131 V(BigInt, 1u << 27) \ 133 V(Signed31, kUnsigned30 | kNegative31) \ 134 V(Signed32, kSigned31 | kOtherUnsigned31 | \ 136 V(Signed32OrMinusZero, kSigned32 | kMinusZero) \ 137 V(Signed32OrMinusZeroOrNaN, kSigned32 | kMinusZero | kNaN) \ 138 V(Negative32, kNegative31 | kOtherSigned32) \ 139 V(Unsigned31, kUnsigned30 | kOtherUnsigned31) \ 140 V(Unsigned32, kUnsigned30 | kOtherUnsigned31 | \ 142 V(Unsigned32OrMinusZero, kUnsigned32 | kMinusZero) \ 143 V(Unsigned32OrMinusZeroOrNaN, kUnsigned32 | kMinusZero | kNaN) \ 144 V(Integral32, kSigned32 | kUnsigned32) \ 145 V(Integral32OrMinusZero, kIntegral32 | kMinusZero) \ 146 V(Integral32OrMinusZeroOrNaN, kIntegral32OrMinusZero | kNaN) \ 147 V(PlainNumber, kIntegral32 | kOtherNumber) \ 148 V(OrderedNumber, kPlainNumber | kMinusZero) \ 149 V(MinusZeroOrNaN, kMinusZero | kNaN) \ 150 V(Number, kOrderedNumber | kNaN) \ 151 V(Numeric, kNumber | kBigInt) \ 152 V(String, kInternalizedString | kOtherString) \ 153 V(UniqueName, kSymbol | kInternalizedString) \ 154 V(Name, kSymbol | kString) \ 155 V(InternalizedStringOrNull, kInternalizedString | kNull) \ 156 V(BooleanOrNumber, kBoolean | kNumber) \ 157 V(BooleanOrNullOrNumber, kBooleanOrNumber | kNull) \ 158 V(BooleanOrNullOrUndefined, kBoolean | kNull | kUndefined) \ 159 V(Oddball, kBooleanOrNullOrUndefined | kHole) \ 160 V(NullOrNumber, kNull | kNumber) \ 161 V(NullOrUndefined, kNull | kUndefined) \ 162 V(Undetectable, kNullOrUndefined | kOtherUndetectable) \ 163 V(NumberOrHole, kNumber | kHole) \ 164 V(NumberOrOddball, kNumber | kNullOrUndefined | kBoolean | \ 166 V(NumericOrString, kNumeric | kString) \ 167 V(NumberOrUndefined, kNumber | kUndefined) \ 168 V(NumberOrUndefinedOrNullOrBoolean, \ 169 kNumber | kNullOrUndefined | kBoolean) \ 170 V(PlainPrimitive, kNumber | kString | kBoolean | \ 172 V(NonBigIntPrimitive, kSymbol | kPlainPrimitive) \ 173 V(Primitive, kBigInt | kNonBigIntPrimitive) \ 174 V(OtherUndetectableOrUndefined, kOtherUndetectable | kUndefined) \ 175 V(Proxy, kCallableProxy | kOtherProxy) \ 176 V(ArrayOrOtherObject, kArray | kOtherObject) \ 177 V(ArrayOrProxy, kArray | kProxy) \ 178 V(DetectableCallable, kFunction | kBoundFunction | \ 179 kOtherCallable | kCallableProxy) \ 180 V(Callable, kDetectableCallable | kOtherUndetectable) \ 181 V(NonCallable, kArray | kOtherObject | kOtherProxy) \ 182 V(NonCallableOrNull, kNonCallable | kNull) \ 183 V(DetectableObject, kArray | kFunction | kBoundFunction | \ 184 kOtherCallable | kOtherObject) \ 185 V(DetectableReceiver, kDetectableObject | kProxy) \ 186 V(DetectableReceiverOrNull, kDetectableReceiver | kNull) \ 187 V(Object, kDetectableObject | kOtherUndetectable) \ 188 V(Receiver, kObject | kProxy) \ 189 V(ReceiverOrUndefined, kReceiver | kUndefined) \ 190 V(ReceiverOrNullOrUndefined, kReceiver | kNull | kUndefined) \ 191 V(SymbolOrReceiver, kSymbol | kReceiver) \ 192 V(StringOrReceiver, kString | kReceiver) \ 193 V(Unique, kBoolean | kUniqueName | kNull | \ 194 kUndefined | kReceiver) \ 195 V(Internal, kHole | kExternalPointer | kOtherInternal) \ 196 V(NonInternal, kPrimitive | kReceiver) \ 197 V(NonBigInt, kNonBigIntPrimitive | kReceiver) \ 198 V(NonNumber, kBigInt | kUnique | kString | kInternal) \ 219 #define BITSET_TYPE_LIST(V) \ 220 INTERNAL_BITSET_TYPE_LIST(V) \ 221 PROPER_BITSET_TYPE_LIST(V) 223 class HeapConstantType;
224 class OtherNumberConstantType;
237 #define DECLARE_TYPE(type, value) k##type = (value), 238 BITSET_TYPE_LIST(DECLARE_TYPE)
243 static bitset SignedSmall();
244 static bitset UnsignedSmall();
246 static bool IsNone(
bitset bits) {
return bits ==
kNone; }
249 return (bits1 | bits2) == bits2;
252 static double Min(
bitset);
253 static double Max(
bitset);
255 static bitset Glb(
double min,
double max);
257 return Lub<HeapObjectType>(
type);
259 static bitset Lub(
MapRef const& map) {
return Lub<MapRef>(map); }
260 static bitset Lub(
double value);
261 static bitset Lub(
double min,
double max);
265 static void Print(std::ostream& os,
bitset);
267 static void Print(
bitset);
278 static const Boundary BoundariesArray[];
279 static inline const Boundary* Boundaries();
280 static inline size_t BoundariesSize();
282 template <
typename MapRefLike>
283 static bitset Lub(MapRefLike
const& map);
292 enum Kind { kHeapConstant, kOtherNumberConstant, kTuple, kUnion, kRange };
294 Kind kind()
const {
return kind_; }
295 explicit TypeBase(Kind kind) : kind_(kind) {}
297 static bool IsKind(
Type type, Kind kind);
311 Limits(
double min,
double max) : min(min), max(max) {}
313 : min(range->Min()), max(range->Max()) {}
320 double Min()
const {
return limits_.min; }
321 double Max()
const {
return limits_.max; }
323 static bool IsInteger(
double x) {
324 return nearbyint(x) == x && !IsMinusZero(x);
329 friend class BitsetType;
330 friend class UnionType;
332 static RangeType* New(
double min,
double max, Zone* zone) {
333 return New(Limits(min, max), zone);
336 static RangeType* New(Limits lim, Zone* zone) {
337 DCHECK(IsInteger(lim.min) && IsInteger(lim.max));
338 DCHECK(lim.min <= lim.max);
339 BitsetType::bitset bits = BitsetType::Lub(lim.min, lim.max);
341 return new (zone->New(
sizeof(RangeType))) RangeType(bits, lim);
344 RangeType(BitsetType::bitset bitset, Limits limits)
345 : TypeBase(kRange), bitset_(bitset), limits_(limits) {}
347 BitsetType::bitset Lub()
const {
return bitset_; }
349 BitsetType::bitset bitset_;
358 typedef BitsetType::bitset
bitset;
361 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ 362 static Type type() { return NewBitset(BitsetType::k##type); } 363 PROPER_BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR)
364 #undef DEFINE_TYPE_CONSTRUCTOR 366 Type() : payload_(0) {}
368 static Type SignedSmall() {
return NewBitset(BitsetType::SignedSmall()); }
369 static Type UnsignedSmall() {
return NewBitset(BitsetType::UnsignedSmall()); }
371 static Type OtherNumberConstant(
double value,
Zone* zone);
378 static Type Union(
int length,
Zone* zone);
383 static Type NewConstant(
double value,
Zone* zone);
389 return NewBitset(BitsetType::ExpandInternals(BitsetType::Lub(
type)));
392 return NewBitset(BitsetType::ExpandInternals(BitsetType::Lub(
type)));
396 bool IsNone()
const {
return payload_ ==
None().payload_; }
397 bool IsInvalid()
const {
return payload_ == 0u; }
399 bool Is(
Type that)
const {
400 return payload_ == that.payload_ || this->SlowIs(that);
403 bool Equals(
Type that)
const {
return this->Is(that) && that.Is(*
this); }
406 bool IsBitset()
const {
return payload_ & 1; }
407 bool IsRange()
const {
return IsKind(TypeBase::kRange); }
408 bool IsHeapConstant()
const {
return IsKind(TypeBase::kHeapConstant); }
409 bool IsOtherNumberConstant()
const {
410 return IsKind(TypeBase::kOtherNumberConstant);
412 bool IsTuple()
const {
return IsKind(TypeBase::kTuple); }
428 Type GetRange()
const;
430 int NumConstants()
const;
432 static Type Invalid() {
return Type(); }
434 bool operator==(
Type other)
const {
return payload_ == other.payload_; }
435 bool operator!=(
Type other)
const {
return payload_ != other.payload_; }
439 void PrintTo(std::ostream& os)
const;
446 bool IsUnionForTesting() {
return IsUnion(); }
447 bitset AsBitsetForTesting() {
return AsBitset(); }
448 const UnionType* AsUnionForTesting() {
return AsUnion(); }
449 Type BitsetGlbForTesting() {
return NewBitset(BitsetGlb()); }
450 Type BitsetLubForTesting() {
return NewBitset(BitsetLub()); }
455 friend class Iterator;
458 friend size_t hash_value(
Type type);
462 : payload_(reinterpret_cast<uintptr_t>(type_base)) {}
465 bool IsKind(TypeBase::Kind kind)
const {
466 if (IsBitset())
return false;
467 const TypeBase* base = ToTypeBase();
468 return base->kind() == kind;
471 const TypeBase* ToTypeBase()
const {
472 return reinterpret_cast<TypeBase*
>(payload_);
476 bool IsAny()
const {
return payload_ == Any().payload_; }
477 bool IsUnion()
const {
return IsKind(TypeBase::kUnion); }
481 return static_cast<bitset>(payload_) ^ 1u;
489 bool SlowIs(
Type that)
const;
502 bool SimplyEquals(
Type that)
const;
515 inline size_t hash_value(
Type type) {
return type.payload_; }
516 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
Type type);
523 double Value()
const {
return value_; }
525 static bool IsOtherNumberConstant(
double value);
537 :
TypeBase(kOtherNumberConstant), value_(value) {
538 CHECK(IsOtherNumberConstant(value));
556 DCHECK(!heap_ref.IsHeapNumber());
557 DCHECK_IMPLIES(heap_ref.IsString(), heap_ref.IsInternalizedString());
575 int LengthForTesting()
const {
return Length(); }
580 int Length()
const {
return length_; }
582 Type Get(
int i)
const {
583 DCHECK(0 <=
i && i < this->Length());
588 DCHECK(0 <=
i && i < this->Length());
592 void Shrink(
int length) {
593 DCHECK(2 <= length && length <= this->Length());
599 elements_ =
reinterpret_cast<Type*
>(zone->New(
sizeof(
Type) * length));
612 int Arity()
const {
return this->Length(); }
613 Type Element(
int i)
const {
return this->Get(
i); }
645 bool Wellformed()
const;
652 #endif // V8_COMPILER_TYPES_H_