[llvm] [NFC][SPIR-V] Fuse redundant full-traversal loops in prepare/emit-intrinsics/structurizer passes (PR #211299)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 00:35:58 PDT 2026


================
@@ -169,15 +142,33 @@ static std::vector<Instruction *> getMergeInstructions(BasicBlock &BB) {
   return Output;
 }
 
-// Returns all basic blocks in |F| referenced as continue target by at least 1
-// OpLoopMerge instruction.
-static SmallPtrSet<BasicBlock *, 2> getContinueBlocks(Function &F) {
-  SmallPtrSet<BasicBlock *, 2> Output;
+// Bundles the header/merge/continue block sets computed by
+// getHeaderMergeContinueBlocks so callers only needing a subset of them can
+// still share the single underlying scan.
+struct HeaderMergeContinueBlocks {
+  // Blocks in F having at least one OpLoopMerge or OpSelectionMerge
+  // instruction.
+  SmallPtrSet<BasicBlock *, 2> Header;
+  // Blocks in F referenced by at least 1 OpSelectionMerge/OpLoopMerge
+  // instruction.
+  SmallPtrSet<BasicBlock *, 2> Merge;
+  // Blocks in F referenced as continue target by at least 1 OpLoopMerge
+  // instruction.
+  SmallPtrSet<BasicBlock *, 2> Continue;
+};
+
+// Computes Header, Merge and Continue block sets for |F| in a single scan,
+// since they all classify the same instructions.
+static HeaderMergeContinueBlocks getHeaderMergeContinueBlocks(Function &F) {
----------------
jmmartinez wrote:

This function could be the constructor of `HeaderMergeContinueBlocks`.

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


More information about the llvm-commits mailing list