[Mlir-commits] [mlir] b2d1de2 - [mlir][Interfaces][NFC] Delete dead code from OffsetSizeAndStrideOpInterface

Matthias Springer llvmlistbot at llvm.org
Thu Aug 3 02:47:17 PDT 2023


Author: Matthias Springer
Date: 2023-08-03T11:47:01+02:00
New Revision: b2d1de2d632b7d4f2cb677f6b8ba36c6dda2c846

URL: https://github.com/llvm/llvm-project/commit/b2d1de2d632b7d4f2cb677f6b8ba36c6dda2c846
DIFF: https://github.com/llvm/llvm-project/commit/b2d1de2d632b7d4f2cb677f6b8ba36c6dda2c846.diff

LOG: [mlir][Interfaces][NFC] Delete dead code from OffsetSizeAndStrideOpInterface

Also make `getNumDynamicEntriesUpToIdx` a helper function. It does not have to be an interface method.

Differential Revision: https://reviews.llvm.org/D156864

Added: 
    

Modified: 
    mlir/include/mlir/Interfaces/ViewLikeInterface.h
    mlir/include/mlir/Interfaces/ViewLikeInterface.td
    mlir/lib/Interfaces/ViewLikeInterface.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Interfaces/ViewLikeInterface.h b/mlir/include/mlir/Interfaces/ViewLikeInterface.h
index cbc034ca9958a4..a114e9af126f11 100644
--- a/mlir/include/mlir/Interfaces/ViewLikeInterface.h
+++ b/mlir/include/mlir/Interfaces/ViewLikeInterface.h
@@ -32,6 +32,11 @@ bool sameOffsetsSizesAndStrides(
     OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b,
     llvm::function_ref<bool(OpFoldResult, OpFoldResult)> cmp);
 
+/// Helper method to compute the number of dynamic entries of `staticVals`,
+/// up to `idx`.
+unsigned getNumDynamicEntriesUpToIdx(ArrayRef<int64_t> staticVals,
+                                     unsigned idx);
+
 } // namespace detail
 } // namespace mlir
 

diff  --git a/mlir/include/mlir/Interfaces/ViewLikeInterface.td b/mlir/include/mlir/Interfaces/ViewLikeInterface.td
index 6c5e7c6a93302c..8029380a2c8f1d 100644
--- a/mlir/include/mlir/Interfaces/ViewLikeInterface.td
+++ b/mlir/include/mlir/Interfaces/ViewLikeInterface.td
@@ -279,8 +279,8 @@ def OffsetSizeAndStrideOpInterface : OpInterface<"OffsetSizeAndStrideOpInterface
       /*methodBody=*/"",
       /*defaultImplementation=*/[{
         assert($_op.isDynamicOffset(idx) && "expected dynamic offset");
-        auto numDynamic = getNumDynamicEntriesUpToIdx(
-          getStaticOffsets(), ::mlir::ShapedType::isDynamic, idx);
+        auto numDynamic = ::mlir::detail::getNumDynamicEntriesUpToIdx(
+          getStaticOffsets(), idx);
         return $_op.getOffsetSizeAndStrideStartOperandIndex() + numDynamic;
       }]
     >,
@@ -295,8 +295,8 @@ def OffsetSizeAndStrideOpInterface : OpInterface<"OffsetSizeAndStrideOpInterface
       /*methodBody=*/"",
       /*defaultImplementation=*/[{
         assert($_op.isDynamicSize(idx) && "expected dynamic size");
-        auto numDynamic = getNumDynamicEntriesUpToIdx(
-          getStaticSizes(), ::mlir::ShapedType::isDynamic, idx);
+        auto numDynamic = ::mlir::detail::getNumDynamicEntriesUpToIdx(
+          getStaticSizes(), idx);
         return $_op.getOffsetSizeAndStrideStartOperandIndex() +
           getOffsets().size() + numDynamic;
       }]
