[llvm] [SandboxIR] Preserve the order of switch cases after revert. (PR #115577)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 11 15:12:45 PST 2024
================
@@ -170,7 +170,19 @@ void CatchSwitchAddHandler::revert(Tracker &Tracker) {
LLVMCSI->removeHandler(LLVMCSI->handler_begin() + HandlerIdx);
}
-void SwitchRemoveCase::revert(Tracker &Tracker) { Switch->addCase(Val, Dest); }
+void SwitchRemoveCase::revert(Tracker &Tracker) {
+ // removeCase swaps the last case with the deleted one. To revert it, we use
+ // addCase (which adds the new case to the end), and swap the newly-added
+ // value and successor operands to the positions for the original case index.
+ Switch->addCase(Val, Dest);
+ auto ValUseA = Switch->getOperandUse(2 + Index * 2);
+ auto SucUseA = Switch->getOperandUse(2 + Index * 2 + 1);
+ unsigned NumOps = Switch->getNumOperands();
+ auto ValUseB = Switch->getOperandUse(NumOps - 2);
+ auto SucUseB = Switch->getOperandUse(NumOps - 2 + 1);
+ ValUseA.swap(ValUseB);
----------------
vporpo wrote:
> I can try to rephrase/expand it if it wasn't clear enough.
Sorry, what I wanted to say is that it would be nice to show the example with the ordering of cases by actually showing them too like with `(case0, case1, case2)`.
> Which one do you prefer?
I am fine with either, but if we stick with this one, we should probably be very specific about the fact that this is implementation dependent and that it could break.
https://github.com/llvm/llvm-project/pull/115577
More information about the llvm-commits
mailing list