[llvm] [SandboxVec] Add print-region pass (PR #131019)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 12 13:35:16 PDT 2025
https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/131019
>From 4ed789f61390a30f5d8e5fded7756f000d979087 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Wed, 12 Mar 2025 12:20:20 -0700
Subject: [PATCH] [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.
---
llvm/include/llvm/SandboxIR/Region.h | 6 ++---
.../SandboxVectorizer/Passes/PrintRegion.h | 23 +++++++++++++++++
llvm/lib/SandboxIR/Region.cpp | 4 +--
.../SandboxVectorizer/Passes/PassRegistry.def | 1 +
.../SandboxVectorizerPassBuilder.cpp | 1 +
.../SandboxVectorizer/print_region_pass.ll | 25 +++++++++++++++++++
6 files changed, 55 insertions(+), 5 deletions(-)
create mode 100644 llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h
create mode 100644 llvm/test/Transforms/SandboxVectorizer/print_region_pass.ll
diff --git a/llvm/include/llvm/SandboxIR/Region.h b/llvm/include/llvm/SandboxIR/Region.h
index 14f35c9c4d8a9..abac2b981a254 100644
--- a/llvm/include/llvm/SandboxIR/Region.h
+++ b/llvm/include/llvm/SandboxIR/Region.h
@@ -161,13 +161,13 @@ class Region {
bool operator==(const Region &Other) const;
bool operator!=(const Region &other) const { return !(*this == other); }
- void dump(raw_ostream &OS) const;
void dump() const;
+#endif
+ void print(raw_ostream &OS) const;
friend raw_ostream &operator<<(raw_ostream &OS, const Region &Rgn) {
- Rgn.dump(OS);
+ Rgn.print(OS);
return OS;
}
-#endif
};
/// A helper client-attorney class for unit tests.
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h
new file mode 100644
index 0000000000000..334886a22f114
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h
@@ -0,0 +1,23 @@
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H
+
+#include "llvm/SandboxIR/Pass.h"
+#include "llvm/SandboxIR/Region.h"
+
+namespace llvm::sandboxir {
+
+/// A Region pass that does nothing, for use as a placeholder in tests.
+class PrintRegion final : public RegionPass {
+public:
+ PrintRegion() : RegionPass("print-region") {}
+ bool runOnRegion(Region &R, const Analyses &A) final {
+ raw_ostream &OS = outs();
+ OS << "-- Region --\n";
+ OS << R << "\n";
+ return false;
+ }
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H
diff --git a/llvm/lib/SandboxIR/Region.cpp b/llvm/lib/SandboxIR/Region.cpp
index 2eb84bd72ed00..58012dd243e02 100644
--- a/llvm/lib/SandboxIR/Region.cpp
+++ b/llvm/lib/SandboxIR/Region.cpp
@@ -123,7 +123,7 @@ bool Region::operator==(const Region &Other) const {
return true;
}
-void Region::dump(raw_ostream &OS) const {
+void Region::print(raw_ostream &OS) const {
for (auto *I : Insts)
OS << *I << "\n";
if (!Aux.empty()) {
@@ -138,7 +138,7 @@ void Region::dump(raw_ostream &OS) const {
}
void Region::dump() const {
- dump(dbgs());
+ print(dbgs());
dbgs() << "\n";
}
#endif // NDEBUG
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def
index c525608804955..f2eb769420e7f 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def
@@ -19,6 +19,7 @@
REGION_PASS("null", ::llvm::sandboxir::NullPass)
REGION_PASS("print-instruction-count", ::llvm::sandboxir::PrintInstructionCount)
+REGION_PASS("print-region", ::llvm::sandboxir::PrintRegion)
REGION_PASS("tr-save", ::llvm::sandboxir::TransactionSave)
REGION_PASS("tr-accept", ::llvm::sandboxir::TransactionAlwaysAccept)
REGION_PASS("tr-accept-or-revert", ::llvm::sandboxir::TransactionAcceptOrRevert)
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
index 013ccf6e3d945..5918cfd38b374 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
@@ -3,6 +3,7 @@
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/NullPass.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintInstructionCount.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromMetadata.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.h"
diff --git a/llvm/test/Transforms/SandboxVectorizer/print_region_pass.ll b/llvm/test/Transforms/SandboxVectorizer/print_region_pass.ll
new file mode 100644
index 0000000000000..ed56a6ec034e5
--- /dev/null
+++ b/llvm/test/Transforms/SandboxVectorizer/print_region_pass.ll
@@ -0,0 +1,25 @@
+; RUN: opt -disable-output -passes=sandbox-vectorizer -sbvec-passes="regions-from-metadata<print-region>" %s | FileCheck %s
+
+define void @foo(i8 %v) {
+; CHECK: -- Region --
+; CHECK-NEXT: %add0 = add i8 %v, 0, !sandboxvec !0 {{.*}}
+; CHECK: -- Region --
+; CHECK-NEXT: %add1 = add i8 %v, 1, !sandboxvec !1 {{.*}}
+; CHECK-NEXT: %add2 = add i8 %v, 2, !sandboxvec !1 {{.*}}
+; CHECK-NEXT: %add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2 {{.*}}
+; CHECK-NEXT: %add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3 {{.*}}
+; CHECK: Aux:
+; CHECK-NEXT: %add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2 {{.*}}
+; CHECK-NEXT: %add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3 {{.*}}
+ %add0 = add i8 %v, 0, !sandboxvec !0
+ %add1 = add i8 %v, 1, !sandboxvec !1
+ %add2 = add i8 %v, 2, !sandboxvec !1
+ %add3 = add i8 %v, 3, !sandboxvec !1, !sandboxaux !2
+ %add4 = add i8 %v, 4, !sandboxvec !1, !sandboxaux !3
+ ret void
+}
+
+!0 = distinct !{!"sandboxregion"}
+!1 = distinct !{!"sandboxregion"}
+!2 = !{i32 0}
+!3 = !{i32 1}
More information about the llvm-commits
mailing list