Skip to content

Commit 3db5be7

Browse files
authored
[SandboxVec] Add print-region pass (#131019)
This patch implements a simple printing pass for regions. This is meant to be used in tests and for debugging.
1 parent 1ff7491 commit 3db5be7

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
#ifndef NDEBUG
16+
OS << "-- Region --\n";
17+
OS << R << "\n";
18+
#else
19+
// TODO: Make this available in all builds, depends on enabling SandboxIR
20+
// dumps in non-debug builds.
21+
OS << "Region dump only available in DEBUG build!";
22+
#endif
23+
return false;
24+
}
25+
};
26+
27+
} // namespace llvm::sandboxir
28+
29+
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H

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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: opt -disable-output -passes=sandbox-vectorizer -sbvec-passes="regions-from-metadata<print-region>" %s | FileCheck %s
2+
; REQUIRES: asserts
3+
4+
define void @foo(i8 %v) {
5+
; CHECK: -- Region --
6+
; CHECK-NEXT: %add0 = add i8 %v, 0, !sandboxvec !0 {{.*}}
7+
; CHECK: -- Region --
8+
; CHECK-NEXT: %add1 = add i8 %v, 1, !sandboxvec !1 {{.*}}
9+
; CHECK-NEXT: %add2 = add i8 %v, 2, !sandboxvec !1 {{.*}}
10+
; CHECK-NEXT: %add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2 {{.*}}
11+
; CHECK-NEXT: %add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3 {{.*}}
12+
; CHECK: Aux:
13+
; CHECK-NEXT: %add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2 {{.*}}
14+
; CHECK-NEXT: %add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3 {{.*}}
15+
%add0 = add i8 %v, 0, !sandboxvec !0
16+
%add1 = add i8 %v, 1, !sandboxvec !1
17+
%add2 = add i8 %v, 2, !sandboxvec !1
18+
%add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2
19+
%add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3
20+
ret void
21+
}
22+
23+
!0 = distinct !{!"sandboxregion"}
24+
!1 = distinct !{!"sandboxregion"}
25+
!2 = !{i32 0}
26+
!3 = !{i32 1}

0 commit comments

Comments
 (0)