[Mlir-commits] [mlir] b23e72a - [mlir][shape] Rename dim.dim to dim.index (NFC)

Jacques Pienaar llvmlistbot at llvm.org
Sat Aug 13 09:35:02 PDT 2022


Author: Jacques Pienaar
Date: 2022-08-13T09:34:37-07:00
New Revision: b23e72a2e786cf18eaff2206439a56f90c756bdd

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

LOG: [mlir][shape] Rename dim.dim to dim.index (NFC)

dim member on dim was confusing, change to be consistent with
tensor::dim.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
    mlir/lib/Dialect/Shape/IR/Shape.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index eeace76b632c0..9eebe4306a798 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -333,26 +333,26 @@ def Shape_DimOp : Shape_Op<"dim",
   let summary = "Gets the specified extent from the shape of a shaped input";
   let description = [{
     Gets the extent indexed by `dim` from the shape of the `value` operand. If
-    the dim is error or out-of-bound then it returns an invalid size if the
+    the index is error or out-of-bound then it returns an invalid size if the
     return type carries error information else the behavior is undefined.
 
     This is a convenience op that performs the equivalent of getting the extent
     of a shape (e.g., `dim(x, i) == get_extent(shape_of(x), i)`).
   }];
   let arguments = (ins AnyShaped:$value,
-                       Shape_SizeOrIndexType:$dim);
+                       Shape_SizeOrIndexType:$index);
   let results = (outs Shape_SizeOrIndexType:$extent);
-  let assemblyFormat = "$value `,` $dim attr-dict `:` type($value) `,` type($dim) `->` "
+  let assemblyFormat = "$value `,` $index attr-dict `:` type($value) `,` type($index) `->` "
                        "type($extent)";
 
   let builders = [
     // Builder that allows passing a constant dimension as a simple integer.
-    OpBuilder<(ins "Value":$value, "int64_t":$dim)>
+    OpBuilder<(ins "Value":$value, "int64_t":$index)>
   ];
 
   let extraClassDeclaration = [{
-    /// Get the `dim` value as integer if it is constant.
-    Optional<int64_t> getConstantDim();
+    /// Get the `index` value as integer if it is constant.
+    Optional<int64_t> getConstantIndex();
 
     /// Returns when two result types are compatible for this op; method used by
     /// InferTypeOpInterface

diff  --git a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
index 972484ba435a8..3a3a336f3ee6a 100644
--- a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
+++ b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
@@ -340,7 +340,7 @@ DimOpConverter::matchAndRewrite(DimOp op, OpAdaptor adaptor,
   // steps.
   auto shapeOf = rewriter.create<shape::ShapeOfOp>(op.getLoc(), op.getValue());
   rewriter.replaceOpWithNewOp<shape::GetExtentOp>(op, op.getType(), shapeOf,
-                                                  op.getDim());
+                                                  op.getIndex());
   return success();
 }
 

diff  --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index 9c6ab1fbc2212..133e7577335f4 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -1068,10 +1068,10 @@ OpFoldResult CstrRequireOp::fold(ArrayRef<Attribute> operands) {
 // DimOp
 //===----------------------------------------------------------------------===//
 
-Optional<int64_t> DimOp::getConstantDim() {
-  if (auto constSizeOp = getDim().getDefiningOp<ConstSizeOp>())
+Optional<int64_t> DimOp::getConstantIndex() {
+  if (auto constSizeOp = getIndex().getDefiningOp<ConstSizeOp>())
     return constSizeOp.getValue().getLimitedValue();
-  if (auto constantOp = getDim().getDefiningOp<arith::ConstantOp>())
+  if (auto constantOp = getIndex().getDefiningOp<arith::ConstantOp>())
     return constantOp.getValue().cast<IntegerAttr>().getInt();
   return llvm::None;
 }
@@ -1081,12 +1081,12 @@ OpFoldResult DimOp::fold(ArrayRef<Attribute> operands) {
   auto valShapedType = valType.dyn_cast<ShapedType>();
   if (!valShapedType || !valShapedType.hasRank())
     return nullptr;
-  Optional<int64_t> dim = getConstantDim();
-  if (!dim.has_value())
+  Optional<int64_t> index = getConstantIndex();
+  if (!index.has_value())
     return nullptr;
-  if (dim.value() >= valShapedType.getRank())
+  if (index.value() >= valShapedType.getRank())
     return nullptr;
-  auto extent = valShapedType.getDimSize(*dim);
+  auto extent = valShapedType.getDimSize(*index);
   if (ShapedType::isDynamic(extent))
     return nullptr;
   return IntegerAttr::get(IndexType::get(getContext()), extent);
@@ -1097,7 +1097,7 @@ LogicalResult mlir::shape::DimOp::inferReturnTypes(
     DictionaryAttr attributes, RegionRange regions,
     SmallVectorImpl<Type> &inferredReturnTypes) {
   DimOpAdaptor dimOp(operands);
-  inferredReturnTypes.assign({dimOp.getDim().getType()});
+  inferredReturnTypes.assign({dimOp.getIndex().getType()});
   return success();
 }
 
@@ -1109,8 +1109,8 @@ LogicalResult mlir::shape::DimOp::verify() {
   auto st = getValue().getType().cast<ShapedType>();
   if (!st.hasRank())
     return success();
-  if (auto dim = getConstantDim()) {
-    if (*dim < 0 || *dim >= st.getRank())
+  if (auto index = getConstantIndex()) {
+    if (*index < 0 || *index >= st.getRank())
       return emitOpError("index is out of range");
   }
   return success();


        


More information about the Mlir-commits mailing list