Skip to content

Conversation

@Evanyl
Copy link
Contributor

@Evanyl Evanyl commented Jun 21, 2025

Make getStridesAndOffset const.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir mlir:ods labels Jun 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 21, 2025

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Evan Liu (Evanyl)

Changes

Make getStridesAndOffset const.


Full diff: https://github.com/llvm/llvm-project/pull/145148.diff

2 Files Affected:

  • (modified) mlir/include/mlir/IR/BuiltinTypes.td (+2-2)
  • (modified) mlir/lib/IR/BuiltinTypes.cpp (+3-2)
diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td
index 55d64d663f7ed..89ade79a3ac02 100644
--- a/mlir/include/mlir/IR/BuiltinTypes.td
+++ b/mlir/include/mlir/IR/BuiltinTypes.td
@@ -863,11 +863,11 @@ def Builtin_MemRef : Builtin_Type<"MemRef", "memref", [
     /// the distance in the number of elements between successive entries along
     /// a particular dimension.
     LogicalResult getStridesAndOffset(SmallVectorImpl<int64_t> &strides,
-                                      int64_t &offset);
+                                      int64_t &offset) const;
 
     /// Wrapper around getStridesAndOffset(SmallVectorImpl<int64_t>, int64_t)
     /// that will assert if the logical result is not succeeded.
-    std::pair<SmallVector<int64_t>, int64_t> getStridesAndOffset();
+    std::pair<SmallVector<int64_t>, int64_t> getStridesAndOffset() const;
 
     /// Return "true" if the layout is compatible with strided semantics.
     bool isStrided();
diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 97bab479c79bf..e3a00ac5a14b1 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -730,11 +730,12 @@ MemRefType MemRefType::canonicalizeStridedLayout() {
 }
 
 LogicalResult MemRefType::getStridesAndOffset(SmallVectorImpl<int64_t> &strides,
-                                              int64_t &offset) {
+                                              int64_t &offset) const {
   return getLayout().getStridesAndOffset(getShape(), strides, offset);
 }
 
-std::pair<SmallVector<int64_t>, int64_t> MemRefType::getStridesAndOffset() {
+std::pair<SmallVector<int64_t>, int64_t>
+MemRefType::getStridesAndOffset() const {
   SmallVector<int64_t> strides;
   int64_t offset;
   LogicalResult status = getStridesAndOffset(strides, offset);

@Evanyl
Copy link
Contributor Author

Evanyl commented Jun 21, 2025

cc @matthias-springer who moved this to a member function, thank you!

@Evanyl
Copy link
Contributor Author

Evanyl commented Jun 21, 2025

@matthias-springer would you also mind merging this in when you can? Thank you!

@matthias-springer matthias-springer merged commit 6ae5b89 into llvm:main Jun 22, 2025
11 checks passed
@Evanyl Evanyl deleted the user/evliu/06_20_get_strides_and_offset_const branch June 22, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir:ods mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants