Skip to content

Commit

Permalink
Merge pull request swiftlang#33112 from gottesmm/pr-c334b2062d3c019bc…
Browse files Browse the repository at this point in the history
…c64f91201c92417548b8992

[sil] Add an implementation of isIndirectResultOperand() onto ApplySite that returns false for partial_apply.
  • Loading branch information
gottesmm authored Jul 27, 2020
2 parents 8a45c9c + 7082dbb commit 396709c
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions include/swift/SIL/ApplySite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef SWIFT_SIL_APPLYSITE_H
#define SWIFT_SIL_APPLYSITE_H

#include "swift/Basic/STLExtras.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILBasicBlock.h"
#include "swift/SIL/SILFunction.h"
Expand All @@ -29,6 +30,8 @@

namespace swift {

class FullApplySite;

//===----------------------------------------------------------------------===//
// ApplySite
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -396,6 +399,10 @@ class ApplySite {
llvm_unreachable("covered switch");
}

/// Returns true if \p op is an operand that passes an indirect
/// result argument to the apply site.
bool isIndirectResultOperand(const Operand &op) const;

/// Return whether the given apply is of a formally-throwing function
/// which is statically known not to throw.
bool isNonThrowing() const {
Expand Down Expand Up @@ -425,6 +432,10 @@ class ApplySite {
}

void dump() const LLVM_ATTRIBUTE_USED { getInstruction()->dump(); }

/// Attempt to cast this apply site to a full apply site, returning None on
/// failure.
Optional<FullApplySite> asFullApplySite() const;
};

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -562,12 +573,6 @@ class FullApplySite : public ApplySite {
return op.getOperandNumber() < getOperandIndexOfFirstArgument();
}

/// Returns true if \p op is an operand that passes an indirect
/// result argument to the apply site.
bool isIndirectResultOperand(const Operand &op) const {
return getCalleeArgIndex(op) < getNumIndirectSILResults();
}

/// Is this an ApplySite that begins the evaluation of a coroutine.
bool beginsCoroutineEvaluation() const {
switch (getKind()) {
Expand Down Expand Up @@ -637,6 +642,12 @@ class FullApplySite : public ApplySite {
llvm_unreachable("covered switch isn't covered");
}

/// Returns true if \p op is an operand that passes an indirect
/// result argument to the apply site.
bool isIndirectResultOperand(const Operand &op) const {
return getCalleeArgIndex(op) < getNumIndirectSILResults();
}

static FullApplySite getFromOpaqueValue(void *p) { return FullApplySite(p); }

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

} // namespace llvm

//===----------------------------------------------------------------------===//
// Inline Definitions to work around Forward Declaration
//===----------------------------------------------------------------------===//

namespace swift {

inline Optional<FullApplySite> ApplySite::asFullApplySite() const {
return FullApplySite::isa(getInstruction());
}

inline bool ApplySite::isIndirectResultOperand(const Operand &op) const {
auto fas = asFullApplySite();
if (!fas)
return false;
return fas->isIndirectResultOperand(op);
}

} // namespace swift

#endif

0 comments on commit 396709c

Please sign in to comment.