Skip to content

Commit 4ed789f

Browse files
committed
[SandboxVec] Add print-region pass
This patch implements a simple printing pass for regions. This is meant to be used in tests and for debugging.
1 parent 3b33560 commit 4ed789f

File tree

6 files changed

+55
-5
lines changed

6 files changed

+55
-5
lines changed

llvm/include/llvm/SandboxIR/Region.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ class Region {
161161
bool operator==(const Region &Other) const;
162162
bool operator!=(const Region &other) const { return !(*this == other); }
163163

164-
void dump(raw_ostream &OS) const;
165164
void dump() const;
165+
#endif
166+
void print(raw_ostream &OS) const;
166167
friend raw_ostream &operator<<(raw_ostream &OS, const Region &Rgn) {
167-
Rgn.dump(OS);
168+
Rgn.print(OS);
168169
return OS;
169170
}
170-
#endif
171171
};
172172

173173
/// A helper client-attorney class for unit tests.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H
2+
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H
3+
4+
#include "llvm/SandboxIR/Pass.h"
5+
#include "llvm/SandboxIR/Region.h"
6+
7+
namespace llvm::sandboxir {
8+
9+
/// A Region pass that does nothing, for use as a placeholder in tests.
10+
class PrintRegion final : public RegionPass {
11+
public:
12+
PrintRegion() : RegionPass("print-region") {}
13+
bool runOnRegion(Region &R, const Analyses &A) final {
14+
raw_ostream &OS = outs();
15+
OS << "-- Region --\n";
16+
OS << R << "\n";
17+
return false;
18+
}
19+
};
20+
21+
} // namespace llvm::sandboxir
22+
23+
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H

llvm/lib/SandboxIR/Region.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool Region::operator==(const Region &Other) const {
123123
return true;
124124
}
125125

126-
void Region::dump(raw_ostream &OS) const {
126+
void Region::print(raw_ostream &OS) const {
127127
for (auto *I : Insts)
128128
OS << *I << "\n";
129129
if (!Aux.empty()) {
@@ -138,7 +138,7 @@ void Region::dump(raw_ostream &OS) const {
138138
}
139139

140140
void Region::dump() const {
141-
dump(dbgs());
141+
print(dbgs());
142142
dbgs() << "\n";
143143
}
144144
#endif // NDEBUG

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
REGION_PASS("null", ::llvm::sandboxir::NullPass)
2121
REGION_PASS("print-instruction-count", ::llvm::sandboxir::PrintInstructionCount)
22+
REGION_PASS("print-region", ::llvm::sandboxir::PrintRegion)
2223
REGION_PASS("tr-save", ::llvm::sandboxir::TransactionSave)
2324
REGION_PASS("tr-accept", ::llvm::sandboxir::TransactionAlwaysAccept)
2425
REGION_PASS("tr-accept-or-revert", ::llvm::sandboxir::TransactionAcceptOrRevert)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h"
44
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/NullPass.h"
55
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintInstructionCount.h"
6+
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h"
67
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.h"
78
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromMetadata.h"
89
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.h"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: opt -disable-output -passes=sandbox-vectorizer -sbvec-passes="regions-from-metadata<print-region>" %s | FileCheck %s
2+
3+
define void @foo(i8 %v) {
4+
; CHECK: -- Region --
5+
; CHECK-NEXT: %add0 = add i8 %v, 0, !sandboxvec !0 {{.*}}
6+
; CHECK: -- Region --
7+
; CHECK-NEXT: %add1 = add i8 %v, 1, !sandboxvec !1 {{.*}}
8+
; CHECK-NEXT: %add2 = add i8 %v, 2, !sandboxvec !1 {{.*}}
9+
; CHECK-NEXT: %add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2 {{.*}}
10+
; CHECK-NEXT: %add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3 {{.*}}
11+
; CHECK: Aux:
12+
; CHECK-NEXT: %add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2 {{.*}}
13+
; CHECK-NEXT: %add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3 {{.*}}
14+
%add0 = add i8 %v, 0, !sandboxvec !0
15+
%add1 = add i8 %v, 1, !sandboxvec !1
16+
%add2 = add i8 %v, 2, !sandboxvec !1
17+
%add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2
18+
%add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3
19+
ret void
20+
}
21+
22+
!0 = distinct !{!"sandboxregion"}
23+
!1 = distinct !{!"sandboxregion"}
24+
!2 = !{i32 0}
25+
!3 = !{i32 1}

0 commit comments

Comments
 (0)