|
10 | 10 | #include "llvm/ADT/STLExtras.h" |
11 | 11 | #include "llvm/IR/BasicBlock.h" |
12 | 12 | #include "llvm/IR/Instruction.h" |
13 | | -#include "llvm/IR/Module.h" |
14 | | -#include "llvm/IR/StructuralHash.h" |
15 | 13 | #include "llvm/SandboxIR/Instruction.h" |
16 | 14 | #include <sstream> |
17 | 15 |
|
18 | 16 | using namespace llvm::sandboxir; |
19 | 17 |
|
20 | 18 | #ifndef NDEBUG |
21 | | - |
22 | | -std::string IRSnapshotChecker::dumpIR(const llvm::Function &F) const { |
23 | | - std::string Result; |
24 | | - raw_string_ostream SS(Result); |
25 | | - F.print(SS, /*AssemblyAnnotationWriter=*/nullptr); |
26 | | - return Result; |
27 | | -} |
28 | | - |
29 | | -IRSnapshotChecker::ContextSnapshot IRSnapshotChecker::takeSnapshot() const { |
30 | | - ContextSnapshot Result; |
31 | | - for (const auto &Entry : Ctx.LLVMModuleToModuleMap) |
32 | | - for (const auto &F : *Entry.first) { |
33 | | - FunctionSnapshot Snapshot; |
34 | | - Snapshot.Hash = StructuralHash(F, /*DetailedHash=*/true); |
35 | | - Snapshot.TextualIR = dumpIR(F); |
36 | | - Result[&F] = Snapshot; |
37 | | - } |
38 | | - return Result; |
39 | | -} |
40 | | - |
41 | | -bool IRSnapshotChecker::diff(const ContextSnapshot &Orig, |
42 | | - const ContextSnapshot &Curr) const { |
43 | | - bool DifferenceFound = false; |
44 | | - for (const auto &[F, OrigFS] : Orig) { |
45 | | - auto CurrFSIt = Curr.find(F); |
46 | | - if (CurrFSIt == Curr.end()) { |
47 | | - DifferenceFound = true; |
48 | | - dbgs() << "Function " << F->getName() << " not found in current IR.\n"; |
49 | | - dbgs() << OrigFS.TextualIR << "\n"; |
50 | | - continue; |
51 | | - } |
52 | | - const FunctionSnapshot &CurrFS = CurrFSIt->second; |
53 | | - if (OrigFS.Hash != CurrFS.Hash) { |
54 | | - DifferenceFound = true; |
55 | | - dbgs() << "Found IR difference in Function " << F->getName() << "\n"; |
56 | | - dbgs() << "Original:\n" << OrigFS.TextualIR << "\n"; |
57 | | - dbgs() << "Current:\n" << CurrFS.TextualIR << "\n"; |
58 | | - } |
59 | | - } |
60 | | - // Check that Curr doesn't contain any new functions. |
61 | | - for (const auto &[F, CurrFS] : Curr) { |
62 | | - if (!Orig.contains(F)) { |
63 | | - DifferenceFound = true; |
64 | | - dbgs() << "Function " << F->getName() |
65 | | - << " found in current IR but not in original snapshot.\n"; |
66 | | - dbgs() << CurrFS.TextualIR << "\n"; |
67 | | - } |
68 | | - } |
69 | | - return DifferenceFound; |
70 | | -} |
71 | | - |
72 | | -void IRSnapshotChecker::save() { OrigContextSnapshot = takeSnapshot(); } |
73 | | - |
74 | | -void IRSnapshotChecker::expectNoDiff() { |
75 | | - ContextSnapshot CurrContextSnapshot = takeSnapshot(); |
76 | | - if (diff(OrigContextSnapshot, CurrContextSnapshot)) { |
77 | | - llvm_unreachable( |
78 | | - "Original and current IR differ! Probably a checkpointing bug."); |
79 | | - } |
80 | | -} |
81 | | - |
82 | 19 | void UseSet::dump() const { |
83 | 20 | dump(dbgs()); |
84 | 21 | dbgs() << "\n"; |
@@ -338,22 +275,14 @@ void CmpSwapOperands::dump() const { |
338 | 275 | } |
339 | 276 | #endif |
340 | 277 |
|
341 | | -void Tracker::save() { |
342 | | - State = TrackerState::Record; |
343 | | -#if !defined(NDEBUG) && defined(EXPENSIVE_CHECKS) |
344 | | - SnapshotChecker.save(); |
345 | | -#endif |
346 | | -} |
| 278 | +void Tracker::save() { State = TrackerState::Record; } |
347 | 279 |
|
348 | 280 | void Tracker::revert() { |
349 | 281 | assert(State == TrackerState::Record && "Forgot to save()!"); |
350 | 282 | State = TrackerState::Disabled; |
351 | 283 | for (auto &Change : reverse(Changes)) |
352 | 284 | Change->revert(*this); |
353 | 285 | Changes.clear(); |
354 | | -#if !defined(NDEBUG) && defined(EXPENSIVE_CHECKS) |
355 | | - SnapshotChecker.expectNoDiff(); |
356 | | -#endif |
357 | 286 | } |
358 | 287 |
|
359 | 288 | void Tracker::accept() { |
|
0 commit comments