Skip to content

Commit 9764359

Browse files
committed
[sil] Add new API to ApplySite called getOperandsWithoutSelf().
Needed this API. Unwrapping the onion to make further commits easier to review.
1 parent 48b4ca0 commit 9764359

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,21 @@ class ApplySite {
485485
llvm_unreachable("covered switch");
486486
}
487487

488+
/// Return a list of applied operands of the apply without self.
489+
ArrayRef<Operand> getOperandsWithoutSelf() const {
490+
switch (ApplySiteKind(Inst->getKind())) {
491+
case ApplySiteKind::ApplyInst:
492+
return cast<ApplyInst>(Inst)->getOperandsWithoutSelf();
493+
case ApplySiteKind::BeginApplyInst:
494+
return cast<BeginApplyInst>(Inst)->getOperandsWithoutSelf();
495+
case ApplySiteKind::TryApplyInst:
496+
return cast<TryApplyInst>(Inst)->getOperandsWithoutSelf();
497+
case ApplySiteKind::PartialApplyInst:
498+
llvm_unreachable("Unhandled case");
499+
}
500+
llvm_unreachable("covered switch");
501+
}
502+
488503
/// Returns true if \p op is an operand that passes an indirect
489504
/// result argument to the apply site.
490505
bool isIndirectResultOperand(const Operand &op) const;

include/swift/SIL/SILInstruction.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,20 +2877,30 @@ class ApplyInstBase<Impl, Base, true>
28772877
void setSelfArgument(SILValue V) {
28782878
assert(hasSelfArgument() && "Must have a self argument");
28792879
assert(getNumArguments() && "Should only be called when Callee has "
2880-
"arguments.");
2880+
"arguments.");
28812881
getArgumentOperands()[getNumArguments() - 1].set(V);
28822882
}
28832883

28842884
OperandValueArrayRef getArgumentsWithoutSelf() const {
2885-
assert(hasSelfArgument() && "Must have a self argument");
28862885
assert(getNumArguments() && "Should only be called when Callee has "
2887-
"at least a self parameter.");
2886+
"at least a self parameter.");
28882887
ArrayRef<Operand> ops = this->getArgumentOperands();
2889-
ArrayRef<Operand> opsWithoutSelf = ArrayRef<Operand>(&ops[0],
2890-
ops.size()-1);
2888+
if (!hasSelfArgument())
2889+
return ops;
2890+
auto opsWithoutSelf = ArrayRef<Operand>(&ops[0], ops.size() - 1);
28912891
return OperandValueArrayRef(opsWithoutSelf);
28922892
}
28932893

2894+
ArrayRef<Operand> getOperandsWithoutSelf() const {
2895+
assert(getNumArguments() && "Should only be called when Callee has "
2896+
"at least a self parameter.");
2897+
ArrayRef<Operand> ops = this->getArgumentOperands();
2898+
if (!hasSelfArgument())
2899+
return ops;
2900+
auto opsWithoutSelf = ArrayRef<Operand>(&ops[0], ops.size() - 1);
2901+
return opsWithoutSelf;
2902+
}
2903+
28942904
llvm::Optional<SILResultInfo> getSingleResult() const {
28952905
auto SubstCallee = getSubstCalleeType();
28962906
if (SubstCallee->getNumResults() != 1)

0 commit comments

Comments
 (0)