This PR re-lands https://github.com/llvm/llvm-project/pull/115968 with a
fix for a buildbot failure.
The `IRSnapshotChecker` class is only defined in debug mode, so its unit
tests must also be inside `#ifndef NDEBUG`.
Preserving the case order is not strictly necessary to preserve
semantics (for example, operations like SwitchInst::removeCase will
happily swap cases around). However, I'm planning to introduce an
optional verification step for SandboxIR that will use StructuralHash to
compare IR after a revert to the original IR to help catch tracker bugs,
and the order difference triggers a difference there.
Note that PointerUnion::{is,get,dyn_cast} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>
This patch adds a generic change tracker class, similar to
GenericSetter, but for getter/setter functions that also take an index
argument. For example: `Foo:get(Idx)` and `Foo::set(Idx, Val)`. These
setter/getter patterns are common enough that using a common
implementation seems beneficial.
This patch introduces Tracker::emplaceIfTracking(), a wrapper of Tracker::track() that will conditionally create the change object if tracking is enabled.
This patch also removes the `Parent` member field of `IRChangeBase`.
This patch introduces the `GenericSetter` tracker class that can be used
to track and revert simple instruction setters.
This patch also replaces several setter tracker classes with the generic
one.
This patch adds tracking support for the creation of SandboxIR
instructions. This allows us to undo the creation of instructions during
revert().
Please note that we don't allow creation of detached instructions,
meaning that the instructions need to be inserted into a block upon
creation. This is why the tracker class combines creation and insertion.
This patch implements sandboxir::CallBrInst which mirrors
llvm::CallBrInst.
LLVM IR does not expose the Uses to DefaultDest and IndirectDest so we
need special Tracker objects for both of setters.
This patch implements sandboxir::BranchInst which mirrors
llvm::BranchInst.
BranchInst::swapSuccessors() relies on User::swapOperandsInternal() so
this patch also adds Use::swap() and the corresponding tracking code and
test.
This patch adds tracking support for Instruction::eraseFromParent(). The
Instruction is not actually being erased, but instead it is detached
from the instruction list and drops its Use edges. The original
instruction position and Use edges are saved in the `EraseFromParent`
change object, and are being used during `revert()` to restore the
original state.
This is the first patch in a series of patches for the IR change
tracking component of SandboxIR.
The tracker collects changes in a vector of `IRChangeBase` objects and
provides a `save()`/`accept()`/`revert()` API.
Each type of IR changing event is captured by a dedicated subclass of
`IRChangeBase`. This patch implements only one of them, that for
updating a `sandboxir::Use` source value, named `UseSet`.