LLVM 24.0.0git
Tracker.h
Go to the documentation of this file.
1//===- Tracker.h ------------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is the component of SandboxIR that tracks all changes made to its
10// state, such that we can revert the state when needed.
11//
12// Tracking changes
13// ----------------
14// The user needs to call `Tracker::save()` to enable tracking changes
15// made to SandboxIR. From that point on, any change made to SandboxIR, will
16// automatically create a change tracking object and register it with the
17// tracker. IR-change objects are subclasses of `IRChangeBase` and get
18// registered with the `Tracker::track()` function. The change objects
19// are saved in the order they are registered with the tracker and are stored in
20// the `Tracker::Changes` vector. All of this is done transparently to
21// the user.
22// Calling `Tracker::save()` a second time without having accepted/reverted the
23// state, creates a second nested checkpoint.
24//
25// Reverting changes
26// -----------------
27// Calling `Tracker::revert()` will restore the state saved when the last
28// `Tracker::save()` was called. Internally this goes through the
29// change objects in `Tracker::Changes` in reverse order, calling their
30// `IRChangeBase::revert()` function one by one.
31// In the context of a nested checkpoint, this will revert the state
32// until the last `Tracker::save()` checkpoint.
33// You can revert all changes with `Tracker::revert(/*RevertAll=*/true)`.
34//
35// Accepting changes
36// -----------------
37// The user needs to either revert or accept changes before the tracker object
38// is destroyed. This is enforced in the tracker's destructor.
39// This is the job of `Tracker::accept()`. Internally this will go
40// through the change objects in `Tracker::Changes` in order, calling
41// `IRChangeBase::accept()`.
42// In the context of a nested checkpoint, this will leave the state unchanged
43// and will remove the last checkpoint for the stack.
44// You can accept all changes with `Tracker::accept(/*AcceptAll=*/true)`.
45//
46//===----------------------------------------------------------------------===//
47
48#ifndef LLVM_SANDBOXIR_TRACKER_H
49#define LLVM_SANDBOXIR_TRACKER_H
50
54#include "llvm/IR/IRBuilder.h"
55#include "llvm/IR/Instruction.h"
56#include "llvm/SandboxIR/Use.h"
59#include "llvm/Support/Debug.h"
60#include <memory>
61
62namespace llvm::sandboxir {
63
64class BasicBlock;
65class Instruction;
66class Tracker;
67class CatchSwitchInst;
68class SwitchInst;
69class ConstantInt;
71class CmpInst;
72
73#ifndef NDEBUG
74
75/// A class that saves hashes and textual IR snapshots of functions in a
76/// SandboxIR Context, and does hash comparison when `expectNoDiff` is called.
77/// If hashes differ, it prints textual IR for both old and new versions to
78/// aid debugging.
79///
80/// This is used as an additional debug check when reverting changes to
81/// SandboxIR, to verify the reverted state matches the initial state.
83 Context &Ctx;
84
85 // A snapshot of textual IR for a function, with a hash for quick comparison.
86 struct FunctionSnapshot {
88 std::string TextualIR;
89 };
90
91 // A snapshot for each llvm::Function found in every module in the SandboxIR
92 // Context. In practice there will always be one module, but sandbox IR
93 // save/restore ops work at the Context level, so we must take the full state
94 // into account.
96
97 ContextSnapshot OrigContextSnapshot;
98
99 // Dumps to a string the textual IR for a single Function.
100 std::string dumpIR(const llvm::Function &F) const;
101
102 // Returns a snapshot of all the modules in the sandbox IR context.
103 ContextSnapshot takeSnapshot() const;
104
105 // Compares two snapshots and returns true if they differ.
106 bool diff(const ContextSnapshot &Orig, const ContextSnapshot &Curr) const;
107
108public:
109 IRSnapshotChecker(Context &Ctx) : Ctx(Ctx) {}
110
111 /// Saves a snapshot of the current state. If there was any previous snapshot,
112 /// it will be replaced with the new one.
113 LLVM_ABI void save();
114
115 /// Checks current state against saved state, crashes if different.
116 LLVM_ABI void expectNoDiff();
117};
118
119#endif // NDEBUG
120
121/// The base class for IR Change classes.
123protected:
124 friend class Tracker; // For Parent.
125
126public:
127 /// This runs when changes get reverted.
128 virtual void revert(Tracker &Tracker) = 0;
129 /// This runs when changes get accepted.
130 virtual void accept() = 0;
131 virtual ~IRChangeBase() = default;
132#ifndef NDEBUG
133 virtual void dump(raw_ostream &OS) const = 0;
134 LLVM_DUMP_METHOD virtual void dump() const = 0;
136 C.dump(OS);
137 return OS;
138 }
139#endif
140};
141
142/// Tracks the change of the source Value of a sandboxir::Use.
143class UseSet : public IRChangeBase {
144 Use U;
145 Value *OrigV = nullptr;
146
147public:
148 UseSet(const Use &U) : U(U), OrigV(U.get()) {}
149 void revert(Tracker &Tracker) final { U.set(OrigV); }
150 void accept() final {}
151#ifndef NDEBUG
152 void dump(raw_ostream &OS) const final { OS << "UseSet"; }
153 LLVM_DUMP_METHOD void dump() const final;
154#endif
155};
156
158 PHINode *PHI;
159 unsigned RemovedIdx;
160 Value *RemovedV;
161 BasicBlock *RemovedBB;
162
163public:
164 PHIRemoveIncoming(PHINode *PHI, unsigned RemovedIdx);
165 void revert(Tracker &Tracker) final;
166 void accept() final {}
167#ifndef NDEBUG
168 void dump(raw_ostream &OS) const final { OS << "PHISetIncoming"; }
169 LLVM_DUMP_METHOD void dump() const final;
170#endif
171};
172
174 PHINode *PHI;
175 unsigned Idx;
176
177public:
179 void revert(Tracker &Tracker) final;
180 void accept() final {}
181#ifndef NDEBUG
182 void dump(raw_ostream &OS) const final { OS << "PHISetIncoming"; }
183 LLVM_DUMP_METHOD void dump() const final;
184#endif
185};
186
188 CmpInst *Cmp;
189
190public:
192 void revert(Tracker &Tracker) final;
193 void accept() final {}
194#ifndef NDEBUG
195 void dump(raw_ostream &OS) const final { OS << "CmpSwapOperands"; }
196 LLVM_DUMP_METHOD void dump() const final;
197#endif
198};
199
200/// Tracks swapping a Use with another Use.
201class UseSwap : public IRChangeBase {
202 Use ThisUse;
203 Use OtherUse;
204
205public:
206 UseSwap(const Use &ThisUse, const Use &OtherUse)
207 : ThisUse(ThisUse), OtherUse(OtherUse) {
208 assert(ThisUse.getUser() == OtherUse.getUser() && "Expected same user!");
209 }
210 void revert(Tracker &Tracker) final { ThisUse.swap(OtherUse); }
211 void accept() final {}
212#ifndef NDEBUG
213 void dump(raw_ostream &OS) const final { OS << "UseSwap"; }
214 LLVM_DUMP_METHOD void dump() const final;
215#endif
216};
217
219 /// Contains all the data we need to restore an "erased" (i.e., detached)
220 /// instruction: the instruction itself and its operands in order.
221 struct InstrAndOperands {
222 /// The operands that got dropped.
224 /// The instruction that got "erased".
225 llvm::Instruction *LLVMI;
226 };
227 /// The instruction data is in reverse program order, which helps create the
228 /// original program order during revert().
230 /// This is either the next Instruction in the stream, or the parent
231 /// BasicBlock if at the end of the BB.
233 /// We take ownership of the "erased" instruction.
234 std::unique_ptr<sandboxir::Value> ErasedIPtr;
235
236public:
237 EraseFromParent(std::unique_ptr<sandboxir::Value> &&IPtr);
238 void revert(Tracker &Tracker) final;
239 void accept() final;
240#ifndef NDEBUG
241 void dump(raw_ostream &OS) const final { OS << "EraseFromParent"; }
242 LLVM_DUMP_METHOD void dump() const final;
243 friend raw_ostream &operator<<(raw_ostream &OS, const EraseFromParent &C) {
244 C.dump(OS);
245 return OS;
246 }
247#endif
248};
249
251 /// The instruction that is about to get removed.
252 Instruction *RemovedI = nullptr;
253 /// This is either the next instr, or the parent BB if at the end of the BB.
255
256public:
257 RemoveFromParent(Instruction *RemovedI);
258 void revert(Tracker &Tracker) final;
259 void accept() final {};
260 Instruction *getInstruction() const { return RemovedI; }
261#ifndef NDEBUG
262 void dump(raw_ostream &OS) const final { OS << "RemoveFromParent"; }
263 LLVM_DUMP_METHOD void dump() const final;
264#endif // NDEBUG
265};
266
267/// This class can be used for tracking most instruction setters.
268/// The two template arguments are:
269/// - GetterFn: The getter member function pointer (e.g., `&Foo::get`)
270/// - SetterFn: The setter member function pointer (e.g., `&Foo::set`)
271/// Upon construction, it saves a copy of the original value by calling the
272/// getter function. Revert sets the value back to the one saved, using the
273/// setter function provided.
274///
275/// Example:
276/// Tracker.track(std::make_unique<
277/// GenericSetter<&FooInst::get, &FooInst::set>>(I, Tracker));
278///
279template <auto GetterFn, auto SetterFn>
280class GenericSetter final : public IRChangeBase {
281 /// Traits for getting the class type from GetterFn type.
282 template <typename> struct GetClassTypeFromGetter;
283 template <typename RetT, typename ClassT>
284 struct GetClassTypeFromGetter<RetT (ClassT::*)() const> {
285 using ClassType = ClassT;
286 };
287 using InstrT = typename GetClassTypeFromGetter<decltype(GetterFn)>::ClassType;
288 using SavedValT = std::invoke_result_t<decltype(GetterFn), InstrT>;
289 InstrT *I;
290 SavedValT OrigVal;
291
292public:
293 GenericSetter(InstrT *I) : I(I), OrigVal((I->*GetterFn)()) {}
294 void revert(Tracker &Tracker) final { (I->*SetterFn)(OrigVal); }
295 void accept() final {}
296#ifndef NDEBUG
297 void dump(raw_ostream &OS) const final { OS << "GenericSetter"; }
299 dump(dbgs());
300 dbgs() << "\n";
301 }
302#endif
303};
304
305/// Similar to GenericSetter but the setters/getters have an index as their
306/// first argument. This is commont in cases like: getOperand(unsigned Idx)
307template <auto GetterFn, auto SetterFn>
308class GenericSetterWithIdx final : public IRChangeBase {
309 /// Helper for getting the class type from the getter
310 template <typename ClassT, typename RetT>
311 static ClassT getClassTypeFromGetter(RetT (ClassT::*Fn)(unsigned) const);
312 template <typename ClassT, typename RetT>
313 static ClassT getClassTypeFromGetter(RetT (ClassT::*Fn)(unsigned));
314
315 using InstrT = decltype(getClassTypeFromGetter(GetterFn));
316 using SavedValT = std::invoke_result_t<decltype(GetterFn), InstrT, unsigned>;
317 InstrT *I;
318 SavedValT OrigVal;
319 unsigned Idx;
320
321public:
322 GenericSetterWithIdx(InstrT *I, unsigned Idx)
323 : I(I), OrigVal((I->*GetterFn)(Idx)), Idx(Idx) {}
324 void revert(Tracker &Tracker) final { (I->*SetterFn)(Idx, OrigVal); }
325 void accept() final {}
326#ifndef NDEBUG
327 void dump(raw_ostream &OS) const final { OS << "GenericSetterWithIdx"; }
329 dump(dbgs());
330 dbgs() << "\n";
331 }
332#endif
333};
334
336 CatchSwitchInst *CSI;
337 unsigned HandlerIdx;
338
339public:
341 void revert(Tracker &Tracker) final;
342 void accept() final {}
343#ifndef NDEBUG
344 void dump(raw_ostream &OS) const final { OS << "CatchSwitchAddHandler"; }
346 dump(dbgs());
347 dbgs() << "\n";
348 }
349#endif // NDEBUG
350};
351
353 SwitchInst *Switch;
354 ConstantInt *Val;
355
356public:
358 : Switch(Switch), Val(Val) {}
359 void revert(Tracker &Tracker) final;
360 void accept() final {}
361#ifndef NDEBUG
362 void dump(raw_ostream &OS) const final { OS << "SwitchAddCase"; }
363 LLVM_DUMP_METHOD void dump() const final;
364#endif // NDEBUG
365};
366
368 SwitchInst *Switch;
369 struct Case {
370 ConstantInt *Val;
371 BasicBlock *Dest;
372 };
373 SmallVector<Case> Cases;
374
375public:
377
378 void revert(Tracker &Tracker) final;
379 void accept() final {}
380#ifndef NDEBUG
381 void dump(raw_ostream &OS) const final { OS << "SwitchRemoveCase"; }
382 LLVM_DUMP_METHOD void dump() const final;
383#endif // NDEBUG
384};
385
387 /// The instruction that moved.
388 Instruction *MovedI;
389 /// This is either the next instruction in the block, or the parent BB if at
390 /// the end of the BB.
392
393public:
395 void revert(Tracker &Tracker) final;
396 void accept() final {}
397#ifndef NDEBUG
398 void dump(raw_ostream &OS) const final { OS << "MoveInstr"; }
399 LLVM_DUMP_METHOD void dump() const final;
400#endif // NDEBUG
401};
402
403class LLVM_ABI InsertIntoBB final : public IRChangeBase {
404 Instruction *InsertedI = nullptr;
405
406public:
407 InsertIntoBB(Instruction *InsertedI);
408 void revert(Tracker &Tracker) final;
409 void accept() final {}
410#ifndef NDEBUG
411 void dump(raw_ostream &OS) const final { OS << "InsertIntoBB"; }
412 LLVM_DUMP_METHOD void dump() const final;
413#endif // NDEBUG
414};
415
417 Instruction *NewI = nullptr;
418
419public:
420 CreateAndInsertInst(Instruction *NewI) : NewI(NewI) {}
421 void revert(Tracker &Tracker) final;
422 void accept() final {}
423#ifndef NDEBUG
424 void dump(raw_ostream &OS) const final { OS << "CreateAndInsertInst"; }
425 LLVM_DUMP_METHOD void dump() const final;
426#endif
427};
428
431 SmallVector<int, 8> PrevMask;
432
433public:
435 void revert(Tracker &Tracker) final;
436 void accept() final {}
437#ifndef NDEBUG
438 void dump(raw_ostream &OS) const final { OS << "ShuffleVectorSetMask"; }
439 LLVM_DUMP_METHOD void dump() const final;
440#endif
441};
442
443/// The tracker collects all the change objects and implements the main API for
444/// saving / reverting / accepting.
445class Tracker {
446public:
447 enum class TrackerState {
448 Disabled, ///> Tracking is disabled
449 Record, ///> Tracking changes
450 Reverting, ///> Reverting changes
451 };
452
453private:
454 /// The list of changes that are being tracked.
456 /// The current state of the tracker.
457 TrackerState State = TrackerState::Disabled;
458 /// Nested snapshots require us to track the index of each snapshot in the
459 /// `Changes` vector.
460 SmallVector<unsigned, 8> Snapshots;
461 Context &Ctx;
462
463#ifndef NDEBUG
464 /// One checker per nested snapshot.
465 SmallVector<IRSnapshotChecker> SnapshotChecker;
466#endif
467
468public:
469#ifndef NDEBUG
470 /// Helps catch bugs where we are creating new change objects while in the
471 /// middle of creating other change objects.
473#endif // NDEBUG
474
475 explicit Tracker(Context &Ctx) : Ctx(Ctx) {}
476
478 Context &getContext() const { return Ctx; }
479 /// \Returns true if there are no changes tracked.
480 bool empty() const { return Changes.empty(); }
481 /// Record \p Change and take ownership. This is the main function used to
482 /// track Sandbox IR changes.
483 void track(std::unique_ptr<IRChangeBase> &&Change) {
484 assert(State == TrackerState::Record && "The tracker should be tracking!");
485#ifndef NDEBUG
487 "We are in the middle of creating another change!");
488 if (isTracking())
490#endif // NDEBUG
491 Changes.push_back(std::move(Change));
492
493#ifndef NDEBUG
495#endif
496 }
497 /// A convenience wrapper for `track()` that constructs and tracks the Change
498 /// object if tracking is enabled. \Returns true if tracking is enabled.
499 template <typename ChangeT, typename... ArgsT>
500 bool emplaceIfTracking(ArgsT... Args) {
501 if (!isTracking())
502 return false;
503 track(std::make_unique<ChangeT>(Args...));
504 return true;
505 }
506 /// \Returns true if the tracker is recording changes.
507 bool isTracking() const { return State == TrackerState::Record; }
508 /// \Returns the current state of the tracker.
509 TrackerState getState() const { return State; }
510 /// Turns on IR tracking. If tracking is already enabled this creates a new
511 /// nested checkpoint.
512 LLVM_ABI void save();
513 /// Stops tracking and accept changes. If we have nested checkpoints, this
514 /// will remove the last checkpoint from the stack without modifying the
515 /// state.
516 LLVM_ABI void accept(bool AcceptAll = false);
517 /// Stops tracking and reverts to saved state. If we have nested checkpoints
518 /// this will revert the state to the last checkpoint.
519 LLVM_ABI void revert(bool RevertAll = false);
520 /// \returns the number of nested (outstanding) checkpoints.
521 unsigned nestingDepth() const { return Snapshots.size(); }
522
523#ifndef NDEBUG
524 void print(raw_ostream &OS) const;
525 LLVM_DUMP_METHOD void dump() const;
527 Tracker.print(OS);
528 return OS;
529 }
530#endif // NDEBUG
531};
532
533} // namespace llvm::sandboxir
534
535#endif // LLVM_SANDBOXIR_TRACKER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:702
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file defines the PointerUnion class, which is a discriminated union of pointer types.
SI Fold Operands
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.
Definition raw_ostream.h:53
LLVM_DUMP_METHOD void dump() const final
Definition Tracker.h:345
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:219
CatchSwitchAddHandler(CatchSwitchInst *CSI)
Definition Tracker.cpp:216
void accept() final
This runs when changes get accepted.
Definition Tracker.h:342
void dump(raw_ostream &OS) const final
Definition Tracker.h:344
void dump(raw_ostream &OS) const final
Definition Tracker.h:195
void accept() final
This runs when changes get accepted.
Definition Tracker.h:193
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:323
void accept() final
This runs when changes get accepted.
Definition Tracker.h:422
CreateAndInsertInst(Instruction *NewI)
Definition Tracker.h:420
void dump(raw_ostream &OS) const final
Definition Tracker.h:424
void dump(raw_ostream &OS) const final
Definition Tracker.h:241
void accept() final
This runs when changes get accepted.
Definition Tracker.cpp:159
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:164
EraseFromParent(std::unique_ptr< sandboxir::Value > &&IPtr)
Definition Tracker.cpp:135
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.h:324
LLVM_DUMP_METHOD void dump() const final
Definition Tracker.h:328
void dump(raw_ostream &OS) const final
Definition Tracker.h:327
GenericSetterWithIdx(InstrT *I, unsigned Idx)
Definition Tracker.h:322
void accept() final
This runs when changes get accepted.
Definition Tracker.h:325
void dump(raw_ostream &OS) const final
Definition Tracker.h:297
void accept() final
This runs when changes get accepted.
Definition Tracker.h:295
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.h:294
LLVM_DUMP_METHOD void dump() const final
Definition Tracker.h:298
The base class for IR Change classes.
Definition Tracker.h:122
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)
Definition Tracker.h:135
virtual ~IRChangeBase()=default
virtual void accept()=0
This runs when changes get accepted.
virtual void dump(raw_ostream &OS) const =0
LLVM_ABI void expectNoDiff()
Checks current state against saved state, crashes if different.
Definition Tracker.cpp:72
LLVM_ABI void save()
Saves a snapshot of the current state.
Definition Tracker.cpp:70
void dump(raw_ostream &OS) const final
Definition Tracker.h:411
void accept() final
This runs when changes get accepted.
Definition Tracker.h:409
InsertIntoBB(Instruction *InsertedI)
Definition Tracker.cpp:289
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:287
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
MoveInstr(sandboxir::Instruction *I)
Definition Tracker.cpp:264
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:271
void accept() final
This runs when changes get accepted.
Definition Tracker.h:396
void dump(raw_ostream &OS) const final
Definition Tracker.h:398
void dump(raw_ostream &OS) const final
Definition Tracker.h:182
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:122
void accept() final
This runs when changes get accepted.
Definition Tracker.h:180
void accept() final
This runs when changes get accepted.
Definition Tracker.h:166
PHIRemoveIncoming(PHINode *PHI, unsigned RemovedIdx)
Definition Tracker.cpp:91
void dump(raw_ostream &OS) const final
Definition Tracker.h:168
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:97
void dump(raw_ostream &OS) const final
Definition Tracker.h:262
Instruction * getInstruction() const
Definition Tracker.h:260
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:200
void accept() final
This runs when changes get accepted.
Definition Tracker.h:259
RemoveFromParent(Instruction *RemovedI)
Definition Tracker.cpp:193
ShuffleVectorSetMask(ShuffleVectorInst *SVI)
Definition Tracker.cpp:307
void accept() final
This runs when changes get accepted.
Definition Tracker.h:436
void dump(raw_ostream &OS) const final
Definition Tracker.h:438
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:310
SwitchAddCase(SwitchInst *Switch, ConstantInt *Val)
Definition Tracker.h:357
void dump(raw_ostream &OS) const final
Definition Tracker.h:362
void accept() final
This runs when changes get accepted.
Definition Tracker.h:360
void dump(raw_ostream &OS) const final
Definition Tracker.h:381
SwitchRemoveCase(SwitchInst *Switch)
Definition Tracker.cpp:226
void accept() final
This runs when changes get accepted.
Definition Tracker.h:379
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.cpp:231
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
Definition Tracker.h:445
LLVM_ABI void revert(bool RevertAll=false)
Stops tracking and reverts to saved state.
Definition Tracker.cpp:341
unsigned nestingDepth() const
Definition Tracker.h:521
TrackerState getState() const
\Returns the current state of the tracker.
Definition Tracker.h:509
bool empty() const
\Returns true if there are no changes tracked.
Definition Tracker.h:480
friend raw_ostream & operator<<(raw_ostream &OS, const Tracker &Tracker)
Definition Tracker.h:526
void print(raw_ostream &OS) const
Definition Tracker.cpp:392
bool isTracking() const
\Returns true if the tracker is recording changes.
Definition Tracker.h:507
LLVM_ABI void accept(bool AcceptAll=false)
Stops tracking and accept changes.
Definition Tracker.cpp:371
LLVM_ABI void save()
Turns on IR tracking.
Definition Tracker.cpp:331
Tracker(Context &Ctx)
Definition Tracker.h:475
void track(std::unique_ptr< IRChangeBase > &&Change)
Record Change and take ownership.
Definition Tracker.h:483
bool InMiddleOfCreatingChange
Helps catch bugs where we are creating new change objects while in the middle of creating other chang...
Definition Tracker.h:472
Context & getContext() const
Definition Tracker.h:478
bool emplaceIfTracking(ArgsT... Args)
A convenience wrapper for track() that constructs and tracks the Change object if tracking is enabled...
Definition Tracker.h:500
LLVM_DUMP_METHOD void dump() const
Definition Tracker.cpp:410
UseSet(const Use &U)
Definition Tracker.h:148
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.h:149
void dump(raw_ostream &OS) const final
Definition Tracker.h:152
void accept() final
This runs when changes get accepted.
Definition Tracker.h:150
LLVM_DUMP_METHOD void dump() const final
Definition Tracker.cpp:80
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.h:210
LLVM_DUMP_METHOD void dump() const final
Definition Tracker.cpp:85
void accept() final
This runs when changes get accepted.
Definition Tracker.h:211
void dump(raw_ostream &OS) const final
Definition Tracker.h:213
UseSwap(const Use &ThisUse, const Use &OtherUse)
Definition Tracker.h:206
Represents a Def-use/Use-def edge in SandboxIR.
Definition Use.h:42
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
Definition BasicBlock.h:75
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.
Definition Debug.cpp:209