Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! [SandboxIR] IR Tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
vporpo committed Jul 17, 2024
1 parent 27cb385 commit f26c90d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
6 changes: 0 additions & 6 deletions llvm/include/llvm/SandboxIR/Tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ class Tracker {
enum class TrackerState {
Disabled, ///> Tracking is disabled
Record, ///> Tracking changes
Revert, ///> Undoing changes
Accept, ///> Accepting changes
};

private:
Expand Down Expand Up @@ -141,10 +139,6 @@ class Tracker {
void accept();
/// Stops tracking and reverts to saved state.
void revert();
/// \Returns the number of change entries recorded so far.
unsigned size() const { return Changes.size(); }
/// \Returns true if there are no change entries recorded so far.
bool empty() const { return Changes.empty(); }

#ifndef NDEBUG
void dump(raw_ostream &OS) const;
Expand Down
9 changes: 3 additions & 6 deletions llvm/lib/SandboxIR/Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ Tracker::~Tracker() {
}

void Tracker::track(std::unique_ptr<IRChangeBase> &&Change) {
assert(State != TrackerState::Revert &&
"No changes should be tracked during revert()!");
assert(State == TrackerState::Record && "The tracker should be tracking!");
Changes.push_back(std::move(Change));

#ifndef NDEBUG
Expand All @@ -55,20 +54,18 @@ void Tracker::save() { State = TrackerState::Record; }

void Tracker::revert() {
assert(State == TrackerState::Record && "Forgot to save()!");
State = TrackerState::Revert;
State = TrackerState::Disabled;
for (auto &Change : reverse(Changes))
Change->revert();
Changes.clear();
State = TrackerState::Disabled;
}

void Tracker::accept() {
assert(State == TrackerState::Record && "Forgot to save()!");
State = TrackerState::Accept;
State = TrackerState::Disabled;
for (auto &Change : Changes)
Change->accept();
Changes.clear();
State = TrackerState::Disabled;
}

#ifndef NDEBUG
Expand Down
9 changes: 0 additions & 9 deletions llvm/unittests/SandboxIR/TrackerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ define void @foo(ptr %ptr) {
auto *Ld = &*It++;
auto *St = &*It++;
St->setOperand(0, Ld);
EXPECT_EQ(Tracker.size(), 1u);
St->setOperand(1, Gep1);
EXPECT_EQ(Tracker.size(), 2u);
Ld->setOperand(0, Gep1);
EXPECT_EQ(Tracker.size(), 3u);
EXPECT_EQ(St->getOperand(0), Ld);
EXPECT_EQ(St->getOperand(1), Gep1);
EXPECT_EQ(Ld->getOperand(0), Gep1);
Expand All @@ -85,7 +82,6 @@ define void @foo(ptr %ptr) {
llvm::Function &LLVMF = *M->getFunction("foo");
sandboxir::Context Ctx(C);
llvm::BasicBlock *LLVMBB = &*LLVMF.begin();
auto &Tracker = Ctx.getTracker();
Ctx.createFunction(&LLVMF);
auto *BB = cast<sandboxir::BasicBlock>(Ctx.getValue(LLVMBB));
auto It = BB->begin();
Expand All @@ -96,11 +92,9 @@ define void @foo(ptr %ptr) {
Ctx.save();
// Check RUWIf when the lambda returns false.
Ld0->replaceUsesWithIf(Ld1, [](const sandboxir::Use &Use) { return false; });
EXPECT_TRUE(Tracker.empty());

// Check RUWIf when the lambda returns true.
Ld0->replaceUsesWithIf(Ld1, [](const sandboxir::Use &Use) { return true; });
EXPECT_EQ(Tracker.size(), 2u);
EXPECT_EQ(St0->getOperand(0), Ld1);
EXPECT_EQ(St1->getOperand(0), Ld1);
Ctx.revert();
Expand Down Expand Up @@ -139,17 +133,14 @@ define void @foo(ptr %ptr) {
// Check RUOW.
Ctx.save();
St0->replaceUsesOfWith(Ld0, Ld1);
EXPECT_EQ(Tracker.size(), 1u);
EXPECT_EQ(St0->getOperand(0), Ld1);
Ctx.revert();
EXPECT_EQ(St0->getOperand(0), Ld0);

// Check accept().
Ctx.save();
St0->replaceUsesOfWith(Ld0, Ld1);
EXPECT_EQ(Tracker.size(), 1u);
EXPECT_EQ(St0->getOperand(0), Ld1);
Ctx.accept();
EXPECT_TRUE(Tracker.empty());
EXPECT_EQ(St0->getOperand(0), Ld1);
}

0 comments on commit f26c90d

Please sign in to comment.