Skip to content

[NFC][mlir][bufferization] Remove getMemRefType() helper - #199034

Merged
andrey-golubev merged 1 commit into
llvm:mainfrom
andrey-golubev:simpler_get_buffer_type
Jun 3, 2026
Merged

andrey-golubev merged 1 commit into
llvm:mainfrom
andrey-golubev:simpler_get_buffer_type

Conversation

@andrey-golubev

@andrey-golubev andrey-golubev commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Replace getMemRefType() helper with a direct usage of options.unknownTypeConverterFn() hook. This does not change any behaviour since all the existing call-sites would already implicitly call the hook. The major difference could have been in the handling of the memref layout but this does not seem to be properly handled anyhow.

As the getMemRefType() helper is removed, there are two cases to keep in mind for downstream users that need to adjust the code accordingly:

  1. For creating memrefs without layouts, call options.unknownTypeConverterFn hook directly (the same way this patch is doing for upstream)
  2. For creating memrefs with layouts (assuming, custom ones), please (re)implement the same helper. As only ranked memrefs can have a layout, a call to mlir::MemRefType::get(shape, elementType, /*your custom layout=*/myLayout, memorySpace) should be sufficient.

@andrey-golubev

Copy link
Copy Markdown
Contributor Author

I guess we can start with this first and foremost.

@llvmorg-github-actions llvmorg-github-actions Bot added mlir mlir:bufferization Bufferization infrastructure labels May 21, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-mlir-bufferization

Author: Andrei Golubev (andrey-golubev)

Changes

