Skip to content

Commit 4a283be

Browse files
committed
[nfc] ApplySite argument APIs: cleanup and add comments.
Use consistent terminology, clarify comments, and group APIs. This matches the documentation in SILDevelopment.md.
1 parent f6ba49e commit 4a283be

File tree

1 file changed

+67
-49
lines changed

1 file changed

+67
-49
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 67 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,7 @@ class ApplyInstBase<Impl, Base, true>
19361936
return OperandValueArrayRef(opsWithoutSelf);
19371937
}
19381938

1939+
/// Return the SILArgumentConvention for the given applied argument index.
19391940
SILArgumentConvention getArgumentConvention(unsigned index) const {
19401941
return getSubstCalleeConv().getSILArgumentConvention(index);
19411942
}
@@ -7620,47 +7621,59 @@ class ApplySite {
76207621
FOREACH_IMPL_RETURN(getSubstitutionMap());
76217622
}
76227623

7623-
/// The arguments passed to this instruction.
7624+
/// Return the associated specialization information.
7625+
const GenericSpecializationInformation *getSpecializationInfo() const {
7626+
FOREACH_IMPL_RETURN(getSpecializationInfo());
7627+
}
7628+
7629+
/// Return an operand list corresponding to the applied arguments.
76247630
MutableArrayRef<Operand> getArgumentOperands() const {
76257631
FOREACH_IMPL_RETURN(getArgumentOperands());
76267632
}
76277633

7628-
/// The arguments passed to this instruction.
7634+
/// Return a list of applied argument values.
76297635
OperandValueArrayRef getArguments() const {
76307636
FOREACH_IMPL_RETURN(getArguments());
76317637
}
76327638

7633-
/// The number of call arguments.
7639+
/// Return the number of applied arguments.
76347640
unsigned getNumArguments() const {
76357641
FOREACH_IMPL_RETURN(getNumArguments());
76367642
}
76377643

