LLVM: include/llvm/SandboxIR/Tracker.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#ifndef LLVM_SANDBOXIR_TRACKER_H
41#define LLVM_SANDBOXIR_TRACKER_H
42
52#include
53
55
69
70#ifndef NDEBUG
71
72
73
74
75
76
77
78
81
82
83 struct FunctionSnapshot {
85 std::string TextualIR;
86 };
87
88
89
90
91
93
94 ContextSnapshot OrigContextSnapshot;
95
96
98
99
100 ContextSnapshot takeSnapshot() const;
101
102
103 bool diff(const ContextSnapshot &Orig, const ContextSnapshot &Curr) const;
104
105public:
107
108
109
111
112
114};
115
116#endif
117
118
120protected:
122
123public:
124
126
129#ifndef NDEBUG
133 C.dump(OS);
134 return OS;
135 }
136#endif
137};
138
139
142 Value *OrigV = nullptr;
143
144public:
148#ifndef NDEBUG
151#endif
152};
153
156 unsigned RemovedIdx;
159
160public:
164#ifndef NDEBUG
167#endif
168};
169
172 unsigned Idx;
173
174public:
178#ifndef NDEBUG
181#endif
182};
183
186
187public:
191#ifndef NDEBUG
194#endif
195};
196
197
199 Use ThisUse;
200 Use OtherUse;
201
202public:
204 : ThisUse(ThisUse), OtherUse(OtherUse) {
205 assert(ThisUse.getUser() == OtherUse.getUser() && "Expected same user!");
206 }
209#ifndef NDEBUG
212#endif
213};
214
216
217
218 struct InstrAndOperands {
219
221
223 };
224
225
227
228
230
231 std::unique_ptrsandboxir::Value ErasedIPtr;
232
233public:
234 EraseFromParent(std::unique_ptrsandboxir::Value &&IPtr);
237#ifndef NDEBUG
241 C.dump(OS);
242 return OS;
243 }
244#endif
245};
246
248
250
252
253public:
258#ifndef NDEBUG
261#endif
262};
263
264
265
266
267
268
269
270
271
272
273
274
275
276template <auto GetterFn, auto SetterFn>
278
279 template <typename> struct GetClassTypeFromGetter;
280 template <typename RetT, typename ClassT>
281 struct GetClassTypeFromGetter<RetT (ClassT::*)() const> {
282 using ClassType = ClassT;
283 };
284 using InstrT = typename GetClassTypeFromGetter<decltype(GetterFn)>::ClassType;
285 using SavedValT = std::invoke_result_t<decltype(GetterFn), InstrT>;
286 InstrT *I;
287 SavedValT OrigVal;
288
289public:
290 GenericSetter(InstrT *I) : I(I), OrigVal((I->*GetterFn)()) {}
293#ifndef NDEBUG
297 dbgs() << "\n";
298 }
299#endif
300};
301
302
303
304template <auto GetterFn, auto SetterFn>
306
307 template <typename ClassT, typename RetT>
308 static ClassT getClassTypeFromGetter(RetT (ClassT::*Fn)(unsigned) const);
309 template <typename ClassT, typename RetT>
310 static ClassT getClassTypeFromGetter(RetT (ClassT::*Fn)(unsigned));
311
312 using InstrT = decltype(getClassTypeFromGetter(GetterFn));
313 using SavedValT = std::invoke_result_t<decltype(GetterFn), InstrT, unsigned>;
314 InstrT *I;
315 SavedValT OrigVal;
316 unsigned Idx;
317
318public:
320 : I(I), OrigVal((I->*GetterFn)(Idx)), Idx(Idx) {}
323#ifndef NDEBUG
324 void dump(raw_ostream &OS) const final { OS << "GenericSetterWithIdx"; }
327 dbgs() << "\n";
328 }
329#endif
330};
331
334 unsigned HandlerIdx;
335
336public:
340#ifndef NDEBUG
341 void dump(raw_ostream &OS) const final { OS << "CatchSwitchAddHandler"; }
344 dbgs() << "\n";
345 }
346#endif
347};
348
352
353public:
355 : Switch(Switch), Val(Val) {}
358#ifndef NDEBUG
361#endif
362};
363
366 struct Case {
369 };
371
372public:
374
377#ifndef NDEBUG
380#endif
381};
382
384
386
387
389
390public:
394#ifndef NDEBUG
397#endif
398};
399
402
403public:
407#ifndef NDEBUG
410#endif
411};
412
415
416public:
420#ifndef NDEBUG
421 void dump(raw_ostream &OS) const final { OS << "CreateAndInsertInst"; }
423#endif
424};
425
429
430public:
434#ifndef NDEBUG
435 void dump(raw_ostream &OS) const final { OS << "ShuffleVectorSetMask"; }
437#endif
438};
439
440
441
443public:
449
450private:
451
453
456
457#ifndef NDEBUG
459#endif
460
461public:
462#ifndef NDEBUG
463
464
466#endif
467
469 : Ctx(Ctx)
471 ,
472 SnapshotChecker(Ctx)
473#endif
474 {
475 }
476
479
480 bool empty() const { return Changes.empty(); }
481
482
483 void track(std::unique_ptr &&Change) {
485#ifndef NDEBUG
487 "We are in the middle of creating another change!");
490#endif
491 Changes.push_back(std::move(Change));
492
493#ifndef NDEBUG
495#endif
496 }
497
498
499 template <typename ChangeT, typename... ArgsT>
502 return false;
503 track(std::make_unique(Args...));
504 return true;
505 }
506
508
510
512
514
516
517#ifndef NDEBUG
524#endif
525};
526
527}
528
529#endif
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 bit of the poin...
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
Definition Tracker.h:342
void revert(Tracker &Tracker) final
This runs when changes get reverted.
CatchSwitchAddHandler(CatchSwitchInst *CSI)
void accept() final
This runs when changes get accepted.
Definition Tracker.h:339
void dump(raw_ostream &OS) const final
Definition Tracker.h:341
void dump(raw_ostream &OS) const final
Definition Tracker.h:192
void accept() final
This runs when changes get accepted.
Definition Tracker.h:190
void revert(Tracker &Tracker) final
This runs when changes get reverted.
CmpSwapOperands(CmpInst *Cmp)
void accept() final
This runs when changes get accepted.
Definition Tracker.h:419
CreateAndInsertInst(Instruction *NewI)
Definition Tracker.h:417
void dump(raw_ostream &OS) const final
Definition Tracker.h:421
void dump(raw_ostream &OS) const final
Definition Tracker.h:238
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.
Definition Tracker.h:321
LLVM_DUMP_METHOD void dump() const final
Definition Tracker.h:325
void dump(raw_ostream &OS) const final
Definition Tracker.h:324
GenericSetterWithIdx(InstrT *I, unsigned Idx)
Definition Tracker.h:319
void accept() final
This runs when changes get accepted.
Definition Tracker.h:322
void dump(raw_ostream &OS) const final
Definition Tracker.h:294
GenericSetter(InstrT *I)
Definition Tracker.h:290
void accept() final
This runs when changes get accepted.
Definition Tracker.h:292
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.h:291
LLVM_DUMP_METHOD void dump() const final
Definition Tracker.h:295
The base class for IR Change classes.
Definition Tracker.h:119
friend class Tracker
Definition Tracker.h:121
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:132
virtual ~IRChangeBase()=default
virtual void accept()=0
This runs when changes get accepted.
virtual void dump(raw_ostream &OS) const =0
A class that saves hashes and textual IR snapshots of functions in a SandboxIR Context,...
Definition Tracker.h:79
IRSnapshotChecker(Context &Ctx)
Definition Tracker.h:106
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
Definition Tracker.h:408
void accept() final
This runs when changes get accepted.
Definition Tracker.h:406
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.
Definition Tracker.h:393
void dump(raw_ostream &OS) const final
Definition Tracker.h:395
PHIAddIncoming(PHINode *PHI)
void dump(raw_ostream &OS) const final
Definition Tracker.h:179
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void accept() final
This runs when changes get accepted.
Definition Tracker.h:177
void accept() final
This runs when changes get accepted.
Definition Tracker.h:163
PHIRemoveIncoming(PHINode *PHI, unsigned RemovedIdx)
void dump(raw_ostream &OS) const final
Definition Tracker.h:165
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void dump(raw_ostream &OS) const final
Definition Tracker.h:259
Instruction * getInstruction() const
Definition Tracker.h:257
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void accept() final
This runs when changes get accepted.
Definition Tracker.h:256
RemoveFromParent(Instruction *RemovedI)
ShuffleVectorSetMask(ShuffleVectorInst *SVI)
void accept() final
This runs when changes get accepted.
Definition Tracker.h:433
void dump(raw_ostream &OS) const final
Definition Tracker.h:435
void revert(Tracker &Tracker) final
This runs when changes get reverted.
SwitchAddCase(SwitchInst *Switch, ConstantInt *Val)
Definition Tracker.h:354
void dump(raw_ostream &OS) const final
Definition Tracker.h:359
void accept() final
This runs when changes get accepted.
Definition Tracker.h:357
void dump(raw_ostream &OS) const final
Definition Tracker.h:378
SwitchRemoveCase(SwitchInst *Switch)
void accept() final
This runs when changes get accepted.
Definition Tracker.h:376
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...
Definition Tracker.h:442
TrackerState
Definition Tracker.h:444
@ Record
Definition Tracker.h:446
@ Reverting
Definition Tracker.h:447
@ Disabled
Definition Tracker.h:445
LLVM_ABI void revert()
Stops tracking and reverts to saved state.
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:520
bool isTracking() const
\Returns true if the tracker is recording changes.
Definition Tracker.h:507
LLVM_ABI void save()
Turns on IR tracking.
Tracker(Context &Ctx)
Definition Tracker.h:468
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:465
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_ABI void accept()
Stops tracking and accept changes.
LLVM_DUMP_METHOD void dump() const
UseSet(const Use &U)
Definition Tracker.h:145
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.h:146
void dump(raw_ostream &OS) const final
Definition Tracker.h:149
void accept() final
This runs when changes get accepted.
Definition Tracker.h:147
LLVM_DUMP_METHOD void dump() const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
Definition Tracker.h:207
LLVM_DUMP_METHOD void dump() const final
void accept() final
This runs when changes get accepted.
Definition Tracker.h:208
void dump(raw_ostream &OS) const final
Definition Tracker.h:210
UseSwap(const Use &ThisUse, const Use &OtherUse)
Definition Tracker.h:203
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.