Skip to content

Commit de393ad

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 de393ad

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
R.dump(OS);
17+
OS << "\n";
18+
return false;
19+
}
20+
};
21+
22+
} // namespace llvm::sandboxir
23+
24+
#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: 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)