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