[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

@@ -1934,20 +1934,26 @@ bool SimplifyCFG::simplifyCheckedCastBranchBlock(CheckedCastBranchInst *CCBI) {
auto ThisBB = CCBI->getParent();
bool MadeChange = false;
CastOptimizer CastOpt(FuncBuilder,
[&MadeChange](SILInstruction *I,
ValueBase *V) { /* ReplaceInstUsesAction */
CastOptimizer CastOpt(
FuncBuilder,
/* ReplaceValueUsesAction */
[&MadeChange](SILValue oldValue, SILValue newValue) {
MadeChange = true;
},
[&MadeChange](SILInstruction *I) { /* EraseInstAction */
/* ReplaceInstUsesAction */
[&MadeChange](SILInstruction *I, ValueBase *V) { MadeChange = true; },
/* EraseInstAction */
[&MadeChange](SILInstruction *I) {
MadeChange = true;
I->eraseFromParent();
},
[&]() { /* WillSucceedAction */
/* WillSucceedAction */
[&]() {
MadeChange |= removeIfDead(FailureBB);
addToWorklist(ThisBB);
},
[&]() { /* WillFailAction */
/* WillFailAction */
[&]() {
MadeChange |= removeIfDead(SuccessBB);
addToWorklist(ThisBB);
});
@@ -1965,21 +1971,26 @@ bool SimplifyCFG::simplifyCheckedCastValueBranchBlock(
bool MadeChange = false;
CastOptimizer CastOpt(
FuncBuilder,
[&MadeChange](SILInstruction *I,
ValueBase *V) { /* ReplaceInstUsesAction */
MadeChange = true;
/* ReplaceValueUsesAction */
[&MadeChange](SILValue oldValue, SILValue newValue) {
MadeChange = true;
},
[&MadeChange](SILInstruction *I) { /* EraseInstAction */
MadeChange = true;
I->eraseFromParent();
/* ReplaceInstUsesAction */
[&MadeChange](SILInstruction *I, ValueBase *V) { MadeChange = true; },
/* EraseInstAction */
[&MadeChange](SILInstruction *I) {
MadeChange = true;
I->eraseFromParent();
},
[&]() { /* WillSucceedAction */
MadeChange |= removeIfDead(FailureBB);
addToWorklist(ThisBB);
/* WillSucceedAction */
[&]() {
MadeChange |= removeIfDead(FailureBB);
addToWorklist(ThisBB);
},
[&]() { /* WillFailAction */
MadeChange |= removeIfDead(SuccessBB);
addToWorklist(ThisBB);
/* WillFailAction */
[&]() {
MadeChange |= removeIfDead(SuccessBB);
addToWorklist(ThisBB);
});
MadeChange |= bool(CastOpt.simplifyCheckedCastValueBranchInst(CCBI));
@@ -1994,19 +2005,24 @@ simplifyCheckedCastAddrBranchBlock(CheckedCastAddrBranchInst *CCABI) {
auto ThisBB = CCABI->getParent();
bool MadeChange = false;
CastOptimizer CastOpt(FuncBuilder,
[&MadeChange](SILInstruction *I, ValueBase *V) {
MadeChange = true;
}, /* ReplaceInstUsesAction */
[&MadeChange](SILInstruction *I) { /* EraseInstAction */
CastOptimizer CastOpt(
FuncBuilder,
/* ReplaceValueUsesAction */
[&MadeChange](SILValue, SILValue) { MadeChange = true; },
/* ReplaceInstUsesAction */
[&MadeChange](SILInstruction *I, ValueBase *V) { MadeChange = true; },
/* EraseInstAction */
[&MadeChange](SILInstruction *I) {
MadeChange = true;
I->eraseFromParent();
},
[&]() { /* WillSucceedAction */
/* WillSucceedAction */
[&]() {
MadeChange |= removeIfDead(FailureBB);
addToWorklist(ThisBB);
},
[&]() { /* WillFailAction */
/* WillFailAction */
[&]() {
MadeChange |= removeIfDead(SuccessBB);
addToWorklist(ThisBB);
});