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 #include "types.h" | 5 #include "types.h" |
6 | 6 |
7 #include "string-stream.h" | 7 #include "string-stream.h" |
8 #include "types-inl.h" | 8 #include "types-inl.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 template<class Config> | 13 template<class Config> |
14 int TypeImpl<Config>::NumClasses() { | 14 int TypeImpl<Config>::NumClasses() { |
15 if (this->IsClass()) { | 15 if (this->IsClass()) { |
16 return 1; | 16 return 1; |
17 } else if (this->IsUnion()) { | 17 } else if (this->IsUnion()) { |
18 UnionedHandle unioned = this->AsUnion(); | 18 StructHandle unioned = this->AsUnion(); |
19 int result = 0; | 19 int result = 0; |
20 for (int i = 0; i < Config::union_length(unioned); ++i) { | 20 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
21 if (Config::union_get(unioned, i)->IsClass()) ++result; | 21 if (Config::struct_get(unioned, i)->IsClass()) ++result; |
22 } | 22 } |
23 return result; | 23 return result; |
24 } else { | 24 } else { |
25 return 0; | 25 return 0; |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 | 29 |
30 template<class Config> | 30 template<class Config> |
31 int TypeImpl<Config>::NumConstants() { | 31 int TypeImpl<Config>::NumConstants() { |
32 if (this->IsConstant()) { | 32 if (this->IsConstant()) { |
33 return 1; | 33 return 1; |
34 } else if (this->IsUnion()) { | 34 } else if (this->IsUnion()) { |
35 UnionedHandle unioned = this->AsUnion(); | 35 StructHandle unioned = this->AsUnion(); |
36 int result = 0; | 36 int result = 0; |
37 for (int i = 0; i < Config::union_length(unioned); ++i) { | 37 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
38 if (Config::union_get(unioned, i)->IsConstant()) ++result; | 38 if (Config::struct_get(unioned, i)->IsConstant()) ++result; |
39 } | 39 } |
40 return result; | 40 return result; |
41 } else { | 41 } else { |
42 return 0; | 42 return 0; |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 template<class Config> template<class T> | 47 template<class Config> template<class T> |
48 typename TypeImpl<Config>::TypeHandle | 48 typename TypeImpl<Config>::TypeHandle |
49 TypeImpl<Config>::Iterator<T>::get_type() { | 49 TypeImpl<Config>::Iterator<T>::get_type() { |
50 ASSERT(!Done()); | 50 ASSERT(!Done()); |
51 return type_->IsUnion() ? Config::union_get(type_->AsUnion(), index_) : type_; | 51 return type_->IsUnion() |
| 52 ? Config::struct_get(type_->AsUnion(), index_) : type_; |
52 } | 53 } |
53 | 54 |
54 | 55 |
55 // C++ cannot specialise nested templates, so we have to go through this | 56 // C++ cannot specialise nested templates, so we have to go through this |
56 // contortion with an auxiliary template to simulate it. | 57 // contortion with an auxiliary template to simulate it. |
57 template<class Config, class T> | 58 template<class Config, class T> |
58 struct TypeImplIteratorAux { | 59 struct TypeImplIteratorAux { |
59 static bool matches(typename TypeImpl<Config>::TypeHandle type); | 60 static bool matches(typename TypeImpl<Config>::TypeHandle type); |
60 static i::Handle<T> current(typename TypeImpl<Config>::TypeHandle type); | 61 static i::Handle<T> current(typename TypeImpl<Config>::TypeHandle type); |
61 }; | 62 }; |
(...skipping 27 matching lines...) Expand all Loading... |
89 template<class Config> template<class T> | 90 template<class Config> template<class T> |
90 i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() { | 91 i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() { |
91 return TypeImplIteratorAux<Config, T>::current(get_type()); | 92 return TypeImplIteratorAux<Config, T>::current(get_type()); |
92 } | 93 } |
93 | 94 |
94 | 95 |
95 template<class Config> template<class T> | 96 template<class Config> template<class T> |
96 void TypeImpl<Config>::Iterator<T>::Advance() { | 97 void TypeImpl<Config>::Iterator<T>::Advance() { |
97 ++index_; | 98 ++index_; |
98 if (type_->IsUnion()) { | 99 if (type_->IsUnion()) { |
99 UnionedHandle unioned = type_->AsUnion(); | 100 StructHandle unioned = type_->AsUnion(); |
100 for (; index_ < Config::union_length(unioned); ++index_) { | 101 for (; index_ < Config::struct_length(unioned); ++index_) { |
101 if (matches(Config::union_get(unioned, index_))) return; | 102 if (matches(Config::struct_get(unioned, index_))) return; |
102 } | 103 } |
103 } else if (index_ == 0 && matches(type_)) { | 104 } else if (index_ == 0 && matches(type_)) { |
104 return; | 105 return; |
105 } | 106 } |
106 index_ = -1; | 107 index_ = -1; |
107 } | 108 } |
108 | 109 |
109 | 110 |
110 // Get the smallest bitset subsuming this type. | 111 // Get the smallest bitset subsuming this type. |
111 template<class Config> | 112 template<class Config> |
112 int TypeImpl<Config>::LubBitset() { | 113 int TypeImpl<Config>::LubBitset() { |
113 if (this->IsBitset()) { | 114 if (this->IsBitset()) { |
114 return this->AsBitset(); | 115 return this->AsBitset(); |
115 } else if (this->IsUnion()) { | 116 } else if (this->IsUnion()) { |
116 UnionedHandle unioned = this->AsUnion(); | 117 StructHandle unioned = this->AsUnion(); |
117 int bitset = kNone; | 118 int bitset = kNone; |
118 for (int i = 0; i < Config::union_length(unioned); ++i) { | 119 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
119 bitset |= Config::union_get(unioned, i)->LubBitset(); | 120 bitset |= Config::struct_get(unioned, i)->LubBitset(); |
120 } | 121 } |
121 return bitset; | 122 return bitset; |
122 } else if (this->IsClass()) { | 123 } else if (this->IsClass()) { |
123 int bitset = Config::lub_bitset(this); | 124 int bitset = Config::lub_bitset(this); |
124 return bitset ? bitset : LubBitset(*this->AsClass()); | 125 return bitset ? bitset : LubBitset(*this->AsClass()); |
125 } else { | 126 } else { |
126 int bitset = Config::lub_bitset(this); | 127 int bitset = Config::lub_bitset(this); |
127 return bitset ? bitset : LubBitset(*this->AsConstant()); | 128 return bitset ? bitset : LubBitset(*this->AsConstant()); |
128 } | 129 } |
129 } | 130 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 235 } |
235 | 236 |
236 | 237 |
237 // Get the largest bitset subsumed by this type. | 238 // Get the largest bitset subsumed by this type. |
238 template<class Config> | 239 template<class Config> |
239 int TypeImpl<Config>::GlbBitset() { | 240 int TypeImpl<Config>::GlbBitset() { |
240 if (this->IsBitset()) { | 241 if (this->IsBitset()) { |
241 return this->AsBitset(); | 242 return this->AsBitset(); |
242 } else if (this->IsUnion()) { | 243 } else if (this->IsUnion()) { |
243 // All but the first are non-bitsets and thus would yield kNone anyway. | 244 // All but the first are non-bitsets and thus would yield kNone anyway. |
244 return Config::union_get(this->AsUnion(), 0)->GlbBitset(); | 245 return Config::struct_get(this->AsUnion(), 0)->GlbBitset(); |
245 } else { | 246 } else { |
246 return kNone; | 247 return kNone; |
247 } | 248 } |
248 } | 249 } |
249 | 250 |
250 | 251 |
251 // Most precise _current_ type of a value (usually its class). | 252 // Most precise _current_ type of a value (usually its class). |
252 template<class Config> | 253 template<class Config> |
253 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NowOf( | 254 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NowOf( |
254 i::Object* value, Region* region) { | 255 i::Object* value, Region* region) { |
(...skipping 16 matching lines...) Expand all Loading... |
271 | 272 |
272 if (that->IsClass()) { | 273 if (that->IsClass()) { |
273 return this->IsClass() && *this->AsClass() == *that->AsClass(); | 274 return this->IsClass() && *this->AsClass() == *that->AsClass(); |
274 } | 275 } |
275 if (that->IsConstant()) { | 276 if (that->IsConstant()) { |
276 return this->IsConstant() && *this->AsConstant() == *that->AsConstant(); | 277 return this->IsConstant() && *this->AsConstant() == *that->AsConstant(); |
277 } | 278 } |
278 | 279 |
279 // (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T) | 280 // (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T) |
280 if (this->IsUnion()) { | 281 if (this->IsUnion()) { |
281 UnionedHandle unioned = this->AsUnion(); | 282 StructHandle unioned = this->AsUnion(); |
282 for (int i = 0; i < Config::union_length(unioned); ++i) { | 283 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
283 TypeHandle this_i = Config::union_get(unioned, i); | 284 TypeHandle this_i = Config::struct_get(unioned, i); |
284 if (!this_i->Is(that)) return false; | 285 if (!this_i->Is(that)) return false; |
285 } | 286 } |
286 return true; | 287 return true; |
287 } | 288 } |
288 | 289 |
289 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) | 290 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) |
290 // (iff T is not a union) | 291 // (iff T is not a union) |
291 ASSERT(!this->IsUnion()); | 292 ASSERT(!this->IsUnion()); |
292 if (that->IsUnion()) { | 293 if (that->IsUnion()) { |
293 UnionedHandle unioned = that->AsUnion(); | 294 StructHandle unioned = that->AsUnion(); |
294 for (int i = 0; i < Config::union_length(unioned); ++i) { | 295 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
295 TypeHandle that_i = Config::union_get(unioned, i); | 296 TypeHandle that_i = Config::struct_get(unioned, i); |
296 if (this->Is(that_i)) return true; | 297 if (this->Is(that_i)) return true; |
297 if (this->IsBitset()) break; // Fast fail, only first field is a bitset. | 298 if (this->IsBitset()) break; // Fast fail, only first field is a bitset. |
298 } | 299 } |
299 return false; | 300 return false; |
300 } | 301 } |
301 | 302 |
302 return false; | 303 return false; |
303 } | 304 } |
304 | 305 |
305 | 306 |
(...skipping 12 matching lines...) Expand all Loading... |
318 // Fast path for bitsets. | 319 // Fast path for bitsets. |
319 if (this->IsBitset()) { | 320 if (this->IsBitset()) { |
320 return IsInhabited(this->AsBitset() & that->LubBitset()); | 321 return IsInhabited(this->AsBitset() & that->LubBitset()); |
321 } | 322 } |
322 if (that->IsBitset()) { | 323 if (that->IsBitset()) { |
323 return IsInhabited(this->LubBitset() & that->AsBitset()); | 324 return IsInhabited(this->LubBitset() & that->AsBitset()); |
324 } | 325 } |
325 | 326 |
326 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) | 327 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) |
327 if (this->IsUnion()) { | 328 if (this->IsUnion()) { |
328 UnionedHandle unioned = this->AsUnion(); | 329 StructHandle unioned = this->AsUnion(); |
329 for (int i = 0; i < Config::union_length(unioned); ++i) { | 330 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
330 TypeHandle this_i = Config::union_get(unioned, i); | 331 TypeHandle this_i = Config::struct_get(unioned, i); |
331 if (this_i->Maybe(that)) return true; | 332 if (this_i->Maybe(that)) return true; |
332 } | 333 } |
333 return false; | 334 return false; |
334 } | 335 } |
335 | 336 |
336 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) | 337 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) |
337 if (that->IsUnion()) { | 338 if (that->IsUnion()) { |
338 UnionedHandle unioned = that->AsUnion(); | 339 StructHandle unioned = that->AsUnion(); |
339 for (int i = 0; i < Config::union_length(unioned); ++i) { | 340 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
340 TypeHandle that_i = Config::union_get(unioned, i); | 341 TypeHandle that_i = Config::struct_get(unioned, i); |
341 if (this->Maybe(that_i)) return true; | 342 if (this->Maybe(that_i)) return true; |
342 } | 343 } |
343 return false; | 344 return false; |
344 } | 345 } |
345 | 346 |
346 ASSERT(!this->IsUnion() && !that->IsUnion()); | 347 ASSERT(!this->IsUnion() && !that->IsUnion()); |
347 if (this->IsClass()) { | 348 if (this->IsClass()) { |
348 return that->IsClass() && *this->AsClass() == *that->AsClass(); | 349 return that->IsClass() && *this->AsClass() == *that->AsClass(); |
349 } | 350 } |
350 if (this->IsConstant()) { | 351 if (this->IsConstant()) { |
(...skipping 15 matching lines...) Expand all Loading... |
366 | 367 |
367 template<class Config> | 368 template<class Config> |
368 bool TypeImpl<Config>::NowContains(i::Object* value) { | 369 bool TypeImpl<Config>::NowContains(i::Object* value) { |
369 return this->Contains(value) || | 370 return this->Contains(value) || |
370 (this->IsClass() && value->IsHeapObject() && | 371 (this->IsClass() && value->IsHeapObject() && |
371 *this->AsClass() == i::HeapObject::cast(value)->map()); | 372 *this->AsClass() == i::HeapObject::cast(value)->map()); |
372 } | 373 } |
373 | 374 |
374 | 375 |
375 template<class Config> | 376 template<class Config> |
376 bool TypeImpl<Config>::InUnion(UnionedHandle unioned, int current_size) { | 377 bool TypeImpl<Config>::InUnion(StructHandle unioned, int current_size) { |
377 ASSERT(!this->IsUnion()); | 378 ASSERT(!this->IsUnion()); |
378 for (int i = 0; i < current_size; ++i) { | 379 for (int i = 0; i < current_size; ++i) { |
379 TypeHandle type = Config::union_get(unioned, i); | 380 TypeHandle type = Config::struct_get(unioned, i); |
380 if (this->Is(type)) return true; | 381 if (this->Is(type)) return true; |
381 } | 382 } |
382 return false; | 383 return false; |
383 } | 384 } |
384 | 385 |
385 | 386 |
386 // Get non-bitsets from this which are not subsumed by union, store at unioned, | 387 // Get non-bitsets from this which are not subsumed by union, store at result, |
387 // starting at index. Returns updated index. | 388 // starting at index. Returns updated index. |
388 template<class Config> | 389 template<class Config> |
389 int TypeImpl<Config>::ExtendUnion( | 390 int TypeImpl<Config>::ExtendUnion( |
390 UnionedHandle result, TypeHandle type, int current_size) { | 391 StructHandle result, TypeHandle type, int current_size) { |
391 int old_size = current_size; | 392 int old_size = current_size; |
392 if (type->IsClass() || type->IsConstant()) { | 393 if (type->IsClass() || type->IsConstant()) { |
393 if (!type->InUnion(result, old_size)) { | 394 if (!type->InUnion(result, old_size)) { |
394 Config::union_set(result, current_size++, type); | 395 Config::struct_set(result, current_size++, type); |
395 } | 396 } |
396 } else if (type->IsUnion()) { | 397 } else if (type->IsUnion()) { |
397 UnionedHandle unioned = type->AsUnion(); | 398 StructHandle unioned = type->AsUnion(); |
398 for (int i = 0; i < Config::union_length(unioned); ++i) { | 399 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
399 TypeHandle type = Config::union_get(unioned, i); | 400 TypeHandle type = Config::struct_get(unioned, i); |
400 ASSERT(i == 0 || | 401 ASSERT(i == 0 || |
401 !(type->IsBitset() || type->Is(Config::union_get(unioned, 0)))); | 402 !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); |
402 if (!type->IsBitset() && !type->InUnion(result, old_size)) { | 403 if (!type->IsBitset() && !type->InUnion(result, old_size)) { |
403 Config::union_set(result, current_size++, type); | 404 Config::struct_set(result, current_size++, type); |
404 } | 405 } |
405 } | 406 } |
406 } | 407 } |
407 return current_size; | 408 return current_size; |
408 } | 409 } |
409 | 410 |
410 | 411 |
411 // Union is O(1) on simple bit unions, but O(n*m) on structured unions. | 412 // Union is O(1) on simple bit unions, but O(n*m) on structured unions. |
412 // TODO(rossberg): Should we use object sets somehow? Is it worth it? | |
413 template<class Config> | 413 template<class Config> |
414 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( | 414 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( |
415 TypeHandle type1, TypeHandle type2, Region* region) { | 415 TypeHandle type1, TypeHandle type2, Region* region) { |
416 // Fast case: bit sets. | 416 // Fast case: bit sets. |
417 if (type1->IsBitset() && type2->IsBitset()) { | 417 if (type1->IsBitset() && type2->IsBitset()) { |
418 return Config::from_bitset(type1->AsBitset() | type2->AsBitset(), region); | 418 return Config::from_bitset(type1->AsBitset() | type2->AsBitset(), region); |
419 } | 419 } |
420 | 420 |
421 // Fast case: top or bottom types. | 421 // Fast case: top or bottom types. |
422 if (type1->IsAny() || type2->IsNone()) return type1; | 422 if (type1->IsAny() || type2->IsNone()) return type1; |
423 if (type2->IsAny() || type1->IsNone()) return type2; | 423 if (type2->IsAny() || type1->IsNone()) return type2; |
424 | 424 |
425 // Semi-fast case: Unioned objects are neither involved nor produced. | 425 // Semi-fast case: Unioned objects are neither involved nor produced. |
426 if (!(type1->IsUnion() || type2->IsUnion())) { | 426 if (!(type1->IsUnion() || type2->IsUnion())) { |
427 if (type1->Is(type2)) return type2; | 427 if (type1->Is(type2)) return type2; |
428 if (type2->Is(type1)) return type1; | 428 if (type2->Is(type1)) return type1; |
429 } | 429 } |
430 | 430 |
431 // Slow case: may need to produce a Unioned object. | 431 // Slow case: may need to produce a Unioned object. |
432 int size = 0; | 432 int size = 0; |
433 if (!type1->IsBitset()) { | 433 if (!type1->IsBitset()) { |
434 size += (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1); | 434 size += (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1); |
435 } | 435 } |
436 if (!type2->IsBitset()) { | 436 if (!type2->IsBitset()) { |
437 size += (type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1); | 437 size += (type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1); |
438 } | 438 } |
439 int bitset = type1->GlbBitset() | type2->GlbBitset(); | 439 int bitset = type1->GlbBitset() | type2->GlbBitset(); |
440 if (IsInhabited(bitset)) ++size; | 440 if (IsInhabited(bitset)) ++size; |
441 ASSERT(size >= 1); | 441 ASSERT(size >= 1); |
442 UnionedHandle unioned = Config::union_create(size, region); | 442 StructHandle unioned = Config::struct_create(kUnionTag, size, region); |
443 | 443 |
444 size = 0; | 444 size = 0; |
445 if (IsInhabited(bitset)) { | 445 if (IsInhabited(bitset)) { |
446 Config::union_set(unioned, size++, Config::from_bitset(bitset, region)); | 446 Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); |
447 } | 447 } |
448 size = ExtendUnion(unioned, type1, size); | 448 size = ExtendUnion(unioned, type1, size); |
449 size = ExtendUnion(unioned, type2, size); | 449 size = ExtendUnion(unioned, type2, size); |
450 | 450 |
451 if (size == 1) { | 451 if (size == 1) { |
452 return Config::union_get(unioned, 0); | 452 return Config::struct_get(unioned, 0); |
453 } else { | 453 } else { |
454 Config::union_shrink(unioned, size); | 454 Config::struct_shrink(unioned, size); |
455 return Config::from_union(unioned); | 455 return Config::from_struct(unioned); |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 | 459 |
460 // Get non-bitsets from type which are also in other, store at unioned, | 460 // Get non-bitsets from type which are also in other, store at result, |
461 // starting at index. Returns updated index. | 461 // starting at index. Returns updated index. |
462 template<class Config> | 462 template<class Config> |
463 int TypeImpl<Config>::ExtendIntersection( | 463 int TypeImpl<Config>::ExtendIntersection( |
464 UnionedHandle result, TypeHandle type, TypeHandle other, int current_size) { | 464 StructHandle result, TypeHandle type, TypeHandle other, int current_size) { |
465 int old_size = current_size; | 465 int old_size = current_size; |
466 if (type->IsClass() || type->IsConstant()) { | 466 if (type->IsClass() || type->IsConstant()) { |
467 if (type->Is(other) && !type->InUnion(result, old_size)) { | 467 if (type->Is(other) && !type->InUnion(result, old_size)) { |
468 Config::union_set(result, current_size++, type); | 468 Config::struct_set(result, current_size++, type); |
469 } | 469 } |
470 } else if (type->IsUnion()) { | 470 } else if (type->IsUnion()) { |
471 UnionedHandle unioned = type->AsUnion(); | 471 StructHandle unioned = type->AsUnion(); |
472 for (int i = 0; i < Config::union_length(unioned); ++i) { | 472 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
473 TypeHandle type = Config::union_get(unioned, i); | 473 TypeHandle type = Config::struct_get(unioned, i); |
474 ASSERT(i == 0 || | 474 ASSERT(i == 0 || |
475 !(type->IsBitset() || type->Is(Config::union_get(unioned, 0)))); | 475 !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); |
476 if (!type->IsBitset() && type->Is(other) && | 476 if (!type->IsBitset() && type->Is(other) && |
477 !type->InUnion(result, old_size)) { | 477 !type->InUnion(result, old_size)) { |
478 Config::union_set(result, current_size++, type); | 478 Config::struct_set(result, current_size++, type); |
479 } | 479 } |
480 } | 480 } |
481 } | 481 } |
482 return current_size; | 482 return current_size; |
483 } | 483 } |
484 | 484 |
485 | 485 |
486 // Intersection is O(1) on simple bit unions, but O(n*m) on structured unions. | 486 // Intersection is O(1) on simple bit unions, but O(n*m) on structured unions. |
487 // TODO(rossberg): Should we use object sets somehow? Is it worth it? | 487 // TODO(rossberg): Should we use object sets somehow? Is it worth it? |
488 template<class Config> | 488 template<class Config> |
(...skipping 10 matching lines...) Expand all Loading... |
499 | 499 |
500 // Semi-fast case: Unioned objects are neither involved nor produced. | 500 // Semi-fast case: Unioned objects are neither involved nor produced. |
501 if (!(type1->IsUnion() || type2->IsUnion())) { | 501 if (!(type1->IsUnion() || type2->IsUnion())) { |
502 if (type1->Is(type2)) return type1; | 502 if (type1->Is(type2)) return type1; |
503 if (type2->Is(type1)) return type2; | 503 if (type2->Is(type1)) return type2; |
504 } | 504 } |
505 | 505 |
506 // Slow case: may need to produce a Unioned object. | 506 // Slow case: may need to produce a Unioned object. |
507 int size = INT_MAX; | 507 int size = INT_MAX; |
508 if (!type1->IsBitset()) { | 508 if (!type1->IsBitset()) { |
509 size = (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1); | 509 size = (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1); |
510 } | 510 } |
511 if (!type2->IsBitset()) { | 511 if (!type2->IsBitset()) { |
512 size = Min(size, | 512 size = Min(size, |
513 type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1); | 513 type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1); |
514 } | 514 } |
515 int bitset = type1->GlbBitset() & type2->GlbBitset(); | 515 int bitset = type1->GlbBitset() & type2->GlbBitset(); |
516 if (IsInhabited(bitset)) ++size; | 516 if (IsInhabited(bitset)) ++size; |
517 ASSERT(size >= 1); | 517 ASSERT(size >= 1); |
518 UnionedHandle unioned = Config::union_create(size, region); | 518 StructHandle unioned = Config::struct_create(kUnionTag, size, region); |
519 | 519 |
520 size = 0; | 520 size = 0; |
521 if (IsInhabited(bitset)) { | 521 if (IsInhabited(bitset)) { |
522 Config::union_set(unioned, size++, Config::from_bitset(bitset, region)); | 522 Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); |
523 } | 523 } |
524 size = ExtendIntersection(unioned, type1, type2, size); | 524 size = ExtendIntersection(unioned, type1, type2, size); |
525 size = ExtendIntersection(unioned, type2, type1, size); | 525 size = ExtendIntersection(unioned, type2, type1, size); |
526 | 526 |
527 if (size == 0) { | 527 if (size == 0) { |
528 return None(region); | 528 return None(region); |
529 } else if (size == 1) { | 529 } else if (size == 1) { |
530 return Config::union_get(unioned, 0); | 530 return Config::struct_get(unioned, 0); |
531 } else { | 531 } else { |
532 Config::union_shrink(unioned, size); | 532 Config::struct_shrink(unioned, size); |
533 return Config::from_union(unioned); | 533 return Config::from_struct(unioned); |
534 } | 534 } |
535 } | 535 } |
536 | 536 |
537 | 537 |
538 template<class Config> | 538 template<class Config> |
539 template<class OtherType> | 539 template<class OtherType> |
540 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( | 540 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( |
541 typename OtherType::TypeHandle type, Region* region) { | 541 typename OtherType::TypeHandle type, Region* region) { |
542 if (type->IsBitset()) { | 542 if (type->IsBitset()) { |
543 return Config::from_bitset(type->AsBitset(), region); | 543 return Config::from_bitset(type->AsBitset(), region); |
544 } else if (type->IsClass()) { | 544 } else if (type->IsClass()) { |
545 return Config::from_class(type->AsClass(), type->LubBitset(), region); | 545 return Config::from_class(type->AsClass(), type->LubBitset(), region); |
546 } else if (type->IsConstant()) { | 546 } else if (type->IsConstant()) { |
547 return Config::from_constant(type->AsConstant(), type->LubBitset(), region); | 547 return Config::from_constant(type->AsConstant(), type->LubBitset(), region); |
548 } else { | 548 } else { |
549 ASSERT(type->IsUnion()); | 549 ASSERT(type->IsUnion()); |
550 typename OtherType::UnionedHandle unioned = type->AsUnion(); | 550 typename OtherType::StructHandle unioned = type->AsUnion(); |
551 int length = OtherType::UnionLength(unioned); | 551 int length = OtherType::StructLength(unioned); |
552 UnionedHandle new_unioned = Config::union_create(length, region); | 552 StructHandle new_unioned = Config::struct_create(kUnionTag, length, region); |
553 for (int i = 0; i < length; ++i) { | 553 for (int i = 0; i < length; ++i) { |
554 Config::union_set(new_unioned, i, | 554 Config::struct_set(new_unioned, i, |
555 Convert<OtherType>(OtherType::UnionGet(unioned, i), region)); | 555 Convert<OtherType>(OtherType::StructGet(unioned, i), region)); |
556 } | 556 } |
557 return Config::from_union(new_unioned); | 557 return Config::from_struct(new_unioned); |
558 } | 558 } |
559 } | 559 } |
560 | 560 |
561 | 561 |
562 // TODO(rossberg): this does not belong here. | 562 // TODO(rossberg): this does not belong here. |
563 Representation Representation::FromType(Type* type) { | 563 Representation Representation::FromType(Type* type) { |
564 if (type->Is(Type::None())) return Representation::None(); | 564 if (type->Is(Type::None())) return Representation::None(); |
565 if (type->Is(Type::SignedSmall())) return Representation::Smi(); | 565 if (type->Is(Type::SignedSmall())) return Representation::Smi(); |
566 if (type->Is(Type::Signed32())) return Representation::Integer32(); | 566 if (type->Is(Type::Signed32())) return Representation::Integer32(); |
567 if (type->Is(Type::Number())) return Representation::Double(); | 567 if (type->Is(Type::Number())) return Representation::Double(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 } else if (this->IsConstant()) { | 650 } else if (this->IsConstant()) { |
651 PrintF(out, "Constant(%p : ", static_cast<void*>(*this->AsConstant())); | 651 PrintF(out, "Constant(%p : ", static_cast<void*>(*this->AsConstant())); |
652 Config::from_bitset(this->LubBitset())->TypePrint(out, dim); | 652 Config::from_bitset(this->LubBitset())->TypePrint(out, dim); |
653 PrintF(out, ")"); | 653 PrintF(out, ")"); |
654 } else if (this->IsClass()) { | 654 } else if (this->IsClass()) { |
655 PrintF(out, "Class(%p < ", static_cast<void*>(*this->AsClass())); | 655 PrintF(out, "Class(%p < ", static_cast<void*>(*this->AsClass())); |
656 Config::from_bitset(this->LubBitset())->TypePrint(out, dim); | 656 Config::from_bitset(this->LubBitset())->TypePrint(out, dim); |
657 PrintF(out, ")"); | 657 PrintF(out, ")"); |
658 } else if (this->IsUnion()) { | 658 } else if (this->IsUnion()) { |
659 PrintF(out, "("); | 659 PrintF(out, "("); |
660 UnionedHandle unioned = this->AsUnion(); | 660 StructHandle unioned = this->AsUnion(); |
661 for (int i = 0; i < Config::union_length(unioned); ++i) { | 661 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
662 TypeHandle type_i = Config::union_get(unioned, i); | 662 TypeHandle type_i = Config::struct_get(unioned, i); |
663 if (i > 0) PrintF(out, " | "); | 663 if (i > 0) PrintF(out, " | "); |
664 type_i->TypePrint(out, dim); | 664 type_i->TypePrint(out, dim); |
665 } | 665 } |
666 PrintF(out, ")"); | 666 PrintF(out, ")"); |
667 } | 667 } |
668 } | 668 } |
669 | 669 |
670 | 670 |
671 template class TypeImpl<ZoneTypeConfig>; | 671 template class TypeImpl<ZoneTypeConfig>; |
672 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>; | 672 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>; |
673 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>; | 673 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>; |
674 | 674 |
675 template class TypeImpl<HeapTypeConfig>; | 675 template class TypeImpl<HeapTypeConfig>; |
676 template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>; | 676 template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>; |
677 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 677 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
678 | 678 |
679 template TypeImpl<ZoneTypeConfig>::TypeHandle | 679 template TypeImpl<ZoneTypeConfig>::TypeHandle |
680 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 680 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
681 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 681 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
682 template TypeImpl<HeapTypeConfig>::TypeHandle | 682 template TypeImpl<HeapTypeConfig>::TypeHandle |
683 TypeImpl<HeapTypeConfig>::Convert<Type>( | 683 TypeImpl<HeapTypeConfig>::Convert<Type>( |
684 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 684 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
685 | 685 |
686 } } // namespace v8::internal | 686 } } // namespace v8::internal |
OLD | NEW |