Skip to content

[SandboxVec] Add print-region pass #131019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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();
#ifndef NDEBUG
OS << "-- Region --\n";
OS << R << "\n";
#else
// TODO: Make this available in all builds, depends on enabling SandboxIR
// dumps in non-debug builds.
OS << "Region dump only available in DEBUG build!";
#endif
return false;
}
};

} // namespace llvm::sandboxir

#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_PRINTREGION_H
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/Transforms/SandboxVectorizer/print_region_pass.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; RUN: opt -disable-output -passes=sandbox-vectorizer -sbvec-passes="regions-from-metadata<print-region>" %s | FileCheck %s
; REQUIRES: asserts

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}