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

Side by Side Diff: src/types.h

Issue 142813003: A64: Synchronize with r15358. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « src/typedarray.js ('k') | src/types.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 30 matching lines...) Expand all
41 // obvious primitive types and some predefined unions, the type language also 41 // obvious primitive types and some predefined unions, the type language also
42 // can express class types (a.k.a. specific maps) and singleton types (i.e., 42 // can express class types (a.k.a. specific maps) and singleton types (i.e.,
43 // concrete constants). 43 // concrete constants).
44 // 44 //
45 // The following equations and inequations hold: 45 // The following equations and inequations hold:
46 // 46 //
47 // None <= T 47 // None <= T
48 // T <= Any 48 // T <= Any
49 // 49 //
50 // Oddball = Boolean \/ Null \/ Undefined 50 // Oddball = Boolean \/ Null \/ Undefined
51 // Number = Integer32 \/ Double 51 // Number = Signed32 \/ Unsigned32 \/ Double
52 // Integer31 < Integer32 52 // Smi <= Signed32
53 // Name = String \/ Symbol 53 // Name = String \/ Symbol
54 // UniqueName = InternalizedString \/ Symbol 54 // UniqueName = InternalizedString \/ Symbol
55 // InternalizedString < String 55 // InternalizedString < String
56 // 56 //
57 // Allocated = Receiver \/ Number \/ Name 57 // Allocated = Receiver \/ Number \/ Name
58 // Detectable = Allocated - Undetectable 58 // Detectable = Allocated - Undetectable
59 // Undetectable < Object 59 // Undetectable < Object
60 // Receiver = Object \/ Proxy 60 // Receiver = Object \/ Proxy
61 // Array < Object 61 // Array < Object
62 // Function < Object 62 // Function < Object
63 // RegExp < Object
63 // 64 //
64 // Class(map) < T iff instance_type(map) < T 65 // Class(map) < T iff instance_type(map) < T
65 // Constant(x) < T iff instance_type(map(x)) < T 66 // Constant(x) < T iff instance_type(map(x)) < T
66 // 67 //
67 // Note that Constant(x) < Class(map(x)) does _not_ hold, since x's map can 68 // Note that Constant(x) < Class(map(x)) does _not_ hold, since x's map can
68 // change! (Its instance type cannot, however.) 69 // change! (Its instance type cannot, however.)
69 // TODO(rossberg): the latter is not currently true for proxies, because of fix, 70 // TODO(rossberg): the latter is not currently true for proxies, because of fix,
70 // but will hold once we implement direct proxies. 71 // but will hold once we implement direct proxies.
71 // 72 //
72 // There are two main functions for testing types: 73 // There are two main functions for testing types:
73 // 74 //
74 // T1->Is(T2) -- tests whether T1 is included in T2 (i.e., T1 <= T2) 75 // T1->Is(T2) -- tests whether T1 is included in T2 (i.e., T1 <= T2)
75 // T1->Maybe(T2) -- tests whether T1 and T2 overlap (i.e., T1 /\ T2 =/= 0) 76 // T1->Maybe(T2) -- tests whether T1 and T2 overlap (i.e., T1 /\ T2 =/= 0)
76 // 77 //
77 // Typically, the former is to be used to select representations (e.g., via 78 // Typically, the former is to be used to select representations (e.g., via
78 // T->Is(Integer31())), and the to check whether a specific case needs handling 79 // T->Is(Integer31())), and the to check whether a specific case needs handling
79 // (e.g., via T->Maybe(Number())). 80 // (e.g., via T->Maybe(Number())).
80 // 81 //
81 // There is no functionality to discover whether a type is a leaf in the 82 // There is no functionality to discover whether a type is a leaf in the
82 // lattice. That is intentional. It should always be possible to refine the 83 // lattice. That is intentional. It should always be possible to refine the
83 // lattice (e.g., splitting up number types further) without invalidating any 84 // lattice (e.g., splitting up number types further) without invalidating any
84 // existing assumptions or tests. 85 // existing assumptions or tests.
85 // 86 //
87 // Consequently, do not use pointer equality for type tests, always use Is!
88 //
86 // Internally, all 'primitive' types, and their unions, are represented as 89 // Internally, all 'primitive' types, and their unions, are represented as
87 // bitsets via smis. Class is a heap pointer to the respective map. Only 90 // bitsets via smis. Class is a heap pointer to the respective map. Only
88 // Constant's, or unions containing Class'es or Constant's, require allocation. 91 // Constant's, or unions containing Class'es or Constant's, require allocation.
92 // Note that the bitset representation is closed under both Union and Intersect.
89 // 93 //
90 // The type representation is heap-allocated, so cannot (currently) be used in 94 // The type representation is heap-allocated, so cannot (currently) be used in
91 // a parallel compilation context. 95 // a parallel compilation context.
92 96
93 class Type : public Object { 97 class Type : public Object {
94 public: 98 public:
95 static Type* None() { return from_bitset(kNone); } 99 static Type* None() { return from_bitset(kNone); }
96 static Type* Any() { return from_bitset(kAny); } 100 static Type* Any() { return from_bitset(kAny); }
97 static Type* Allocated() { return from_bitset(kAllocated); } 101 static Type* Allocated() { return from_bitset(kAllocated); }
98 static Type* Detectable() { return from_bitset(kDetectable); } 102 static Type* Detectable() { return from_bitset(kDetectable); }
99 103
100 static Type* Oddball() { return from_bitset(kOddball); } 104 static Type* Oddball() { return from_bitset(kOddball); }
101 static Type* Boolean() { return from_bitset(kBoolean); } 105 static Type* Boolean() { return from_bitset(kBoolean); }
102 static Type* Null() { return from_bitset(kNull); } 106 static Type* Null() { return from_bitset(kNull); }
103 static Type* Undefined() { return from_bitset(kUndefined); } 107 static Type* Undefined() { return from_bitset(kUndefined); }
104 108
105 static Type* Number() { return from_bitset(kNumber); } 109 static Type* Number() { return from_bitset(kNumber); }
106 static Type* Integer31() { return from_bitset(kInteger31); } 110 static Type* Smi() { return from_bitset(kSmi); }
107 static Type* Integer32() { return from_bitset(kInteger32); } 111 static Type* Signed32() { return from_bitset(kSigned32); }
112 static Type* Unsigned32() { return from_bitset(kUnsigned32); }
108 static Type* Double() { return from_bitset(kDouble); } 113 static Type* Double() { return from_bitset(kDouble); }
114 static Type* NumberOrString() { return from_bitset(kNumberOrString); }
109 115
110 static Type* Name() { return from_bitset(kName); } 116 static Type* Name() { return from_bitset(kName); }
111 static Type* UniqueName() { return from_bitset(kUniqueName); } 117 static Type* UniqueName() { return from_bitset(kUniqueName); }
112 static Type* String() { return from_bitset(kString); } 118 static Type* String() { return from_bitset(kString); }
113 static Type* InternalizedString() { return from_bitset(kInternalizedString); } 119 static Type* InternalizedString() { return from_bitset(kInternalizedString); }
114 static Type* Symbol() { return from_bitset(kSymbol); } 120 static Type* Symbol() { return from_bitset(kSymbol); }
115 121
116 static Type* Receiver() { return from_bitset(kReceiver); } 122 static Type* Receiver() { return from_bitset(kReceiver); }
117 static Type* Object() { return from_bitset(kObject); } 123 static Type* Object() { return from_bitset(kObject); }
118 static Type* Undetectable() { return from_bitset(kUndetectable); } 124 static Type* Undetectable() { return from_bitset(kUndetectable); }
119 static Type* Array() { return from_bitset(kArray); } 125 static Type* Array() { return from_bitset(kArray); }
120 static Type* Function() { return from_bitset(kFunction); } 126 static Type* Function() { return from_bitset(kFunction); }
127 static Type* RegExp() { return from_bitset(kRegExp); }
121 static Type* Proxy() { return from_bitset(kProxy); } 128 static Type* Proxy() { return from_bitset(kProxy); }
122 129
123 static Type* Class(Handle<Map> map) { return from_handle(map); } 130 static Type* Class(Handle<Map> map) { return from_handle(map); }
124 static Type* Constant(Handle<HeapObject> value) { 131 static Type* Constant(Handle<HeapObject> value) {
125 return Constant(value, value->GetIsolate()); 132 return Constant(value, value->GetIsolate());
126 } 133 }
127 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) { 134 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) {
128 return from_handle(isolate->factory()->NewBox(value)); 135 return from_handle(isolate->factory()->NewBox(value));
129 } 136 }
130 137
131 static Type* Union(Handle<Type> type1, Handle<Type> type2); 138 static Type* Union(Handle<Type> type1, Handle<Type> type2);
139 static Type* Intersect(Handle<Type> type1, Handle<Type> type2);
132 static Type* Optional(Handle<Type> type); // type \/ Undefined 140 static Type* Optional(Handle<Type> type); // type \/ Undefined
133 141
134 bool Is(Type* that); 142 bool Is(Type* that);
135 bool Is(Handle<Type> that) { return this->Is(*that); } 143 bool Is(Handle<Type> that) { return this->Is(*that); }
136 bool Maybe(Type* that); 144 bool Maybe(Type* that);
137 bool Maybe(Handle<Type> that) { return this->Maybe(*that); } 145 bool Maybe(Handle<Type> that) { return this->Maybe(*that); }
138 146
139 bool IsClass() { return is_class(); } 147 bool IsClass() { return is_class(); }
140 bool IsConstant() { return is_constant(); } 148 bool IsConstant() { return is_constant(); }
141 Handle<Map> AsClass() { return as_class(); } 149 Handle<Map> AsClass() { return as_class(); }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // A union is a fixed array containing types. Invariants: 187 // A union is a fixed array containing types. Invariants:
180 // - its length is at least 2 188 // - its length is at least 2
181 // - at most one field is a bitset, and it must go into index 0 189 // - at most one field is a bitset, and it must go into index 0
182 // - no field is a union 190 // - no field is a union
183 typedef FixedArray Unioned; 191 typedef FixedArray Unioned;
184 192
185 enum { 193 enum {
186 kNull = 1 << 0, 194 kNull = 1 << 0,
187 kUndefined = 1 << 1, 195 kUndefined = 1 << 1,
188 kBoolean = 1 << 2, 196 kBoolean = 1 << 2,
189 kInteger31 = 1 << 3, 197 kSmi = 1 << 3,
190 kOtherInteger = 1 << 4, 198 kOtherSigned32 = 1 << 4,
191 kDouble = 1 << 5, 199 kUnsigned32 = 1 << 5,
192 kSymbol = 1 << 6, 200 kDouble = 1 << 6,
193 kInternalizedString = 1 << 7, 201 kSymbol = 1 << 7,
194 kOtherString = 1 << 8, 202 kInternalizedString = 1 << 8,
195 kUndetectable = 1 << 9, 203 kOtherString = 1 << 9,
196 kArray = 1 << 10, 204 kUndetectable = 1 << 10,
197 kFunction = 1 << 11, 205 kArray = 1 << 11,
198 kOtherObject = 1 << 12, 206 kFunction = 1 << 12,
199 kProxy = 1 << 13, 207 kRegExp = 1 << 13,
208 kOtherObject = 1 << 14,
209 kProxy = 1 << 15,
200 210
201 kOddball = kBoolean | kNull | kUndefined, 211 kOddball = kBoolean | kNull | kUndefined,
202 kInteger32 = kInteger31 | kOtherInteger, 212 kSigned32 = kSmi | kOtherSigned32,
203 kNumber = kInteger32 | kDouble, 213 kNumber = kSigned32 | kUnsigned32 | kDouble,
204 kString = kInternalizedString | kOtherString, 214 kString = kInternalizedString | kOtherString,
205 kUniqueName = kSymbol | kInternalizedString, 215 kUniqueName = kSymbol | kInternalizedString,
206 kName = kSymbol | kString, 216 kName = kSymbol | kString,
207 kObject = kUndetectable | kArray | kFunction | kOtherObject, 217 kNumberOrString = kNumber | kString,
218 kObject = kUndetectable | kArray | kFunction | kRegExp | kOtherObject,
208 kReceiver = kObject | kProxy, 219 kReceiver = kObject | kProxy,
209 kAllocated = kDouble | kName | kReceiver, 220 kAllocated = kDouble | kName | kReceiver,
210 kAny = kOddball | kNumber | kAllocated, 221 kAny = kOddball | kNumber | kAllocated,
211 kDetectable = kAllocated - kUndetectable, 222 kDetectable = kAllocated - kUndetectable,
212 kNone = 0 223 kNone = 0
213 }; 224 };
214 225
215 bool is_bitset() { return this->IsSmi(); } 226 bool is_bitset() { return this->IsSmi(); }
216 bool is_class() { return this->IsMap(); } 227 bool is_class() { return this->IsMap(); }
217 bool is_constant() { return this->IsBox(); } 228 bool is_constant() { return this->IsBox(); }
(...skipping 23 matching lines...) Expand all
241 static Handle<Type> union_get(Handle<Unioned> unioned, int i) { 252 static Handle<Type> union_get(Handle<Unioned> unioned, int i) {
242 Type* type = static_cast<Type*>(unioned->get(i)); 253 Type* type = static_cast<Type*>(unioned->get(i));
243 ASSERT(!type->is_union()); 254 ASSERT(!type->is_union());
244 return type->handle_via_isolate_of(from_handle(unioned)); 255 return type->handle_via_isolate_of(from_handle(unioned));
245 } 256 }
246 257
247 int LubBitset(); // least upper bound that's a bitset 258 int LubBitset(); // least upper bound that's a bitset
248 int GlbBitset(); // greatest lower bound that's a bitset 259 int GlbBitset(); // greatest lower bound that's a bitset
249 bool InUnion(Handle<Unioned> unioned, int current_size); 260 bool InUnion(Handle<Unioned> unioned, int current_size);
250 int ExtendUnion(Handle<Unioned> unioned, int current_size); 261 int ExtendUnion(Handle<Unioned> unioned, int current_size);
262 int ExtendIntersection(
263 Handle<Unioned> unioned, Handle<Type> type, int current_size);
251 }; 264 };
252 265
253 } } // namespace v8::internal 266 } } // namespace v8::internal
254 267
255 #endif // V8_TYPES_H_ 268 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/typedarray.js ('k') | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698