48#ifndef LLVM_SANDBOXIR_TRACKER_H
49#define LLVM_SANDBOXIR_TRACKER_H
91 struct FunctionSnapshot {
93 std::string TextualIR;
102 ContextSnapshot OrigContextSnapshot;
108 ContextSnapshot takeSnapshot()
const;
111 bool diff(
const ContextSnapshot &Orig,
const ContextSnapshot &Curr)
const;
150 Value *OrigV =
nullptr;
212 : ThisUse(ThisUse), OtherUse(OtherUse) {
213 assert(ThisUse.getUser() == OtherUse.getUser() &&
"Expected same user!");
226 struct InstrAndOperands {
239 std::unique_ptr<sandboxir::Value> ErasedIPtr;
284template <auto GetterFn, auto SetterFn>
287 template <
typename>
struct GetClassTypeFromGetter;
288 template <
typename RetT,
typename ClassT>
289 struct GetClassTypeFromGetter<RetT (ClassT::*)()
const> {
290 using ClassType = ClassT;
292 using InstrT =
typename GetClassTypeFromGetter<
decltype(GetterFn)>::ClassType;
293 using SavedValT = std::invoke_result_t<
decltype(GetterFn), InstrT>;
312template <auto GetterFn, auto SetterFn>
315 template <
typename ClassT,
typename RetT>
316 static ClassT getClassTypeFromGetter(RetT (ClassT::*Fn)(
unsigned)
const);
317 template <
typename ClassT,
typename RetT>
318 static ClassT getClassTypeFromGetter(RetT (ClassT::*Fn)(
unsigned));
320 using InstrT =
decltype(getClassTypeFromGetter(GetterFn));
321 using SavedValT = std::invoke_result_t<
decltype(GetterFn), InstrT,
unsigned>;
328 : I(I), OrigVal((I->*GetterFn)(Idx)), Idx(Idx) {}
363 : Switch(Switch), Val(Val) {}
485 bool empty()
const {
return Changes.empty(); }
488 void track(std::unique_ptr<IRChangeBase> &&Change) {
492 "We are in the middle of creating another change!");
496 Changes.push_back(std::move(Change));
504 template <
typename ChangeT,
typename... ArgsT>
508 track(std::make_unique<ChangeT>(Args...));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define LLVM_ABI_FOR_TEST
This file defines the PointerUnion class, which is a discriminated union of pointer types.
This file defines the SmallVector class.
A discriminated union of two or more pointer types, with the discriminator in the low bits of the poi...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_DUMP_METHOD void dump() const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
CatchSwitchAddHandler(CatchSwitchInst *CSI)
void accept() final
This runs when changes get accepted.
void dump(raw_ostream &OS) const final
void dump(raw_ostream &OS) const final
void accept() final
This runs when changes get accepted.
void revert(Tracker &Tracker) final
This runs when changes get reverted.
CmpSwapOperands(CmpInst *Cmp)
void accept() final
This runs when changes get accepted.
CreateAndInsertInst(Instruction *NewI)
void dump(raw_ostream &OS) const final
void dump(raw_ostream &OS) const final
void accept() final
This runs when changes get accepted.
void revert(Tracker &Tracker) final
This runs when changes get reverted.
EraseFromParent(std::unique_ptr< sandboxir::Value > &&IPtr)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
LLVM_DUMP_METHOD void dump() const final
void dump(raw_ostream &OS) const final
GenericSetterWithIdx(InstrT *I, unsigned Idx)
void accept() final
This runs when changes get accepted.
void dump(raw_ostream &OS) const final
void accept() final
This runs when changes get accepted.
void revert(Tracker &Tracker) final
This runs when changes get reverted.
LLVM_DUMP_METHOD void dump() const final
The base class for IR Change classes.
virtual LLVM_DUMP_METHOD void dump() const =0
virtual void revert(Tracker &Tracker)=0
This runs when changes get reverted.
friend raw_ostream & operator<<(raw_ostream &OS, const IRChangeBase &C)
virtual ~IRChangeBase()=default
virtual void accept()=0
This runs when changes get accepted.
virtual void dump(raw_ostream &OS) const =0
IRSnapshotChecker(Context &Ctx)
LLVM_ABI_FOR_TEST void expectNoDiff()
Checks current state against saved state, crashes if different.
LLVM_ABI_FOR_TEST void save()
Saves a snapshot of the current state.
void dump(raw_ostream &OS) const final
void accept() final
This runs when changes get accepted.
InsertIntoBB(Instruction *InsertedI)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
MoveInstr(sandboxir::Instruction *I)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void accept() final
This runs when changes get accepted.
void dump(raw_ostream &OS) const final
PHIAddIncoming(PHINode *PHI)
void dump(raw_ostream &OS) const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void accept() final
This runs when changes get accepted.
void accept() final
This runs when changes get accepted.
PHIRemoveIncoming(PHINode *PHI, unsigned RemovedIdx)
void dump(raw_ostream &OS) const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void dump(raw_ostream &OS) const final
Instruction * getInstruction() const
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void accept() final
This runs when changes get accepted.
RemoveFromParent(Instruction *RemovedI)
ShuffleVectorSetMask(ShuffleVectorInst *SVI)
void accept() final
This runs when changes get accepted.
void dump(raw_ostream &OS) const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
SwitchAddCase(SwitchInst *Switch, ConstantInt *Val)
void dump(raw_ostream &OS) const final
void accept() final
This runs when changes get accepted.
void dump(raw_ostream &OS) const final
SwitchRemoveCase(SwitchInst *Switch)
void accept() final
This runs when changes get accepted.
void revert(Tracker &Tracker) final
This runs when changes get reverted.
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
LLVM_ABI void revert(bool RevertAll=false)
Stops tracking and reverts to saved state.
unsigned nestingDepth() const
TrackerState getState() const
\Returns the current state of the tracker.
bool empty() const
\Returns true if there are no changes tracked.
friend raw_ostream & operator<<(raw_ostream &OS, const Tracker &Tracker)
bool isTracking() const
\Returns true if the tracker is recording changes.
LLVM_ABI void accept(bool AcceptAll=false)
Stops tracking and accept changes.
LLVM_ABI void save()
Turns on IR tracking.
void track(std::unique_ptr< IRChangeBase > &&Change)
Record Change and take ownership.
bool InMiddleOfCreatingChange
Helps catch bugs where we are creating new change objects while in the middle of creating other chang...
Context & getContext() const
bool emplaceIfTracking(ArgsT... Args)
A convenience wrapper for track() that constructs and tracks the Change object if tracking is enabled...
LLVM_DUMP_METHOD void dump() const
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void dump(raw_ostream &OS) const final
void accept() final
This runs when changes get accepted.
LLVM_DUMP_METHOD void dump() const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
LLVM_DUMP_METHOD void dump() const final
void accept() final
This runs when changes get accepted.
void dump(raw_ostream &OS) const final
UseSwap(const Use &ThisUse, const Use &OtherUse)
Represents a Def-use/Use-def edge in SandboxIR.
A SandboxIR Value has users. This is the base class.
@ C
The default llvm calling convention, compatible with C.
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
uint64_t stable_hash
An opaque object representing a stable hash code.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.