SILBuilder: add an API to insert _after_ an instruction.

... and use that API in FullApplySite::insertAfterInvocation.

Also change FullApplySite::insertAfterInvocation/insertAfterFullEvaluation to directly pass a SILBuilder instead of just an insertion point to the callback.
This makes more sense (given the function names) and simplifies the usages.

It's a NFC.
This commit is contained in:
Erik Eckstein
2020-10-16 16:23:13 +02:00
parent 6310dfcc93
commit 9a10ec7d58
8 changed files with 101 additions and 64 deletions

View File

@@ -661,3 +661,19 @@ CheckedCastBranchInst *SILBuilder::createCheckedCastBranch(
destLoweredTy, destFormalTy, successBB, failureBB,
getFunction(), C.OpenedArchetypes, target1Count, target2Count));
}
void SILBuilderWithScope::insertAfter(SILInstruction *inst,
function_ref<void(SILBuilder &)> func) {
if (isa<TermInst>(inst)) {
for (const SILSuccessor &succ : inst->getParent()->getSuccessors()) {
SILBasicBlock *succBlock = succ;
assert(succBlock->getSinglePredecessorBlock() == inst->getParent() &&
"the terminator instruction must not have critical successors");
SILBuilderWithScope builder(succBlock->begin());
func(builder);
}
} else {
SILBuilderWithScope builder(std::next(inst->getIterator()));
func(builder);
}
}