[llvm] [SPIR-V][NewPM] Register SPIRVStructurizer with the new pass manager (PR #209965)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 22:13:10 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Arseniy Obolenskiy (aobolensk)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp (+37-27) 


``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
index f02bd261244aa..df1ee0bc13076 100644
--- a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
@@ -23,7 +23,6 @@
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/IntrinsicsSPIRV.h"
-#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -282,7 +281,10 @@ static void replaceBranchTargets(BasicBlock *BB, BasicBlock *OldTarget,
 namespace {
 // Given a reducible CFG, produces a structurized CFG in the SPIR-V sense,
 // adding merge instructions when required.
-class SPIRVStructurizer : public FunctionPass {
+class SPIRVStructurizerImpl {
+  LoopInfo &LI;
+  ConvergenceRegionInfo &RegionInfo;
+
   struct DivergentConstruct;
   // Represents a list of condition/loops/switch constructs.
   // See SPIR-V 2.11.2. Structured Control-flow Constructs for the list of
@@ -514,11 +516,7 @@ class SPIRVStructurizer : public FunctionPass {
 
   // Add OpLoopMerge instruction on cycles.
   bool addMergeForLoops(Function &F) {
-    LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
-    auto *TopLevelRegion =
-        getAnalysis<SPIRVConvergenceRegionAnalysisWrapperPass>()
-            .getRegionInfo()
-            .getTopLevelRegion();
+    auto *TopLevelRegion = RegionInfo.getTopLevelRegion();
 
     bool Modified = false;
     for (auto &BB : F) {
@@ -875,7 +873,6 @@ class SPIRVStructurizer : public FunctionPass {
   }
 
   bool splitCriticalEdges(Function &F) {
-    LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
     Splitter S(F, LI);
 
     DivergentConstruct Root;
@@ -1070,11 +1067,10 @@ class SPIRVStructurizer : public FunctionPass {
   }
 
 public:
-  static char ID;
+  SPIRVStructurizerImpl(LoopInfo &LI, ConvergenceRegionInfo &RegionInfo)
+      : LI(LI), RegionInfo(RegionInfo) {}
 
-  SPIRVStructurizer() : FunctionPass(ID) {}
-
-  bool runOnFunction(Function &F) override {
+  bool run(Function &F) {
     bool Modified = false;
 
     // In LLVM, Switches are allowed to have several cases branching to the same
@@ -1140,15 +1136,6 @@ class SPIRVStructurizer : public FunctionPass {
     return Modified;
   }
 
-  void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.addRequired<DominatorTreeWrapperPass>();
-    AU.addRequired<LoopInfoWrapperPass>();
-    AU.addRequired<SPIRVConvergenceRegionAnalysisWrapperPass>();
-
-    AU.addPreserved<SPIRVConvergenceRegionAnalysisWrapperPass>();
-    FunctionPass::getAnalysisUsage(AU);
-  }
-
   void createOpSelectMerge(IRBuilder<> *Builder, BlockAddress *MergeAddress) {
     Instruction *BBTerminatorInst = Builder->GetInsertBlock()->getTerminator();
 
@@ -1168,6 +1155,30 @@ class SPIRVStructurizer : public FunctionPass {
                              {MergeAddress->getType()}, Args);
   }
 };
+
+class SPIRVStructurizer : public FunctionPass {
+public:
+  static char ID;
+
+  SPIRVStructurizer() : FunctionPass(ID) {}
+
+  bool runOnFunction(Function &F) override {
+    LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
+    ConvergenceRegionInfo &RegionInfo =
+        getAnalysis<SPIRVConvergenceRegionAnalysisWrapperPass>()
+            .getRegionInfo();
+    return SPIRVStructurizerImpl(LI, RegionInfo).run(F);
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+    AU.addRequired<DominatorTreeWrapperPass>();
+    AU.addRequired<LoopInfoWrapperPass>();
+    AU.addRequired<SPIRVConvergenceRegionAnalysisWrapperPass>();
+
+    AU.addPreserved<SPIRVConvergenceRegionAnalysisWrapperPass>();
+    FunctionPass::getAnalysisUsage(AU);
+  }
+};
 } // anonymous namespace
 
 char SPIRVStructurizer::ID = 0;
@@ -1187,12 +1198,11 @@ FunctionPass *llvm::createSPIRVStructurizerPass() {
 }
 
 PreservedAnalyses SPIRVStructurizerWrapper::run(Function &F,
-                                                FunctionAnalysisManager &AF) {
-
-  auto FPM = legacy::FunctionPassManager(F.getParent());
-  FPM.add(createSPIRVStructurizerPass());
-
-  if (!FPM.run(F))
+                                                FunctionAnalysisManager &AM) {
+  LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
+  ConvergenceRegionInfo &RegionInfo =
+      AM.getResult<SPIRVConvergenceRegionAnalysis>(F);
+  if (!SPIRVStructurizerImpl(LI, RegionInfo).run(F))
     return PreservedAnalyses::all();
   PreservedAnalyses PA;
   PA.preserveSet<CFGAnalyses>();

``````````

</details>


https://github.com/llvm/llvm-project/pull/209965


More information about the llvm-commits mailing list