Skip to content

Commit 6f22e43

Browse files
committed
[MandatoryInlining] Strip all ownership insts.
Previously, just copies and borrows were stripped. All ownership instructions, specifically, newly, move_value instructions, should be stripped.
1 parent 329dd2c commit 6f22e43

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ static void diagnose(ASTContext &Context, SourceLoc loc, Diag<T...> diag,
6767
Context.Diags.diagnose(loc, diag, std::forward<U>(args)...);
6868
}
6969

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-
7770
/// Fixup reference counts after inlining a function call (which is a no-op
7871
/// unless the function is a thick function).
7972
///
@@ -388,7 +381,7 @@ static void cleanupCalleeValue(SILValue calleeValue,
388381
if (auto loadedValue = cleanupLoadedCalleeValue(calleeValue))
389382
calleeValue = loadedValue;
390383

391-
calleeValue = stripCopiesAndBorrows(calleeValue);
384+
calleeValue = lookThroughOwnershipInsts(calleeValue);
392385

393386
// Inline constructor
394387
auto calleeSource = ([&]() -> SILValue {
@@ -398,12 +391,12 @@ static void cleanupCalleeValue(SILValue calleeValue,
398391
// will delete any uses of the closure, including a
399392
// convert_escape_to_noescape conversion.
400393
if (auto *cfi = dyn_cast<ConvertFunctionInst>(calleeValue))
401-
return stripCopiesAndBorrows(cfi->getOperand());
394+
return lookThroughOwnershipInsts(cfi->getOperand());
402395

403396
if (auto *cvt = dyn_cast<ConvertEscapeToNoEscapeInst>(calleeValue))
404-
return stripCopiesAndBorrows(cvt->getOperand());
397+
return lookThroughOwnershipInsts(cvt->getOperand());
405398

406-
return stripCopiesAndBorrows(calleeValue);
399+
return lookThroughOwnershipInsts(calleeValue);
407400
})();
408401

409402
if (auto *pai = dyn_cast<PartialApplyInst>(calleeSource)) {
@@ -419,7 +412,7 @@ static void cleanupCalleeValue(SILValue calleeValue,
419412
}
420413
invalidatedStackNesting = true;
421414

422-
calleeValue = stripCopiesAndBorrows(calleeValue);
415+
calleeValue = lookThroughOwnershipInsts(calleeValue);
423416

424417
// Handle function_ref -> convert_function -> partial_apply/thin_to_thick.
425418
if (auto *cfi = dyn_cast<ConvertFunctionInst>(calleeValue)) {
@@ -599,7 +592,7 @@ static SILValue getLoadedCalleeValue(LoadInst *li) {
599592
// a cast.
600593
static SILValue stripFunctionConversions(SILValue CalleeValue) {
601594
// Skip any copies that we see.
602-
CalleeValue = stripCopiesAndBorrows(CalleeValue);
595+
CalleeValue = lookThroughOwnershipInsts(CalleeValue);
603596

604597
// We can also allow a thin @escape to noescape conversion as such:
605598
// %1 = function_ref @thin_closure_impl : $@convention(thin) () -> ()
@@ -626,7 +619,7 @@ static SILValue stripFunctionConversions(SILValue CalleeValue) {
626619
if (FromCalleeTy != EscapingCalleeTy)
627620
return CalleeValue;
628621

629-
return stripCopiesAndBorrows(ConvertFn->getOperand());
622+
return lookThroughOwnershipInsts(ConvertFn->getOperand());
630623
}
631624

632625
// Ignore mark_dependence users. A partial_apply [stack] uses them to mark
@@ -642,7 +635,7 @@ static SILValue stripFunctionConversions(SILValue CalleeValue) {
642635

643636
auto *CFI = dyn_cast<ConvertEscapeToNoEscapeInst>(CalleeValue);
644637
if (!CFI)
645-
return stripCopiesAndBorrows(CalleeValue);
638+
return lookThroughOwnershipInsts(CalleeValue);
646639

647640
// TODO: Handle argument conversion. All the code in this file needs to be
648641
// cleaned up and generalized. The argument conversion handling in
@@ -658,9 +651,9 @@ static SILValue stripFunctionConversions(SILValue CalleeValue) {
658651
auto EscapingCalleeTy =
659652
ToCalleeTy->getWithExtInfo(ToCalleeTy->getExtInfo().withNoEscape(false));
660653
if (FromCalleeTy != EscapingCalleeTy)
661-
return stripCopiesAndBorrows(CalleeValue);
654+
return lookThroughOwnershipInsts(CalleeValue);
662655

663-
return stripCopiesAndBorrows(CFI->getOperand());
656+
return lookThroughOwnershipInsts(CFI->getOperand());
664657
}
665658

666659
/// Returns the callee SILFunction called at a call site, in the case
@@ -687,7 +680,7 @@ getCalleeFunction(SILFunction *F, FullApplySite AI, bool &IsThick,
687680

688681
// Then grab a first approximation of our apply by stripping off all copy
689682
// operations.
690-
SILValue CalleeValue = stripCopiesAndBorrows(AI.getCallee());
683+
SILValue CalleeValue = lookThroughOwnershipInsts(AI.getCallee());
691684

692685
// If after stripping off copy_values, we have a load then see if we the
693686
// function we want to inline has a simple available value through a simple
@@ -696,7 +689,7 @@ getCalleeFunction(SILFunction *F, FullApplySite AI, bool &IsThick,
696689
CalleeValue = getLoadedCalleeValue(li);
697690
if (!CalleeValue)
698691
return nullptr;
699-
CalleeValue = stripCopiesAndBorrows(CalleeValue);
692+
CalleeValue = lookThroughOwnershipInsts(CalleeValue);
700693
}
701694

702695
// Look through a escape to @noescape conversion.
@@ -709,11 +702,11 @@ getCalleeFunction(SILFunction *F, FullApplySite AI, bool &IsThick,
709702
// Collect the applied arguments and their convention.
710703
collectPartiallyAppliedArguments(PAI, CapturedArgConventions, FullArgs);
711704

712-
CalleeValue = stripCopiesAndBorrows(PAI->getCallee());
705+
CalleeValue = lookThroughOwnershipInsts(PAI->getCallee());
713706
IsThick = true;
714707
PartialApply = PAI;
715708
} else if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeValue)) {
716-
CalleeValue = stripCopiesAndBorrows(TTTFI->getOperand());
709+
CalleeValue = lookThroughOwnershipInsts(TTTFI->getOperand());
717710
IsThick = true;
718711
}
719712

0 commit comments

Comments
 (0)