[llvm] [Transforms][Utils] Add LoopSplit for iteration-space loop splitting (PR #217232)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 14 03:32:00 PDT 2026
================
@@ -0,0 +1,150 @@
+//===- LoopSplit.h - Split a loop's iteration space -------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Splits a counted loop's iteration space into a chain of per-partition
+// sub-loops. See LoopSplit.cpp for the structure produced.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_UTILS_LOOPSPLIT_H
+#define LLVM_TRANSFORMS_UTILS_LOOPSPLIT_H
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Support/Compiler.h"
+#include <optional>
+
+namespace llvm {
+
+class DominatorTree;
+class SCEV;
+class SCEVExpander;
+class ScalarEvolution;
+
+/// Splits a counted loop into a chain of per-partition sub-loops.
+///
+/// Usage:
+/// \code
+/// if (auto LS = LoopSplit::get(L, LI, SE, DT)) {
+/// LS->addPartition(S0, E0); // one call per partition, in order
+/// LS->addPartition(S1, E1);
+/// LS->split();
+/// }
+/// \endcode
+class LoopSplit {
+public:
+ /// Analyze \p L and, if it is a counted loop this utility can split, return a
+ /// LoopSplit ready for addPartition() and split(). Otherwise return
+ /// std::nullopt. Eligible loops are bottom-tested single-exit loops in LCSSA
+ /// form with dedicated exits, no loop-carried and no escaping values, a
+ /// unique unit-step integer induction, and a computable trip count that
+ /// cannot wrap.
+ LLVM_ABI static std::optional<LoopSplit>
+ get(Loop *L, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT);
+
+ /// Return the loop's induction variable. Valid only on a legal LoopSplit.
+ LLVM_ABI PHINode *getInductionVariable() const {
+ return L->getInductionVariable(*SE);
+ }
----------------
fhahn wrote:
I don't think we need this, the only caller can just call L->getIndictonVariable?
https://github.com/llvm/llvm-project/pull/217232
More information about the llvm-commits
mailing list