Skip to content

Commit 78a8409

Browse files
committed
[ApplySite] Promoted insertAfter to ApplySite.
Previously the API was only on FullApplySite, but it is useful to be able to insert code after a partial_apply as well.
1 parent c0abe0b commit 78a8409

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,29 @@ class ApplySite {
474474
llvm_unreachable("covered switch");
475475
}
476476

477+
/// If this is a terminator apply site, then pass a builder to insert at the
478+
/// first instruction of each successor to \p func. Otherwise, pass a builder
479+
/// to insert at std::next(Inst).
480+
///
481+
/// The intention is that this abstraction will enable the compiler writer to
482+
/// ignore whether or not an apply site is a terminator when inserting
483+
/// instructions after an apply site. This results in eliminating unnecessary
484+
/// if-else code otherwise required to handle such situations.
485+
///
486+
/// NOTE: We pass std::next() for begin_apply. If one wishes to insert code
487+
/// /after/ the end_apply/abort_apply, please use instead
488+
/// insertAfterFullEvaluation.
489+
void insertAfterInvocation(function_ref<void(SILBuilder &)> func) const;
490+
491+
/// Pass a builder with insertion points that are guaranteed to be immediately
492+
/// after this full apply site has completely finished executing.
493+
///
494+
/// This is just like insertAfterInvocation except that if the full apply site
495+
/// is a begin_apply, we pass the insertion points after the end_apply,
496+
/// abort_apply rather than an insertion point right after the
497+
/// begin_apply. For such functionality, please invoke insertAfterInvocation.
498+
void insertAfterFullEvaluation(function_ref<void(SILBuilder &)> func) const;
499+
477500
/// Return whether the given apply is of a formally-throwing function
478501
/// which is statically known not to throw.
479502
bool isNonThrowing() const {
@@ -660,29 +683,6 @@ class FullApplySite : public ApplySite {
660683
llvm_unreachable("Covered switch isn't covered?!");
661684
}
662685

663-
/// If this is a terminator apply site, then pass a builder to insert at the
664-
/// first instruction of each successor to \p func. Otherwise, pass a builder
665-
/// to insert at std::next(Inst).
666-
///
667-
/// The intention is that this abstraction will enable the compiler writer to
668-
/// ignore whether or not an apply site is a terminator when inserting
669-
/// instructions after an apply site. This results in eliminating unnecessary
670-
/// if-else code otherwise required to handle such situations.
671-
///
672-
/// NOTE: We pass std::next() for begin_apply. If one wishes to insert code
673-
/// /after/ the end_apply/abort_apply, please use instead
674-
/// insertAfterFullEvaluation.
675-
void insertAfterInvocation(function_ref<void(SILBuilder &)> func) const;
676-
677-
/// Pass a builder with insertion points that are guaranteed to be immediately
678-
/// after this full apply site has completely finished executing.
679-
///
680-
/// This is just like insertAfterInvocation except that if the full apply site
681-
/// is a begin_apply, we pass the insertion points after the end_apply,
682-
/// abort_apply rather than an insertion point right after the
683-
/// begin_apply. For such functionality, please invoke insertAfterInvocation.
684-
void insertAfterFullEvaluation(function_ref<void(SILBuilder &)> func) const;
685-
686686
/// Returns true if \p op is an operand that passes an indirect
687687
/// result argument to the apply site.
688688
bool isIndirectResultOperand(const Operand &op) const {

lib/SIL/IR/ApplySite.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717
using namespace swift;
1818

19-
void FullApplySite::insertAfterInvocation(function_ref<void(SILBuilder &)> func) const {
19+
void ApplySite::insertAfterInvocation(function_ref<void(SILBuilder &)> func) const {
2020
SILBuilderWithScope::insertAfter(getInstruction(), func);
2121
}
2222

23-
void FullApplySite::insertAfterFullEvaluation(
23+
void ApplySite::insertAfterFullEvaluation(
2424
function_ref<void(SILBuilder &)> func) const {
2525
switch (getKind()) {
26-
case FullApplySiteKind::ApplyInst:
27-
case FullApplySiteKind::TryApplyInst:
26+
case ApplySiteKind::ApplyInst:
27+
case ApplySiteKind::TryApplyInst:
28+
case ApplySiteKind::PartialApplyInst:
2829
return insertAfterInvocation(func);
29-
case FullApplySiteKind::BeginApplyInst:
30+
case ApplySiteKind::BeginApplyInst:
3031
SmallVector<EndApplyInst *, 2> endApplies;
3132
SmallVector<AbortApplyInst *, 2> abortApplies;
3233
auto *bai = cast<BeginApplyInst>(getInstruction());

0 commit comments

Comments
 (0)