Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: src/type-cache.h

Issue 1409763004: [types] Use the TypeCache consistently for common types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/typer.cc ('k') | src/type-cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_ZONE_TYPE_CACHE_H_ 5 #ifndef V8_TYPE_CACHE_H_
6 #define V8_ZONE_TYPE_CACHE_H_ 6 #define V8_TYPE_CACHE_H_
7
8 7
9 #include "src/types.h" 8 #include "src/types.h"
10 9
11 namespace v8 { 10 namespace v8 {
12 namespace internal { 11 namespace internal {
13 12
14 class ZoneTypeCache final { 13 class TypeCache final {
15 private: 14 private:
16 // This has to be first for the initialization magic to work. 15 // This has to be first for the initialization magic to work.
17 Zone zone_; 16 Zone zone_;
18 17
19 public: 18 public:
20 ZoneTypeCache() = default; 19 static TypeCache const& Get();
20
21 TypeCache() = default;
21 22
22 Type* const kInt8 = 23 Type* const kInt8 =
23 CreateNative(CreateRange<int8_t>(), Type::UntaggedSigned8()); 24 CreateNative(CreateRange<int8_t>(), Type::UntaggedSigned8());
24 Type* const kUint8 = 25 Type* const kUint8 =
25 CreateNative(CreateRange<uint8_t>(), Type::UntaggedUnsigned8()); 26 CreateNative(CreateRange<uint8_t>(), Type::UntaggedUnsigned8());
26 Type* const kUint8Clamped = kUint8; 27 Type* const kUint8Clamped = kUint8;
27 Type* const kInt16 = 28 Type* const kInt16 =
28 CreateNative(CreateRange<int16_t>(), Type::UntaggedSigned16()); 29 CreateNative(CreateRange<int16_t>(), Type::UntaggedSigned16());
29 Type* const kUint16 = 30 Type* const kUint16 =
30 CreateNative(CreateRange<uint16_t>(), Type::UntaggedUnsigned16()); 31 CreateNative(CreateRange<uint16_t>(), Type::UntaggedUnsigned16());
31 Type* const kInt32 = CreateNative(Type::Signed32(), Type::UntaggedSigned32()); 32 Type* const kInt32 = CreateNative(Type::Signed32(), Type::UntaggedSigned32());
32 Type* const kUint32 = 33 Type* const kUint32 =
33 CreateNative(Type::Unsigned32(), Type::UntaggedUnsigned32()); 34 CreateNative(Type::Unsigned32(), Type::UntaggedUnsigned32());
34 Type* const kFloat32 = CreateNative(Type::Number(), Type::UntaggedFloat32()); 35 Type* const kFloat32 = CreateNative(Type::Number(), Type::UntaggedFloat32());
35 Type* const kFloat64 = CreateNative(Type::Number(), Type::UntaggedFloat64()); 36 Type* const kFloat64 = CreateNative(Type::Number(), Type::UntaggedFloat64());
36 37
38 Type* const kSmi = CreateNative(Type::SignedSmall(), Type::TaggedSigned());
39 Type* const kHeapNumber = CreateNative(Type::Number(), Type::TaggedPointer());
40
37 Type* const kSingletonZero = CreateRange(0.0, 0.0); 41 Type* const kSingletonZero = CreateRange(0.0, 0.0);
38 Type* const kSingletonOne = CreateRange(1.0, 1.0); 42 Type* const kSingletonOne = CreateRange(1.0, 1.0);
39 Type* const kZeroOrOne = CreateRange(0.0, 1.0); 43 Type* const kZeroOrOne = CreateRange(0.0, 1.0);
40 Type* const kZeroToThirtyTwo = CreateRange(0.0, 32.0); 44 Type* const kZeroToThirtyTwo = CreateRange(0.0, 32.0);
41 Type* const kZeroish = 45 Type* const kZeroish =
42 Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone()); 46 Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone());
43 Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY); 47 Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY);
44 Type* const kWeakint = Type::Union(kInteger, Type::MinusZeroOrNaN(), zone()); 48 Type* const kWeakint = Type::Union(kInteger, Type::MinusZeroOrNaN(), zone());
45 49
50 // The FixedArray::length property always containts a smi in the range
51 // [0, FixedArray::kMaxLength].
52 Type* const kFixedArrayLengthType = CreateNative(
53 CreateRange(0.0, FixedArray::kMaxLength), Type::TaggedSigned());
54
55 // The FixedDoubleArray::length property always containts a smi in the range
56 // [0, FixedDoubleArray::kMaxLength].
57 Type* const kFixedDoubleArrayLengthType = CreateNative(
58 CreateRange(0.0, FixedDoubleArray::kMaxLength), Type::TaggedSigned());
59
60 // The JSArray::length property always contains a tagged number in the range
61 // [0, kMaxUInt32].
62 Type* const kJSArrayLengthType =
63 CreateNative(CreateRange(0.0, kMaxUInt32), Type::Tagged());
64
65 // The String::length property always contains a smi in the range
66 // [0, String::kMaxLength].
67 Type* const kStringLengthType =
68 CreateNative(CreateRange(0.0, String::kMaxLength), Type::TaggedSigned());
69
46 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ 70 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \
47 Type* const k##TypeName##Array = CreateArray(k##TypeName); 71 Type* const k##TypeName##Array = CreateArray(k##TypeName);
48 TYPED_ARRAYS(TYPED_ARRAY) 72 TYPED_ARRAYS(TYPED_ARRAY)
49 #undef TYPED_ARRAY 73 #undef TYPED_ARRAY
50 74
51 private: 75 private:
52 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } 76 Type* CreateArray(Type* element) { return Type::Array(element, zone()); }
53 77
54 Type* CreateArrayFunction(Type* array) { 78 Type* CreateArrayFunction(Type* array) {
55 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); 79 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone());
(...skipping 15 matching lines...) Expand all
71 Type* CreateRange(double min, double max) { 95 Type* CreateRange(double min, double max) {
72 return Type::Range(min, max, zone()); 96 return Type::Range(min, max, zone());
73 } 97 }
74 98
75 Zone* zone() { return &zone_; } 99 Zone* zone() { return &zone_; }
76 }; 100 };
77 101
78 } // namespace internal 102 } // namespace internal
79 } // namespace v8 103 } // namespace v8
80 104
81 #endif // V8_ZONE_TYPE_CACHE_H_ 105 #endif // V8_TYPE_CACHE_H_
OLDNEW
« no previous file with comments | « src/compiler/typer.cc ('k') | src/type-cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698