@@ -398,24 +398,6 @@ class ApplySite {
398
398
}
399
399
}
400
400
401
- // / If this is a terminator apply site, then pass the first instruction of
402
- // / each successor to fun. Otherwise, pass std::next(Inst).
403
- // /
404
- // / The intention is that this abstraction will enable the compiler writer to
405
- // / ignore whether or not an apply site is a terminator when inserting
406
- // / instructions after an apply site. This results in eliminating unnecessary
407
- // / if-else code otherwise required to handle such situations.
408
- void insertAfter (llvm::function_ref<void (SILBasicBlock::iterator)> func) {
409
- auto *ti = dyn_cast<TermInst>(Inst);
410
- if (!ti) {
411
- return func (std::next (Inst->getIterator ()));
412
- }
413
-
414
- for (auto *succBlock : ti->getSuccessorBlocks ()) {
415
- func (succBlock->begin ());
416
- }
417
- }
418
-
419
401
static ApplySite getFromOpaqueValue (void *p) { return ApplySite (p); }
420
402
421
403
friend bool operator ==(ApplySite lhs, ApplySite rhs) {
@@ -533,6 +515,63 @@ class FullApplySite : public ApplySite {
533
515
return getCalleeArgIndex (op) < getNumIndirectSILResults ();
534
516
}
535
517
518
+ // / If this is a terminator apply site, then pass the first instruction of
519
+ // / each successor to fun. Otherwise, pass std::next(Inst).
520
+ // /
521
+ // / The intention is that this abstraction will enable the compiler writer to
522
+ // / ignore whether or not an apply site is a terminator when inserting
523
+ // / instructions after an apply site. This results in eliminating unnecessary
524
+ // / if-else code otherwise required to handle such situations.
525
+ // /
526
+ // / NOTE: We return std::next() for begin_apply. If one wishes to insert code
527
+ // / /after/ the end_apply/abort_apply, please use instead
528
+ // / insertAfterFullEvaluation.
529
+ void insertAfterInvocation (
530
+ function_ref<void (SILBasicBlock::iterator)> func) const {
531
+ switch (getKind ()) {
532
+ case FullApplySiteKind::ApplyInst:
533
+ case FullApplySiteKind::BeginApplyInst:
534
+ return func (std::next (getInstruction ()->getIterator ()));
535
+ case FullApplySiteKind::TryApplyInst:
536
+ for (auto *succBlock :
537
+ cast<TermInst>(getInstruction ())->getSuccessorBlocks ()) {
538
+ func (succBlock->begin ());
539
+ }
540
+ return ;
541
+ }
542
+ llvm_unreachable (" Covered switch isn't covered" );
543
+ }
544
+
545
+ // / Pass to func insertion points that are guaranteed to be immediately after
546
+ // / this full apply site has completely finished executing.
547
+ // /
548
+ // / This is just like insertAfterInvocation except that if the full apply site
549
+ // / is a begin_apply, we pass the insertion points after the end_apply,
550
+ // / abort_apply rather than an insertion point right after the
551
+ // / begin_apply. For such functionality, please invoke insertAfterInvocation.
552
+ void insertAfterFullEvaluation (
553
+ function_ref<void (SILBasicBlock::iterator)> func) const {
554
+ switch (getKind ()) {
555
+ case FullApplySiteKind::ApplyInst:
556
+ case FullApplySiteKind::TryApplyInst:
557
+ return insertAfterInvocation (func);
558
+ case FullApplySiteKind::BeginApplyInst:
559
+ SmallVector<EndApplyInst *, 2 > endApplies;
560
+ SmallVector<AbortApplyInst *, 2 > abortApplies;
561
+ auto *bai = cast<BeginApplyInst>(getInstruction ());
562
+ bai->getCoroutineEndPoints (endApplies, abortApplies);
563
+ for (auto *eai : endApplies) {
564
+ func (std::next (eai->getIterator ()));
565
+ }
566
+ for (auto *aai : abortApplies) {
567
+ func (std::next (aai->getIterator ()));
568
+ }
569
+ return ;
570
+ }
571
+
572
+ llvm_unreachable (" covered switch isn't covered" );
573
+ }
574
+
536
575
static FullApplySite getFromOpaqueValue (void *p) { return FullApplySite (p); }
537
576
538
577
static bool classof (const SILInstruction *inst) {
0 commit comments