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

Side by Side Diff: src/types.h

Issue 148593004: A64: Synchronize with r18084. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // 88 //
89 // Internally, all 'primitive' types, and their unions, are represented as 89 // Internally, all 'primitive' types, and their unions, are represented as
90 // 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
91 // 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. 92 // Note that the bitset representation is closed under both Union and Intersect.
93 // 93 //
94 // 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
95 // a concurrent compilation context. 95 // a concurrent compilation context.
96 96
97 97
98 #define PRIMITIVE_TYPE_LIST(V) \ 98 #define BITSET_TYPE_LIST(V) \
99 V(None, 0) \ 99 V(None, 0) \
100 V(Null, 1 << 0) \ 100 V(Null, 1 << 0) \
101 V(Undefined, 1 << 1) \ 101 V(Undefined, 1 << 1) \
102 V(Boolean, 1 << 2) \ 102 V(Boolean, 1 << 2) \
103 V(Smi, 1 << 3) \ 103 V(Smi, 1 << 3) \
104 V(OtherSigned32, 1 << 4) \ 104 V(OtherSigned32, 1 << 4) \
105 V(Unsigned32, 1 << 5) \ 105 V(Unsigned32, 1 << 5) \
106 V(Double, 1 << 6) \ 106 V(Double, 1 << 6) \
107 V(Symbol, 1 << 7) \ 107 V(Symbol, 1 << 7) \
108 V(InternalizedString, 1 << 8) \ 108 V(InternalizedString, 1 << 8) \
109 V(OtherString, 1 << 9) \ 109 V(OtherString, 1 << 9) \
110 V(Undetectable, 1 << 10) \ 110 V(Undetectable, 1 << 10) \
111 V(Array, 1 << 11) \ 111 V(Array, 1 << 11) \
112 V(Function, 1 << 12) \ 112 V(Function, 1 << 12) \
113 V(RegExp, 1 << 13) \ 113 V(RegExp, 1 << 13) \
114 V(OtherObject, 1 << 14) \ 114 V(OtherObject, 1 << 14) \
115 V(Proxy, 1 << 15) \ 115 V(Proxy, 1 << 15) \
116 V(Internal, 1 << 16) 116 V(Internal, 1 << 16) \
117 117 \
118 #define COMPOSED_TYPE_LIST(V) \
119 V(Oddball, kBoolean | kNull | kUndefined) \ 118 V(Oddball, kBoolean | kNull | kUndefined) \
120 V(Signed32, kSmi | kOtherSigned32) \ 119 V(Signed32, kSmi | kOtherSigned32) \
121 V(Number, kSigned32 | kUnsigned32 | kDouble) \ 120 V(Number, kSigned32 | kUnsigned32 | kDouble) \
122 V(String, kInternalizedString | kOtherString) \ 121 V(String, kInternalizedString | kOtherString) \
123 V(UniqueName, kSymbol | kInternalizedString) \ 122 V(UniqueName, kSymbol | kInternalizedString) \
124 V(Name, kSymbol | kString) \ 123 V(Name, kSymbol | kString) \
125 V(NumberOrString, kNumber | kString) \ 124 V(NumberOrString, kNumber | kString) \
126 V(Object, kUndetectable | kArray | kFunction | \ 125 V(Object, kUndetectable | kArray | kFunction | \
127 kRegExp | kOtherObject) \ 126 kRegExp | kOtherObject) \
128 V(Receiver, kObject | kProxy) \ 127 V(Receiver, kObject | kProxy) \
129 V(Allocated, kDouble | kName | kReceiver) \ 128 V(Allocated, kDouble | kName | kReceiver) \
130 V(Any, kOddball | kNumber | kAllocated | kInternal) \ 129 V(Any, kOddball | kNumber | kAllocated | kInternal) \
131 V(NonNumber, kAny - kNumber) \ 130 V(NonNumber, kAny - kNumber) \
132 V(Detectable, kAllocated - kUndetectable) 131 V(Detectable, kAllocated - kUndetectable)
133 132
134 #define TYPE_LIST(V) \
135 PRIMITIVE_TYPE_LIST(V) \
136 COMPOSED_TYPE_LIST(V)
137
138
139 133
140 class Type : public Object { 134 class Type : public Object {
141 public: 135 public:
142 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ 136 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \
143 static Type* type() { return from_bitset(k##type); } 137 static Type* type() { return from_bitset(k##type); }
144 TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) 138 BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR)
145 #undef DEFINE_TYPE_CONSTRUCTOR 139 #undef DEFINE_TYPE_CONSTRUCTOR
146 140
147 static Type* Class(Handle<i::Map> map) { return from_handle(map); } 141 static Type* Class(Handle<i::Map> map) { return from_handle(map); }
148 static Type* Constant(Handle<i::HeapObject> value) { 142 static Type* Constant(Handle<i::HeapObject> value) {
149 return Constant(value, value->GetIsolate()); 143 return Constant(value, value->GetIsolate());
150 } 144 }
151 static Type* Constant(Handle<i::Object> value, Isolate* isolate) { 145 static Type* Constant(Handle<i::Object> value, Isolate* isolate) {
152 return from_handle(isolate->factory()->NewBox(value)); 146 return from_handle(isolate->factory()->NewBox(value));
153 } 147 }
154 148
155 static Type* Union(Handle<Type> type1, Handle<Type> type2); 149 static Type* Union(Handle<Type> type1, Handle<Type> type2);
156 static Type* Intersect(Handle<Type> type1, Handle<Type> type2); 150 static Type* Intersect(Handle<Type> type1, Handle<Type> type2);
157 static Type* Optional(Handle<Type> type); // type \/ Undefined 151 static Type* Optional(Handle<Type> type); // type \/ Undefined
158 152
159 static Type* Of(Handle<i::Object> value) { 153 static Type* Of(Handle<i::Object> value) {
160 return from_bitset(LubBitset(*value)); 154 return from_bitset(LubBitset(*value));
161 } 155 }
162 static Type* CurrentOf(Handle<i::Object> value);
163 156
164 bool Is(Type* that) { return (this == that) ? true : SlowIs(that); } 157 bool Is(Type* that) { return this == that || SlowIs(that); }
165 bool Is(Handle<Type> that) { return this->Is(*that); } 158 bool Is(Handle<Type> that) { return this->Is(*that); }
166 bool Maybe(Type* that); 159 bool Maybe(Type* that);
167 bool Maybe(Handle<Type> that) { return this->Maybe(*that); } 160 bool Maybe(Handle<Type> that) { return this->Maybe(*that); }
168 161
162 // State-dependent versions of Of and Is that consider subtyping between
163 // a constant and its map class.
164 static Type* OfCurrently(Handle<i::Object> value);
165 bool IsCurrently(Type* that);
166 bool IsCurrently(Handle<Type> that) { return this->IsCurrently(*that); }
167
169 bool IsClass() { return is_class(); } 168 bool IsClass() { return is_class(); }
170 bool IsConstant() { return is_constant(); } 169 bool IsConstant() { return is_constant(); }
171 Handle<i::Map> AsClass() { return as_class(); } 170 Handle<i::Map> AsClass() { return as_class(); }
172 Handle<i::Object> AsConstant() { return as_constant(); } 171 Handle<i::Object> AsConstant() { return as_constant(); }
173 172
174 int NumClasses(); 173 int NumClasses();
175 int NumConstants(); 174 int NumConstants();
176 175
177 template<class T> 176 template<class T>
178 class Iterator { 177 class Iterator {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 218
220 private: 219 private:
221 // A union is a fixed array containing types. Invariants: 220 // A union is a fixed array containing types. Invariants:
222 // - its length is at least 2 221 // - its length is at least 2
223 // - at most one field is a bitset, and it must go into index 0 222 // - at most one field is a bitset, and it must go into index 0
224 // - no field is a union 223 // - no field is a union
225 typedef FixedArray Unioned; 224 typedef FixedArray Unioned;
226 225
227 enum { 226 enum {
228 #define DECLARE_TYPE(type, value) k##type = (value), 227 #define DECLARE_TYPE(type, value) k##type = (value),
229 TYPE_LIST(DECLARE_TYPE) 228 BITSET_TYPE_LIST(DECLARE_TYPE)
230 #undef DECLARE_TYPE 229 #undef DECLARE_TYPE
231 kUnusedEOL = 0 230 kUnusedEOL = 0
232 }; 231 };
233 232
234 bool is_none() { return this == None(); } 233 bool is_none() { return this == None(); }
235 bool is_bitset() { return this->IsSmi(); } 234 bool is_bitset() { return this->IsSmi(); }
236 bool is_class() { return this->IsMap(); } 235 bool is_class() { return this->IsMap(); }
237 bool is_constant() { return this->IsBox(); } 236 bool is_constant() { return this->IsBox(); }
238 bool is_union() { return this->IsFixedArray(); } 237 bool is_union() { return this->IsFixedArray(); }
239 238
(...skipping 30 matching lines...) Expand all
270 int GlbBitset(); // greatest lower bound that's a bitset 269 int GlbBitset(); // greatest lower bound that's a bitset
271 270
272 static int LubBitset(i::Object* value); 271 static int LubBitset(i::Object* value);
273 static int LubBitset(i::Map* map); 272 static int LubBitset(i::Map* map);
274 273
275 bool InUnion(Handle<Unioned> unioned, int current_size); 274 bool InUnion(Handle<Unioned> unioned, int current_size);
276 int ExtendUnion(Handle<Unioned> unioned, int current_size); 275 int ExtendUnion(Handle<Unioned> unioned, int current_size);
277 int ExtendIntersection( 276 int ExtendIntersection(
278 Handle<Unioned> unioned, Handle<Type> type, int current_size); 277 Handle<Unioned> unioned, Handle<Type> type, int current_size);
279 278
280 static const char* GetComposedName(int type) { 279 static const char* bitset_name(int bitset);
281 switch (type) {
282 #define PRINT_COMPOSED_TYPE(type, value) \
283 case k##type: \
284 return # type;
285 COMPOSED_TYPE_LIST(PRINT_COMPOSED_TYPE)
286 #undef PRINT_COMPOSED_TYPE
287 }
288 return NULL;
289 }
290
291 static const char* GetPrimitiveName(int type) {
292 switch (type) {
293 #define PRINT_PRIMITIVE_TYPE(type, value) \
294 case k##type: \
295 return # type;
296 PRIMITIVE_TYPE_LIST(PRINT_PRIMITIVE_TYPE)
297 #undef PRINT_PRIMITIVE_TYPE
298 default:
299 UNREACHABLE();
300 return "InvalidType";
301 }
302 }
303 }; 280 };
304 281
305 282
306 // A simple struct to represent a pair of lower/upper type bounds. 283 // A simple struct to represent a pair of lower/upper type bounds.
307 struct Bounds { 284 struct Bounds {
308 Handle<Type> lower; 285 Handle<Type> lower;
309 Handle<Type> upper; 286 Handle<Type> upper;
310 287
311 Bounds() {} 288 Bounds() {}
312 Bounds(Handle<Type> l, Handle<Type> u) : lower(l), upper(u) { 289 Bounds(Handle<Type> l, Handle<Type> u) : lower(l), upper(u) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) { 328 static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) {
352 return Bounds( 329 return Bounds(
353 handle(Type::Intersect(b.lower, t), isl), 330 handle(Type::Intersect(b.lower, t), isl),
354 handle(Type::Intersect(b.upper, t), isl)); 331 handle(Type::Intersect(b.upper, t), isl));
355 } 332 }
356 }; 333 };
357 334
358 } } // namespace v8::internal 335 } } // namespace v8::internal
359 336
360 #endif // V8_TYPES_H_ 337 #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