[llvm] [SandboxVec] Add print-region pass (PR #131019)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 12 13:10:45 PDT 2025
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/131019
This patch implements a simple printing pass for regions. This is meant to be used in tests and for debugging.
>From de393ad41a2315761b09cbc5118a651dc70419d0 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.
---
.../SandboxVectorizer/Passes/PrintRegion.h | 24 ++++++++++++++++++
.../SandboxVectorizer/Passes/PassRegistry.def | 1 +
.../SandboxVectorizerPassBuilder.cpp | 1 +
.../SandboxVectorizer/print_region_pass.ll | 25 +++++++++++++++++++
4 files changed, 51 insertions(+)
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/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h
new file mode 100644
index 0000000000000..5b5dee574f930
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/PrintRegion.h
@@ -0,0 +1,24 @@
+#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";
+ R.dump(OS);
+ OS << "\n";
+ return false;
+ }
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H
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