The implementation for a builtin TensorType's TensorLikeType interface is a bit overly complex for no reason: it calls getMemRefType() whereas in reality options.unknownTypeConverterFn() would directly be called due to the way the current code is written. Remove what is effectively a wrapper function so that the current semantics is a bit clearer.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp (+1-1)
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
index bd177ba1afccd..b36aac8c68d36 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
@@ -48,7 +48,7 @@ struct BuiltinTensorExternalModel
       return emitError() << "could not infer memory space";
 
     return cast<BufferLikeType>(
-        getMemRefType(tensorType, options, /*layout=*/{}, *memSpace));
+        options.unknownTypeConverterFn(tensorType, *memSpace, options));
   }
 
   mlir::LogicalResult verifyCompatibleBufferType(

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-mlir

Author: Andrei Golubev (andrey-golubev)

Changes

The implementation for a builtin TensorType's TensorLikeType interface is a bit overly complex for no reason: it calls getMemRefType() whereas in reality options.unknownTypeConverterFn() would directly be called due to the way the current code is written. Remove what is effectively a wrapper function so that the current semantics is a bit clearer.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp (+1-1)
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
index bd177ba1afccd..b36aac8c68d36 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
@@ -48,7 +48,7 @@ struct BuiltinTensorExternalModel
       return emitError() << "could not infer memory space";
 
     return cast<BufferLikeType>(
-        getMemRefType(tensorType, options, /*layout=*/{}, *memSpace));
+        options.unknownTypeConverterFn(tensorType, *memSpace, options));
   }
 
   mlir::LogicalResult verifyCompatibleBufferType(

Replace getMemRefType() helper with a direct usage of
options.unknownTypeConverterFn() hook. This does not change any
behaviour since all the existing call-sites would already implicitly
call the hook. The major difference could have been in the handling of
the memref layout but this does not seem to be properly handled anyhow.
@andrey-golubev
andrey-golubev force-pushed the simpler_get_buffer_type branch from 24f007b to 1d2ee75 Compare June 3, 2026 08:42
@andrey-golubev andrey-golubev changed the title [NFC][mlir][bufferization] Simplify TensorType::getBufferType() [NFC][mlir][bufferization] Remove getMemRefType() helper Jun 3, 2026
@andrey-golubev
andrey-golubev marked this pull request as ready for review June 3, 2026 08:42
/// Note: Canonicalization patterns could clean up layout maps and infer more
/// precise layout maps after bufferization. However, many possible
/// canonicalizations are currently not implemented.
BaseMemRefType getMemRefType(TensorType tensorType,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this function? Some downstream projects (e.g. IREE) are using it. Alternatively, if we remove it, mention in the commit message how to fix the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the PR description, would it be sufficient?

@andrey-golubev
andrey-golubev merged commit 4cfaaa6 into llvm:main Jun 3, 2026
10 checks passed
@andrey-golubev
andrey-golubev deleted the simpler_get_buffer_type branch June 3, 2026 10:13
andrey-golubev added a commit to intel-staging/npu-compiler-llvm that referenced this pull request Jun 3, 2026
Replace getMemRefType() helper with a direct usage of
options.unknownTypeConverterFn() hook. This does not change any
behaviour since all the existing call-sites would already implicitly
call the hook. The major difference could have been in the handling of
the memref layout but this does not seem to be properly handled anyhow.

As the `getMemRefType()` helper is removed, there are two cases to keep
in mind for downstream users that need to adjust the code accordingly:
1. For creating memrefs without layouts, call
`options.unknownTypeConverterFn` hook directly (the same way this patch
is doing for upstream)
2. For creating memrefs with layouts (assuming, custom ones), please
(re)implement the same helper. As only ranked memrefs can have a layout,
a call to `mlir::MemRefType::get(shape, elementType, /*your custom
layout=*/myLayout, memorySpace)` should be sufficient.
Devjiu pushed a commit to intel-staging/npu-compiler-llvm that referenced this pull request Jun 23, 2026
Replace getMemRefType() helper with a direct usage of
options.unknownTypeConverterFn() hook. This does not change any
behaviour since all the existing call-sites would already implicitly
call the hook. The major difference could have been in the handling of
the memref layout but this does not seem to be properly handled anyhow.

As the `getMemRefType()` helper is removed, there are two cases to keep
in mind for downstream users that need to adjust the code accordingly:
1. For creating memrefs without layouts, call
`options.unknownTypeConverterFn` hook directly (the same way this patch
is doing for upstream)
2. For creating memrefs with layouts (assuming, custom ones), please
(re)implement the same helper. As only ranked memrefs can have a layout,
a call to `mlir::MemRefType::get(shape, elementType, /*your custom
layout=*/myLayout, memorySpace)` should be sufficient.
Devjiu pushed a commit to intel-staging/npu-compiler-llvm that referenced this pull request Jun 23, 2026
Replace getMemRefType() helper with a direct usage of
options.unknownTypeConverterFn() hook. This does not change any
behaviour since all the existing call-sites would already implicitly
call the hook. The major difference could have been in the handling of
the memref layout but this does not seem to be properly handled anyhow.

As the `getMemRefType()` helper is removed, there are two cases to keep
in mind for downstream users that need to adjust the code accordingly:
1. For creating memrefs without layouts, call
`options.unknownTypeConverterFn` hook directly (the same way this patch
is doing for upstream)
2. For creating memrefs with layouts (assuming, custom ones), please
(re)implement the same helper. As only ranked memrefs can have a layout,
a call to `mlir::MemRefType::get(shape, elementType, /*your custom
layout=*/myLayout, memorySpace)` should be sufficient.
andrey-golubev added a commit to intel-staging/npu-compiler-llvm that referenced this pull request Jun 25, 2026
Replace getMemRefType() helper with a direct usage of
options.unknownTypeConverterFn() hook. This does not change any
behaviour since all the existing call-sites would already implicitly
call the hook. The major difference could have been in the handling of
the memref layout but this does not seem to be properly handled anyhow.

As the `getMemRefType()` helper is removed, there are two cases to keep
in mind for downstream users that need to adjust the code accordingly:
1. For creating memrefs without layouts, call
`options.unknownTypeConverterFn` hook directly (the same way this patch
is doing for upstream)
2. For creating memrefs with layouts (assuming, custom ones), please
(re)implement the same helper. As only ranked memrefs can have a layout,
a call to `mlir::MemRefType::get(shape, elementType, /*your custom
layout=*/myLayout, memorySpace)` should be sufficient.
ggladilo pushed a commit to ggladilo/npu-compiler-llvm that referenced this pull request Jun 25, 2026
Replace getMemRefType() helper with a direct usage of
options.unknownTypeConverterFn() hook. This does not change any
behaviour since all the existing call-sites would already implicitly
call the hook. The major difference could have been in the handling of
the memref layout but this does not seem to be properly handled anyhow.

As the `getMemRefType()` helper is removed, there are two cases to keep
in mind for downstream users that need to adjust the code accordingly:
1. For creating memrefs without layouts, call
`options.unknownTypeConverterFn` hook directly (the same way this patch
is doing for upstream)
2. For creating memrefs with layouts (assuming, custom ones), please
(re)implement the same helper. As only ranked memrefs can have a layout,
a call to `mlir::MemRefType::get(shape, elementType, /*your custom
layout=*/myLayout, memorySpace)` should be sufficient.
ggladilo added a commit to intel-staging/npu-compiler-llvm that referenced this pull request Jul 1, 2026
* [mlir][RFC] Allow to skip operands type specification in ASM form
* Add FlatSymbolRefAttr and ArrayAttr for memory space representation (llvm#44/llvm#45)
* [mlir] Relax ASM parser requirements about operands Type presence
* [mlir] Remove LIT tests affected by ASM simplification
* Add method getInlineBlockAndPoint for DialectInlinerInterface
* Initialize pass options using pipeline options
* Fix compilation issue with MSVC
* Port Ubunu-24 warning fixes to npu/release/18.x (llvm#45)
* Extend Quant dialect with Quantile Quantization type (llvm#53)
* Extending QuantileQuantizedType with quantileType mlir::Type member (llvm#60)
* Relax negative scales conditions in Quant Dialect (llvm#61)
* Adding missing check in QuantileQuantizedPerAxisType::verify (llvm#66)
* Adding new quantileType types to mlir test (llvm#85)
* Add Value back to SideEffectInterfaces
* EISW-130780: remove all wd flag to enable warnings when LLVM_ENABLE_WARNINGS is ON (llvm#99)
* EISW-176770 Fix argument parsing issue in mlir-src-sharder after command-line parser reset
* Enable quantization for FP4 type
* [MLIR] Make printing Value to a stream thread-safe (llvm#185762)
* [MLIR] Fix mlir-doc build failures by adding -dialect to add_mlir_doc calls
* [MLIR] Add getter for the action handler of MLIR context (llvm#197230)
* Silence deprecation warning for OpBuilder::create
* [MLIR] make One-Shot and SCF bufferization TensorLikeType-aware (llvm#189073)
* [NFC][mlir][bufferization] Remove getMemRefType() helper (llvm#199034)
* [mlir][bufferization] Drop TensorLikeType::getBufferType() (llvm#201350)

---------

Signed-off-by: Gladilov, Gleb <[email protected]>
Signed-off-by: Zhu, Shaojie <[email protected]>
Signed-off-by: Dmitrii Makarenko <[email protected]>
Co-authored-by: Vladislav Vinogradov <[email protected]>
Co-authored-by: Nikita Kudriavtsev <[email protected]>
Co-authored-by: Schondube, Jorn <[email protected]>
Co-authored-by: Daria Mityagina <[email protected]>
Co-authored-by: Luca Sarti <[email protected]>
Co-authored-by: Zoran Zomborat <[email protected]>
Co-authored-by: Ngun, Raymond <[email protected]>
Co-authored-by: Shaojie Zhu <[email protected]>
Co-authored-by: Surendar Rama Sitaraman <[email protected]>
Co-authored-by: Andruszkiewicz, Jacenty <[email protected]>
Co-authored-by: Mehdi Amini <[email protected]>
Co-authored-by: Kigyosi Alexandru <[email protected]>
Co-authored-by: Dmitrii Makarenko <[email protected]>
Co-authored-by: Andrei Golubev <[email protected]>
andrey-golubev added a commit to intel-staging/npu-compiler-llvm that referenced this pull request Jul 29, 2026
Replace getMemRefType() helper with a direct usage of
options.unknownTypeConverterFn() hook. This does not change any
behaviour since all the existing call-sites would already implicitly
call the hook. The major difference could have been in the handling of
the memref layout but this does not seem to be properly handled anyhow.

As the `getMemRefType()` helper is removed, there are two cases to keep
in mind for downstream users that need to adjust the code accordingly:
1. For creating memrefs without layouts, call
`options.unknownTypeConverterFn` hook directly (the same way this patch
is doing for upstream)
2. For creating memrefs with layouts (assuming, custom ones), please
(re)implement the same helper. As only ranked memrefs can have a layout,
a call to `mlir::MemRefType::get(shape, elementType, /*your custom
layout=*/myLayout, memorySpace)` should be sufficient.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:bufferization Bufferization infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants