Skip to content

Commit 9c6a442

Browse files
authored
[SandboxVec] Add TransactionAlwaysRevert pass (#141688)
This patch adds a region pass that reverts the IR state unconditionally. This is used for testing.
1 parent 894a0dd commit 9c6a442

File tree

4 files changed

+397
-76
lines changed

4 files changed

+397
-76
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===- TransactionAlwaysRevert.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 is a region pass that always reverts the transaction without checking
10+
// its cost. This is mainly used as a final pass in lit tests.
11+
//
12+
13+
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TRANSACTIONALWAYSREVERT_H
14+
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TRANSACTIONALWAYSREVERT_H
15+
16+
#include "llvm/SandboxIR/Pass.h"
17+
#include "llvm/SandboxIR/Region.h"
18+
19+
namespace llvm::sandboxir {
20+
21+
class TransactionAlwaysRevert : public RegionPass {
22+
public:
23+
TransactionAlwaysRevert() : RegionPass("tr-revert") {}
24+
bool runOnRegion(Region &Rgn, const Analyses &A) final {
25+
auto &Tracker = Rgn.getContext().getTracker();
26+
bool HasChanges = !Tracker.empty();
27+
Tracker.revert();
28+
return HasChanges;
29+
}
30+
};
31+
32+
} // namespace llvm::sandboxir
33+
34+
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TRANSACTIONALWAYSREVERT_H

llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ REGION_PASS("print-instruction-count", ::llvm::sandboxir::PrintInstructionCount)
2222
REGION_PASS("print-region", ::llvm::sandboxir::PrintRegion)
2323
REGION_PASS("tr-save", ::llvm::sandboxir::TransactionSave)
2424
REGION_PASS("tr-accept", ::llvm::sandboxir::TransactionAlwaysAccept)
25+
REGION_PASS("tr-revert", ::llvm::sandboxir::TransactionAlwaysRevert)
2526
REGION_PASS("tr-accept-or-revert", ::llvm::sandboxir::TransactionAcceptOrRevert)
2627
REGION_PASS("bottom-up-vec", ::llvm::sandboxir::BottomUpVec)
2728

llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.h"
1010
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.h"
1111
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAlwaysAccept.h"
12+
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAlwaysRevert.h"
1213
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionSave.h"
1314

1415
namespace llvm::sandboxir {

0 commit comments

Comments
 (0)