v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
type-cache.h
Go to the documentation of this file.
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
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_TYPE_CACHE_H_
6#define V8_COMPILER_TYPE_CACHE_H_
7
10#include "src/date/date.h"
12#include "src/objects/string.h"
13
14namespace v8 {
15namespace internal {
16namespace compiler {
17
19 private:
20 // This has to be first for the initialization magic to work.
23
24 public:
25 static TypeCache const* Get();
26
27 TypeCache() : zone_(&allocator, ZONE_NAME) {}
28
29 Type const kInt8 = CreateRange<int8_t>();
30 Type const kUint8 = CreateRange<uint8_t>();
31 Type const kUint8Clamped = kUint8;
32 Type const kUint8OrMinusZeroOrNaN =
33 Type::Union(kUint8, Type::MinusZeroOrNaN(), zone());
34 Type const kInt16 = CreateRange<int16_t>();
35 Type const kUint16 = CreateRange<uint16_t>();
36 Type const kUnsigned31 = Type::Unsigned31();
37 Type const kInt32 = Type::Signed32();
38 Type const kUint32 = Type::Unsigned32();
39 Type const kDoubleRepresentableInt64 = CreateRange(
40 std::numeric_limits<int64_t>::min(), kMaxDoubleRepresentableInt64);
41 Type const kDoubleRepresentableInt64OrMinusZero =
42 Type::Union(kDoubleRepresentableInt64, Type::MinusZero(), zone());
43 Type const kDoubleRepresentableUint64 = CreateRange(
44 std::numeric_limits<uint64_t>::min(), kMaxDoubleRepresentableUint64);
45 Type const kFloat16 = Type::Number();
46 Type const kFloat32 = Type::Number();
47 Type const kFloat64 = Type::Number();
48 Type const kBigInt64 = Type::SignedBigInt64();
49 Type const kBigUint64 = Type::UnsignedBigInt64();
50
51 Type const kHoleySmi = Type::Union(Type::SignedSmall(), Type::Hole(), zone());
52
53 Type const kSingletonZero = CreateRange(0.0, 0.0);
54 Type const kSingletonOne = CreateRange(1.0, 1.0);
55 Type const kSingletonTen = CreateRange(10.0, 10.0);
56 Type const kSingletonMinusOne = CreateRange(-1.0, -1.0);
57 Type const kZeroOrMinusZero =
58 Type::Union(kSingletonZero, Type::MinusZero(), zone());
59 Type const kZeroOrUndefined =
60 Type::Union(kSingletonZero, Type::Undefined(), zone());
61 Type const kTenOrUndefined =
62 Type::Union(kSingletonTen, Type::Undefined(), zone());
63 Type const kMinusOneOrZero = CreateRange(-1.0, 0.0);
64 Type const kMinusOneToOneOrMinusZeroOrNaN = Type::Union(
65 Type::Union(CreateRange(-1.0, 1.0), Type::MinusZero(), zone()),
66 Type::NaN(), zone());
67 Type const kZeroOrOne = CreateRange(0.0, 1.0);
68 Type const kZeroOrOneOrNaN = Type::Union(kZeroOrOne, Type::NaN(), zone());
69 Type const kZeroToThirtyOne = CreateRange(0.0, 31.0);
70 Type const kZeroToThirtyTwo = CreateRange(0.0, 32.0);
71 Type const kZeroish =
72 Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone());
73 Type const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY);
74 Type const kIntegerOrMinusZero =
75 Type::Union(kInteger, Type::MinusZero(), zone());
76 Type const kIntegerOrMinusZeroOrNaN =
77 Type::Union(kIntegerOrMinusZero, Type::NaN(), zone());
78 Type const kPositiveInteger = CreateRange(0.0, V8_INFINITY);
79 Type const kPositiveIntegerOrMinusZero =
80 Type::Union(kPositiveInteger, Type::MinusZero(), zone());
81 Type const kPositiveIntegerOrNaN =
82 Type::Union(kPositiveInteger, Type::NaN(), zone());
83 Type const kPositiveIntegerOrMinusZeroOrNaN =
84 Type::Union(kPositiveIntegerOrMinusZero, Type::NaN(), zone());
85
86 Type const kSafeInteger = CreateRange(-kMaxSafeInteger, kMaxSafeInteger);
88 CreateRange(kMinAdditiveSafeInteger, kMaxAdditiveSafeInteger);
89 Type const kAdditiveSafeIntegerOrMinusZero =
90 Type::Union(kAdditiveSafeInteger, Type::MinusZero(), zone());
91 Type const kSafeIntegerOrMinusZero =
92 Type::Union(kSafeInteger, Type::MinusZero(), zone());
93 Type const kPositiveSafeInteger = CreateRange(0.0, kMaxSafeInteger);
94
95 // The FixedArray::length property always containts a smi in the range
96 // [0, FixedArray::kMaxLength].
97 Type const kFixedArrayLengthType = CreateRange(0.0, FixedArray::kMaxLength);
98
99 // The WeakFixedArray::length property always containts a smi in the range:
100 Type const kWeakFixedArrayLengthType =
101 CreateRange(0.0, WeakFixedArray::kMaxCapacity);
102
103 // The FixedDoubleArray::length property always containts a smi in the range
104 // [0, FixedDoubleArray::kMaxLength].
105 Type const kFixedDoubleArrayLengthType =
106 CreateRange(0.0, FixedDoubleArray::kMaxLength);
107
108 // The JSArray::length property always contains a tagged number in the range
109 // [0, kMaxUInt32].
110 Type const kJSArrayLengthType = Type::Unsigned32();
111
112 // The JSArrayBuffer::byte_length property is limited to safe integer range
113 // per specification, but on 32-bit architectures is implemented as uint32_t
114 // field, so it's in the [0, kMaxUInt32] range in that case.
115 Type const kJSArrayBufferByteLengthType =
116 CreateRange(0.0, JSArrayBuffer::kMaxByteLength);
117
118 // The type for the JSArrayBufferView::byte_length property is the same as
119 // JSArrayBuffer::byte_length above.
120 Type const kJSArrayBufferViewByteLengthType = kJSArrayBufferByteLengthType;
121
122 // The type for the JSArrayBufferView::byte_offset property is the same as
123 // JSArrayBuffer::byte_length above.
124 Type const kJSArrayBufferViewByteOffsetType = kJSArrayBufferByteLengthType;
125
126 // The JSTypedArray::length property always contains an untagged number in
127 // the range [0, JSTypedArray::kMaxByteLength].
128 Type const kJSTypedArrayLengthType =
129 CreateRange(0.0, JSTypedArray::kMaxByteLength);
130
131 // The String::length property always contains a smi in the range
132 // [0, String::kMaxLength].
133 Type const kStringLengthType = CreateRange(0.0, String::kMaxLength);
134
135 // A time value always contains a tagged number in the range
136 // [-kMaxTimeInMs, kMaxTimeInMs].
137 Type const kTimeValueType =
138 CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs);
139
140 // The JSDate::day property always contains a tagged number in the range
141 // [1, 31] or NaN.
142 Type const kJSDateDayType =
143 Type::Union(CreateRange(1, 31.0), Type::NaN(), zone());
144
145 // The JSDate::hour property always contains a tagged number in the range
146 // [0, 23] or NaN.
147 Type const kJSDateHourType =
148 Type::Union(CreateRange(0, 23.0), Type::NaN(), zone());
149
150 // The JSDate::minute property always contains a tagged number in the range
151 // [0, 59] or NaN.
152 Type const kJSDateMinuteType =
153 Type::Union(CreateRange(0, 59.0), Type::NaN(), zone());
154
155 // The JSDate::month property always contains a tagged number in the range
156 // [0, 11] or NaN.
157 Type const kJSDateMonthType =
158 Type::Union(CreateRange(0, 11.0), Type::NaN(), zone());
159
160 // The JSDate::second property always contains a tagged number in the range
161 // [0, 59] or NaN.
162 Type const kJSDateSecondType = kJSDateMinuteType;
163
164 // The JSDate::value property always contains a tagged number in the range
165 // [-kMaxTimeInMs, kMaxTimeInMs] or NaN.
166 Type const kJSDateValueType =
167 Type::Union(kTimeValueType, Type::NaN(), zone());
168
169 // The JSDate::weekday property always contains a tagged number in the range
170 // [0, 6] or NaN.
171 Type const kJSDateWeekdayType =
172 Type::Union(CreateRange(0, 6.0), Type::NaN(), zone());
173
174 // The JSDate::year property always contains a tagged number in the range
175 // [-271821, 275760] or NaN.
176 Type const kJSDateYearType =
177 Type::Union(CreateRange(-271821, 275760), Type::NaN(), zone());
178
179 // The valid number of arguments for JavaScript functions. We can never
180 // materialize more than the max size of a fixed array, because we require a
181 // fixed array in spread/apply calls.
182 Type const kArgumentsLengthType = CreateRange(0.0, FixedArray::kMaxLength);
183
184 // The valid number of arguments for rest parameters. We can never
185 // materialize more than the max size of a fixed array, because we require a
186 // fixed array in spread/apply calls.
187 Type const kRestLengthType = CreateRange(0.0, FixedArray::kMaxLength);
188
189 // The JSArrayIterator::kind property always contains an integer in the
190 // range [0, 2], representing the possible IterationKinds.
191 Type const kJSArrayIteratorKindType = CreateRange(0.0, 2.0);
192
193 private:
194 template <typename T>
196 T min = std::numeric_limits<T>::min();
197 T max = std::numeric_limits<T>::max();
198 DCHECK_EQ(min, static_cast<T>(static_cast<double>(min)));
199 DCHECK_EQ(max, static_cast<T>(static_cast<double>(max)));
200 return CreateRange(min, max);
201 }
202
203 Type CreateRange(double min, double max) {
204 return Type::Range(min, max, zone());
205 }
206
207 Zone* zone() { return &zone_; }
208};
209
210} // namespace compiler
211} // namespace internal
212} // namespace v8
213
214#endif // V8_COMPILER_TYPE_CACHE_H_
AccountingAllocator allocator
Definition type-cache.h:21
static TypeCache const * Get()
Type CreateRange(double min, double max)
Definition type-cache.h:203
Zone * zone_
#define V8_INFINITY
Definition globals.h:23
constexpr double kMaxDoubleRepresentableInt64
Definition globals.h:176
constexpr double kMaxDoubleRepresentableUint64
Definition globals.h:179
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define ZONE_NAME
Definition zone.h:22