10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " swift/SIL/ApplySite.h"
13
14
#include " swift/SIL/SILVisitor.h"
14
15
#include " swift/SIL/SILBuiltinVisitor.h"
15
16
#include " swift/SIL/SILModule.h"
@@ -347,14 +348,18 @@ ValueOwnershipKind ValueOwnershipKindClassifier::visitSILFunctionArgument(
347
348
return Arg->getOwnershipKind ();
348
349
}
349
350
350
- ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst (ApplyInst *ai) {
351
- auto *f = ai->getFunction ();
352
- bool isTrivial = ai->getType ().isTrivial (*f);
351
+ // We have to separate out ResultType here as `begin_apply` does not produce
352
+ // normal results, `end_apply` does and there might be multiple `end_apply`'s
353
+ // that correspond to a single `begin_apply`.
354
+ static ValueOwnershipKind visitFullApplySite (FullApplySite fai,
355
+ SILType ResultType) {
356
+ auto *f = fai->getFunction ();
357
+ bool isTrivial = ResultType.isTrivial (*f);
353
358
// Quick is trivial check.
354
359
if (isTrivial)
355
360
return OwnershipKind::None;
356
361
357
- SILFunctionConventions fnConv (ai-> getSubstCalleeType (), f->getModule ());
362
+ SILFunctionConventions fnConv (fai. getSubstCalleeType (), f->getModule ());
358
363
auto results = fnConv.getDirectSILResults ();
359
364
// No results => None.
360
365
if (results.empty ())
@@ -363,7 +368,7 @@ ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst(ApplyInst *ai) {
363
368
// Otherwise, map our results to their ownership kinds and then merge them!
364
369
auto resultOwnershipKinds =
365
370
makeTransformRange (results, [&](const SILResultInfo &info) {
366
- return info.getOwnershipKind (*f, ai-> getSubstCalleeType ());
371
+ return info.getOwnershipKind (*f, fai. getSubstCalleeType ());
367
372
});
368
373
auto mergedOwnershipKind = ValueOwnershipKind::merge (resultOwnershipKinds);
369
374
if (!mergedOwnershipKind) {
@@ -373,31 +378,12 @@ ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst(ApplyInst *ai) {
373
378
return mergedOwnershipKind;
374
379
}
375
380
376
- ValueOwnershipKind ValueOwnershipKindClassifier::visitEndApplyInst (EndApplyInst *eai) {
377
- auto *bai = eai->getBeginApply ();
378
- auto *f = bai->getFunction ();
379
- bool isTrivial = eai->getType ().isTrivial (*f);
380
- // Quick is trivial check.
381
- if (isTrivial)
382
- return OwnershipKind::None;
383
-
384
- SILFunctionConventions fnConv (bai->getSubstCalleeType (), f->getModule ());
385
- auto results = fnConv.getDirectSILResults ();
386
- // No results => None.
387
- if (results.empty ())
388
- return OwnershipKind::None;
389
-
390
- // Otherwise, map our results to their ownership kinds and then merge them!
391
- auto resultOwnershipKinds =
392
- makeTransformRange (results, [&](const SILResultInfo &info) {
393
- return info.getOwnershipKind (*f, bai->getSubstCalleeType ());
394
- });
395
- auto mergedOwnershipKind = ValueOwnershipKind::merge (resultOwnershipKinds);
396
- if (!mergedOwnershipKind) {
397
- llvm_unreachable (" Forwarding inst with mismatching ownership kinds?!" );
398
- }
381
+ ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst (ApplyInst *ai) {
382
+ return visitFullApplySite (ai, ai->getType ());
383
+ }
399
384
400
- return mergedOwnershipKind;
385
+ ValueOwnershipKind ValueOwnershipKindClassifier::visitEndApplyInst (EndApplyInst *eai) {
386
+ return visitFullApplySite (eai->getBeginApply (), eai->getType ());
401
387
}
402
388
403
389
ValueOwnershipKind ValueOwnershipKindClassifier::visitLoadInst (LoadInst *LI) {
0 commit comments