-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[sil-inst-opt] Change InstModCallbacks to specify a setUseValue callback instead of RAUW callbacks. #35256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sil-inst-opt] Change InstModCallbacks to specify a setUseValue callback instead of RAUW callbacks. #35256
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,8 +148,9 @@ class MandatoryCombiner final | |
instructionsPendingDeletion.push_back(instruction); | ||
}, | ||
[&](SILInstruction *instruction) { worklist.add(instruction); }, | ||
[this](SILValue oldValue, SILValue newValue) { | ||
worklist.replaceValueUsesWith(oldValue, newValue); | ||
[this](Operand *use, SILValue newValue) { | ||
use->set(newValue); | ||
worklist.add(use->getUser()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be doing a hash lookup on every operand update! |
||
}), | ||
createdInstructions(createdInstructions), | ||
deadEndBlocks(deadEndBlocks){}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,9 +53,9 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor | |
: ctx(fn, onlyGuaranteedOpts, | ||
InstModCallbacks( | ||
[this](SILInstruction *inst) { eraseInstruction(inst); }, | ||
[](SILInstruction *) {}, [](SILValue, SILValue) {}, | ||
[this](SingleValueInstruction *i, SILValue value) { | ||
eraseAndRAUWSingleValueInstruction(i, value); | ||
[this](Operand *use, SILValue newValue) { | ||
use->set(newValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hunk may be slightly confusing. What is happening is that rather than passing an empty argument for createdNewInst, I am just using an overload of InstModCallback's constructor that omits it (and thus assumes we want the default... which we do). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A single RAUW could replace thousands of operands. We design IR's very carefully so operand setting can be as efficient as possible. We definitely don't want to do a hash lookup each time. There only needs to be a single worklist insertion per RAUW operation. |
||
worklist.insert(newValue); | ||
})) {} | ||
|
||
void reset() { | ||
|
@@ -118,14 +118,7 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor | |
drainVisitedSinceLastMutationIntoWorklist(); | ||
} | ||
|
||
InstModCallbacks getCallbacks() { | ||
return InstModCallbacks( | ||
[this](SILInstruction *inst) { eraseInstruction(inst); }, | ||
[](SILInstruction *) {}, [](SILValue, SILValue) {}, | ||
[this](SingleValueInstruction *i, SILValue value) { | ||
eraseAndRAUWSingleValueInstruction(i, value); | ||
}); | ||
} | ||
InstModCallbacks &getCallbacks() { return ctx.instModCallbacks; } | ||
|
||
bool visitSILInstruction(SILInstruction *i) { | ||
assert((isa<OwnershipForwardingTermInst>(i) || | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,7 +434,7 @@ void OwnershipRAUWUtility::eliminateReborrowsOfRecursiveBorrows( | |
|
||
// Then set our borrowing operand to take our innerBorrow instead of value | ||
// (whose lifetime we just ended). | ||
borrowingOperand->set(innerBorrow); | ||
callbacks.setUseValue(*borrowingOperand, innerBorrow); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one of the files where I already knew there were issues with us not having full coverage of IR changes via InstModCallbacks. I went through and fixed it in all of the appropriate places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but who needs to know that borrowingOperand changed as opposed to innerBorrow? |
||
// Add our outer end borrow as a use point to make sure that we extend our | ||
// base value to this point. | ||
usePoints.push_back(&outerEndBorrow->getAllOperands()[0]); | ||
|
@@ -500,7 +500,7 @@ void OwnershipRAUWUtility::rewriteReborrows( | |
callbacks.createdNewInst(innerBorrow); | ||
callbacks.createdNewInst(outerEndBorrow); | ||
|
||
reborrow->set(innerBorrow); | ||
callbacks.setUseValue(*reborrow, innerBorrow); | ||
|
||
auto *borrowedArg = | ||
const_cast<SILPhiArgument *>(bi->getArgForOperand(reborrow.op)); | ||
|
@@ -570,7 +570,7 @@ SILBasicBlock::iterator OwnershipRAUWUtility::handleUnowned() { | |
auto *newInst = builder.createUncheckedOwnershipConversion( | ||
ti->getLoc(), use->get(), OwnershipKind::Unowned); | ||
callbacks.createdNewInst(newInst); | ||
use->set(newInst); | ||
callbacks.setUseValue(use, newInst); | ||
} | ||
} | ||
} | ||
|
@@ -602,7 +602,7 @@ SILBasicBlock::iterator OwnershipRAUWUtility::handleUnowned() { | |
auto *newInst = builder.createUncheckedOwnershipConversion( | ||
ti->getLoc(), use->get(), OwnershipKind::Unowned); | ||
callbacks.createdNewInst(newInst); | ||
use->set(newInst); | ||
callbacks.setUseValue(use, newInst); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the files where I already knew there were issues with us not having full coverage of IR changes via InstModCallbacks. I went through and fixed it in all of the appropriate places to use callbacks.setUseValue();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The obvious fix here would just have been to call the rauw callback, which we'll still need to do anyway.