Fix several incorrect uses of ApplySite::getArgumentConvention.

At least most of these were latent bugs since the code was
unreachable in the PartialApply case. But that's no excuse to misuse
the API.

Also, whenever referring to an integer index, be explicit about
whether it is an applied argument or callee argument.
This commit is contained in:
Andrew Trick
2018-07-20 14:25:53 -07:00
parent 401be14483
commit 89ed064808
7 changed files with 19 additions and 39 deletions

View File

@@ -152,12 +152,10 @@ static SILArgumentConvention getAddressArgConvention(ApplyInst *Apply,
Operand *&Oper) {
Oper = nullptr;
auto Args = Apply->getArgumentOperands();
llvm::Optional<unsigned> FoundArgIdx;
for (auto ArgIdx : indices(Args)) {
if (Args[ArgIdx].get() != Address)
continue;
FoundArgIdx = ArgIdx;
assert(!Oper && "Address can only be passed once as an indirection.");
Oper = &Args[ArgIdx];
#ifdef NDEBUG
@@ -165,7 +163,7 @@ static SILArgumentConvention getAddressArgConvention(ApplyInst *Apply,
#endif
}
assert(Oper && "Address value not passed as an argument to this call.");
return Apply->getArgumentConvention(FoundArgIdx.getValue());
return ApplySite(Apply).getArgumentConvention(*Oper);
}
/// If the given instruction is a store, return the stored value.
@@ -1633,10 +1631,10 @@ bool TempRValueOptPass::collectLoads(
return false;
case SILInstructionKind::ApplyInst: {
auto *AI = cast<ApplyInst>(user);
auto Convention = AI->getArgumentConvention(userOp->getOperandNumber() - 1);
ApplySite apply(user);
auto Convention = apply.getArgumentConvention(*userOp);
if (Convention.isGuaranteedConvention()) {
loadInsts.insert(AI);
loadInsts.insert(user);
return true;
}
LLVM_DEBUG(llvm::dbgs() << " Temp consuming use may write/destroy "