Skip to content

Commit b32b0e5

Browse files
authored
Merge pull request #11830 from gottesmm/pr-f4029048592ac607ab0149eb627e2c3cc8846a98
2 parents 40c5055 + fc1a639 commit b32b0e5

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6529,6 +6529,16 @@ class ApplySite {
65296529
FOREACH_IMPL_RETURN(getSubstitutions());
65306530
}
65316531

6532+
/// Return a begin iterator for the substitution array.
6533+
auto subs_begin() const -> decltype(getSubstitutions().begin()) {
6534+
return getSubstitutions().begin();
6535+
}
6536+
6537+
/// Return an end iterator for the substitution array.
6538+
auto subs_end() const -> decltype(getSubstitutions().end()) {
6539+
return getSubstitutions().end();
6540+
}
6541+
65326542
/// The arguments passed to this instruction.
65336543
MutableArrayRef<Operand> getArgumentOperands() const {
65346544
FOREACH_IMPL_RETURN(getArgumentOperands());

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,35 @@ runOnFunctionRecursively(SILFunction *F, FullApplySite AI,
418418
return false;
419419
}
420420

421+
// Create our initial list of substitutions.
422+
llvm::SmallVector<Substitution, 16> ApplySubs(InnerAI.subs_begin(),
423+
InnerAI.subs_end());
424+
425+
// Then if we have a partial_apply, add any additional subsitutions that
426+
// we may require to the end of the list.
427+
if (PAI) {
428+
copy(PAI->getSubstitutions(), std::back_inserter(ApplySubs));
429+
}
430+
431+
SILOpenedArchetypesTracker OpenedArchetypesTracker(F);
432+
F->getModule().registerDeleteNotificationHandler(
433+
&OpenedArchetypesTracker);
434+
// The callee only needs to know about opened archetypes used in
435+
// the substitution list.
436+
OpenedArchetypesTracker.registerUsedOpenedArchetypes(
437+
InnerAI.getInstruction());
438+
if (PAI) {
439+
OpenedArchetypesTracker.registerUsedOpenedArchetypes(PAI);
440+
}
441+
442+
SILInliner Inliner(*F, *CalleeFunction,
443+
SILInliner::InlineKind::MandatoryInline, ApplySubs,
444+
OpenedArchetypesTracker);
445+
if (!Inliner.canInlineFunction(InnerAI)) {
446+
I = InnerAI.getInstruction()->getIterator();
447+
continue;
448+
}
449+
421450
// Inline function at I, which also changes I to refer to the first
422451
// instruction inlined in the case that it succeeds. We purposely
423452
// process the inlined body after inlining, because the inlining may
@@ -456,31 +485,6 @@ runOnFunctionRecursively(SILFunction *F, FullApplySite AI,
456485
else
457486
I = ApplyBlock->end();
458487

459-
std::vector<Substitution> ApplySubs(InnerAI.getSubstitutions());
460-
461-
if (PAI) {
462-
auto PAISubs = PAI->getSubstitutions();
463-
ApplySubs.insert(ApplySubs.end(), PAISubs.begin(), PAISubs.end());
464-
}
465-
466-
SILOpenedArchetypesTracker OpenedArchetypesTracker(F);
467-
F->getModule().registerDeleteNotificationHandler(
468-
&OpenedArchetypesTracker);
469-
// The callee only needs to know about opened archetypes used in
470-
// the substitution list.
471-
OpenedArchetypesTracker.registerUsedOpenedArchetypes(InnerAI.getInstruction());
472-
if (PAI) {
473-
OpenedArchetypesTracker.registerUsedOpenedArchetypes(PAI);
474-
}
475-
476-
SILInliner Inliner(*F, *CalleeFunction,
477-
SILInliner::InlineKind::MandatoryInline,
478-
ApplySubs, OpenedArchetypesTracker);
479-
if (!Inliner.canInlineFunction(InnerAI)) {
480-
I = InnerAI.getInstruction()->getIterator();
481-
continue;
482-
}
483-
484488
Inliner.inlineFunction(InnerAI, FullArgs);
485489

486490
// We were able to inline successfully. Remove the apply.

0 commit comments

Comments
 (0)