| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 233 } |
| 233 | 234 |
| 234 | 235 |
| 235 // Get the largest bitset subsumed by this type. | 236 // Get the largest bitset subsumed by this type. |
| 236 template<class Config> | 237 template<class Config> |
| 237 int TypeImpl<Config>::GlbBitset() { | 238 int TypeImpl<Config>::GlbBitset() { |
| 238 if (this->IsBitset()) { | 239 if (this->IsBitset()) { |
| 239 return this->AsBitset(); | 240 return this->AsBitset(); |
| 240 } else if (this->IsUnion()) { | 241 } else if (this->IsUnion()) { |
| 241 // All but the first are non-bitsets and thus would yield kNone anyway. | 242 // All but the first are non-bitsets and thus would yield kNone anyway. |
| 242 return Config::union_get(this->AsUnion(), 0)->GlbBitset(); | 243 return Config::struct_get(this->AsUnion(), 0)->GlbBitset(); |
| 243 } else { | 244 } else { |
| 244 return kNone; | 245 return kNone; |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 248 | 249 |
| 249 // Most precise _current_ type of a value (usually its class). | 250 // Most precise _current_ type of a value (usually its class). |
| 250 template<class Config> | 251 template<class Config> |
| 251 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NowOf( | 252 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::NowOf( |
| 252 i::Object* value, Region* region) { | 253 i::Object* value, Region* region) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 270 | 271 |
| 271 if (that->IsClass()) { | 272 if (that->IsClass()) { |
| 272 return this->IsClass() && *this->AsClass() == *that->AsClass(); | 273 return this->IsClass() && *this->AsClass() == *that->AsClass(); |
| 273 } | 274 } |
| 274 if (that->IsConstant()) { | 275 if (that->IsConstant()) { |
| 275 return this->IsConstant() && *this->AsConstant() == *that->AsConstant(); | 276 return this->IsConstant() && *this->AsConstant() == *that->AsConstant(); |
| 276 } | 277 } |
| 277 | 278 |
| 278 // (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T) | 279 // (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T) |
| 279 if (this->IsUnion()) { | 280 if (this->IsUnion()) { |
| 280 UnionedHandle unioned = this->AsUnion(); | 281 StructHandle unioned = this->AsUnion(); |
| 281 for (int i = 0; i < Config::union_length(unioned); ++i) { | 282 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
| 282 TypeHandle this_i = Config::union_get(unioned, i); | 283 TypeHandle this_i = Config::struct_get(unioned, i); |
| 283 if (!this_i->Is(that)) return false; | 284 if (!this_i->Is(that)) return false; |
| 284 } | 285 } |
| 285 return true; | 286 return true; |
| 286 } | 287 } |
| 287 | 288 |
| 288 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) | 289 // T <= (T1 \/ ... \/ Tn) <=> (T <= T1) \/ ... \/ (T <= Tn) |
| 289 // (iff T is not a union) | 290 // (iff T is not a union) |
| 290 ASSERT(!this->IsUnion()); | 291 ASSERT(!this->IsUnion()); |
| 291 if (that->IsUnion()) { | 292 if (that->IsUnion()) { |
| 292 UnionedHandle unioned = that->AsUnion(); | 293 StructHandle unioned = that->AsUnion(); |
| 293 for (int i = 0; i < Config::union_length(unioned); ++i) { | 294 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
| 294 TypeHandle that_i = Config::union_get(unioned, i); | 295 TypeHandle that_i = Config::struct_get(unioned, i); |
| 295 if (this->Is(that_i)) return true; | 296 if (this->Is(that_i)) return true; |
| 296 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. |
| 297 } | 298 } |
| 298 return false; | 299 return false; |
| 299 } | 300 } |
| 300 | 301 |
| 301 return false; | 302 return false; |
| 302 } | 303 } |
| 303 | 304 |
| 304 | 305 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 317 // Fast path for bitsets. | 318 // Fast path for bitsets. |
| 318 if (this->IsBitset()) { | 319 if (this->IsBitset()) { |
| 319 return IsInhabited(this->AsBitset() & that->LubBitset()); | 320 return IsInhabited(this->AsBitset() & that->LubBitset()); |
| 320 } | 321 } |
| 321 if (that->IsBitset()) { | 322 if (that->IsBitset()) { |
| 322 return IsInhabited(this->LubBitset() & that->AsBitset()); | 323 return IsInhabited(this->LubBitset() & that->AsBitset()); |
| 323 } | 324 } |
| 324 | 325 |
| 325 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) | 326 // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) |
| 326 if (this->IsUnion()) { | 327 if (this->IsUnion()) { |
| 327 UnionedHandle unioned = this->AsUnion(); | 328 StructHandle unioned = this->AsUnion(); |
| 328 for (int i = 0; i < Config::union_length(unioned); ++i) { | 329 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
| 329 TypeHandle this_i = Config::union_get(unioned, i); | 330 TypeHandle this_i = Config::struct_get(unioned, i); |
| 330 if (this_i->Maybe(that)) return true; | 331 if (this_i->Maybe(that)) return true; |
| 331 } | 332 } |
| 332 return false; | 333 return false; |
| 333 } | 334 } |
| 334 | 335 |
| 335 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) | 336 // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) |
| 336 if (that->IsUnion()) { | 337 if (that->IsUnion()) { |
| 337 UnionedHandle unioned = that->AsUnion(); | 338 StructHandle unioned = that->AsUnion(); |
| 338 for (int i = 0; i < Config::union_length(unioned); ++i) { | 339 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
| 339 TypeHandle that_i = Config::union_get(unioned, i); | 340 TypeHandle that_i = Config::struct_get(unioned, i); |
| 340 if (this->Maybe(that_i)) return true; | 341 if (this->Maybe(that_i)) return true; |
| 341 } | 342 } |
| 342 return false; | 343 return false; |
| 343 } | 344 } |
| 344 | 345 |
| 345 ASSERT(!this->IsUnion() && !that->IsUnion()); | 346 ASSERT(!this->IsUnion() && !that->IsUnion()); |
| 346 if (this->IsClass()) { | 347 if (this->IsClass()) { |
| 347 return that->IsClass() && *this->AsClass() == *that->AsClass(); | 348 return that->IsClass() && *this->AsClass() == *that->AsClass(); |
| 348 } | 349 } |
| 349 if (this->IsConstant()) { | 350 if (this->IsConstant()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 365 | 366 |
| 366 template<class Config> | 367 template<class Config> |
| 367 bool TypeImpl<Config>::NowContains(i::Object* value) { | 368 bool TypeImpl<Config>::NowContains(i::Object* value) { |
| 368 return this->Contains(value) || | 369 return this->Contains(value) || |
| 369 (this->IsClass() && value->IsHeapObject() && | 370 (this->IsClass() && value->IsHeapObject() && |
| 370 *this->AsClass() == i::HeapObject::cast(value)->map()); | 371 *this->AsClass() == i::HeapObject::cast(value)->map()); |
| 371 } | 372 } |
| 372 | 373 |
| 373 | 374 |
| 374 template<class Config> | 375 template<class Config> |
| 375 bool TypeImpl<Config>::InUnion(UnionedHandle unioned, int current_size) { | 376 bool TypeImpl<Config>::InUnion(StructHandle unioned, int current_size) { |
| 376 ASSERT(!this->IsUnion()); | 377 ASSERT(!this->IsUnion()); |
| 377 for (int i = 0; i < current_size; ++i) { | 378 for (int i = 0; i < current_size; ++i) { |
| 378 TypeHandle type = Config::union_get(unioned, i); | 379 TypeHandle type = Config::struct_get(unioned, i); |
| 379 if (this->Is(type)) return true; | 380 if (this->Is(type)) return true; |
| 380 } | 381 } |
| 381 return false; | 382 return false; |
| 382 } | 383 } |
| 383 | 384 |
| 384 | 385 |
| 385 // Get non-bitsets from this which are not subsumed by union, store at unioned, | 386 // Get non-bitsets from this which are not subsumed by union, store at result, |
| 386 // starting at index. Returns updated index. | 387 // starting at index. Returns updated index. |
| 387 template<class Config> | 388 template<class Config> |
| 388 int TypeImpl<Config>::ExtendUnion( | 389 int TypeImpl<Config>::ExtendUnion( |
| 389 UnionedHandle result, TypeHandle type, int current_size) { | 390 StructHandle result, TypeHandle type, int current_size) { |
| 390 int old_size = current_size; | 391 int old_size = current_size; |
| 391 if (type->IsClass() || type->IsConstant()) { | 392 if (type->IsClass() || type->IsConstant()) { |
| 392 if (!type->InUnion(result, old_size)) { | 393 if (!type->InUnion(result, old_size)) { |
| 393 Config::union_set(result, current_size++, type); | 394 Config::struct_set(result, current_size++, type); |
| 394 } | 395 } |
| 395 } else if (type->IsUnion()) { | 396 } else if (type->IsUnion()) { |
| 396 UnionedHandle unioned = type->AsUnion(); | 397 StructHandle unioned = type->AsUnion(); |
| 397 for (int i = 0; i < Config::union_length(unioned); ++i) { | 398 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
| 398 TypeHandle type = Config::union_get(unioned, i); | 399 TypeHandle type = Config::struct_get(unioned, i); |
| 399 ASSERT(i == 0 || | 400 ASSERT(i == 0 || |
| 400 !(type->IsBitset() || type->Is(Config::union_get(unioned, 0)))); | 401 !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); |
| 401 if (!type->IsBitset() && !type->InUnion(result, old_size)) { | 402 if (!type->IsBitset() && !type->InUnion(result, old_size)) { |
| 402 Config::union_set(result, current_size++, type); | 403 Config::struct_set(result, current_size++, type); |
| 403 } | 404 } |
| 404 } | 405 } |
| 405 } | 406 } |
| 406 return current_size; | 407 return current_size; |
| 407 } | 408 } |
| 408 | 409 |
| 409 | 410 |
| 410 // 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. |
| 411 // TODO(rossberg): Should we use object sets somehow? Is it worth it? | |
| 412 template<class Config> | 412 template<class Config> |
| 413 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( | 413 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( |
| 414 TypeHandle type1, TypeHandle type2, Region* region) { | 414 TypeHandle type1, TypeHandle type2, Region* region) { |
| 415 // Fast case: bit sets. | 415 // Fast case: bit sets. |
| 416 if (type1->IsBitset() && type2->IsBitset()) { | 416 if (type1->IsBitset() && type2->IsBitset()) { |
| 417 return Config::from_bitset(type1->AsBitset() | type2->AsBitset(), region); | 417 return Config::from_bitset(type1->AsBitset() | type2->AsBitset(), region); |
| 418 } | 418 } |
| 419 | 419 |
| 420 // Fast case: top or bottom types. | 420 // Fast case: top or bottom types. |
| 421 if (type1->IsAny() || type2->IsNone()) return type1; | 421 if (type1->IsAny() || type2->IsNone()) return type1; |
| 422 if (type2->IsAny() || type1->IsNone()) return type2; | 422 if (type2->IsAny() || type1->IsNone()) return type2; |
| 423 | 423 |
| 424 // Semi-fast case: Unioned objects are neither involved nor produced. | 424 // Semi-fast case: Unioned objects are neither involved nor produced. |
| 425 if (!(type1->IsUnion() || type2->IsUnion())) { | 425 if (!(type1->IsUnion() || type2->IsUnion())) { |
| 426 if (type1->Is(type2)) return type2; | 426 if (type1->Is(type2)) return type2; |
| 427 if (type2->Is(type1)) return type1; | 427 if (type2->Is(type1)) return type1; |
| 428 } | 428 } |
| 429 | 429 |
| 430 // Slow case: may need to produce a Unioned object. | 430 // Slow case: may need to produce a Unioned object. |
| 431 int size = 0; | 431 int size = 0; |
| 432 if (!type1->IsBitset()) { | 432 if (!type1->IsBitset()) { |
| 433 size += (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1); | 433 size += (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1); |
| 434 } | 434 } |
| 435 if (!type2->IsBitset()) { | 435 if (!type2->IsBitset()) { |
| 436 size += (type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1); | 436 size += (type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1); |
| 437 } | 437 } |
| 438 int bitset = type1->GlbBitset() | type2->GlbBitset(); | 438 int bitset = type1->GlbBitset() | type2->GlbBitset(); |
| 439 if (IsInhabited(bitset)) ++size; | 439 if (IsInhabited(bitset)) ++size; |
| 440 ASSERT(size >= 1); | 440 ASSERT(size >= 1); |
| 441 UnionedHandle unioned = Config::union_create(size, region); | 441 StructHandle unioned = Config::struct_create(kUnionTag, size, region); |
| 442 | 442 |
| 443 size = 0; | 443 size = 0; |
| 444 if (IsInhabited(bitset)) { | 444 if (IsInhabited(bitset)) { |
| 445 Config::union_set(unioned, size++, Config::from_bitset(bitset, region)); | 445 Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); |
| 446 } | 446 } |
| 447 size = ExtendUnion(unioned, type1, size); | 447 size = ExtendUnion(unioned, type1, size); |
| 448 size = ExtendUnion(unioned, type2, size); | 448 size = ExtendUnion(unioned, type2, size); |
| 449 | 449 |
| 450 if (size == 1) { | 450 if (size == 1) { |
| 451 return Config::union_get(unioned, 0); | 451 return Config::struct_get(unioned, 0); |
| 452 } else { | 452 } else { |
| 453 Config::union_shrink(unioned, size); | 453 Config::struct_shrink(unioned, size); |
| 454 return Config::from_union(unioned); | 454 return Config::from_struct(unioned); |
| 455 } | 455 } |
| 456 } | 456 } |
| 457 | 457 |
| 458 | 458 |
| 459 // Get non-bitsets from type which are also in other, store at unioned, | 459 // Get non-bitsets from type which are also in other, store at result, |
| 460 // starting at index. Returns updated index. | 460 // starting at index. Returns updated index. |
| 461 template<class Config> | 461 template<class Config> |
| 462 int TypeImpl<Config>::ExtendIntersection( | 462 int TypeImpl<Config>::ExtendIntersection( |
| 463 UnionedHandle result, TypeHandle type, TypeHandle other, int current_size) { | 463 StructHandle result, TypeHandle type, TypeHandle other, int current_size) { |
| 464 int old_size = current_size; | 464 int old_size = current_size; |
| 465 if (type->IsClass() || type->IsConstant()) { | 465 if (type->IsClass() || type->IsConstant()) { |
| 466 if (type->Is(other) && !type->InUnion(result, old_size)) { | 466 if (type->Is(other) && !type->InUnion(result, old_size)) { |
| 467 Config::union_set(result, current_size++, type); | 467 Config::struct_set(result, current_size++, type); |
| 468 } | 468 } |
| 469 } else if (type->IsUnion()) { | 469 } else if (type->IsUnion()) { |
| 470 UnionedHandle unioned = type->AsUnion(); | 470 StructHandle unioned = type->AsUnion(); |
| 471 for (int i = 0; i < Config::union_length(unioned); ++i) { | 471 for (int i = 0; i < Config::struct_length(unioned); ++i) { |
| 472 TypeHandle type = Config::union_get(unioned, i); | 472 TypeHandle type = Config::struct_get(unioned, i); |
| 473 ASSERT(i == 0 || | 473 ASSERT(i == 0 || |
| 474 !(type->IsBitset() || type->Is(Config::union_get(unioned, 0)))); | 474 !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); |
| 475 if (!type->IsBitset() && type->Is(other) && | 475 if (!type->IsBitset() && type->Is(other) && |
| 476 !type->InUnion(result, old_size)) { | 476 !type->InUnion(result, old_size)) { |
| 477 Config::union_set(result, current_size++, type); | 477 Config::struct_set(result, current_size++, type); |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 return current_size; | 481 return current_size; |
| 482 } | 482 } |
| 483 | 483 |
| 484 | 484 |
| 485 // Intersection is O(1) on simple bit unions, but O(n*m) on structured unions. | 485 // Intersection is O(1) on simple bit unions, but O(n*m) on structured unions. |
| 486 // TODO(rossberg): Should we use object sets somehow? Is it worth it? | 486 // TODO(rossberg): Should we use object sets somehow? Is it worth it? |
| 487 template<class Config> | 487 template<class Config> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 498 | 498 |
| 499 // Semi-fast case: Unioned objects are neither involved nor produced. | 499 // Semi-fast case: Unioned objects are neither involved nor produced. |
| 500 if (!(type1->IsUnion() || type2->IsUnion())) { | 500 if (!(type1->IsUnion() || type2->IsUnion())) { |
| 501 if (type1->Is(type2)) return type1; | 501 if (type1->Is(type2)) return type1; |
| 502 if (type2->Is(type1)) return type2; | 502 if (type2->Is(type1)) return type2; |
| 503 } | 503 } |
| 504 | 504 |
| 505 // Slow case: may need to produce a Unioned object. | 505 // Slow case: may need to produce a Unioned object. |
| 506 int size = INT_MAX; | 506 int size = INT_MAX; |
| 507 if (!type1->IsBitset()) { | 507 if (!type1->IsBitset()) { |
| 508 size = (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1); | 508 size = (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1); |
| 509 } | 509 } |
| 510 if (!type2->IsBitset()) { | 510 if (!type2->IsBitset()) { |
| 511 size = Min(size, | 511 size = Min(size, |
| 512 type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1); | 512 type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1); |
| 513 } | 513 } |
| 514 int bitset = type1->GlbBitset() & type2->GlbBitset(); | 514 int bitset = type1->GlbBitset() & type2->GlbBitset(); |
| 515 if (IsInhabited(bitset)) ++size; | 515 if (IsInhabited(bitset)) ++size; |
| 516 ASSERT(size >= 1); | 516 ASSERT(size >= 1); |
| 517 UnionedHandle unioned = Config::union_create(size, region); | 517 StructHandle unioned = Config::struct_create(kUnionTag, size, region); |
| 518 | 518 |
| 519 size = 0; | 519 size = 0; |
| 520 if (IsInhabited(bitset)) { | 520 if (IsInhabited(bitset)) { |
| 521 Config::union_set(unioned, size++, Config::from_bitset(bitset, region)); | 521 Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); |
| 522 } | 522 } |
| 523 size = ExtendIntersection(unioned, type1, type2, size); | 523 size = ExtendIntersection(unioned, type1, type2, size); |
| 524 size = ExtendIntersection(unioned, type2, type1, size); | 524 size = ExtendIntersection(unioned, type2, type1, size); |
| 525 | 525 |
| 526 if (size == 0) { | 526 if (size == 0) { |
| 527 return None(region); | 527 return None(region); |
| 528 } else if (size == 1) { | 528 } else if (size == 1) { |
| 529 return Config::union_get(unioned, 0); | 529 return Config::struct_get(unioned, 0); |
| 530 } else { | 530 } else { |
| 531 Config::union_shrink(unioned, size); | 531 Config::struct_shrink(unioned, size); |
| 532 return Config::from_union(unioned); | 532 return Config::from_struct(unioned); |
| 533 } | 533 } |
| 534 } | 534 } |
| 535 | 535 |
| 536 | 536 |
| 537 template<class Config> | 537 template<class Config> |
| 538 template<class OtherType> | 538 template<class OtherType> |
| 539 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( | 539 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( |
| 540 typename OtherType::TypeHandle type, Region* region) { | 540 typename OtherType::TypeHandle type, Region* region) { |
| 541 if (type->IsBitset()) { | 541 if (type->IsBitset()) { |
| 542 return Config::from_bitset(type->AsBitset(), region); | 542 return Config::from_bitset(type->AsBitset(), region); |
| 543 } else if (type->IsClass()) { | 543 } else if (type->IsClass()) { |
| 544 return Config::from_class(type->AsClass(), type->LubBitset(), region); | 544 return Config::from_class(type->AsClass(), type->LubBitset(), region); |
| 545 } else if (type->IsConstant()) { | 545 } else if (type->IsConstant()) { |
| 546 return Config::from_constant(type->AsConstant(), type->LubBitset(), region); | 546 return Config::from_constant(type->AsConstant(), type->LubBitset(), region); |
| 547 } else { | 547 } else { |
| 548 ASSERT(type->IsUnion()); | 548 ASSERT(type->IsUnion()); |
| 549 typename OtherType::UnionedHandle unioned = type->AsUnion(); | 549 typename OtherType::StructHandle unioned = type->AsUnion(); |
| 550 int length = OtherType::UnionLength(unioned); | 550 int length = OtherType::StructLength(unioned); |
| 551 UnionedHandle new_unioned = Config::union_create(length, region); | 551 StructHandle new_unioned = Config::struct_create(kUnionTag, length, region); |
| 552 for (int i = 0; i < length; ++i) { | 552 for (int i = 0; i < length; ++i) { |
| 553 Config::union_set(new_unioned, i, | 553 Config::struct_set(new_unioned, i, |
| 554 Convert<OtherType>(OtherType::UnionGet(unioned, i), region)); | 554 Convert<OtherType>(OtherType::StructGet(unioned, i), region)); |
| 555 } | 555 } |
| 556 return Config::from_union(new_unioned); | 556 return Config::from_struct(new_unioned); |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 | 559 |
| 560 | 560 |
| 561 // TODO(rossberg): this does not belong here. | 561 // TODO(rossberg): this does not belong here. |
| 562 Representation Representation::FromType(Type* type) { | 562 Representation Representation::FromType(Type* type) { |
| 563 if (type->Is(Type::None())) return Representation::None(); | 563 if (type->Is(Type::None())) return Representation::None(); |
| 564 if (type->Is(Type::SignedSmall())) return Representation::Smi(); | 564 if (type->Is(Type::SignedSmall())) return Representation::Smi(); |
| 565 if (type->Is(Type::Signed32())) return Representation::Integer32(); | 565 if (type->Is(Type::Signed32())) return Representation::Integer32(); |
| 566 if (type->Is(Type::Number())) return Representation::Double(); | 566 if (type->Is(Type::Number())) return Representation::Double(); |
| (...skipping 83 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); | 652 Config::from_bitset(this->LubBitset())->TypePrint(out); |
| 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); | 656 Config::from_bitset(this->LubBitset())->TypePrint(out); |
| 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 #endif | 669 #endif |
| 670 | 670 |
| 671 | 671 |
| 672 template class TypeImpl<ZoneTypeConfig>; | 672 template class TypeImpl<ZoneTypeConfig>; |
| 673 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>; | 673 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>; |
| 674 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>; | 674 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>; |
| 675 | 675 |
| 676 template class TypeImpl<HeapTypeConfig>; | 676 template class TypeImpl<HeapTypeConfig>; |
| 677 template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>; | 677 template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>; |
| 678 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 678 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
| 679 | 679 |
| 680 template TypeImpl<ZoneTypeConfig>::TypeHandle | 680 template TypeImpl<ZoneTypeConfig>::TypeHandle |
| 681 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 681 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
| 682 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 682 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
| 683 template TypeImpl<HeapTypeConfig>::TypeHandle | 683 template TypeImpl<HeapTypeConfig>::TypeHandle |
| 684 TypeImpl<HeapTypeConfig>::Convert<Type>( | 684 TypeImpl<HeapTypeConfig>::Convert<Type>( |
| 685 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 685 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
| 686 | 686 |
| 687 } } // namespace v8::internal | 687 } } // namespace v8::internal |
| OLD | NEW |