mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[sil-optimizer] Get rid of the InstModCallback constructors in favor of onDelete/onCreatedNewInst/etc.
Without this when constructing an InstModCallback it is hard to distinguish which closure is meant for which operation when passed to the constructor of InstModCallback (if this was in Swift, we could use argument labels, but we do not have such things in c++). This new value type sort of formulation makes it unambiguous which callback is used for what when constructing one of these.
This commit is contained in:
@@ -143,18 +143,22 @@ public:
|
||||
DeadEndBlocks &deadEndBlocks)
|
||||
: compilingWithOptimization(optimized), worklist("MC"), madeChange(false),
|
||||
iteration(0),
|
||||
instModCallbacks(
|
||||
[&](SILInstruction *instruction) {
|
||||
worklist.erase(instruction);
|
||||
instructionsPendingDeletion.push_back(instruction);
|
||||
},
|
||||
[&](SILInstruction *instruction) { worklist.add(instruction); },
|
||||
[this](Operand *use, SILValue newValue) {
|
||||
use->set(newValue);
|
||||
worklist.add(use->getUser());
|
||||
}),
|
||||
instModCallbacks(),
|
||||
createdInstructions(createdInstructions),
|
||||
deadEndBlocks(deadEndBlocks){};
|
||||
deadEndBlocks(deadEndBlocks) {
|
||||
instModCallbacks = InstModCallbacks()
|
||||
.onDelete([&](SILInstruction *instruction) {
|
||||
worklist.erase(instruction);
|
||||
instructionsPendingDeletion.push_back(instruction);
|
||||
})
|
||||
.onCreateNewInst([&](SILInstruction *instruction) {
|
||||
worklist.add(instruction);
|
||||
})
|
||||
.onSetUseValue([this](Operand *use, SILValue newValue) {
|
||||
use->set(newValue);
|
||||
worklist.add(use->getUser());
|
||||
});
|
||||
};
|
||||
|
||||
void addReachableCodeToWorklist(SILFunction &function);
|
||||
|
||||
|
||||
@@ -527,7 +527,7 @@ static bool stripOwnership(SILFunction &func) {
|
||||
auto value = visitor.instructionsToSimplify.pop_back_val();
|
||||
if (!value.hasValue())
|
||||
continue;
|
||||
InstModCallbacks callbacks([&](SILInstruction *instToErase) {
|
||||
auto callbacks = InstModCallbacks().onDelete([&](SILInstruction *instToErase) {
|
||||
visitor.eraseInstruction(instToErase);
|
||||
});
|
||||
// We are no longer in OSSA, so we don't need to pass in a deBlocks.
|
||||
|
||||
@@ -116,19 +116,21 @@ public:
|
||||
},
|
||||
/* EraseAction */
|
||||
[&](SILInstruction *I) { eraseInstFromFunction(*I); }),
|
||||
instModCallbacks(
|
||||
[&](SILInstruction *instToDelete) {
|
||||
eraseInstFromFunction(*instToDelete);
|
||||
},
|
||||
[&](SILInstruction *newlyCreatedInst) {
|
||||
Worklist.add(newlyCreatedInst);
|
||||
},
|
||||
[&](Operand *use, SILValue newValue) {
|
||||
use->set(newValue);
|
||||
Worklist.add(use->getUser());
|
||||
}),
|
||||
instModCallbacks(),
|
||||
deBlocks(&B.getFunction()),
|
||||
ownershipFixupContext(instModCallbacks, deBlocks) {}
|
||||
ownershipFixupContext(instModCallbacks, deBlocks) {
|
||||
instModCallbacks = InstModCallbacks()
|
||||
.onDelete([&](SILInstruction *instToDelete) {
|
||||
eraseInstFromFunction(*instToDelete);
|
||||
})
|
||||
.onCreateNewInst([&](SILInstruction *newlyCreatedInst) {
|
||||
Worklist.add(newlyCreatedInst);
|
||||
})
|
||||
.onSetUseValue([&](Operand *use, SILValue newValue) {
|
||||
use->set(newValue);
|
||||
Worklist.add(use->getUser());
|
||||
});
|
||||
}
|
||||
|
||||
bool runOnFunction(SILFunction &F);
|
||||
|
||||
|
||||
@@ -52,9 +52,10 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor
|
||||
explicit SemanticARCOptVisitor(SILFunction &fn, DeadEndBlocks &deBlocks,
|
||||
bool onlyMandatoryOpts)
|
||||
: ctx(fn, deBlocks, onlyMandatoryOpts,
|
||||
InstModCallbacks(
|
||||
[this](SILInstruction *inst) { eraseInstruction(inst); },
|
||||
[this](Operand *use, SILValue newValue) {
|
||||
InstModCallbacks()
|
||||
.onDelete(
|
||||
[this](SILInstruction *inst) { eraseInstruction(inst); })
|
||||
.onSetUseValue([this](Operand *use, SILValue newValue) {
|
||||
use->set(newValue);
|
||||
worklist.insert(newValue);
|
||||
})) {}
|
||||
|
||||
@@ -783,7 +783,7 @@ void TempRValueOptPass::run() {
|
||||
}
|
||||
}
|
||||
|
||||
InstModCallbacks callbacks(
|
||||
auto callbacks = InstModCallbacks().onDelete(
|
||||
[](SILInstruction *instToKill) {
|
||||
// SimplifyInstruction is not in the business of removing
|
||||
// copy_addr. If it were, then we would need to update deadCopies.
|
||||
|
||||
Reference in New Issue
Block a user