@@ -312,32 +312,12 @@ def OffsetSizeAndStrideOpInterface : OpInterface<"OffsetSizeAndStrideOpInterface
       /*methodBody=*/"",
       /*defaultImplementation=*/[{
         assert($_op.isDynamicStride(idx) && "expected dynamic stride");
-        auto numDynamic = getNumDynamicEntriesUpToIdx(
-          getStaticStrides(), ::mlir::ShapedType::isDynamic, idx);
+        auto numDynamic = ::mlir::detail::getNumDynamicEntriesUpToIdx(
+          getStaticStrides(), idx);
         return $_op.getOffsetSizeAndStrideStartOperandIndex() +
           getOffsets().size() + getSizes().size() + numDynamic;
       }]
     >,
-    InterfaceMethod<
-      /*desc=*/[{
-        Helper method to compute the number of dynamic entries of `staticVals`,
-        up to `idx` using `isDynamic` to determine whether an entry is dynamic.
-      }],
-      /*retTy=*/"unsigned",
-      /*methodName=*/"getNumDynamicEntriesUpToIdx",
-      /*args=*/(ins "::llvm::ArrayRef<int64_t>":$staticVals,
-                    "::llvm::function_ref<bool(int64_t)>":$isDynamic,
-                    "unsigned":$idx),
-      /*methodBody=*/"",
-      /*defaultImplementation=*/[{
-        return std::count_if(
-          staticVals.begin(), staticVals.begin() + idx,
-          [&](int64_t val) {
-            return isDynamic(val);
-          });
-      }]
-    >,
-
     InterfaceMethod<
       /*desc=*/[{
         Assert the offset `idx` is dynamic and return its value.
@@ -417,29 +397,6 @@ def OffsetSizeAndStrideOpInterface : OpInterface<"OffsetSizeAndStrideOpInterface
     >,
   ];
 
-  let extraClassDeclaration = [{
-    static unsigned getOffsetOperandGroupPosition() { return 0; }
-    static unsigned getSizeOperandGroupPosition() { return 1; }
-    static unsigned getStrideOperandGroupPosition() { return 2; }
-    static ::llvm::StringRef getStaticOffsetsAttrName() {
-      return "static_offsets";
-    }
-    static ::llvm::StringRef getStaticSizesAttrName() {
-      return "static_sizes";
-    }
-    static ::llvm::StringRef getStaticStridesAttrName() {
-      return "static_strides";
-    }
-    static ::llvm::ArrayRef<::llvm::StringRef> getSpecialAttrNames() {
-      static ::llvm::SmallVector<::llvm::StringRef, 4> names{
-        ::mlir::OffsetSizeAndStrideOpInterface::getStaticOffsetsAttrName(),
-        ::mlir::OffsetSizeAndStrideOpInterface::getStaticSizesAttrName(),
-        ::mlir::OffsetSizeAndStrideOpInterface::getStaticStridesAttrName(),
-        ::mlir::OpTrait::AttrSizedOperandSegments<void>::getOperandSegmentSizeAttr()};
-      return names;
-    }
-  }];
-
   let verify = [{
     return ::mlir::detail::verifyOffsetSizeAndStrideOp(
         ::mlir::cast<::mlir::OffsetSizeAndStrideOpInterface>($_op));

diff  --git a/mlir/lib/Interfaces/ViewLikeInterface.cpp b/mlir/lib/Interfaces/ViewLikeInterface.cpp
index 907c3534d2af31..9247f571d9ab2c 100644
--- a/mlir/lib/Interfaces/ViewLikeInterface.cpp
+++ b/mlir/lib/Interfaces/ViewLikeInterface.cpp
@@ -196,3 +196,9 @@ bool mlir::detail::sameOffsetsSizesAndStrides(
       return false;
   return true;
 }
+
+unsigned mlir::detail::getNumDynamicEntriesUpToIdx(ArrayRef<int64_t> staticVals,
+                                                   unsigned idx) {
+  return std::count_if(staticVals.begin(), staticVals.begin() + idx,
+                       [&](int64_t val) { return ShapedType::isDynamic(val); });
+}


        


More information about the Mlir-commits mailing list