[Mlir-commits] [mlir] bafa2f4 - [mlir][memref] Check memory space before lowering alloc ops (#134427)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Apr 7 05:38:22 PDT 2025
Author: Matthias Springer
Date: 2025-04-07T14:38:18+02:00
New Revision: bafa2f4442bcee26f05c22369d41646d5c8befb9
URL: https://github.com/llvm/llvm-project/commit/bafa2f4442bcee26f05c22369d41646d5c8befb9
DIFF: https://github.com/llvm/llvm-project/commit/bafa2f4442bcee26f05c22369d41646d5c8befb9.diff
LOG: [mlir][memref] Check memory space before lowering alloc ops (#134427)
Check the memory space before lowering allocation ops, instead of
starting the lowering and then rolling back the pattern when the memory
space was found to be incompatible with LLVM.
Note: This is in preparation of the One-Shot Dialect Conversion
refactoring.
Note: `isConvertibleAndHasIdentityMaps` now also checks the memory
space.
Added:
Modified:
mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
mlir/lib/Conversion/LLVMCommon/Pattern.cpp
mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
mlir/test/Conversion/MemRefToLLVM/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h b/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
index c65f7d7217be5..66c8731ec2bf4 100644
--- a/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
+++ b/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
@@ -75,8 +75,8 @@ class ConvertToLLVMPattern : public ConversionPattern {
ValueRange indices,
ConversionPatternRewriter &rewriter) const;
- /// Returns if the given memref has identity maps and the element type is
- /// convertible to LLVM.
+ /// Returns if the given memref type is convertible to LLVM and has an
+ /// identity layout map.
bool isConvertibleAndHasIdentityMaps(MemRefType type) const;
/// Returns the type of a pointer to an element of the memref.
diff --git a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
index 71b68619cc793..32bfd72475569 100644
--- a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
@@ -99,9 +99,9 @@ Value ConvertToLLVMPattern::getStridedElementPtr(
// only support memrefs with identity maps.
bool ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(
MemRefType type) const {
- if (!typeConverter->convertType(type.getElementType()))
+ if (!type.getLayout().isIdentity())
return false;
- return type.getLayout().isIdentity();
+ return static_cast<bool>(typeConverter->convertType(type));
}
Type ConvertToLLVMPattern::getElementPtrType(MemRefType type) const {
diff --git a/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp b/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
index c5b2e83df93dc..bad209a4ddecf 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
@@ -73,12 +73,7 @@ std::tuple<Value, Value> AllocationOpLLVMLowering::allocateBufferManuallyAlign(
MemRefType memRefType = getMemRefResultType(op);
// Allocate the underlying buffer.
Type elementPtrType = this->getElementPtrType(memRefType);
- if (!elementPtrType) {
- emitError(loc, "conversion of memref memory space ")
- << memRefType.getMemorySpace()
- << " to integer address space "
- "failed. Consider adding memory space conversions.";
- }
+ assert(elementPtrType && "could not compute element ptr type");
FailureOr<LLVM::LLVMFuncOp> allocFuncOp = getNotalignedAllocFn(
getTypeConverter(), op->getParentWithTrait<OpTrait::SymbolTable>(),
getIndexType());
diff --git a/mlir/test/Conversion/MemRefToLLVM/invalid.mlir b/mlir/test/Conversion/MemRefToLLVM/invalid.mlir
index 61c67005a08fc..0d04bba96bcdb 100644
--- a/mlir/test/Conversion/MemRefToLLVM/invalid.mlir
+++ b/mlir/test/Conversion/MemRefToLLVM/invalid.mlir
@@ -22,7 +22,7 @@ func.func @bad_address_space(%a: memref<2xindex, "foo">) {
// CHECK-LABEL: @invalid_int_conversion
func.func @invalid_int_conversion() {
- // expected-error at +1 {{conversion of memref memory space 1 : ui64 to integer address space failed. Consider adding memory space conversions.}}
+ // expected-error at unknown{{conversion of memref memory space 1 : ui64 to integer address space failed. Consider adding memory space conversions.}}
%alloc = memref.alloc() {alignment = 64 : i64} : memref<10xf32, 1 : ui64>
return
}
@@ -32,7 +32,6 @@ func.func @invalid_int_conversion() {
// expected-error at unknown{{conversion of memref memory space #gpu.address_space<workgroup> to integer address space failed. Consider adding memory space conversions}}
// CHECK-LABEL: @issue_70160
func.func @issue_70160() {
- // expected-error at +1{{conversion of memref memory space #gpu.address_space<workgroup> to integer address space failed. Consider adding memory space conversions}}
%alloc = memref.alloc() : memref<1x32x33xi32, #gpu.address_space<workgroup>>
%alloc1 = memref.alloc() : memref<i32>
%c0 = arith.constant 0 : index
More information about the Mlir-commits
mailing list