7638-
unsigned getOperandIndexOfFirstArgument() {
7639-
FOREACH_IMPL_RETURN(getArgumentOperandNumber());
7644+
/// Return the apply operand for the given applied argument index.
7645+
Operand &getArgumentRef(unsigned i) const { return getArgumentOperands()[i]; }
7646+
7647+
/// Return the ith applied argument.
7648+
SILValue getArgument(unsigned i) const { return getArguments()[i]; }
7649+
7650+
/// Set the ith applied argument.
7651+
void setArgument(unsigned i, SILValue V) const {
7652+
getArgumentOperands()[i].set(V);
76407653
}
76417654

7642-
/// Return the associated specialization information.
7643-
const GenericSpecializationInformation *getSpecializationInfo() const {
7644-
FOREACH_IMPL_RETURN(getSpecializationInfo());
7655+
/// Return the operand index of the first applied argument.
7656+
unsigned getOperandIndexOfFirstArgument() const {
7657+
FOREACH_IMPL_RETURN(getArgumentOperandNumber());
76457658
}
76467659
#undef FOREACH_IMPL_RETURN
76477660

7648-
/// The arguments passed to this instruction, without self.
7649-
OperandValueArrayRef getArgumentsWithoutSelf() const {
7650-
switch (Inst->getKind()) {
7651-
case SILInstructionKind::ApplyInst:
7652-
return cast<ApplyInst>(Inst)->getArgumentsWithoutSelf();
7653-
case SILInstructionKind::BeginApplyInst:
7654-
return cast<BeginApplyInst>(Inst)->getArgumentsWithoutSelf();
7655-
case SILInstructionKind::TryApplyInst:
7656-
return cast<TryApplyInst>(Inst)->getArgumentsWithoutSelf();
7657-
default:
7658-
llvm_unreachable("not implemented for this instruction!");
7659-
}
7661+
/// Returns true if \p oper is an argument operand and not the callee
7662+
/// operand.
7663+
bool isArgumentOperand(const Operand &oper) const {
7664+
return oper.getOperandNumber() >= getOperandIndexOfFirstArgument();
7665+
}
7666+
7667+
/// Return the applied argument index for the given operand.
7668+
unsigned getArgumentIndex(const Operand &oper) const {
7669+
assert(oper.getUser() == Inst);
7670+
assert(isArgumentOperand(oper));
7671+
7672+
return oper.getOperandNumber() - getOperandIndexOfFirstArgument();
76607673
}
76617674

7662-
// Get the callee argument index corresponding to the caller's first applied
7663-
// argument. Returns 0 for full applies. May return > 0 for partial applies.
7675+
/// Return the callee's function argument index corresponding to the first
7676+
/// applied argument: 0 for full applies; >= 0 for partial applies.
76647677
unsigned getCalleeArgIndexOfFirstAppliedArg() const {
76657678
switch (Inst->getKind()) {
76667679
case SILInstructionKind::ApplyInst:
@@ -7683,35 +7696,30 @@ class ApplySite {
76837696
}
76847697
}
76857698

7686-
/// Returns true if \p oper is an argument operand and not the callee
7687-
/// operand.
7688-
bool isArgumentOperand(const Operand &oper) {
7689-
return oper.getOperandNumber() >= getOperandIndexOfFirstArgument();
7699+
/// Return the callee's function argument index corresponding to the given
7700+
/// apply operand. Each function argument index identifies a
7701+
/// SILFunctionArgument in the callee and can be used as a
7702+
/// SILFunctionConvention argument index.
7703+
///
7704+
/// Note: Passing an applied argument index into SILFunctionConvention, as
7705+
/// opposed to a function argument index, is incorrect.
7706+
unsigned getCalleeArgIndex(const Operand &oper) const {
7707+
return getCalleeArgIndexOfFirstAppliedArg() + getArgumentIndex(oper);
76907708
}
76917709

7692-
// Translate the index of the argument to the full apply or partial_apply into
7693-
// to the corresponding index into the arguments of the called function.
7694-
unsigned getCalleeArgIndex(const Operand &oper) {
7695-
assert(oper.getUser() == Inst);
7696-
assert(isArgumentOperand(oper));
7697-
7698-
unsigned appliedArgIdx =
7699-
oper.getOperandNumber() - getOperandIndexOfFirstArgument();
7700-
7701-
return getCalleeArgIndexOfFirstAppliedArg() + appliedArgIdx;
7710+
/// Return the SILArgumentConvention for the given applied argument operand.
7711+
SILArgumentConvention getArgumentConvention(Operand &oper) const {
7712+
unsigned calleeArgIdx =
7713+
getCalleeArgIndexOfFirstAppliedArg() + getArgumentIndex(oper);
7714+
return getSubstCalleeConv().getSILArgumentConvention(calleeArgIdx);
77027715
}
77037716

7704-
Operand &getArgumentRef(unsigned i) const { return getArgumentOperands()[i]; }
7705-
7706-
/// Return the ith argument passed to this instruction.
7707-
SILValue getArgument(unsigned i) const { return getArguments()[i]; }
7708-
7709-
/// Set the ith argument of this instruction.
7710-
void setArgument(unsigned i, SILValue V) const {
7711-
getArgumentOperands()[i].set(V);
7717+
// FIXME: This is incorrect. It will be removed in the next commit.
7718+
SILArgumentConvention getArgumentConvention(unsigned index) const {
7719+
return getSubstCalleeConv().getSILArgumentConvention(index);
77127720
}
77137721

7714-
/// Return the self argument passed to this instruction.
7722+
/// Return true if 'self' is an applied argument.
77157723
bool hasSelfArgument() const {
77167724
switch (Inst->getKind()) {
77177725
case SILInstructionKind::ApplyInst:
@@ -7725,7 +7733,7 @@ class ApplySite {
77257733
}
77267734
}
77277735

7728-
/// Return the self argument passed to this instruction.
7736+
/// Return the applied 'self' argument value.
77297737
SILValue getSelfArgument() const {
77307738
switch (Inst->getKind()) {
77317739
case SILInstructionKind::ApplyInst:
@@ -7739,7 +7747,7 @@ class ApplySite {
77397747
}
77407748
}
77417749

7742-
/// Return the self operand passed to this instruction.
7750+
/// Return the 'self' apply operand.
77437751
Operand &getSelfArgumentOperand() {
77447752
switch (Inst->getKind()) {
77457753
case SILInstructionKind::ApplyInst:
@@ -7753,8 +7761,18 @@ class ApplySite {
77537761
}
77547762
}
77557763

7756-
SILArgumentConvention getArgumentConvention(unsigned index) const {
7757-
return getSubstCalleeConv().getSILArgumentConvention(index);
7764+
/// Return a list of applied arguments without self.
7765+
OperandValueArrayRef getArgumentsWithoutSelf() const {
7766+
switch (Inst->getKind()) {
7767+
case SILInstructionKind::ApplyInst:
7768+
return cast<ApplyInst>(Inst)->getArgumentsWithoutSelf();
7769+
case SILInstructionKind::BeginApplyInst:
7770+
return cast<BeginApplyInst>(Inst)->getArgumentsWithoutSelf();
7771+
case SILInstructionKind::TryApplyInst:
7772+
return cast<TryApplyInst>(Inst)->getArgumentsWithoutSelf();
7773+
default:
7774+
llvm_unreachable("not implemented for this instruction!");
7775+
}
77587776
}
77597777

77607778
static ApplySite getFromOpaqueValue(void *p) {

0 commit comments

Comments
 (0)