[Mlir-commits] [mlir] [MLIR][SCF] Fix LoopPeelOp documentation (NFC) (PR #113179)

Hugo Trachino llvmlistbot at llvm.org
Tue Oct 29 08:40:42 PDT 2024


https://github.com/nujaa updated https://github.com/llvm/llvm-project/pull/113179

>From 25e0b03e421b01bf1c0cc515e25e59fdb490374a Mon Sep 17 00:00:00 2001
From: Hugo <hugo.trachino at huawei.com>
Date: Fri, 18 Oct 2024 16:41:20 +0800
Subject: [PATCH 1/5] [MLIR][SCF] Fix LoopPeelOp documentation (NFC)

---
 .../mlir/Dialect/SCF/TransformOps/SCFTransformOps.td | 12 ++++++------
 .../Dialect/SCF/Transforms/LoopSpecialization.cpp    | 11 +++++------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
index 20880d94a83cac..d13c1ba9a8ed1e 100644
--- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
+++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
@@ -146,7 +146,7 @@ def LoopPeelOp : Op<Transform_Dialect, "loop.peel",
   let summary = "Peels the first or last iteration of the loop";
   let description = [{
      Rewrite the given loop with a main loop and a partial (first or last) loop.
-     When the `peelFront` option is set as true, the first iteration is peeled off.
+     When the `peelFront` option is set to true, the first iteration is peeled off.
      Otherwise, updates the given loop so that its step evenly divides its range and puts
      the remaining iteration into a separate loop or a conditional.
 
@@ -158,12 +158,12 @@ def LoopPeelOp : Op<Transform_Dialect, "loop.peel",
      This operation ignores non-scf::ForOp ops and drops them in the return.
 
      When `peelFront` is true, this operation returns two scf::ForOp Ops, the
-     first scf::ForOp corresponds to the first iteration of the loop which can
-     be canonicalized away in the following optimization. The second loop Op
-     contains the remaining iteration, and the new lower bound is the original
-     lower bound plus the number of steps.
+     first scf::ForOp corresponds to the target loop, whose lower bound has
+     been updated to the original lower bound plus the step. The second result
+     is the first iteration of the loop which can be canonicalized away in the
+     following optimization.
 
-     When `peelFront` is not true, this operation returns two scf::ForOp Ops, with the first
+     When `peelFront` is false, this operation returns two scf::ForOp Ops, with the first
      scf::ForOp satisfying: "the loop trip count is divisible by the step".
      The second loop Op contains the remaining iteration. Note that even though the
      Payload IR modification may be performed in-place, this operation consumes
diff --git a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp
index a30e349d49136c..c06a448c3108c3 100644
--- a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp
@@ -206,12 +206,11 @@ LogicalResult mlir::scf::peelForLoopAndSimplifyBounds(RewriterBase &rewriter,
   return success();
 }
 
-/// When the `peelFront` option is set as true, the first iteration of the loop
-/// is peeled off. This function rewrites the original scf::ForOp as two
-/// scf::ForOp Ops, the first scf::ForOp corresponds to the first iteration of
-/// the loop which can be canonicalized away in the following optimization. The
-/// second loop Op contains the remaining iteration, and the new lower bound is
-/// the original lower bound plus the number of steps.
+/// Rewrites the original scf::ForOp as two scf::ForOp Ops, the first scf::ForOp
+/// corresponds to the first iteration of the loop which can be canonicalized
+/// away in the following optimization. The second loop Op contains the
+/// remaining iteration, and the new lower bound is the original lower bound
+/// plus the number of steps.
 LogicalResult mlir::scf::peelForLoopFirstIteration(RewriterBase &b, ForOp forOp,
                                                    ForOp &firstIteration) {
   RewriterBase::InsertionGuard guard(b);

>From 8bf6967302798eeb3b0b808d76d1b89d48cab791 Mon Sep 17 00:00:00 2001
From: Hugo <hugo.trachino at huawei.com>
Date: Fri, 25 Oct 2024 19:13:13 +0800
Subject: [PATCH 2/5] fixup! [MLIR][SCF] Fix LoopPeelOp documentation (NFC)

---
 .../SCF/TransformOps/SCFTransformOps.td       | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
index d13c1ba9a8ed1e..6381168256d129 100644
--- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
+++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
@@ -156,18 +156,18 @@ def LoopPeelOp : Op<Transform_Dialect, "loop.peel",
      #### Return modes
 
      This operation ignores non-scf::ForOp ops and drops them in the return.
-
-     When `peelFront` is true, this operation returns two scf::ForOp Ops, the
-     first scf::ForOp corresponds to the target loop, whose lower bound has
-     been updated to the original lower bound plus the step. The second result
-     is the first iteration of the loop which can be canonicalized away in the
-     following optimization.
-
-     When `peelFront` is false, this operation returns two scf::ForOp Ops, with the first
-     scf::ForOp satisfying: "the loop trip count is divisible by the step".
-     The second loop Op contains the remaining iteration. Note that even though the
-     Payload IR modification may be performed in-place, this operation consumes
-     the operand handle and produces a new one.
+     The op returns two loops, the peeled loop and the remainder loop.
+
+     When `peelFront` is true, the first scf::ForOp (the remainder loop)
+     executes all iterations of the target loop but the first one. The second
+     scf::ForOp corresponds to the first iteration of the loop which can be
+     canonicalized away in the following optimizations (the peeled loop).
+
+     When `peelFront` is false, the first result (the main loop) is "the loop
+     with the highest upper bound that is divisible by the step". The second
+     loopOp (remainder loop) contains the remaining iterations. Note that even
+     though the Payload IR modification may be performed in-place, this
+     operation consumes the operand handle and produces a new one.
 
      #### Return Modes
 

>From 507cee20d7c1851a792cee330c0f26600d465838 Mon Sep 17 00:00:00 2001
From: Hugo Trachino <hugo.trachino at huawei.com>
Date: Mon, 28 Oct 2024 10:02:35 +0000
Subject: [PATCH 3/5] imporove consistency in naming

---
 .../include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
index 6381168256d129..0ac6615c6768e8 100644
--- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
+++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
@@ -156,14 +156,15 @@ def LoopPeelOp : Op<Transform_Dialect, "loop.peel",
      #### Return modes
 
      This operation ignores non-scf::ForOp ops and drops them in the return.
-     The op returns two loops, the peeled loop and the remainder loop.
+     The op returns two loops, the peeled loop whose tripcount is divisible by
+     the step and the remainder loop.
 
      When `peelFront` is true, the first scf::ForOp (the remainder loop)
      executes all iterations of the target loop but the first one. The second
      scf::ForOp corresponds to the first iteration of the loop which can be
      canonicalized away in the following optimizations (the peeled loop).
 
-     When `peelFront` is false, the first result (the main loop) is "the loop
+     When `peelFront` is false, the first result (peeled loop) is "the loop
      with the highest upper bound that is divisible by the step". The second
      loopOp (remainder loop) contains the remaining iterations. Note that even
      though the Payload IR modification may be performed in-place, this

>From 17019aac45cb9f7b9b14f0c4dcfd2459434577ea Mon Sep 17 00:00:00 2001
From: Hugo <hugo.trachino at huawei.com>
Date: Tue, 29 Oct 2024 22:51:01 +0800
Subject: [PATCH 4/5] fixup! imporove consistency in naming

---
 .../SCF/TransformOps/SCFTransformOps.td       | 27 ++++++++++---------
 .../SCF/Transforms/LoopSpecialization.cpp     | 10 +++----
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
index 0ac6615c6768e8..3ebe2b2947fcca 100644
--- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
+++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
@@ -156,19 +156,20 @@ def LoopPeelOp : Op<Transform_Dialect, "loop.peel",
      #### Return modes
 
      This operation ignores non-scf::ForOp ops and drops them in the return.
-     The op returns two loops, the peeled loop whose tripcount is divisible by
-     the step and the remainder loop.
-
-     When `peelFront` is true, the first scf::ForOp (the remainder loop)
-     executes all iterations of the target loop but the first one. The second
-     scf::ForOp corresponds to the first iteration of the loop which can be
-     canonicalized away in the following optimizations (the peeled loop).
-
-     When `peelFront` is false, the first result (peeled loop) is "the loop
-     with the highest upper bound that is divisible by the step". The second
-     loopOp (remainder loop) contains the remaining iterations. Note that even
-     though the Payload IR modification may be performed in-place, this
-     operation consumes the operand handle and produces a new one.
+     The op returns two loops, the peeled loop which has trip count divisible
+     by the step, and the remainder loop.
+
+     When `peelFront` is true, the first result (remainder loop) executes all
+     but the first iteration of the target loop. The second result (peeled
+     loop) corresponds to the first iteration of the loop which can be
+     canonicalized away in the following optimizations .
+
+     When `peelFront` is false, the first result (peeled loop) is the portion
+     of the target loop with the highest upper bound that is divisible by the
+     step. The second result (remainder loop) contains the remaining iterations. 
+     
+     Note that even though the Payload IR modification may be performed
+     in-place, this operation consumes the operand handle and produces a new one.
 
      #### Return Modes
 
diff --git a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp
index c06a448c3108c3..5104ad4b3a3038 100644
--- a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp
@@ -206,11 +206,11 @@ LogicalResult mlir::scf::peelForLoopAndSimplifyBounds(RewriterBase &rewriter,
   return success();
 }
 
-/// Rewrites the original scf::ForOp as two scf::ForOp Ops, the first scf::ForOp
-/// corresponds to the first iteration of the loop which can be canonicalized
-/// away in the following optimization. The second loop Op contains the
-/// remaining iteration, and the new lower bound is the original lower bound
-/// plus the number of steps.
+/// Rewrites the original scf::ForOp as two scf::ForOp Ops, the first
+/// scf::ForOp corresponds to the first iteration of the loop which can be
+/// canonicalized away in the following optimizations. The second loop Op
+/// contains the remaining iterations, with a lower bound updated as the
+/// original lower bound plus the step (i.e. skips the first iteration).
 LogicalResult mlir::scf::peelForLoopFirstIteration(RewriterBase &b, ForOp forOp,
                                                    ForOp &firstIteration) {
   RewriterBase::InsertionGuard guard(b);

>From 9180951984340770e630bb1f24ea29addf52b092 Mon Sep 17 00:00:00 2001
From: Hugo Trachino <hugo.trachino at huawei.com>
Date: Tue, 29 Oct 2024 15:40:33 +0000
Subject: [PATCH 5/5] Update
 mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Andrzej WarzyƄski <andrzej.warzynski at gmail.com>
---
 mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
index 3ebe2b2947fcca..5dba8c5e57ba86 100644
--- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
+++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
@@ -162,7 +162,7 @@ def LoopPeelOp : Op<Transform_Dialect, "loop.peel",
      When `peelFront` is true, the first result (remainder loop) executes all
      but the first iteration of the target loop. The second result (peeled
      loop) corresponds to the first iteration of the loop which can be
-     canonicalized away in the following optimizations .
+     canonicalized away in the following optimizations.
 
      When `peelFront` is false, the first result (peeled loop) is the portion
      of the target loop with the highest upper bound that is divisible by the



More information about the Mlir-commits mailing list