@@ -67,13 +67,6 @@ static void diagnose(ASTContext &Context, SourceLoc loc, Diag<T...> diag,
67
67
Context.Diags .diagnose (loc, diag, std::forward<U>(args)...);
68
68
}
69
69
70
- static SILValue stripCopiesAndBorrows (SILValue v) {
71
- while (isa<CopyValueInst>(v) || isa<BeginBorrowInst>(v)) {
72
- v = cast<SingleValueInstruction>(v)->getOperand (0 );
73
- }
74
- return v;
75
- }
76
-
77
70
// / Fixup reference counts after inlining a function call (which is a no-op
78
71
// / unless the function is a thick function).
79
72
// /
@@ -388,7 +381,7 @@ static void cleanupCalleeValue(SILValue calleeValue,
388
381
if (auto loadedValue = cleanupLoadedCalleeValue (calleeValue))
389
382
calleeValue = loadedValue;
390
383
391
- calleeValue = stripCopiesAndBorrows (calleeValue);
384
+ calleeValue = lookThroughOwnershipInsts (calleeValue);
392
385
393
386
// Inline constructor
394
387
auto calleeSource = ([&]() -> SILValue {
@@ -398,12 +391,12 @@ static void cleanupCalleeValue(SILValue calleeValue,
398
391
// will delete any uses of the closure, including a
399
392
// convert_escape_to_noescape conversion.
400
393
if (auto *cfi = dyn_cast<ConvertFunctionInst>(calleeValue))
401
- return stripCopiesAndBorrows (cfi->getOperand ());
394
+ return lookThroughOwnershipInsts (cfi->getOperand ());
402
395
403
396
if (auto *cvt = dyn_cast<ConvertEscapeToNoEscapeInst>(calleeValue))
404
- return stripCopiesAndBorrows (cvt->getOperand ());
397
+ return lookThroughOwnershipInsts (cvt->getOperand ());
405
398
406
- return stripCopiesAndBorrows (calleeValue);
399
+ return lookThroughOwnershipInsts (calleeValue);
407
400
})();
408
401
409
402
if (auto *pai = dyn_cast<PartialApplyInst>(calleeSource)) {
@@ -419,7 +412,7 @@ static void cleanupCalleeValue(SILValue calleeValue,
419
412
}
420
413
invalidatedStackNesting = true ;
421
414
422
- calleeValue = stripCopiesAndBorrows (calleeValue);
415
+ calleeValue = lookThroughOwnershipInsts (calleeValue);
423
416
424
417
// Handle function_ref -> convert_function -> partial_apply/thin_to_thick.
425
418
if (auto *cfi = dyn_cast<ConvertFunctionInst>(calleeValue)) {
@@ -599,7 +592,7 @@ static SILValue getLoadedCalleeValue(LoadInst *li) {
599
592
// a cast.
600
593
static SILValue stripFunctionConversions (SILValue CalleeValue) {
601
594
// Skip any copies that we see.
602
- CalleeValue = stripCopiesAndBorrows (CalleeValue);
595
+ CalleeValue = lookThroughOwnershipInsts (CalleeValue);
603
596
604
597
// We can also allow a thin @escape to noescape conversion as such:
605
598
// %1 = function_ref @thin_closure_impl : $@convention(thin) () -> ()
@@ -626,7 +619,7 @@ static SILValue stripFunctionConversions(SILValue CalleeValue) {
626
619
if (FromCalleeTy != EscapingCalleeTy)
627
620
return CalleeValue;
628
621
629
- return stripCopiesAndBorrows (ConvertFn->getOperand ());
622
+ return lookThroughOwnershipInsts (ConvertFn->getOperand ());
630
623
}
631
624
632
625
// Ignore mark_dependence users. A partial_apply [stack] uses them to mark
@@ -642,7 +635,7 @@ static SILValue stripFunctionConversions(SILValue CalleeValue) {
642
635
643
636
auto *CFI = dyn_cast<ConvertEscapeToNoEscapeInst>(CalleeValue);
644
637
if (!CFI)
645
- return stripCopiesAndBorrows (CalleeValue);
638
+ return lookThroughOwnershipInsts (CalleeValue);
646
639
647
640
// TODO: Handle argument conversion. All the code in this file needs to be
648
641
// cleaned up and generalized. The argument conversion handling in
@@ -658,9 +651,9 @@ static SILValue stripFunctionConversions(SILValue CalleeValue) {
658
651
auto EscapingCalleeTy =
659
652
ToCalleeTy->getWithExtInfo (ToCalleeTy->getExtInfo ().withNoEscape (false ));
660
653
if (FromCalleeTy != EscapingCalleeTy)
661
- return stripCopiesAndBorrows (CalleeValue);
654
+ return lookThroughOwnershipInsts (CalleeValue);
662
655
663
- return stripCopiesAndBorrows (CFI->getOperand ());
656
+ return lookThroughOwnershipInsts (CFI->getOperand ());
664
657
}
665
658
666
659
// / Returns the callee SILFunction called at a call site, in the case
@@ -687,7 +680,7 @@ getCalleeFunction(SILFunction *F, FullApplySite AI, bool &IsThick,
687
680
688
681
// Then grab a first approximation of our apply by stripping off all copy
689
682
// operations.
690
- SILValue CalleeValue = stripCopiesAndBorrows (AI.getCallee ());
683
+ SILValue CalleeValue = lookThroughOwnershipInsts (AI.getCallee ());
691
684
692
685
// If after stripping off copy_values, we have a load then see if we the
693
686
// function we want to inline has a simple available value through a simple
@@ -696,7 +689,7 @@ getCalleeFunction(SILFunction *F, FullApplySite AI, bool &IsThick,
696
689
CalleeValue = getLoadedCalleeValue (li);
697
690
if (!CalleeValue)
698
691
return nullptr ;
699
- CalleeValue = stripCopiesAndBorrows (CalleeValue);
692
+ CalleeValue = lookThroughOwnershipInsts (CalleeValue);
700
693
}
701
694
702
695
// Look through a escape to @noescape conversion.
@@ -709,11 +702,11 @@ getCalleeFunction(SILFunction *F, FullApplySite AI, bool &IsThick,
709
702
// Collect the applied arguments and their convention.
710
703
collectPartiallyAppliedArguments (PAI, CapturedArgConventions, FullArgs);
711
704
712
- CalleeValue = stripCopiesAndBorrows (PAI->getCallee ());
705
+ CalleeValue = lookThroughOwnershipInsts (PAI->getCallee ());
713
706
IsThick = true ;
714
707
PartialApply = PAI;
715
708
} else if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeValue)) {
716
- CalleeValue = stripCopiesAndBorrows (TTTFI->getOperand ());
709
+ CalleeValue = lookThroughOwnershipInsts (TTTFI->getOperand ());
717
710
IsThick = true ;
718
711
}
719
712
0 commit comments