Skip to content

Commit d6fb3c5

Browse files
authored
Merge pull request #11860 from gottesmm/pr-4655275dd4
2 parents 5626c72 + 29378a8 commit d6fb3c5

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
216216
///
217217
/// In the case that a non-null value is returned, FullArgs contains effective
218218
/// argument operands for the callee function.
219-
static SILFunction *
220-
getCalleeFunction(FullApplySite AI, bool &IsThick,
221-
SmallVectorImpl<SILValue>& CaptureArgs,
222-
SmallVectorImpl<SILValue>& FullArgs,
223-
PartialApplyInst *&PartialApply,
224-
SILModule::LinkingMode Mode) {
219+
static SILFunction *getCalleeFunction(SILFunction *F, FullApplySite AI,
220+
bool &IsThick,
221+
SmallVectorImpl<SILValue> &CaptureArgs,
222+
SmallVectorImpl<SILValue> &FullArgs,
223+
PartialApplyInst *&PartialApply,
224+
SILModule::LinkingMode Mode) {
225225
IsThick = false;
226226
PartialApply = nullptr;
227227
CaptureArgs.clear();
@@ -276,8 +276,7 @@ getCalleeFunction(FullApplySite AI, bool &IsThick,
276276
// We are allowed to see through exactly one "partial apply" instruction or
277277
// one "thin to thick function" instructions, since those are the patterns
278278
// generated when using auto closures.
279-
if (PartialApplyInst *PAI =
280-
dyn_cast<PartialApplyInst>(CalleeValue)) {
279+
if (auto *PAI = dyn_cast<PartialApplyInst>(CalleeValue)) {
281280
for (const auto &Arg : PAI->getArguments()) {
282281
CaptureArgs.push_back(Arg);
283282
FullArgs.push_back(Arg);
@@ -286,14 +285,12 @@ getCalleeFunction(FullApplySite AI, bool &IsThick,
286285
CalleeValue = PAI->getCallee();
287286
IsThick = true;
288287
PartialApply = PAI;
289-
} else if (ThinToThickFunctionInst *TTTFI =
290-
dyn_cast<ThinToThickFunctionInst>(CalleeValue)) {
288+
} else if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeValue)) {
291289
CalleeValue = TTTFI->getOperand();
292290
IsThick = true;
293291
}
294292

295293
auto *FRI = dyn_cast<FunctionRefInst>(CalleeValue);
296-
297294
if (!FRI)
298295
return nullptr;
299296

@@ -318,6 +315,22 @@ getCalleeFunction(FullApplySite AI, bool &IsThick,
318315
if (CalleeFunction->empty()
319316
&& !AI.getModule().linkFunction(CalleeFunction, Mode))
320317
return nullptr;
318+
319+
// If the CalleeFunction is a not-transparent definition, we can not process
320+
// it.
321+
if (CalleeFunction->isTransparent() == IsNotTransparent)
322+
return nullptr;
323+
324+
if (F->isSerialized() && !CalleeFunction->hasValidLinkageForFragileRef()) {
325+
if (!CalleeFunction->hasValidLinkageForFragileInline()) {
326+
llvm::errs() << "caller: " << F->getName() << "\n";
327+
llvm::errs() << "callee: " << CalleeFunction->getName() << "\n";
328+
llvm_unreachable("Should never be inlining a resilient function into "
329+
"a fragile function");
330+
}
331+
return nullptr;
332+
}
333+
321334
return CalleeFunction;
322335
}
323336

@@ -407,24 +420,10 @@ runOnFunctionRecursively(SILFunction *F, FullApplySite AI,
407420
SILValue CalleeValue = InnerAI.getCallee();
408421
bool IsThick;
409422
PartialApplyInst *PAI;
410-
SILFunction *CalleeFunction = getCalleeFunction(InnerAI, IsThick,
411-
CaptureArgs, FullArgs,
412-
PAI,
413-
Mode);
414-
if (!CalleeFunction ||
415-
CalleeFunction->isTransparent() == IsNotTransparent)
416-
continue;
417-
418-
if (F->isSerialized() &&
419-
!CalleeFunction->hasValidLinkageForFragileRef()) {
420-
if (!CalleeFunction->hasValidLinkageForFragileInline()) {
421-
llvm::errs() << "caller: " << F->getName() << "\n";
422-
llvm::errs() << "callee: " << CalleeFunction->getName() << "\n";
423-
llvm_unreachable("Should never be inlining a resilient function into "
424-
"a fragile function");
425-
}
423+
SILFunction *CalleeFunction = getCalleeFunction(
424+
F, InnerAI, IsThick, CaptureArgs, FullArgs, PAI, Mode);
425+
if (!CalleeFunction)
426426
continue;
427-
}
428427

429428
// Then recursively process it first before trying to inline it.
430429
if (!runOnFunctionRecursively(CalleeFunction, InnerAI, Mode,

0 commit comments

Comments
 (0)