Skip to content

[SandboxVec] Add region-from-bbs helper pass #130153

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 8, 2025
Merged

Conversation

vporpo
Copy link
Contributor

@vporpo vporpo commented Mar 6, 2025

RegionFromBBs is a helper Sandbox IR function pass that builds a region for each BB. This helps test region passes in isolation without relying on other parts of the vectorizer, which is especially useful for stress-testing.

RegionFromBBs is a helper Sandbox IR function pass that builds a region for
each BB. This helps test region passes in isolation without relying on other
parts of the vectorizer, which is especially useful for stress-testing.
@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2025

@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: vporpo (vporpo)

Changes

RegionFromBBs is a helper Sandbox IR function pass that builds a region for each BB. This helps test region passes in isolation without relying on other parts of the vectorizer, which is especially useful for stress-testing.


Full diff: https://github.com/llvm/llvm-project/pull/130153.diff

7 Files Affected:

  • (modified) llvm/include/llvm/SandboxIR/Region.h (+1)
  • (added) llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.h (+38)
  • (modified) llvm/lib/Transforms/Vectorize/CMakeLists.txt (+1)
  • (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def (+1)
  • (added) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.cpp (+35)
  • (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp (+1)
  • (added) llvm/test/Transforms/SandboxVectorizer/regions-from-bbs.ll (+31)
diff --git a/llvm/include/llvm/SandboxIR/Region.h b/llvm/include/llvm/SandboxIR/Region.h
index 1a051941e5598..14f35c9c4d8a9 100644
--- a/llvm/include/llvm/SandboxIR/Region.h
+++ b/llvm/include/llvm/SandboxIR/Region.h
@@ -120,6 +120,7 @@ class Region {
   void remove(Instruction *I);
   friend class Context; // The callbacks need to call add() and remove().
   friend class RegionInternalsAttorney; // For unit tests.
+  friend class RegionsFromBBs;          // For add().
 
   /// Set \p I as the \p Idx'th element in the auxiliary vector.
   /// NOTE: This is for internal use, it does not set the metadata.
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.h
new file mode 100644
index 0000000000000..66c9cd42fb878
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.h
@@ -0,0 +1,38 @@
+//===- RegionsFromBBs.h -----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// A SandboxIR function pass that builds one region per BB and then runs a
+// pipeline of region passes on them. This is useful to test region passes in
+// isolation without relying on the output of other vectorizer components.
+//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_REGIONSFROMBBS_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_REGIONSFROMBBS_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/SandboxIR/Pass.h"
+#include "llvm/SandboxIR/PassManager.h"
+
+namespace llvm::sandboxir {
+
+class RegionsFromBBs final : public FunctionPass {
+  // The PM containing the pipeline of region passes.
+  RegionPassManager RPM;
+
+public:
+  RegionsFromBBs(StringRef Pipeline);
+  bool runOnFunction(Function &F, const Analyses &A) final;
+  void printPipeline(raw_ostream &OS) const final {
+    OS << getName() << "\n";
+    RPM.printPipeline(OS);
+  }
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_REGIONSFROMBBS_H
diff --git a/llvm/lib/Transforms/Vectorize/CMakeLists.txt b/llvm/lib/Transforms/Vectorize/CMakeLists.txt
index 38670ba304e53..f8d08b980edb0 100644
--- a/llvm/lib/Transforms/Vectorize/CMakeLists.txt
+++ b/llvm/lib/Transforms/Vectorize/CMakeLists.txt
@@ -8,6 +8,7 @@ add_llvm_component_library(LLVMVectorize
   SandboxVectorizer/Interval.cpp
   SandboxVectorizer/Legality.cpp
   SandboxVectorizer/Passes/BottomUpVec.cpp
+  SandboxVectorizer/Passes/RegionsFromBBs.cpp
   SandboxVectorizer/Passes/RegionsFromMetadata.cpp
   SandboxVectorizer/Passes/SeedCollection.cpp
   SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def
index f745073a1eba6..c525608804955 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def
@@ -31,6 +31,7 @@ REGION_PASS("bottom-up-vec", ::llvm::sandboxir::BottomUpVec)
 #endif
 
 FUNCTION_PASS_WITH_PARAMS("seed-collection", ::llvm::sandboxir::SeedCollection)
+FUNCTION_PASS_WITH_PARAMS("regions-from-bbs", ::llvm::sandboxir::RegionsFromBBs)
 FUNCTION_PASS_WITH_PARAMS("regions-from-metadata", ::llvm::sandboxir::RegionsFromMetadata)
 
 #undef FUNCTION_PASS_WITH_PARAMS
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.cpp
new file mode 100644
index 0000000000000..6801524732ce6
--- /dev/null
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.cpp
@@ -0,0 +1,35 @@
+//===- RegionsFromBBs.cpp - A helper to test RegionPasses -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromBBs.h"
+#include "llvm/SandboxIR/Function.h"
+#include "llvm/SandboxIR/Region.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.h"
+
+namespace llvm::sandboxir {
+
+RegionsFromBBs::RegionsFromBBs(StringRef Pipeline)
+    : FunctionPass("regions-from-bbs"),
+      RPM("rpm", Pipeline, SandboxVectorizerPassBuilder::createRegionPass) {}
+
+bool RegionsFromBBs::runOnFunction(Function &F, const Analyses &A) {
+  SmallVector<std::unique_ptr<Region>, 16> Regions;
+  // Create a region for each BB.
+  for (BasicBlock &BB : F) {
+    Regions.push_back(std::make_unique<Region>(F.getContext(), A.getTTI()));
+    auto &RgnPtr = Regions.back();
+    for (Instruction &I : BB)
+      RgnPtr->add(&I);
+  }
+  // For each region run the region pass pipeline.
+  for (auto &RgnPtr : Regions)
+    RPM.runOnRegion(*RgnPtr, A);
+  return false;
+}
+
+} // namespace llvm::sandboxir
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
index 389f9cc4cae7c..013ccf6e3d945 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/RegionsFromBBs.h"
 #include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/RegionsFromMetadata.h"
 #include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/SeedCollection.h"
 #include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.h"
diff --git a/llvm/test/Transforms/SandboxVectorizer/regions-from-bbs.ll b/llvm/test/Transforms/SandboxVectorizer/regions-from-bbs.ll
new file mode 100644
index 0000000000000..065baadb1478b
--- /dev/null
+++ b/llvm/test/Transforms/SandboxVectorizer/regions-from-bbs.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt --passes=sandbox-vectorizer -sbvec-passes='regions-from-bbs<null>' %s -S | FileCheck %s
+
+define void @foo(i8 %v) {
+; CHECK-LABEL: define void @foo(
+; CHECK-SAME: i8 [[V:%.*]]) {
+; CHECK-NEXT:  [[BBA:.*:]]
+; CHECK-NEXT:    [[ADD0:%.*]] = add i8 [[V]], 0, !sandboxvec [[META0:![0-9]+]]
+; CHECK-NEXT:    br label %[[BBB:.*]], !sandboxvec [[META0]]
+; CHECK:       [[BBB]]:
+; CHECK-NEXT:    [[ADD1:%.*]] = add i8 [[V]], 1, !sandboxvec [[META1:![0-9]+]]
+; CHECK-NEXT:    br label %[[BBC:.*]], !sandboxvec [[META1]]
+; CHECK:       [[BBC]]:
+; CHECK-NEXT:    ret void, !sandboxvec [[META2:![0-9]+]]
+;
+bbA:
+  %add0 = add i8 %v, 0
+  br label %bbB
+
+bbB:
+  %add1 = add i8 %v, 1
+  br label %bbC
+
+bbC:
+  ret void
+}
+;.
+; CHECK: [[META0]] = distinct !{!"sandboxregion"}
+; CHECK: [[META1]] = distinct !{!"sandboxregion"}
+; CHECK: [[META2]] = distinct !{!"sandboxregion"}
+;.

@vporpo vporpo merged commit 2fb1f03 into llvm:main Mar 8, 2025
15 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 8, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building llvm at step 8 "Add check check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/895

Here is the relevant piece of the build log for the reference
Step 8 (Add check check-llvm) failure: test (failure)
******************** TEST 'LLVM-Unit :: Support/./SupportTests/136/175' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/unittests/Support/./SupportTests-LLVM-Unit-2275045-136-175.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=175 GTEST_SHARD_INDEX=136 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/unittests/Support/./SupportTests
--

Script:
--
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/unittests/Support/./SupportTests --gtest_filter=Caching.NoCommit
--
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/llvm/unittests/Support/Caching.cpp:149: Failure
Value of: llvm::detail::TakeError(CFS->commit())
Expected: succeeded
  Actual: failed  (Failed to rename temporary file /tmp/lit-tmp-wzuqu_ft/llvm_test_cache/LLVMTest-efb397.tmp.o to /tmp/lit-tmp-wzuqu_ft/llvm_test_cache/llvmcache-foo: No such file or directory
)


/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/llvm/unittests/Support/Caching.cpp:149
Value of: llvm::detail::TakeError(CFS->commit())
Expected: succeeded
  Actual: failed  (Failed to rename temporary file /tmp/lit-tmp-wzuqu_ft/llvm_test_cache/LLVMTest-efb397.tmp.o to /tmp/lit-tmp-wzuqu_ft/llvm_test_cache/llvmcache-foo: No such file or directory
)



********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 8, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building llvm at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/25119

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM-Unit :: Support/./SupportTests/48/88' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/build/buildbot/premerge-monolithic-linux/build/unittests/Support/./SupportTests-LLVM-Unit-1190634-48-88.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=88 GTEST_SHARD_INDEX=48 /build/buildbot/premerge-monolithic-linux/build/unittests/Support/./SupportTests
--

Script:
--
/build/buildbot/premerge-monolithic-linux/build/unittests/Support/./SupportTests --gtest_filter=Caching.NoCommit
--
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/unittests/Support/Caching.cpp:149: Failure
Value of: llvm::detail::TakeError(CFS->commit())
Expected: succeeded
  Actual: failed  (Failed to rename temporary file /tmp/lit-tmp-7cdk8696/llvm_test_cache/LLVMTest-667add.tmp.o to /tmp/lit-tmp-7cdk8696/llvm_test_cache/llvmcache-foo: No such file or directory
)


/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/unittests/Support/Caching.cpp:149
Value of: llvm::detail::TakeError(CFS->commit())
Expected: succeeded
  Actual: failed  (Failed to rename temporary file /tmp/lit-tmp-7cdk8696/llvm_test_cache/LLVMTest-667add.tmp.o to /tmp/lit-tmp-7cdk8696/llvm_test_cache/llvmcache-foo: No such file or directory
)



********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 8, 2025

LLVM Buildbot has detected a new failure on builder llvm-nvptx64-nvidia-win running on as-builder-8 while building llvm at step 7 "test-build-unified-tree-check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/155/builds/7310

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-llvm) failure: test (failure)
******************** TEST 'LLVM-Unit :: Support/./SupportTests.exe/49/87' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\buildbot\as-builder-8\llvm-nvptx64-nvidia-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-17988-49-87.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=49 C:\buildbot\as-builder-8\llvm-nvptx64-nvidia-win\build\unittests\Support\.\SupportTests.exe
--

Note: This is test shard 50 of 87.

[==========] Running 16 tests from 16 test suites.

[----------] Global test environment set-up.

[----------] 1 test from T2EEBuildAttr

[ RUN      ] T2EEBuildAttr.testBuildAttr

[       OK ] T2EEBuildAttr.testBuildAttr (0 ms)

[----------] 1 test from T2EEBuildAttr (0 ms total)



[----------] 1 test from Caching

[ RUN      ] Caching.Normal

C:\buildbot\as-builder-8\llvm-nvptx64-nvidia-win\llvm-project\llvm\unittests\Support\Caching.cpp(58): error: Value of: bool(FileOrErr)

  Actual: false

Expected: true



Expected<T> must be checked before access or destruction.

Unchecked Expected<T> contained error:

no such file or directory: LLVMTestCache: Can't get a temporary fileException Code: 0x80000003

 #0 0x00007ff773c2d685 (C:\buildbot\as-builder-8\llvm-nvptx64-nvidia-win\build\unittests\Support\SupportTests.exe+0x4fd685)

 #1 0x00007ffb8044d88d (C:\Windows\System32\ucrtbase.dll+0x6d88d)

 #2 0x00007ffb8044e761 (C:\Windows\System32\ucrtbase.dll+0x6e761)

 #3 0x00007ff773812614 (C:\buildbot\as-builder-8\llvm-nvptx64-nvidia-win\build\unittests\Support\SupportTests.exe+0xe2614)

 #4 0x00007ff773836ce6 (C:\buildbot\as-builder-8\llvm-nvptx64-nvidia-win\build\unittests\Support\SupportTests.exe+0x106ce6)

...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 8, 2025

LLVM Buildbot has detected a new failure on builder lld-x86_64-ubuntu-fast running on as-builder-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/12668

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM-Unit :: Support/./SupportTests/47/88' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/unittests/Support/./SupportTests-LLVM-Unit-471766-47-88.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=88 GTEST_SHARD_INDEX=47 /home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/unittests/Support/./SupportTests
--

Script:
--
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/build/unittests/Support/./SupportTests --gtest_filter=Caching.WriteAfterCommit
--
/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/unittests/Support/Caching.cpp:103: Failure
Value of: AddStream
  Actual: false
Expected: true


/home/buildbot/worker/as-builder-4/ramdisk/lld-x86_64/llvm-project/llvm/unittests/Support/Caching.cpp:103
Value of: AddStream
  Actual: false
Expected: true



********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants