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