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::value properties always contains a tagged number in the range | 97 // The JSDate::value properties always contains a tagged number in the range |
108 // [-kMaxTimeInMs, kMaxTimeInMs] or NaN. | 98 // [-kMaxTimeInMs, kMaxTimeInMs] or NaN. |
109 Type* const kJSDateValueType = Type::Union( | 99 Type* const kJSDateValueType = Type::Union( |
110 CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs), | 100 CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs), |
111 Type::NaN(), zone()); | 101 Type::NaN(), zone()); |
112 | 102 |
113 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ | 103 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ |
114 Type* const k##TypeName##Array = CreateArray(k##TypeName); | 104 Type* const k##TypeName##Array = CreateArray(k##TypeName); |
115 TYPED_ARRAYS(TYPED_ARRAY) | 105 TYPED_ARRAYS(TYPED_ARRAY) |
116 #undef TYPED_ARRAY | 106 #undef TYPED_ARRAY |
117 | 107 |
118 private: | 108 private: |
119 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } | 109 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } |
120 | 110 |
121 Type* CreateArrayFunction(Type* array) { | 111 Type* CreateArrayFunction(Type* array) { |
122 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); | 112 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); |
123 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); | 113 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); |
124 Type* arg3 = arg2; | 114 Type* arg3 = arg2; |
125 return Type::Function(array, arg1, arg2, arg3, zone()); | 115 return Type::Function(array, arg1, arg2, arg3, zone()); |
126 } | 116 } |
127 | 117 |
128 Type* CreateNative(Type* semantic, Type* representation) { | |
129 return Type::Intersect(semantic, representation, zone()); | |
130 } | |
131 | |
132 template <typename T> | 118 template <typename T> |
133 Type* CreateRange() { | 119 Type* CreateRange() { |
134 return CreateRange(std::numeric_limits<T>::min(), | 120 return CreateRange(std::numeric_limits<T>::min(), |
135 std::numeric_limits<T>::max()); | 121 std::numeric_limits<T>::max()); |
136 } | 122 } |
137 | 123 |
138 Type* CreateRange(double min, double max) { | 124 Type* CreateRange(double min, double max) { |
139 return Type::Range(min, max, zone()); | 125 return Type::Range(min, max, zone()); |
140 } | 126 } |
141 | 127 |
142 Zone* zone() { return &zone_; } | 128 Zone* zone() { return &zone_; } |
143 }; | 129 }; |
144 | 130 |
145 } // namespace compiler | 131 } // namespace compiler |
146 } // namespace internal | 132 } // namespace internal |
147 } // namespace v8 | 133 } // namespace v8 |
148 | 134 |
149 #endif // V8_COMPILER_TYPE_CACHE_H_ | 135 #endif // V8_COMPILER_TYPE_CACHE_H_ |
OLD | NEW |