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

Side by Side Diff: src/types.h

Issue 157543002: A64: Synchronize with r18581. (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/type-info.cc ('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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 V(NumberOrString, kNumber | kString) \ 124 V(NumberOrString, kNumber | kString) \
125 V(Object, kUndetectable | kArray | kFunction | \ 125 V(Object, kUndetectable | kArray | kFunction | \
126 kRegExp | kOtherObject) \ 126 kRegExp | kOtherObject) \
127 V(Receiver, kObject | kProxy) \ 127 V(Receiver, kObject | kProxy) \
128 V(Allocated, kDouble | kName | kReceiver) \ 128 V(Allocated, kDouble | kName | kReceiver) \
129 V(Any, kOddball | kNumber | kAllocated | kInternal) \ 129 V(Any, kOddball | kNumber | kAllocated | kInternal) \
130 V(NonNumber, kAny - kNumber) \ 130 V(NonNumber, kAny - kNumber) \
131 V(Detectable, kAllocated - kUndetectable) 131 V(Detectable, kAllocated - kUndetectable)
132 132
133 133
134 class Type : public Object { 134 // struct Config {
135 // typedef Base;
136 // typedef Unioned;
137 // typedef Region;
138 // template<class> struct Handle { typedef type; } // No template typedefs...
139 // static Handle<Type>::type handle(Type* type); // !is_bitset(type)
140 // static bool is_bitset(Type* type);
141 // static bool is_class(Type* type);
142 // static bool is_constant(Type* type);
143 // static bool is_union(Type* type);
144 // static int as_bitset(Type* type);
145 // static i::Handle<i::Map> as_class(Type* type);
146 // static i::Handle<i::Object> as_constant(Type* type);
147 // static Handle<Unioned>::type as_union(Type* type);
148 // static Type* from_bitset(int bitset);
149 // static Handle<Type>::type from_bitset(int bitset, Region* region);
150 // static Handle<Type>::type from_class(i::Handle<i::Map> map, Region* region)
151 // static Handle<Type>::type from_constant(
152 // i::Handle<i::Object> value, Region* region);
153 // static Handle<Type>::type from_union(Handle<Unioned>::T unioned);
154 // static Handle<Unioned>::type union_create(int size, Region* region);
155 // static Handle<Type>::type union_get(Handle<Unioned>::T unioned, int i);
156 // }
157 template<class Config>
158 class TypeImpl : public Config::Base {
135 public: 159 public:
136 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ 160 typedef typename Config::template Handle<TypeImpl>::type TypeHandle;
137 static Type* type() { return from_bitset(k##type); } 161 typedef typename Config::Region Region;
162
163 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \
164 static TypeImpl* type() { return Config::from_bitset(k##type); } \
165 static TypeHandle type(Region* region) { \
166 return Config::from_bitset(k##type, region); \
167 }
138 BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) 168 BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR)
139 #undef DEFINE_TYPE_CONSTRUCTOR 169 #undef DEFINE_TYPE_CONSTRUCTOR
140 170
141 static Type* Class(Handle<i::Map> map) { return from_handle(map); } 171 static TypeHandle Class(i::Handle<i::Map> map, Region* region) {
142 static Type* Constant(Handle<i::HeapObject> value) { 172 return Config::from_class(map, region);
143 return Constant(value, value->GetIsolate());
144 } 173 }
145 static Type* Constant(Handle<i::Object> value, Isolate* isolate) { 174 static TypeHandle Constant(i::Handle<i::Object> value, Region* region) {
146 return from_handle(isolate->factory()->NewBox(value)); 175 return Config::from_constant(value, region);
147 } 176 }
148 177
149 static Type* Union(Handle<Type> type1, Handle<Type> type2); 178 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg);
150 static Type* Intersect(Handle<Type> type1, Handle<Type> type2); 179 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg);
151 static Type* Optional(Handle<Type> type); // type \/ Undefined
152 180
153 static Type* Of(Handle<i::Object> value) { 181 static TypeHandle Of(i::Handle<i::Object> value, Region* region) {
154 return from_bitset(LubBitset(*value)); 182 return Config::from_bitset(LubBitset(*value), region);
155 } 183 }
156 184
157 bool Is(Type* that) { return this == that || SlowIs(that); } 185 bool Is(TypeImpl* that) { return this == that || this->SlowIs(that); }
158 bool Is(Handle<Type> that) { return this->Is(*that); } 186 bool Is(TypeHandle that) { return this->Is(*that); }
159 bool Maybe(Type* that); 187 bool Maybe(TypeImpl* that);
160 bool Maybe(Handle<Type> that) { return this->Maybe(*that); } 188 bool Maybe(TypeHandle that) { return this->Maybe(*that); }
161 189
162 // State-dependent versions of Of and Is that consider subtyping between 190 // State-dependent versions of Of and Is that consider subtyping between
163 // a constant and its map class. 191 // a constant and its map class.
164 static Type* OfCurrently(Handle<i::Object> value); 192 static TypeHandle OfCurrently(i::Handle<i::Object> value, Region* region);
165 bool IsCurrently(Type* that); 193 bool IsCurrently(TypeImpl* that);
166 bool IsCurrently(Handle<Type> that) { return this->IsCurrently(*that); } 194 bool IsCurrently(TypeHandle that) { return this->IsCurrently(*that); }
167 195
168 bool IsClass() { return is_class(); } 196 bool IsClass() { return Config::is_class(this); }
169 bool IsConstant() { return is_constant(); } 197 bool IsConstant() { return Config::is_constant(this); }
170 Handle<i::Map> AsClass() { return as_class(); } 198 i::Handle<i::Map> AsClass() { return Config::as_class(this); }
171 Handle<i::Object> AsConstant() { return as_constant(); } 199 i::Handle<i::Object> AsConstant() { return Config::as_constant(this); }
172 200
173 int NumClasses(); 201 int NumClasses();
174 int NumConstants(); 202 int NumConstants();
175 203
176 template<class T> 204 template<class T>
177 class Iterator { 205 class Iterator {
178 public: 206 public:
179 bool Done() const { return index_ < 0; } 207 bool Done() const { return index_ < 0; }
180 Handle<T> Current(); 208 i::Handle<T> Current();
181 void Advance(); 209 void Advance();
182 210
183 private: 211 private:
184 friend class Type; 212 template<class> friend class TypeImpl;
185 213
186 Iterator() : index_(-1) {} 214 Iterator() : index_(-1) {}
187 explicit Iterator(Handle<Type> type) : type_(type), index_(-1) { 215 explicit Iterator(TypeHandle type) : type_(type), index_(-1) {
188 Advance(); 216 Advance();
189 } 217 }
190 218
191 inline bool matches(Handle<Type> type); 219 inline bool matches(TypeHandle type);
192 inline Handle<Type> get_type(); 220 inline TypeHandle get_type();
193 221
194 Handle<Type> type_; 222 TypeHandle type_;
195 int index_; 223 int index_;
196 }; 224 };
197 225
198 Iterator<i::Map> Classes() { 226 Iterator<i::Map> Classes() {
199 if (this->is_bitset()) return Iterator<i::Map>(); 227 if (this->IsBitset()) return Iterator<i::Map>();
200 return Iterator<i::Map>(this->handle()); 228 return Iterator<i::Map>(Config::handle(this));
201 } 229 }
202 Iterator<i::Object> Constants() { 230 Iterator<i::Object> Constants() {
203 if (this->is_bitset()) return Iterator<i::Object>(); 231 if (this->IsBitset()) return Iterator<i::Object>();
204 return Iterator<i::Object>(this->handle()); 232 return Iterator<i::Object>(Config::handle(this));
205 } 233 }
206 234
207 static Type* cast(i::Object* object) { 235 static TypeImpl* cast(i::Object* object) {
208 Type* t = static_cast<Type*>(object); 236 TypeImpl* t = static_cast<TypeImpl*>(object);
209 ASSERT(t->is_bitset() || t->is_class() || 237 ASSERT(t->IsBitset() || t->IsClass() || t->IsConstant() || t->IsUnion());
210 t->is_constant() || t->is_union());
211 return t; 238 return t;
212 } 239 }
213 240
214 #ifdef OBJECT_PRINT 241 #ifdef OBJECT_PRINT
215 void TypePrint(); 242 void TypePrint();
216 void TypePrint(FILE* out); 243 void TypePrint(FILE* out);
217 #endif 244 #endif
218 245
219 private: 246 private:
247 template<class> friend class Iterator;
248
220 // A union is a fixed array containing types. Invariants: 249 // A union is a fixed array containing types. Invariants:
221 // - its length is at least 2 250 // - its length is at least 2
222 // - at most one field is a bitset, and it must go into index 0 251 // - at most one field is a bitset, and it must go into index 0
223 // - no field is a union 252 // - no field is a union
224 typedef FixedArray Unioned; 253 typedef typename Config::Unioned Unioned;
254 typedef typename Config::template Handle<Unioned>::type UnionedHandle;
225 255
226 enum { 256 enum {
227 #define DECLARE_TYPE(type, value) k##type = (value), 257 #define DECLARE_TYPE(type, value) k##type = (value),
228 BITSET_TYPE_LIST(DECLARE_TYPE) 258 BITSET_TYPE_LIST(DECLARE_TYPE)
229 #undef DECLARE_TYPE 259 #undef DECLARE_TYPE
230 kUnusedEOL = 0 260 kUnusedEOL = 0
231 }; 261 };
232 262
233 bool is_none() { return this == None(); } 263 bool IsNone() { return this == None(); }
234 bool is_bitset() { return this->IsSmi(); } 264 bool IsAny() { return this == Any(); }
235 bool is_class() { return this->IsMap(); } 265 bool IsBitset() { return Config::is_bitset(this); }
236 bool is_constant() { return this->IsBox(); } 266 bool IsUnion() { return Config::is_union(this); }
237 bool is_union() { return this->IsFixedArray(); } 267 int AsBitset() { return Config::as_bitset(this); }
268 UnionedHandle AsUnion() { return Config::as_union(this); }
238 269
239 bool SlowIs(Type* that); 270 bool SlowIs(TypeImpl* that);
240
241 int as_bitset() { return Smi::cast(this)->value(); }
242 Handle<i::Map> as_class() { return Handle<i::Map>::cast(handle()); }
243 Handle<i::Object> as_constant() {
244 Handle<i::Box> box = Handle<i::Box>::cast(handle());
245 return i::handle(box->value(), box->GetIsolate());
246 }
247 Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); }
248
249 Handle<Type> handle() { return handle_via_isolate_of(this); }
250 Handle<Type> handle_via_isolate_of(Type* type) {
251 ASSERT(type->IsHeapObject());
252 return i::handle(this, i::HeapObject::cast(type)->GetIsolate());
253 }
254
255 static Type* from_bitset(int bitset) {
256 return static_cast<Type*>(i::Object::cast(i::Smi::FromInt(bitset)));
257 }
258 static Type* from_handle(Handle<i::HeapObject> handle) {
259 return static_cast<Type*>(i::Object::cast(*handle));
260 }
261
262 static Handle<Type> union_get(Handle<Unioned> unioned, int i) {
263 Type* type = static_cast<Type*>(unioned->get(i));
264 ASSERT(!type->is_union());
265 return type->handle_via_isolate_of(from_handle(unioned));
266 }
267 271
268 int LubBitset(); // least upper bound that's a bitset 272 int LubBitset(); // least upper bound that's a bitset
269 int GlbBitset(); // greatest lower bound that's a bitset 273 int GlbBitset(); // greatest lower bound that's a bitset
270 274
271 static int LubBitset(i::Object* value); 275 static int LubBitset(i::Object* value);
272 static int LubBitset(i::Map* map); 276 static int LubBitset(i::Map* map);
273 277
274 bool InUnion(Handle<Unioned> unioned, int current_size); 278 bool InUnion(UnionedHandle unioned, int current_size);
275 int ExtendUnion(Handle<Unioned> unioned, int current_size); 279 int ExtendUnion(UnionedHandle unioned, int current_size);
276 int ExtendIntersection( 280 int ExtendIntersection(
277 Handle<Unioned> unioned, Handle<Type> type, int current_size); 281 UnionedHandle unioned, TypeHandle type, int current_size);
278 282
283 #ifdef OBJECT_PRINT
279 static const char* bitset_name(int bitset); 284 static const char* bitset_name(int bitset);
285 #endif
280 }; 286 };
281 287
282 288
289 struct HeapTypeConfig {
290 typedef TypeImpl<HeapTypeConfig> Type;
291 typedef i::Object Base;
292 typedef i::FixedArray Unioned;
293 typedef i::Isolate Region;
294 template<class T> struct Handle { typedef i::Handle<T> type; };
295
296 static i::Handle<Type> handle(Type* type) {
297 return i::handle(type, i::HeapObject::cast(type)->GetIsolate());
298 }
299
300 static bool is_bitset(Type* type) { return type->IsSmi(); }
301 static bool is_class(Type* type) { return type->IsMap(); }
302 static bool is_constant(Type* type) { return type->IsBox(); }
303 static bool is_union(Type* type) { return type->IsFixedArray(); }
304
305 static int as_bitset(Type* type) {
306 return Smi::cast(type)->value();
307 }
308 static i::Handle<i::Map> as_class(Type* type) {
309 return i::handle(i::Map::cast(type));
310 }
311 static i::Handle<i::Object> as_constant(Type* type) {
312 i::Box* box = i::Box::cast(type);
313 return i::handle(box->value(), box->GetIsolate());
314 }
315 static i::Handle<Unioned> as_union(Type* type) {
316 return i::handle(i::FixedArray::cast(type));
317 }
318
319 static Type* from_bitset(int bitset) {
320 return Type::cast(i::Smi::FromInt(bitset));
321 }
322 static i::Handle<Type> from_bitset(int bitset, Isolate* isolate) {
323 return i::handle(from_bitset(bitset), isolate);
324 }
325 static i::Handle<Type> from_class(i::Handle<i::Map> map, Isolate* isolate) {
326 return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
327 }
328 static i::Handle<Type> from_constant(
329 i::Handle<i::Object> value, Isolate* isolate) {
330 ASSERT(isolate || value->IsHeapObject());
331 if (!isolate) isolate = i::HeapObject::cast(*value)->GetIsolate();
332 i::Handle<Box> box = isolate->factory()->NewBox(value);
333 return i::Handle<Type>::cast(i::Handle<Object>::cast(box));
334 }
335 static i::Handle<Type> from_union(i::Handle<Unioned> unioned) {
336 return i::Handle<Type>::cast(i::Handle<Object>::cast(unioned));
337 }
338
339 static i::Handle<Unioned> union_create(int size, Isolate* isolate) {
340 return isolate->factory()->NewFixedArray(size);
341 }
342 static i::Handle<Type> union_get(i::Handle<Unioned> unioned, int i) {
343 Type* type = static_cast<Type*>(unioned->get(i));
344 ASSERT(!is_union(type));
345 return i::handle(type, unioned->GetIsolate());
346 }
347 };
348
349 typedef TypeImpl<HeapTypeConfig> Type;
350
351
283 // A simple struct to represent a pair of lower/upper type bounds. 352 // A simple struct to represent a pair of lower/upper type bounds.
284 struct Bounds { 353 template<class Config>
285 Handle<Type> lower; 354 struct BoundsImpl {
286 Handle<Type> upper; 355 typedef TypeImpl<Config> Type;
356 typedef typename Type::TypeHandle TypeHandle;
357 typedef typename Type::Region Region;
287 358
288 Bounds() {} 359 TypeHandle lower;
289 Bounds(Handle<Type> l, Handle<Type> u) : lower(l), upper(u) { 360 TypeHandle upper;
290 ASSERT(lower->Is(upper)); 361
291 } 362 BoundsImpl() {}
292 Bounds(Type* l, Type* u, Isolate* isl) : lower(l, isl), upper(u, isl) { 363 explicit BoundsImpl(TypeHandle t) : lower(t), upper(t) {}
293 ASSERT(lower->Is(upper)); 364 BoundsImpl(TypeHandle l, TypeHandle u) : lower(l), upper(u) {
294 }
295 explicit Bounds(Handle<Type> t) : lower(t), upper(t) {
296 ASSERT(lower->Is(upper));
297 }
298 Bounds(Type* t, Isolate* isl) : lower(t, isl), upper(t, isl) {
299 ASSERT(lower->Is(upper)); 365 ASSERT(lower->Is(upper));
300 } 366 }
301 367
302 // Unrestricted bounds. 368 // Unrestricted bounds.
303 static Bounds Unbounded(Isolate* isl) { 369 static BoundsImpl Unbounded(Region* region) {
304 return Bounds(Type::None(), Type::Any(), isl); 370 return BoundsImpl(Type::None(region), Type::Any(region));
305 } 371 }
306 372
307 // Meet: both b1 and b2 are known to hold. 373 // Meet: both b1 and b2 are known to hold.
308 static Bounds Both(Bounds b1, Bounds b2, Isolate* isl) { 374 static BoundsImpl Both(BoundsImpl b1, BoundsImpl b2, Region* region) {
309 Handle<Type> lower(Type::Union(b1.lower, b2.lower), isl); 375 TypeHandle lower = Type::Union(b1.lower, b2.lower, region);
310 Handle<Type> upper(Type::Intersect(b1.upper, b2.upper), isl); 376 TypeHandle upper = Type::Intersect(b1.upper, b2.upper, region);
311 // Lower bounds are considered approximate, correct as necessary. 377 // Lower bounds are considered approximate, correct as necessary.
312 lower = handle(Type::Intersect(lower, upper), isl); 378 lower = Type::Intersect(lower, upper, region);
313 return Bounds(lower, upper); 379 return BoundsImpl(lower, upper);
314 } 380 }
315 381
316 // Join: either b1 or b2 is known to hold. 382 // Join: either b1 or b2 is known to hold.
317 static Bounds Either(Bounds b1, Bounds b2, Isolate* isl) { 383 static BoundsImpl Either(BoundsImpl b1, BoundsImpl b2, Region* region) {
318 return Bounds( 384 TypeHandle lower = Type::Intersect(b1.lower, b2.lower, region);
319 handle(Type::Intersect(b1.lower, b2.lower), isl), 385 TypeHandle upper = Type::Union(b1.upper, b2.upper, region);
320 handle(Type::Union(b1.upper, b2.upper), isl)); 386 return BoundsImpl(lower, upper);
321 } 387 }
322 388
323 static Bounds NarrowLower(Bounds b, Handle<Type> t, Isolate* isl) { 389 static BoundsImpl NarrowLower(BoundsImpl b, TypeHandle t, Region* region) {
324 // Lower bounds are considered approximate, correct as necessary. 390 // Lower bounds are considered approximate, correct as necessary.
325 t = handle(Type::Intersect(t, b.upper), isl); 391 t = Type::Intersect(t, b.upper, region);
326 return Bounds(handle(Type::Union(b.lower, t), isl), b.upper); 392 TypeHandle lower = Type::Union(b.lower, t, region);
393 return BoundsImpl(lower, b.upper);
327 } 394 }
328 static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) { 395 static BoundsImpl NarrowUpper(BoundsImpl b, TypeHandle t, Region* region) {
329 return Bounds( 396 TypeHandle lower = Type::Intersect(b.lower, t, region);
330 handle(Type::Intersect(b.lower, t), isl), 397 TypeHandle upper = Type::Intersect(b.upper, t, region);
331 handle(Type::Intersect(b.upper, t), isl)); 398 return BoundsImpl(lower, upper);
332 } 399 }
333 }; 400 };
334 401
402 typedef BoundsImpl<HeapTypeConfig> Bounds;
403
404
335 } } // namespace v8::internal 405 } } // namespace v8::internal
336 406
337 #endif // V8_TYPES_H_ 407 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/type-info.cc ('k') | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698