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

Side by Side Diff: src/types.h

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

Powered by Google App Engine
This is Rietveld 408576698