[Mlir-commits] [mlir] [mlir][linalg] Remov `computeStaticLoopSizes` (PR #124778)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 28 08:12:19 PST 2025


https://github.com/josel-amd created https://github.com/llvm/llvm-project/pull/124778

`computeStaticLoopSizes()` seems to do the same as `getStaticLoopRanges()`, just in a slightly different way.

This PR is more of a question to the linalg experts. Is there any use for `computeStaticLoopSizes()` or can it be safely removed? :) 

>From 1cfe6c1c36bfca8c945d1210e559ce914a4d12fd Mon Sep 17 00:00:00 2001
From: Jose Lopes <jose.lopes at amd.com>
Date: Mon, 27 Jan 2025 10:25:48 +0000
Subject: [PATCH] Remove duplicated function

---
 .../mlir/Dialect/Linalg/IR/LinalgInterfaces.td      |  5 -----
 mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp     | 13 -------------
 mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp |  2 +-
 3 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
index 244db23925ab3c..4fb2d420093673 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
@@ -860,11 +860,6 @@ def LinalgStructuredInterface
     /// `createFlatListOfOperandDims`.
     SmallVector<Range, 4> createLoopRanges(OpBuilder &b, Location loc);
 
-    /// Compute the static loop sizes necessary to vectorize the computation.
-    /// This is done by applying `getShapesToLoopsMap` to
-    /// `createFlatListOfOperandStaticDims`.
-    SmallVector<int64_t, 4> computeStaticLoopSizes();
-
     /// Returns the value that expresses the shape of the output in terms of
     /// shape of the input operands where possible
     LogicalResult reifyResultShapes(OpBuilder &b,
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
index caf9cdb3a3eb4f..52f2129c77ee3f 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
@@ -1094,19 +1094,6 @@ SmallVector<Range, 4> LinalgOp::createLoopRanges(OpBuilder &b, Location loc) {
   return res;
 }
 
-SmallVector<int64_t, 4> LinalgOp::computeStaticLoopSizes() {
-  AffineMap map = getLoopsToShapesMap();
-  unsigned numDims = map.getNumDims(), numRes = map.getNumResults();
-  SmallVector<int64_t, 4> allShapeSizes = createFlatListOfOperandStaticDims();
-  SmallVector<int64_t, 4> res(numDims, 0);
-  for (unsigned idx = 0; idx < numRes; ++idx) {
-    auto result = map.getResult(idx);
-    if (auto d = dyn_cast<AffineDimExpr>(result))
-      res[d.getPosition()] = allShapeSizes[idx];
-  }
-  return res;
-}
-
 /// Visitor to check if any of the given set of positions from AffineDimExprs
 /// are used within an AffineExpr.
 struct HasAffineDimExprVisitor
diff --git a/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp b/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp
index 2e6079e1402e1d..b53180b5cf7c34 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp
@@ -130,7 +130,7 @@ class FoldConstantBase : public OpInterfaceRewritePattern<LinalgOp> {
         return failure();
     }
 
-    SmallVector<int64_t, 4> loopBounds = linalgOp.computeStaticLoopSizes();
+    SmallVector<int64_t, 4> loopBounds = linalgOp.getStaticLoopRanges();
     int64_t numElements = outputType.getNumElements();
 
     // Use APInt/APFloat instead of Attribute here for constructing the output.



More information about the Mlir-commits mailing list