Skip to content

Commit 396709c

Browse files
authored
Merge pull request swiftlang#33112 from gottesmm/pr-c334b2062d3c019bcc64f91201c92417548b8992
[sil] Add an implementation of isIndirectResultOperand() onto ApplySite that returns false for partial_apply.
2 parents 8a45c9c + 7082dbb commit 396709c

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifndef SWIFT_SIL_APPLYSITE_H
2222
#define SWIFT_SIL_APPLYSITE_H
2323

24+
#include "swift/Basic/STLExtras.h"
2425
#include "swift/SIL/SILArgument.h"
2526
#include "swift/SIL/SILBasicBlock.h"
2627
#include "swift/SIL/SILFunction.h"
@@ -29,6 +30,8 @@
2930

3031
namespace swift {
3132

33+
class FullApplySite;
34+
3235
//===----------------------------------------------------------------------===//
3336
// ApplySite
3437
//===----------------------------------------------------------------------===//
@@ -396,6 +399,10 @@ class ApplySite {
396399
llvm_unreachable("covered switch");
397400
}
398401

402+
/// Returns true if \p op is an operand that passes an indirect
403+
/// result argument to the apply site.
404+
bool isIndirectResultOperand(const Operand &op) const;
405+
399406
/// Return whether the given apply is of a formally-throwing function
400407
/// which is statically known not to throw.
401408
bool isNonThrowing() const {
@@ -425,6 +432,10 @@ class ApplySite {
425432
}
426433

427434
void dump() const LLVM_ATTRIBUTE_USED { getInstruction()->dump(); }
435+
436+
/// Attempt to cast this apply site to a full apply site, returning None on
437+
/// failure.
438+
Optional<FullApplySite> asFullApplySite() const;
428439
};
429440

430441
//===----------------------------------------------------------------------===//
@@ -562,12 +573,6 @@ class FullApplySite : public ApplySite {
562573
return op.getOperandNumber() < getOperandIndexOfFirstArgument();
563574
}
564575

565-
/// Returns true if \p op is an operand that passes an indirect
566-
/// result argument to the apply site.
567-
bool isIndirectResultOperand(const Operand &op) const {
568-
return getCalleeArgIndex(op) < getNumIndirectSILResults();
569-
}
570-
571576
/// Is this an ApplySite that begins the evaluation of a coroutine.
572577
bool beginsCoroutineEvaluation() const {
573578
switch (getKind()) {
@@ -637,6 +642,12 @@ class FullApplySite : public ApplySite {
637642
llvm_unreachable("covered switch isn't covered");
638643
}
639644

645+
/// Returns true if \p op is an operand that passes an indirect
646+
/// result argument to the apply site.
647+
bool isIndirectResultOperand(const Operand &op) const {
648+
return getCalleeArgIndex(op) < getNumIndirectSILResults();
649+
}
650+
640651
static FullApplySite getFromOpaqueValue(void *p) { return FullApplySite(p); }
641652

642653
static bool classof(const SILInstruction *inst) {
@@ -729,4 +740,23 @@ template <> struct DenseMapInfo<::swift::FullApplySite> {
729740

730741
} // namespace llvm
731742

743+
//===----------------------------------------------------------------------===//
744+
// Inline Definitions to work around Forward Declaration
745+
//===----------------------------------------------------------------------===//
746+
747+
namespace swift {
748+
749+
inline Optional<FullApplySite> ApplySite::asFullApplySite() const {
750+
return FullApplySite::isa(getInstruction());
751+
}
752+
753+
inline bool ApplySite::isIndirectResultOperand(const Operand &op) const {
754+
auto fas = asFullApplySite();
755+
if (!fas)
756+
return false;
757+
return fas->isIndirectResultOperand(op);
758+
}
759+
760+
} // namespace swift
761+
732762
#endif

0 commit comments

Comments
 (0)