OLD | NEW |
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_TYPES_H_ | 5 #ifndef V8_TYPES_H_ |
6 #define V8_TYPES_H_ | 6 #define V8_TYPES_H_ |
7 | 7 |
8 #include "handles.h" | 8 #include "handles.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 V(Any, kNumber | kNonNumber) | 157 V(Any, kNumber | kNonNumber) |
158 | 158 |
159 #define BITSET_TYPE_LIST(V) \ | 159 #define BITSET_TYPE_LIST(V) \ |
160 MASK_BITSET_TYPE_LIST(V) \ | 160 MASK_BITSET_TYPE_LIST(V) \ |
161 REPRESENTATION_BITSET_TYPE_LIST(V) \ | 161 REPRESENTATION_BITSET_TYPE_LIST(V) \ |
162 SEMANTIC_BITSET_TYPE_LIST(V) | 162 SEMANTIC_BITSET_TYPE_LIST(V) |
163 | 163 |
164 | 164 |
165 // struct Config { | 165 // struct Config { |
166 // typedef Base; | 166 // typedef Base; |
167 // typedef Unioned; | 167 // typedef Struct; |
168 // typedef Region; | 168 // typedef Region; |
169 // template<class> struct Handle { typedef type; } // No template typedefs... | 169 // template<class> struct Handle { typedef type; } // No template typedefs... |
170 // static Handle<Type>::type handle(Type* type); // !is_bitset(type) | 170 // static Handle<Type>::type handle(Type* type); // !is_bitset(type) |
171 // static bool is_bitset(Type*); | 171 // static bool is_bitset(Type*); |
172 // static bool is_class(Type*); | 172 // static bool is_class(Type*); |
173 // static bool is_constant(Type*); | 173 // static bool is_constant(Type*); |
174 // static bool is_union(Type*); | 174 // static bool is_struct(Type*); |
175 // static int as_bitset(Type*); | 175 // static int as_bitset(Type*); |
176 // static i::Handle<i::Map> as_class(Type*); | 176 // static i::Handle<i::Map> as_class(Type*); |
177 // static i::Handle<i::Object> as_constant(Type*); | 177 // static i::Handle<i::Object> as_constant(Type*); |
178 // static Handle<Unioned>::type as_union(Type*); | 178 // static Handle<Struct>::type as_struct(Type*); |
179 // static Type* from_bitset(int bitset); | 179 // static Type* from_bitset(int bitset); |
180 // static Handle<Type>::type from_bitset(int bitset, Region*); | 180 // static Handle<Type>::type from_bitset(int bitset, Region*); |
181 // static Handle<Type>::type from_class(i::Handle<Map>, int lub, Region*); | 181 // static Handle<Type>::type from_class(i::Handle<Map>, int lub, Region*); |
182 // static Handle<Type>::type from_constant(i::Handle<Object>, int, Region*); | 182 // static Handle<Type>::type from_constant(i::Handle<Object>, int, Region*); |
183 // static Handle<Type>::type from_union(Handle<Unioned>::type); | 183 // static Handle<Type>::type from_struct(Handle<Struct>::type); |
184 // static Handle<Unioned>::type union_create(int size, Region*); | 184 // static Handle<Struct>::type struct_create(int tag, int length, Region*); |
185 // static void union_shrink(Handle<Unioned>::type, int size); | 185 // static void struct_shrink(Handle<Struct>::type, int length); |
186 // static Handle<Type>::type union_get(Handle<Unioned>::type, int); | 186 // static int struct_tag(Handle<Struct>::type); |
187 // static void union_set(Handle<Unioned>::type, int, Handle<Type>::type); | 187 // static int struct_length(Handle<Struct>::type); |
188 // static int union_length(Handle<Unioned>::type); | 188 // static Handle<Type>::type struct_get(Handle<Struct>::type, int); |
| 189 // static void struct_set(Handle<Struct>::type, int, Handle<Type>::type); |
189 // static int lub_bitset(Type*); | 190 // static int lub_bitset(Type*); |
190 // } | 191 // } |
191 template<class Config> | 192 template<class Config> |
192 class TypeImpl : public Config::Base { | 193 class TypeImpl : public Config::Base { |
193 public: | 194 public: |
194 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; | 195 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; |
195 typedef typename Config::Region Region; | 196 typedef typename Config::Region Region; |
196 | 197 |
197 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | 198 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
198 static TypeImpl* type() { return Config::from_bitset(k##type); } \ | 199 static TypeImpl* type() { return Config::from_bitset(k##type); } \ |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 static TypeHandle Convert( | 293 static TypeHandle Convert( |
293 typename OtherTypeImpl::TypeHandle type, Region* region); | 294 typename OtherTypeImpl::TypeHandle type, Region* region); |
294 | 295 |
295 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; | 296 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; |
296 void TypePrint(PrintDimension = BOTH_DIMS); | 297 void TypePrint(PrintDimension = BOTH_DIMS); |
297 void TypePrint(FILE* out, PrintDimension = BOTH_DIMS); | 298 void TypePrint(FILE* out, PrintDimension = BOTH_DIMS); |
298 | 299 |
299 private: | 300 private: |
300 template<class> friend class Iterator; | 301 template<class> friend class Iterator; |
301 template<class> friend class TypeImpl; | 302 template<class> friend class TypeImpl; |
| 303 friend struct ZoneTypeConfig; |
| 304 friend struct HeapTypeConfig; |
302 | 305 |
303 // A union is a fixed array containing types. Invariants: | 306 enum Tag { |
| 307 kClassTag, |
| 308 kConstantTag, |
| 309 kUnionTag |
| 310 }; |
| 311 |
| 312 // A structured type contains a tag an a variable number of type fields. |
| 313 // A union is a structured type with the following invariants: |
304 // - its length is at least 2 | 314 // - its length is at least 2 |
305 // - at most one field is a bitset, and it must go into index 0 | 315 // - at most one field is a bitset, and it must go into index 0 |
306 // - no field is a union | 316 // - no field is a union |
307 typedef typename Config::Unioned Unioned; | 317 typedef typename Config::Struct Struct; |
308 typedef typename Config::template Handle<Unioned>::type UnionedHandle; | 318 typedef typename Config::template Handle<Struct>::type StructHandle; |
309 | 319 |
310 enum { | 320 enum { |
311 #define DECLARE_TYPE(type, value) k##type = (value), | 321 #define DECLARE_TYPE(type, value) k##type = (value), |
312 BITSET_TYPE_LIST(DECLARE_TYPE) | 322 BITSET_TYPE_LIST(DECLARE_TYPE) |
313 #undef DECLARE_TYPE | 323 #undef DECLARE_TYPE |
314 kUnusedEOL = 0 | 324 kUnusedEOL = 0 |
315 }; | 325 }; |
316 | 326 |
317 bool IsNone() { return this == None(); } | 327 bool IsNone() { return this == None(); } |
318 bool IsAny() { return this == Any(); } | 328 bool IsAny() { return this == Any(); } |
319 bool IsBitset() { return Config::is_bitset(this); } | 329 bool IsBitset() { return Config::is_bitset(this); } |
320 bool IsUnion() { return Config::is_union(this); } | 330 bool IsStruct(Tag tag) { |
| 331 return Config::is_struct(this) |
| 332 && Config::struct_tag(Config::as_struct(this)) == tag; |
| 333 } |
| 334 bool IsUnion() { return IsStruct(kUnionTag); } |
| 335 |
321 int AsBitset() { return Config::as_bitset(this); } | 336 int AsBitset() { return Config::as_bitset(this); } |
322 UnionedHandle AsUnion() { return Config::as_union(this); } | 337 StructHandle AsStruct(Tag tag) { |
| 338 ASSERT(IsStruct(tag)); |
| 339 return Config::as_struct(this); |
| 340 } |
| 341 StructHandle AsUnion() { return AsStruct(kUnionTag); } |
323 | 342 |
324 static int UnionLength(UnionedHandle unioned) { | 343 static int StructLength(StructHandle structured) { |
325 return Config::union_length(unioned); | 344 return Config::struct_length(structured); |
326 } | 345 } |
327 static TypeHandle UnionGet(UnionedHandle unioned, int i) { | 346 static TypeHandle StructGet(StructHandle structured, int i) { |
328 return Config::union_get(unioned, i); | 347 return Config::struct_get(structured, i); |
329 } | 348 } |
330 | 349 |
331 bool SlowIs(TypeImpl* that); | 350 bool SlowIs(TypeImpl* that); |
332 | 351 |
333 static bool IsInhabited(int bitset) { | 352 static bool IsInhabited(int bitset) { |
334 return (bitset & kRepresentation) && (bitset & kSemantic); | 353 return (bitset & kRepresentation) && (bitset & kSemantic); |
335 } | 354 } |
336 | 355 |
337 int LubBitset(); // least upper bound that's a bitset | 356 int LubBitset(); // least upper bound that's a bitset |
338 int GlbBitset(); // greatest lower bound that's a bitset | 357 int GlbBitset(); // greatest lower bound that's a bitset |
339 | 358 |
340 static int LubBitset(i::Object* value); | 359 static int LubBitset(i::Object* value); |
341 static int LubBitset(i::Map* map); | 360 static int LubBitset(i::Map* map); |
342 | 361 |
343 bool InUnion(UnionedHandle unioned, int current_size); | 362 bool InUnion(StructHandle unioned, int current_size); |
344 static int ExtendUnion( | 363 static int ExtendUnion( |
345 UnionedHandle unioned, TypeHandle t, int current_size); | 364 StructHandle unioned, TypeHandle t, int current_size); |
346 static int ExtendIntersection( | 365 static int ExtendIntersection( |
347 UnionedHandle unioned, TypeHandle t, TypeHandle other, int current_size); | 366 StructHandle unioned, TypeHandle t, TypeHandle other, int current_size); |
348 | 367 |
349 static const char* bitset_name(int bitset); | 368 static const char* bitset_name(int bitset); |
350 static void BitsetTypePrint(FILE* out, int bitset); | 369 static void BitsetTypePrint(FILE* out, int bitset); |
351 }; | 370 }; |
352 | 371 |
353 | 372 |
354 // Zone-allocated types are either (odd) integers to represent bitsets, or | 373 // Zone-allocated types are either (odd) integers to represent bitsets, or |
355 // (even) pointers to zone lists for everything else. The first slot of every | 374 // (even) pointers to structures for everything else. |
356 // list is an explicit tag value to distinguish representation. | |
357 struct ZoneTypeConfig { | 375 struct ZoneTypeConfig { |
358 private: | |
359 typedef i::ZoneList<void*> Tagged; | |
360 | |
361 enum Tag { | |
362 kClassTag, | |
363 kConstantTag, | |
364 kUnionTag | |
365 }; | |
366 | |
367 static inline Tagged* tagged_create(Tag tag, int size, Zone* zone); | |
368 static inline void tagged_shrink(Tagged* tagged, int size); | |
369 static inline Tag tagged_tag(Tagged* tagged); | |
370 template<class T> static inline T tagged_get(Tagged* tagged, int i); | |
371 template<class T> static inline void tagged_set(Tagged* tagged, int i, T val); | |
372 static inline int tagged_length(Tagged* tagged); | |
373 | |
374 public: | |
375 typedef TypeImpl<ZoneTypeConfig> Type; | 376 typedef TypeImpl<ZoneTypeConfig> Type; |
376 class Base {}; | 377 class Base {}; |
377 typedef i::ZoneList<Type*> Unioned; | 378 typedef void* Struct; |
378 typedef i::Zone Region; | 379 typedef i::Zone Region; |
379 template<class T> struct Handle { typedef T* type; }; | 380 template<class T> struct Handle { typedef T* type; }; |
380 | 381 |
381 static inline Type* handle(Type* type); | 382 static inline Type* handle(Type* type); |
382 static inline bool is(Type* type, Tag tag); | |
383 static inline bool is_bitset(Type* type); | 383 static inline bool is_bitset(Type* type); |
384 static inline bool is_tagged(Type* type); | |
385 static inline bool is_class(Type* type); | 384 static inline bool is_class(Type* type); |
386 static inline bool is_constant(Type* type); | 385 static inline bool is_constant(Type* type); |
387 static inline bool is_union(Type* type); | 386 static inline bool is_struct(Type* type); |
388 static inline bool tagged_is_union(Tagged* tagged); | |
389 static inline int as_bitset(Type* type); | 387 static inline int as_bitset(Type* type); |
390 static inline Tagged* as_tagged(Type* type); | 388 static inline Struct* as_struct(Type* type); |
391 static inline i::Handle<i::Map> as_class(Type* type); | 389 static inline i::Handle<i::Map> as_class(Type* type); |
392 static inline i::Handle<i::Object> as_constant(Type* type); | 390 static inline i::Handle<i::Object> as_constant(Type* type); |
393 static inline Unioned* as_union(Type* type); | |
394 static inline Unioned* tagged_as_union(Tagged* tagged); | |
395 static inline Type* from_bitset(int bitset); | 391 static inline Type* from_bitset(int bitset); |
396 static inline Type* from_bitset(int bitset, Zone* zone); | 392 static inline Type* from_bitset(int bitset, Zone* zone); |
397 static inline Type* from_tagged(Tagged* tagged); | 393 static inline Type* from_struct(Struct* structured); |
398 static inline Type* from_class(i::Handle<i::Map> map, int lub, Zone* zone); | 394 static inline Type* from_class(i::Handle<i::Map> map, int lub, Zone* zone); |
399 static inline Type* from_constant( | 395 static inline Type* from_constant( |
400 i::Handle<i::Object> value, int lub, Zone* zone); | 396 i::Handle<i::Object> value, int lub, Zone* zone); |
401 static inline Type* from_union(Unioned* unioned); | 397 static inline Struct* struct_create(int tag, int length, Zone* zone); |
402 static inline Tagged* tagged_from_union(Unioned* unioned); | 398 static inline void struct_shrink(Struct* structured, int length); |
403 static inline Unioned* union_create(int size, Zone* zone); | 399 static inline int struct_tag(Struct* structured); |
404 static inline void union_shrink(Unioned* unioned, int size); | 400 static inline int struct_length(Struct* structured); |
405 static inline Type* union_get(Unioned* unioned, int i); | 401 static inline Type* struct_get(Struct* structured, int i); |
406 static inline void union_set(Unioned* unioned, int i, Type* type); | 402 static inline void struct_set(Struct* structured, int i, Type* type); |
407 static inline int union_length(Unioned* unioned); | |
408 static inline int lub_bitset(Type* type); | 403 static inline int lub_bitset(Type* type); |
409 }; | 404 }; |
410 | 405 |
411 typedef TypeImpl<ZoneTypeConfig> Type; | 406 typedef TypeImpl<ZoneTypeConfig> Type; |
412 | 407 |
413 | 408 |
414 // Heap-allocated types are either smis for bitsets, maps for classes, boxes for | 409 // Heap-allocated types are either smis for bitsets, maps for classes, boxes for |
415 // constants, or fixed arrays for unions. | 410 // constants, or fixed arrays for unions. |
416 struct HeapTypeConfig { | 411 struct HeapTypeConfig { |
417 typedef TypeImpl<HeapTypeConfig> Type; | 412 typedef TypeImpl<HeapTypeConfig> Type; |
418 typedef i::Object Base; | 413 typedef i::Object Base; |
419 typedef i::FixedArray Unioned; | 414 typedef i::FixedArray Struct; |
420 typedef i::Isolate Region; | 415 typedef i::Isolate Region; |
421 template<class T> struct Handle { typedef i::Handle<T> type; }; | 416 template<class T> struct Handle { typedef i::Handle<T> type; }; |
422 | 417 |
423 static inline i::Handle<Type> handle(Type* type); | 418 static inline i::Handle<Type> handle(Type* type); |
424 static inline bool is_bitset(Type* type); | 419 static inline bool is_bitset(Type* type); |
425 static inline bool is_class(Type* type); | 420 static inline bool is_class(Type* type); |
426 static inline bool is_constant(Type* type); | 421 static inline bool is_constant(Type* type); |
427 static inline bool is_union(Type* type); | 422 static inline bool is_struct(Type* type); |
428 static inline int as_bitset(Type* type); | 423 static inline int as_bitset(Type* type); |
429 static inline i::Handle<i::Map> as_class(Type* type); | 424 static inline i::Handle<i::Map> as_class(Type* type); |
430 static inline i::Handle<i::Object> as_constant(Type* type); | 425 static inline i::Handle<i::Object> as_constant(Type* type); |
431 static inline i::Handle<Unioned> as_union(Type* type); | 426 static inline i::Handle<Struct> as_struct(Type* type); |
432 static inline Type* from_bitset(int bitset); | 427 static inline Type* from_bitset(int bitset); |
433 static inline i::Handle<Type> from_bitset(int bitset, Isolate* isolate); | 428 static inline i::Handle<Type> from_bitset(int bitset, Isolate* isolate); |
434 static inline i::Handle<Type> from_class( | 429 static inline i::Handle<Type> from_class( |
435 i::Handle<i::Map> map, int lub, Isolate* isolate); | 430 i::Handle<i::Map> map, int lub, Isolate* isolate); |
436 static inline i::Handle<Type> from_constant( | 431 static inline i::Handle<Type> from_constant( |
437 i::Handle<i::Object> value, int lub, Isolate* isolate); | 432 i::Handle<i::Object> value, int lub, Isolate* isolate); |
438 static inline i::Handle<Type> from_union(i::Handle<Unioned> unioned); | 433 static inline i::Handle<Type> from_struct(i::Handle<Struct> structured); |
439 static inline i::Handle<Unioned> union_create(int size, Isolate* isolate); | 434 static inline i::Handle<Struct> struct_create( |
440 static inline void union_shrink(i::Handle<Unioned> unioned, int size); | 435 int tag, int length, Isolate* isolate); |
441 static inline i::Handle<Type> union_get(i::Handle<Unioned> unioned, int i); | 436 static inline void struct_shrink(i::Handle<Struct> structured, int length); |
442 static inline void union_set( | 437 static inline int struct_tag(i::Handle<Struct> structured); |
443 i::Handle<Unioned> unioned, int i, i::Handle<Type> type); | 438 static inline int struct_length(i::Handle<Struct> structured); |
444 static inline int union_length(i::Handle<Unioned> unioned); | 439 static inline i::Handle<Type> struct_get(i::Handle<Struct> structured, int i); |
| 440 static inline void struct_set( |
| 441 i::Handle<Struct> structured, int i, i::Handle<Type> type); |
445 static inline int lub_bitset(Type* type); | 442 static inline int lub_bitset(Type* type); |
446 }; | 443 }; |
447 | 444 |
448 typedef TypeImpl<HeapTypeConfig> HeapType; | 445 typedef TypeImpl<HeapTypeConfig> HeapType; |
449 | 446 |
450 | 447 |
451 // A simple struct to represent a pair of lower/upper type bounds. | 448 // A simple struct to represent a pair of lower/upper type bounds. |
452 template<class Config> | 449 template<class Config> |
453 struct BoundsImpl { | 450 struct BoundsImpl { |
454 typedef TypeImpl<Config> Type; | 451 typedef TypeImpl<Config> Type; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 bool Narrows(BoundsImpl that) { | 497 bool Narrows(BoundsImpl that) { |
501 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 498 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
502 } | 499 } |
503 }; | 500 }; |
504 | 501 |
505 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 502 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
506 | 503 |
507 } } // namespace v8::internal | 504 } } // namespace v8::internal |
508 | 505 |
509 #endif // V8_TYPES_H_ | 506 #endif // V8_TYPES_H_ |
OLD | NEW |