@@ -423,13 +423,14 @@ class AvailableValueAggregator {
423
423
void print (llvm::raw_ostream &os) const ;
424
424
void dump () const LLVM_ATTRIBUTE_USED;
425
425
private:
426
- SILValue aggregateFullyAvailableValue (SILType LoadTy, unsigned FirstElt);
427
- SILValue aggregateTupleSubElts (TupleType *TT, SILType LoadTy,
428
- SILValue Address, unsigned FirstElt);
429
- SILValue aggregateStructSubElts (StructDecl *SD, SILType LoadTy,
430
- SILValue Address, unsigned FirstElt);
431
- SILValue handlePrimitiveValue (SILType LoadTy, SILValue Address,
432
- unsigned FirstElt);
426
+ SILValue aggregateFullyAvailableValue (SILType loadTy, unsigned firstElt);
427
+ SILValue aggregateTupleSubElts (TupleType *tt, SILType loadTy,
428
+ SILValue address, unsigned firstElt);
429
+ SILValue aggregateStructSubElts (StructDecl *sd, SILType loadTy,
430
+ SILValue address, unsigned firstElt);
431
+ SILValue handlePrimitiveValue (SILType loadTy, SILValue address,
432
+ unsigned firstElt);
433
+ bool isFullyAvailable (SILType loadTy, unsigned firstElt) const ;
433
434
};
434
435
435
436
} // end anonymous namespace
@@ -444,6 +445,26 @@ void AvailableValueAggregator::print(llvm::raw_ostream &os) const {
444
445
}
445
446
}
446
447
448
+ bool AvailableValueAggregator::isFullyAvailable (SILType loadTy,
449
+ unsigned firstElt) const {
450
+ if (firstElt >= AvailableValueList.size ()) { // #Elements may be zero.
451
+ return false ;
452
+ }
453
+
454
+ auto &firstVal = AvailableValueList[firstElt];
455
+
456
+ // Make sure that the first element is available and is the correct type.
457
+ if (!firstVal || firstVal.getType () != loadTy)
458
+ return false ;
459
+
460
+ return llvm::all_of (range (getNumSubElements (loadTy, M)),
461
+ [&](unsigned index) -> bool {
462
+ auto &val = AvailableValueList[firstElt + index];
463
+ return val.getValue () == firstVal.getValue () &&
464
+ val.getSubElementNumber () == index;
465
+ });
466
+ }
467
+
447
468
// / Given a bunch of primitive subelement values, build out the right aggregate
448
469
// / type (LoadTy) by emitting tuple and struct instructions as necessary.
449
470
SILValue AvailableValueAggregator::aggregateValues (SILType LoadTy,
@@ -475,26 +496,13 @@ SILValue AvailableValueAggregator::aggregateValues(SILType LoadTy,
475
496
SILValue
476
497
AvailableValueAggregator::aggregateFullyAvailableValue (SILType loadTy,
477
498
unsigned firstElt) {
478
- if (firstElt >= AvailableValueList.size ()) { // #Elements may be zero.
499
+ // Check if our underlying type is fully available. If it isn't, bail.
500
+ if (!isFullyAvailable (loadTy, firstElt))
479
501
return SILValue ();
480
- }
481
502
503
+ // Ok, grab out first value. (note: any actually will do).
482
504
auto &firstVal = AvailableValueList[firstElt];
483
505
484
- // Make sure that the first element is available and is the correct type.
485
- if (!firstVal || firstVal.getType () != loadTy)
486
- return SILValue ();
487
-
488
- // If the first element of this value is available, check that any extra
489
- // available values are from the same place as our first value.
490
- if (llvm::any_of (range (getNumSubElements (loadTy, M)),
491
- [&](unsigned index) -> bool {
492
- auto &val = AvailableValueList[firstElt + index];
493
- return val.getValue () != firstVal.getValue () ||
494
- val.getSubElementNumber () != index;
495
- }))
496
- return SILValue ();
497
-
498
506
// Ok, we know that all of our available values are all parts of the same
499
507
// value. Without ownership, we can just return the underlying first value.
500
508
if (!B.hasOwnership ())
0 commit comments