[NFC] Avoid repeatedly instantiating std::function

This commit is contained in:
Brent Royal-Gordon
2020-09-01 12:54:01 -07:00
parent 9057123739
commit dd726a0015
4 changed files with 45 additions and 18 deletions

View File

@@ -308,21 +308,22 @@ bool tryCheckedCastBrJumpThreading(
/// A structure containing callbacks that are called when an instruction is
/// removed or added.
struct InstModCallbacks {
std::function<void(SILInstruction *)> deleteInst = [](SILInstruction *inst) {
inst->eraseFromParent();
};
std::function<void(SILInstruction *)> createdNewInst = [](SILInstruction *) {
};
std::function<void(SILValue, SILValue)> replaceValueUsesWith =
[](SILValue oldValue, SILValue newValue) {
oldValue->replaceAllUsesWith(newValue);
};
static const std::function<void(SILInstruction *)> defaultDeleteInst;
static const std::function<void(SILInstruction *)> defaultCreatedNewInst;
static const std::function<void(SILValue, SILValue)> defaultReplaceValueUsesWith;
static const std::function<void(SingleValueInstruction *, SILValue)>
defaultEraseAndRAUWSingleValueInst;
std::function<void(SILInstruction *)> deleteInst =
InstModCallbacks::defaultDeleteInst;
std::function<void(SILInstruction *)> createdNewInst =
InstModCallbacks::defaultCreatedNewInst;
std::function<void(SILValue, SILValue)>
replaceValueUsesWith =
InstModCallbacks::defaultReplaceValueUsesWith;
std::function<void(SingleValueInstruction *, SILValue)>
eraseAndRAUWSingleValueInst =
[](SingleValueInstruction *i, SILValue newValue) {
i->replaceAllUsesWith(newValue);
i->eraseFromParent();
};
InstModCallbacks::defaultEraseAndRAUWSingleValueInst;
InstModCallbacks(decltype(deleteInst) deleteInst,
decltype(createdNewInst) createdNewInst,
@@ -330,10 +331,7 @@ struct InstModCallbacks {
: deleteInst(deleteInst), createdNewInst(createdNewInst),
replaceValueUsesWith(replaceValueUsesWith),
eraseAndRAUWSingleValueInst(
[](SingleValueInstruction *i, SILValue newValue) {
i->replaceAllUsesWith(newValue);
i->eraseFromParent();
}) {}
InstModCallbacks::defaultEraseAndRAUWSingleValueInst) {}
InstModCallbacks(
decltype(deleteInst) deleteInst, decltype(createdNewInst) createdNewInst,