| 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 StructHandle unioned = this->AsUnion(); | 18 UnionedHandle unioned = this->AsUnion(); |
| 19 int result = 0; | 19 int result = 0; |
| 20 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 20 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 21 if (Config::struct_get(unioned, i)->IsClass()) ++result; | 21 if (Config::union_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 StructHandle unioned = this->AsUnion(); | 35 UnionedHandle unioned = this->AsUnion(); |
| 36 int result = 0; | 36 int result = 0; |
| 37 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 37 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 38 if (Config::struct_get(unioned, i)->IsConstant()) ++result; | 38 if (Config::union_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() | 51 return type_->IsUnion() ? Config::union_get(type_->AsUnion(), index_) : type_; |
| 52 ? Config::struct_get(type_->AsUnion(), index_) : type_; | |
| 53 } | 52 } |
| 54 | 53 |
| 55 | 54 |
| 56 // C++ cannot specialise nested templates, so we have to go through this | 55 // C++ cannot specialise nested templates, so we have to go through this |
| 57 // contortion with an auxiliary template to simulate it. | 56 // contortion with an auxiliary template to simulate it. |
| 58 template<class Config, class T> | 57 template<class Config, class T> |
| 59 struct TypeImplIteratorAux { | 58 struct TypeImplIteratorAux { |
| 60 static bool matches(typename TypeImpl<Config>::TypeHandle type); | 59 static bool matches(typename TypeImpl<Config>::TypeHandle type); |
| 61 static i::Handle<T> current(typename TypeImpl<Config>::TypeHandle type); | 60 static i::Handle<T> current(typename TypeImpl<Config>::TypeHandle type); |
| 62 }; | 61 }; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 90 template<class Config> template<class T> | 89 template<class Config> template<class T> |
| 91 i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() { | 90 i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() { |
| 92 return TypeImplIteratorAux<Config, T>::current(get_type()); | 91 return TypeImplIteratorAux<Config, T>::current(get_type()); |
| 93 } | 92 } |
| 94 | 93 |
| 95 | 94 |
| 96 template<class Config> template<class T> | 95 template<class Config> template<class T> |
| 97 void TypeImpl<Config>::Iterator<T>::Advance() { | 96 void TypeImpl<Config>::Iterator<T>::Advance() { |
| 98 ++index_; | 97 ++index_; |
| 99 if (type_->IsUnion()) { | 98 if (type_->IsUnion()) { |
| 100 StructHandle unioned = type_->AsUnion(); | 99 UnionedHandle unioned = type_->AsUnion(); |
| 101 for (; index_ < Config::struct_length(unioned); ++index_) { | 100 for (; index_ < Config::union_length(unioned); ++index_) { |
| 102 if (matches(Config::struct_get(unioned, index_))) return; | 101 if (matches(Config::union_get(unioned, index_))) return; |
| 103 } | 102 } |
| 104 } else if (index_ == 0 && matches(type_)) { | 103 } else if (index_ == 0 && matches(type_)) { |
| 105 return; | 104 return; |
| 106 } | 105 } |
| 107 index_ = -1; | 106 index_ = -1; |
| 108 } | 107 } |
| 109 | 108 |
| 110 | 109 |
| 111 // Get the smallest bitset subsuming this type. | 110 // Get the smallest bitset subsuming this type. |
| 112 template<class Config> | 111 template<class Config> |
| 113 int TypeImpl<Config>::LubBitset() { | 112 int TypeImpl<Config>::LubBitset() { |
| 114 if (this->IsBitset()) { | 113 if (this->IsBitset()) { |
| 115 return this->AsBitset(); | 114 return this->AsBitset(); |
| 116 } else if (this->IsUnion()) { | 115 } else if (this->IsUnion()) { |
| 117 StructHandle unioned = this->AsUnion(); | 116 UnionedHandle unioned = this->AsUnion(); |
| 118 int bitset = kNone; | 117 int bitset = kNone; |
| 119 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 118 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 120 bitset |= Config::struct_get(unioned, i)->LubBitset(); | 119 bitset |= Config::union_get(unioned, i)->LubBitset(); |
| 121 } | 120 } |
| 122 return bitset; | 121 return bitset; |
| 123 } else if (this->IsClass()) { | 122 } else if (this->IsClass()) { |
| 124 int bitset = Config::lub_bitset(this); | 123 int bitset = Config::lub_bitset(this); |
| 125 return bitset ? bitset : LubBitset(*this->AsClass()); | 124 return bitset ? bitset : LubBitset(*this->AsClass()); |
| 126 } else { | 125 } else { |
| 127 int bitset = Config::lub_bitset(this); | 126 int bitset = Config::lub_bitset(this); |
| 128 return bitset ? bitset : LubBitset(*this->AsConstant()); | 127 return bitset ? bitset : LubBitset(*this->AsConstant()); |
| 129 } | 128 } |
| 130 } | 129 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 234 } |
| 236 | 235 |
| 237 | 236 |
| 238 // Get the largest bitset subsumed by this type. | 237 // Get the largest bitset subsumed by this type. |
| 239 template<class Config> | 238 template<class Config> |
| 240 int TypeImpl<Config>::GlbBitset() { | 239 int TypeImpl<Config>::GlbBitset() { |
| 241 if (this->IsBitset()) { | 240 if (this->IsBitset()) { |
| 242 return this->AsBitset(); | 241 return this->AsBitset(); |
| 243 } else if (this->IsUnion()) { | 242 } else if (this->IsUnion()) { |
| 244 // All but the first are non-bitsets and thus would yield kNone anyway. | 243 // All but the first are non-bitsets and thus would yield kNone anyway. |
| 245 return Config::struct_get(this->AsUnion(), 0)->GlbBitset(); | 244 return Config::union_get(this->AsUnion(), 0)->GlbBitset(); |
| 246 } else { | 245 } else { |
| 247 return kNone; | 246 return kNone; |
| 248 } | 247 } |
| 249 } | 248 } |
| 250 | 249 |
| 251 | 250 |
| 252 // Most precise _current_ type of a value (usually its class). | 251 // Most precise _current_ type of a value (usually its class). |
| 253 template<class Config> | 252 template<class Config> |
| 254 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NowOf( | 253 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NowOf( |
| 255 i::Object* value, Region* region) { | 254 i::Object* value, Region* region) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 272 | 271 |
| 273 if (that->IsClass()) { | 272 if (that->IsClass()) { |
| 274 return this->IsClass() && *this->AsClass() == *that->AsClass(); | 273 return this->IsClass() && *this->AsClass() == *that->AsClass(); |
| 275 } | 274 } |
| 276 if (that->IsConstant()) { | 275 if (that->IsConstant()) { |
| 277 return this->IsConstant() && *this->AsConstant() == *that->AsConstant(); | 276 return this->IsConstant() && *this->AsConstant() == *that->AsConstant(); |
| 278 } | 277 } |
| 279 | 278 |
| 280 // (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T) | 279 // (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T) |
| 281 if (this->IsUnion()) { | 280 if (this->IsUnion()) { |
| 282 StructHandle unioned = this->AsUnion(); | 281 UnionedHandle unioned = this->AsUnion(); |
| 283 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 282 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 284 TypeHandle this_i = Config::struct_get(unioned, i); | 283 TypeHandle this_i = Config::union_get(unioned, i); |
| 285 if (!this_i->Is(that)) return false; | 284 if (!this_i->Is(that)) return false; |
| 286 } | 285 } |
| 287 return true; | 286 return true; |
| 288 } | 287 } |
| 289 | 288 |
| 290 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) | 289 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) |
| 291 // (iff T is not a union) | 290 // (iff T is not a union) |
| 292 ASSERT(!this->IsUnion()); | 291 ASSERT(!this->IsUnion()); |
| 293 if (that->IsUnion()) { | 292 if (that->IsUnion()) { |
| 294 StructHandle unioned = that->AsUnion(); | 293 UnionedHandle unioned = that->AsUnion(); |
| 295 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 294 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 296 TypeHandle that_i = Config::struct_get(unioned, i); | 295 TypeHandle that_i = Config::union_get(unioned, i); |
| 297 if (this->Is(that_i)) return true; | 296 if (this->Is(that_i)) return true; |
| 298 if (this->IsBitset()) break; // Fast fail, only first field is a bitset. | 297 if (this->IsBitset()) break; // Fast fail, only first field is a bitset. |
| 299 } | 298 } |
| 300 return false; | 299 return false; |
| 301 } | 300 } |
| 302 | 301 |
| 303 return false; | 302 return false; |
| 304 } | 303 } |
| 305 | 304 |
| 306 | 305 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 319 // Fast path for bitsets. | 318 // Fast path for bitsets. |
| 320 if (this->IsBitset()) { | 319 if (this->IsBitset()) { |
| 321 return IsInhabited(this->AsBitset() & that->LubBitset()); | 320 return IsInhabited(this->AsBitset() & that->LubBitset()); |
| 322 } | 321 } |
| 323 if (that->IsBitset()) { | 322 if (that->IsBitset()) { |
| 324 return IsInhabited(this->LubBitset() & that->AsBitset()); | 323 return IsInhabited(this->LubBitset() & that->AsBitset()); |
| 325 } | 324 } |
| 326 | 325 |
| 327 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) | 326 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) |
| 328 if (this->IsUnion()) { | 327 if (this->IsUnion()) { |
| 329 StructHandle unioned = this->AsUnion(); | 328 UnionedHandle unioned = this->AsUnion(); |
| 330 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 329 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 331 TypeHandle this_i = Config::struct_get(unioned, i); | 330 TypeHandle this_i = Config::union_get(unioned, i); |
| 332 if (this_i->Maybe(that)) return true; | 331 if (this_i->Maybe(that)) return true; |
| 333 } | 332 } |
| 334 return false; | 333 return false; |
| 335 } | 334 } |
| 336 | 335 |
| 337 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) | 336 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) |
| 338 if (that->IsUnion()) { | 337 if (that->IsUnion()) { |
| 339 StructHandle unioned = that->AsUnion(); | 338 UnionedHandle unioned = that->AsUnion(); |
| 340 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 339 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 341 TypeHandle that_i = Config::struct_get(unioned, i); | 340 TypeHandle that_i = Config::union_get(unioned, i); |
| 342 if (this->Maybe(that_i)) return true; | 341 if (this->Maybe(that_i)) return true; |
| 343 } | 342 } |
| 344 return false; | 343 return false; |
| 345 } | 344 } |
| 346 | 345 |
| 347 ASSERT(!this->IsUnion() && !that->IsUnion()); | 346 ASSERT(!this->IsUnion() && !that->IsUnion()); |
| 348 if (this->IsClass()) { | 347 if (this->IsClass()) { |
| 349 return that->IsClass() && *this->AsClass() == *that->AsClass(); | 348 return that->IsClass() && *this->AsClass() == *that->AsClass(); |
| 350 } | 349 } |
| 351 if (this->IsConstant()) { | 350 if (this->IsConstant()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 367 | 366 |
| 368 template<class Config> | 367 template<class Config> |
| 369 bool TypeImpl<Config>::NowContains(i::Object* value) { | 368 bool TypeImpl<Config>::NowContains(i::Object* value) { |
| 370 return this->Contains(value) || | 369 return this->Contains(value) || |
| 371 (this->IsClass() && value->IsHeapObject() && | 370 (this->IsClass() && value->IsHeapObject() && |
| 372 *this->AsClass() == i::HeapObject::cast(value)->map()); | 371 *this->AsClass() == i::HeapObject::cast(value)->map()); |
| 373 } | 372 } |
| 374 | 373 |
| 375 | 374 |
| 376 template<class Config> | 375 template<class Config> |
| 377 bool TypeImpl<Config>::InUnion(StructHandle unioned, int current_size) { | 376 bool TypeImpl<Config>::InUnion(UnionedHandle unioned, int current_size) { |
| 378 ASSERT(!this->IsUnion()); | 377 ASSERT(!this->IsUnion()); |
| 379 for (int i = 0; i < current_size; ++i) { | 378 for (int i = 0; i < current_size; ++i) { |
| 380 TypeHandle type = Config::struct_get(unioned, i); | 379 TypeHandle type = Config::union_get(unioned, i); |
| 381 if (this->Is(type)) return true; | 380 if (this->Is(type)) return true; |
| 382 } | 381 } |
| 383 return false; | 382 return false; |
| 384 } | 383 } |
| 385 | 384 |
| 386 | 385 |
| 387 // Get non-bitsets from this which are not subsumed by union, store at result, | 386 // Get non-bitsets from this which are not subsumed by union, store at unioned, |
| 388 // starting at index. Returns updated index. | 387 // starting at index. Returns updated index. |
| 389 template<class Config> | 388 template<class Config> |
| 390 int TypeImpl<Config>::ExtendUnion( | 389 int TypeImpl<Config>::ExtendUnion( |
| 391 StructHandle result, TypeHandle type, int current_size) { | 390 UnionedHandle result, TypeHandle type, int current_size) { |
| 392 int old_size = current_size; | 391 int old_size = current_size; |
| 393 if (type->IsClass() || type->IsConstant()) { | 392 if (type->IsClass() || type->IsConstant()) { |
| 394 if (!type->InUnion(result, old_size)) { | 393 if (!type->InUnion(result, old_size)) { |
| 395 Config::struct_set(result, current_size++, type); | 394 Config::union_set(result, current_size++, type); |
| 396 } | 395 } |
| 397 } else if (type->IsUnion()) { | 396 } else if (type->IsUnion()) { |
| 398 StructHandle unioned = type->AsUnion(); | 397 UnionedHandle unioned = type->AsUnion(); |
| 399 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 398 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 400 TypeHandle type = Config::struct_get(unioned, i); | 399 TypeHandle type = Config::union_get(unioned, i); |
| 401 ASSERT(i == 0 || | 400 ASSERT(i == 0 || |
| 402 !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); | 401 !(type->IsBitset() || type->Is(Config::union_get(unioned, 0)))); |
| 403 if (!type->IsBitset() && !type->InUnion(result, old_size)) { | 402 if (!type->IsBitset() && !type->InUnion(result, old_size)) { |
| 404 Config::struct_set(result, current_size++, type); | 403 Config::union_set(result, current_size++, type); |
| 405 } | 404 } |
| 406 } | 405 } |
| 407 } | 406 } |
| 408 return current_size; | 407 return current_size; |
| 409 } | 408 } |
| 410 | 409 |
| 411 | 410 |
| 412 // Union is O(1) on simple bit unions, but O(n*m) on structured unions. | 411 // 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::struct_length(type1->AsUnion()) : 1); | 434 size += (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1); |
| 435 } | 435 } |
| 436 if (!type2->IsBitset()) { | 436 if (!type2->IsBitset()) { |
| 437 size += (type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1); | 437 size += (type2->IsUnion() ? Config::union_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 StructHandle unioned = Config::struct_create(kUnionTag, size, region); | 442 UnionedHandle unioned = Config::union_create(size, region); |
| 443 | 443 |
| 444 size = 0; | 444 size = 0; |
| 445 if (IsInhabited(bitset)) { | 445 if (IsInhabited(bitset)) { |
| 446 Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); | 446 Config::union_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::struct_get(unioned, 0); | 452 return Config::union_get(unioned, 0); |
| 453 } else { | 453 } else { |
| 454 Config::struct_shrink(unioned, size); | 454 Config::union_shrink(unioned, size); |
| 455 return Config::from_struct(unioned); | 455 return Config::from_union(unioned); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 | 459 |
| 460 // Get non-bitsets from type which are also in other, store at result, | 460 // Get non-bitsets from type which are also in other, store at unioned, |
| 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 StructHandle result, TypeHandle type, TypeHandle other, int current_size) { | 464 UnionedHandle 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::struct_set(result, current_size++, type); | 468 Config::union_set(result, current_size++, type); |
| 469 } | 469 } |
| 470 } else if (type->IsUnion()) { | 470 } else if (type->IsUnion()) { |
| 471 StructHandle unioned = type->AsUnion(); | 471 UnionedHandle unioned = type->AsUnion(); |
| 472 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 472 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 473 TypeHandle type = Config::struct_get(unioned, i); | 473 TypeHandle type = Config::union_get(unioned, i); |
| 474 ASSERT(i == 0 || | 474 ASSERT(i == 0 || |
| 475 !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); | 475 !(type->IsBitset() || type->Is(Config::union_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::struct_set(result, current_size++, type); | 478 Config::union_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::struct_length(type1->AsUnion()) : 1); | 509 size = (type1->IsUnion() ? Config::union_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::struct_length(type2->AsUnion()) : 1); | 513 type2->IsUnion() ? Config::union_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 StructHandle unioned = Config::struct_create(kUnionTag, size, region); | 518 UnionedHandle unioned = Config::union_create(size, region); |
| 519 | 519 |
| 520 size = 0; | 520 size = 0; |
| 521 if (IsInhabited(bitset)) { | 521 if (IsInhabited(bitset)) { |
| 522 Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); | 522 Config::union_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::struct_get(unioned, 0); | 530 return Config::union_get(unioned, 0); |
| 531 } else { | 531 } else { |
| 532 Config::struct_shrink(unioned, size); | 532 Config::union_shrink(unioned, size); |
| 533 return Config::from_struct(unioned); | 533 return Config::from_union(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::StructHandle unioned = type->AsUnion(); | 550 typename OtherType::UnionedHandle unioned = type->AsUnion(); |
| 551 int length = OtherType::StructLength(unioned); | 551 int length = OtherType::UnionLength(unioned); |
| 552 StructHandle new_unioned = Config::struct_create(kUnionTag, length, region); | 552 UnionedHandle new_unioned = Config::union_create(length, region); |
| 553 for (int i = 0; i < length; ++i) { | 553 for (int i = 0; i < length; ++i) { |
| 554 Config::struct_set(new_unioned, i, | 554 Config::union_set(new_unioned, i, |
| 555 Convert<OtherType>(OtherType::StructGet(unioned, i), region)); | 555 Convert<OtherType>(OtherType::UnionGet(unioned, i), region)); |
| 556 } | 556 } |
| 557 return Config::from_struct(new_unioned); | 557 return Config::from_union(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 StructHandle unioned = this->AsUnion(); | 660 UnionedHandle unioned = this->AsUnion(); |
| 661 for (int i = 0; i < Config::struct_length(unioned); ++i) { | 661 for (int i = 0; i < Config::union_length(unioned); ++i) { |
| 662 TypeHandle type_i = Config::struct_get(unioned, i); | 662 TypeHandle type_i = Config::union_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 |