[cast-opt] Add a new callback: ReplaceValueUsesAction.

This is the first in a series of patches to update the cast optimizer for
ownership and multiple value instructions.

This specific patch is NFC.
This commit is contained in:
Michael Gottesman
2019-02-03 19:53:43 -08:00
parent 48e48f22fe
commit a5b47e127d
5 changed files with 113 additions and 54 deletions

View File

@@ -1439,26 +1439,34 @@ ConstantFolder::processWorkList() {
llvm::DenseSet<SILInstruction *> ErrorSet;
llvm::SetVector<SILInstruction *> FoldedUsers;
CastOptimizer CastOpt(FuncBuilder,
[&](SingleValueInstruction *I, ValueBase *V) { /* ReplaceInstUsesAction */
/* ReplaceValueUsesAction */
[&](SILValue oldValue, SILValue newValue) {
InvalidateInstructions = true;
oldValue->replaceAllUsesWith(newValue);
},
/* ReplaceInstUsesAction */
[&](SingleValueInstruction *I, ValueBase *V) {
InvalidateInstructions = true;
I->replaceAllUsesWith(V);
},
/* EraseAction */
[&](SILInstruction *I) {
auto *TI = dyn_cast<TermInst>(I);
InvalidateInstructions = true;
I->replaceAllUsesWith(V);
},
[&](SILInstruction *I) { /* EraseAction */
auto *TI = dyn_cast<TermInst>(I);
if (TI) {
// Invalidate analysis information related to
// branches. Replacing
// unconditional_check_branch type instructions
// by a trap will also invalidate branches/the
// CFG.
InvalidateBranches = true;
}
if (TI) {
// Invalidate analysis information related to branches. Replacing
// unconditional_check_branch type instructions by a trap will also
// invalidate branches/the CFG.
InvalidateBranches = true;
}
InvalidateInstructions = true;
InvalidateInstructions = true;
WorkList.remove(I);
I->eraseFromParent();
});
WorkList.remove(I);
I->eraseFromParent();
});
while (!WorkList.empty()) {
SILInstruction *I = WorkList.pop_back_val();