@@ -320,6 +320,29 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const AvailableValue &V) {
320
320
// Subelement Extraction
321
321
// ===----------------------------------------------------------------------===//
322
322
323
+ static bool isFullyAvailable (SILType loadTy, unsigned firstElt,
324
+ ArrayRef<AvailableValue> AvailableValues) {
325
+ if (firstElt >= AvailableValues.size ()) { // #Elements may be zero.
326
+ return false ;
327
+ }
328
+
329
+ auto &firstVal = AvailableValues[firstElt];
330
+
331
+ // Make sure that the first element is available and is the correct type.
332
+ if (!firstVal || firstVal.getType () != loadTy)
333
+ return false ;
334
+
335
+ auto *function = firstVal.getValue ()->getFunction ();
336
+ return llvm::all_of (
337
+ range (getNumSubElements (loadTy, function->getModule (),
338
+ TypeExpansionContext (*function))),
339
+ [&](unsigned index) -> bool {
340
+ auto &val = AvailableValues[firstElt + index];
341
+ return val.getValue () == firstVal.getValue () &&
342
+ val.getSubElementNumber () == index;
343
+ });
344
+ }
345
+
323
346
// / Given an aggregate value and an access path, non-destructively extract the
324
347
// / value indicated by the path.
325
348
static SILValue nonDestructivelyExtractSubElement (const AvailableValue &Val,
@@ -493,7 +516,6 @@ class AvailableValueAggregator {
493
516
SILValue address, unsigned firstElt);
494
517
SILValue handlePrimitiveValue (SILType loadTy, SILValue address,
495
518
unsigned firstElt);
496
- bool isFullyAvailable (SILType loadTy, unsigned firstElt) const ;
497
519
498
520
499
521
// / If as a result of us copying values, we may have unconsumed destroys, find
@@ -520,27 +542,6 @@ void AvailableValueAggregator::print(llvm::raw_ostream &os) const {
520
542
}
521
543
}
522
544
523
- bool AvailableValueAggregator::isFullyAvailable (SILType loadTy,
524
- unsigned firstElt) const {
525
- if (firstElt >= AvailableValueList.size ()) { // #Elements may be zero.
526
- return false ;
527
- }
528
-
529
- auto &firstVal = AvailableValueList[firstElt];
530
-
531
- // Make sure that the first element is available and is the correct type.
532
- if (!firstVal || firstVal.getType () != loadTy)
533
- return false ;
534
-
535
- return llvm::all_of (range (getNumSubElements (
536
- loadTy, M, TypeExpansionContext (B.getFunction ()))),
537
- [&](unsigned index) -> bool {
538
- auto &val = AvailableValueList[firstElt + index];
539
- return val.getValue () == firstVal.getValue () &&
540
- val.getSubElementNumber () == index;
541
- });
542
- }
543
-
544
545
// We can only take if we never have to split a larger value to promote this
545
546
// address.
546
547
bool AvailableValueAggregator::canTake (SILType loadTy,
@@ -552,7 +553,7 @@ bool AvailableValueAggregator::canTake(SILType loadTy,
552
553
return true ;
553
554
554
555
// If we are trivially fully available, just return true.
555
- if (isFullyAvailable (loadTy, firstElt))
556
+ if (isFullyAvailable (loadTy, firstElt, AvailableValueList ))
556
557
return true ;
557
558
558
559
// Otherwise see if we are an aggregate with fully available leaf types.
@@ -659,7 +660,7 @@ SILValue
659
660
AvailableValueAggregator::aggregateFullyAvailableValue (SILType loadTy,
660
661
unsigned firstElt) {
661
662
// Check if our underlying type is fully available. If it isn't, bail.
662
- if (!isFullyAvailable (loadTy, firstElt))
663
+ if (!isFullyAvailable (loadTy, firstElt, AvailableValueList ))
663
664
return SILValue ();
664
665
665
666
// Ok, grab out first value. (note: any actually will do).
0 commit comments