[Mlir-commits] [mlir] [mlir][bufferization] Add buffer-loop-merging pass (PR #213183)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 30 17:56:07 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- mlir/lib/Dialect/Bufferization/Transforms/BufferLoopMerging.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferLoopMerging.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferLoopMerging.cpp
index 0298da282..599790d63 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferLoopMerging.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferLoopMerging.cpp
@@ -22,20 +22,21 @@
// scf.yield %yield
// }
//
-// The iter_arg is not loop-invariant, so the `scf.for` remains a blocking use of
-// both allocations and Mem2Reg abandons them (`scf.for` implements
-// `PromotableRegionOpInterface`, but is not itself a promotable or aliasing op).
-// The buffers are nonetheless interchangeable: `%it` denotes `%init` only on the
-// first iteration and `%yield` on every later one, and no iteration reads a
-// buffer it has not first written except through `%it`. Rewriting all uses of
+// The iter_arg is not loop-invariant, so the `scf.for` remains a blocking use
+// of both allocations and Mem2Reg abandons them (`scf.for` implements
+// `PromotableRegionOpInterface`, but is not itself a promotable or aliasing
+// op). The buffers are nonetheless interchangeable: `%it` denotes `%init` only
+// on the first iteration and `%yield` on every later one, and no iteration
+// reads a buffer it has not first written except through `%it`. Rewriting all
+// uses of
// `%yield` to `%init` makes the iter_arg loop-invariant, after which existing
// canonicalization drops it and Mem2Reg promotes the slot.
//
// Merging redirects the body's stores from `%yield` into `%init`, so it is only
// sound when the buffers cannot be distinguished outside the loop after that
-// redirection: every non-threading use of `%init` must strictly precede the loop
-// (its contents change from the loop onward), and `%yield` must never be written
-// outside the loop (such a write would be lost or reordered).
+// redirection: every non-threading use of `%init` must strictly precede the
+// loop (its contents change from the loop onward), and `%yield` must never be
+// written outside the loop (such a write would be lost or reordered).
//
//===----------------------------------------------------------------------===//
@@ -62,7 +63,8 @@ namespace {
/// How an operation uses a buffer value.
enum class BufferUseKind {
- /// The use is the `scf.yield` of the loop being considered, or an init operand
+ /// The use is the `scf.yield` of the loop being considered, or an init
+ /// operand
/// of the loop itself. Both are the threading of the buffer through the
/// iter_arg, which this transform is rewriting.
Yield,
@@ -80,9 +82,9 @@ enum class BufferUseKind {
} // namespace
/// Classifies how `use` accesses the buffer it refers to. Only operations whose
-/// memory effects are fully known and limited to reads and writes of the operand
-/// are safe to redirect; anything else may observe the buffer's address rather
-/// than just its contents, which merging does not preserve.
+/// memory effects are fully known and limited to reads and writes of the
+/// operand are safe to redirect; anything else may observe the buffer's address
+/// rather than just its contents, which merging does not preserve.
static BufferUseKind classifyBufferUse(OpOperand &use, ForOp loop) {
Operation *user = use.getOwner();
if (isa<scf::YieldOp>(user) && user->getParentOp() == loop)
``````````
</details>
https://github.com/llvm/llvm-project/pull/213183
More information about the Mlir-commits
mailing list