| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_TYPE_CACHE_H_ | 5 #ifndef V8_COMPILER_TYPE_CACHE_H_ |
| 6 #define V8_COMPILER_TYPE_CACHE_H_ | 6 #define V8_COMPILER_TYPE_CACHE_H_ |
| 7 | 7 |
| 8 #include "src/date.h" | 8 #include "src/date.h" |
| 9 #include "src/types.h" | 9 #include "src/types.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace compiler { | 13 namespace compiler { |
| 14 | 14 |
| 15 class TypeCache final { | 15 class TypeCache final { |
| 16 private: | 16 private: |
| 17 // This has to be first for the initialization magic to work. | 17 // This has to be first for the initialization magic to work. |
| 18 base::AccountingAllocator allocator; | 18 base::AccountingAllocator allocator; |
| 19 Zone zone_; | 19 Zone zone_; |
| 20 | 20 |
| 21 public: | 21 public: |
| 22 static TypeCache const& Get(); | 22 static TypeCache const& Get(); |
| 23 | 23 |
| 24 TypeCache() : zone_(&allocator) {} | 24 TypeCache() : zone_(&allocator) {} |
| 25 | 25 |
| 26 Type* const kInt8 = | 26 Type* const kInt8 = CreateRange<int8_t>(); |
| 27 CreateNative(CreateRange<int8_t>(), Type::UntaggedIntegral8()); | 27 Type* const kUint8 = CreateRange<uint8_t>(); |
| 28 Type* const kUint8 = | |
| 29 CreateNative(CreateRange<uint8_t>(), Type::UntaggedIntegral8()); | |
| 30 Type* const kUint8Clamped = kUint8; | 28 Type* const kUint8Clamped = kUint8; |
| 31 Type* const kInt16 = | 29 Type* const kInt16 = CreateRange<int16_t>(); |
| 32 CreateNative(CreateRange<int16_t>(), Type::UntaggedIntegral16()); | 30 Type* const kUint16 = CreateRange<uint16_t>(); |
| 33 Type* const kUint16 = | 31 Type* const kInt32 = Type::Signed32(); |
| 34 CreateNative(CreateRange<uint16_t>(), Type::UntaggedIntegral16()); | 32 Type* const kUint32 = Type::Unsigned32(); |
| 35 Type* const kInt32 = | 33 Type* const kFloat32 = Type::Number(); |
| 36 CreateNative(Type::Signed32(), Type::UntaggedIntegral32()); | 34 Type* const kFloat64 = Type::Number(); |
| 37 Type* const kUint32 = | |
| 38 CreateNative(Type::Unsigned32(), Type::UntaggedIntegral32()); | |
| 39 Type* const kFloat32 = CreateNative(Type::Number(), Type::UntaggedFloat32()); | |
| 40 Type* const kFloat64 = CreateNative(Type::Number(), Type::UntaggedFloat64()); | |
| 41 | 35 |
| 42 Type* const kSmi = CreateNative(Type::SignedSmall(), Type::TaggedSigned()); | 36 Type* const kSmi = Type::SignedSmall(); |
| 43 Type* const kHoleySmi = Type::Union(kSmi, Type::Hole(), zone()); | 37 Type* const kHoleySmi = Type::Union(kSmi, Type::Hole(), zone()); |
| 44 Type* const kHeapNumber = CreateNative(Type::Number(), Type::TaggedPointer()); | 38 Type* const kHeapNumber = Type::Number(); |
| 45 | 39 |
| 46 Type* const kSingletonZero = CreateRange(0.0, 0.0); | 40 Type* const kSingletonZero = CreateRange(0.0, 0.0); |
| 47 Type* const kSingletonOne = CreateRange(1.0, 1.0); | 41 Type* const kSingletonOne = CreateRange(1.0, 1.0); |
| 48 Type* const kSingletonTen = CreateRange(10.0, 10.0); | 42 Type* const kSingletonTen = CreateRange(10.0, 10.0); |
| 49 Type* const kSingletonMinusOne = CreateRange(-1.0, -1.0); | 43 Type* const kSingletonMinusOne = CreateRange(-1.0, -1.0); |
| 50 Type* const kZeroOrUndefined = | 44 Type* const kZeroOrUndefined = |
| 51 Type::Union(kSingletonZero, Type::Undefined(), zone()); | 45 Type::Union(kSingletonZero, Type::Undefined(), zone()); |
| 52 Type* const kTenOrUndefined = | 46 Type* const kTenOrUndefined = |
| 53 Type::Union(kSingletonTen, Type::Undefined(), zone()); | 47 Type::Union(kSingletonTen, Type::Undefined(), zone()); |
| 54 Type* const kMinusOneOrZero = CreateRange(-1.0, 0.0); | 48 Type* const kMinusOneOrZero = CreateRange(-1.0, 0.0); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 74 CreateRange(-4503599627370496.0, 4503599627370496.0); | 68 CreateRange(-4503599627370496.0, 4503599627370496.0); |
| 75 Type* const kSafeInteger = CreateRange(-kMaxSafeInteger, kMaxSafeInteger); | 69 Type* const kSafeInteger = CreateRange(-kMaxSafeInteger, kMaxSafeInteger); |
| 76 Type* const kAdditiveSafeIntegerOrMinusZero = | 70 Type* const kAdditiveSafeIntegerOrMinusZero = |
| 77 Type::Union(kAdditiveSafeInteger, Type::MinusZero(), zone()); | 71 Type::Union(kAdditiveSafeInteger, Type::MinusZero(), zone()); |
| 78 Type* const kSafeIntegerOrMinusZero = | 72 Type* const kSafeIntegerOrMinusZero = |
| 79 Type::Union(kSafeInteger, Type::MinusZero(), zone()); | 73 Type::Union(kSafeInteger, Type::MinusZero(), zone()); |
| 80 Type* const kPositiveSafeInteger = CreateRange(0.0, kMaxSafeInteger); | 74 Type* const kPositiveSafeInteger = CreateRange(0.0, kMaxSafeInteger); |
| 81 | 75 |
| 82 // The FixedArray::length property always containts a smi in the range | 76 // The FixedArray::length property always containts a smi in the range |
| 83 // [0, FixedArray::kMaxLength]. | 77 // [0, FixedArray::kMaxLength]. |
| 84 Type* const kFixedArrayLengthType = CreateNative( | 78 Type* const kFixedArrayLengthType = CreateRange(0.0, FixedArray::kMaxLength); |
| 85 CreateRange(0.0, FixedArray::kMaxLength), Type::TaggedSigned()); | |
| 86 | 79 |
| 87 // The FixedDoubleArray::length property always containts a smi in the range | 80 // The FixedDoubleArray::length property always containts a smi in the range |
| 88 // [0, FixedDoubleArray::kMaxLength]. | 81 // [0, FixedDoubleArray::kMaxLength]. |
| 89 Type* const kFixedDoubleArrayLengthType = CreateNative( | 82 Type* const kFixedDoubleArrayLengthType = |
| 90 CreateRange(0.0, FixedDoubleArray::kMaxLength), Type::TaggedSigned()); | 83 CreateRange(0.0, FixedDoubleArray::kMaxLength); |
| 91 | 84 |
| 92 // The JSArray::length property always contains a tagged number in the range | 85 // The JSArray::length property always contains a tagged number in the range |
| 93 // [0, kMaxUInt32]. | 86 // [0, kMaxUInt32]. |
| 94 Type* const kJSArrayLengthType = | 87 Type* const kJSArrayLengthType = Type::Unsigned32(); |
| 95 CreateNative(Type::Unsigned32(), Type::Tagged()); | |
| 96 | 88 |
| 97 // The JSTyped::length property always contains a tagged number in the range | 89 // The JSTyped::length property always contains a tagged number in the range |
| 98 // [0, kMaxSmiValue]. | 90 // [0, kMaxSmiValue]. |
| 99 Type* const kJSTypedArrayLengthType = | 91 Type* const kJSTypedArrayLengthType = Type::UnsignedSmall(); |
| 100 CreateNative(Type::UnsignedSmall(), Type::TaggedSigned()); | |
| 101 | 92 |
| 102 // The String::length property always contains a smi in the range | 93 // The String::length property always contains a smi in the range |
| 103 // [0, String::kMaxLength]. | 94 // [0, String::kMaxLength]. |
| 104 Type* const kStringLengthType = | 95 Type* const kStringLengthType = CreateRange(0.0, String::kMaxLength); |
| 105 CreateNative(CreateRange(0.0, String::kMaxLength), Type::TaggedSigned()); | |
| 106 | 96 |
| 107 // The JSDate::day property always contains a tagged number in the range | 97 // The JSDate::day property always contains a tagged number in the range |
| 108 // [1, 31] or NaN. | 98 // [1, 31] or NaN. |
| 109 Type* const kJSDateDayType = | 99 Type* const kJSDateDayType = |
| 110 Type::Union(CreateRange(1, 31.0), Type::NaN(), zone()); | 100 Type::Union(CreateRange(1, 31.0), Type::NaN(), zone()); |
| 111 | 101 |
| 112 // The JSDate::hour property always contains a tagged number in the range | 102 // The JSDate::hour property always contains a tagged number in the range |
| 113 // [0, 23] or NaN. | 103 // [0, 23] or NaN. |
| 114 Type* const kJSDateHourType = | 104 Type* const kJSDateHourType = |
| 115 Type::Union(CreateRange(0, 23.0), Type::NaN(), zone()); | 105 Type::Union(CreateRange(0, 23.0), Type::NaN(), zone()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 private: | 142 private: |
| 153 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } | 143 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } |
| 154 | 144 |
| 155 Type* CreateArrayFunction(Type* array) { | 145 Type* CreateArrayFunction(Type* array) { |
| 156 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); | 146 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); |
| 157 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); | 147 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); |
| 158 Type* arg3 = arg2; | 148 Type* arg3 = arg2; |
| 159 return Type::Function(array, arg1, arg2, arg3, zone()); | 149 return Type::Function(array, arg1, arg2, arg3, zone()); |
| 160 } | 150 } |
| 161 | 151 |
| 162 Type* CreateNative(Type* semantic, Type* representation) { | |
| 163 return Type::Intersect(semantic, representation, zone()); | |
| 164 } | |
| 165 | |
| 166 template <typename T> | 152 template <typename T> |
| 167 Type* CreateRange() { | 153 Type* CreateRange() { |
| 168 return CreateRange(std::numeric_limits<T>::min(), | 154 return CreateRange(std::numeric_limits<T>::min(), |
| 169 std::numeric_limits<T>::max()); | 155 std::numeric_limits<T>::max()); |
| 170 } | 156 } |
| 171 | 157 |
| 172 Type* CreateRange(double min, double max) { | 158 Type* CreateRange(double min, double max) { |
| 173 return Type::Range(min, max, zone()); | 159 return Type::Range(min, max, zone()); |
| 174 } | 160 } |
| 175 | 161 |
| 176 Zone* zone() { return &zone_; } | 162 Zone* zone() { return &zone_; } |
| 177 }; | 163 }; |
| 178 | 164 |
| 179 } // namespace compiler | 165 } // namespace compiler |
| 180 } // namespace internal | 166 } // namespace internal |
| 181 } // namespace v8 | 167 } // namespace v8 |
| 182 | 168 |
| 183 #endif // V8_COMPILER_TYPE_CACHE_H_ | 169 #endif // V8_COMPILER_TYPE_CACHE_H_ |
| OLD | NEW |