[Mlir-commits] [mlir] 5ceaeed - Improve type conversion error propagation/failure during LLVM lowering
Uday Bondhugula
llvmlistbot at llvm.org
Sat Dec 3 03:06:06 PST 2022
Author: Uday Bondhugula
Date: 2022-12-03T16:30:44+05:30
New Revision: 5ceaeed65962a1d93442718cf72fa055c6b94d83
URL: https://github.com/llvm/llvm-project/commit/5ceaeed65962a1d93442718cf72fa055c6b94d83
DIFF: https://github.com/llvm/llvm-project/commit/5ceaeed65962a1d93442718cf72fa055c6b94d83.diff
LOG: Improve type conversion error propagation/failure during LLVM lowering
Improve type conversion error propagation/failure during LLVM lowering.
BEFORE
```
llvm-mlir/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp:304: SmallVector<mlir::Type, 5> mlir::LLVMTypeConverter::getMemRefDescriptorFields(mlir::MemRefType, bool): Assertion `isStrided(type) && "Non-strided layout maps must have been normalized away"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
...
```
AFTER
```
<unknown>:0: error: integer overflow during size computation
<unknown>:0: error: Conversion to strided form failed either due to non-strided layout maps (which should have been normalized away) or other reasons
<unknown>:0: error: failed to legalize operation 'gpu.func' that was explicitly marked illegal
<unknown>:0: note: see current operation:
"gpu.func"() ( {
...
```
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D139072
Added:
Modified:
mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
index 40fb8e25d312c..85001d54d093d 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
@@ -43,9 +43,11 @@ GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp gpuFuncOp, OpAdaptor adaptor,
}
// Rewrite the original GPU function to an LLVM function.
- auto funcType = typeConverter->convertType(gpuFuncOp.getFunctionType())
- .template cast<LLVM::LLVMPointerType>()
- .getElementType();
+ auto convertedType = typeConverter->convertType(gpuFuncOp.getFunctionType());
+ if (!convertedType)
+ return failure();
+ auto funcType =
+ convertedType.template cast<LLVM::LLVMPointerType>().getElementType();
// Remap proper input types.
TypeConverter::SignatureConversion signatureConversion(
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index ee939fa4ce36e..9842947948d7e 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -199,6 +199,8 @@ Type LLVMTypeConverter::convertFunctionType(FunctionType type) {
SignatureConversion conversion(type.getNumInputs());
Type converted =
convertFunctionSignature(type, /*isVariadic=*/false, conversion);
+ if (!converted)
+ return {};
return LLVM::LLVMPointerType::get(converted);
}
@@ -298,8 +300,13 @@ LLVMTypeConverter::convertFunctionTypeCWrapper(FunctionType type) {
SmallVector<Type, 5>
LLVMTypeConverter::getMemRefDescriptorFields(MemRefType type,
bool unpackAggregates) {
- assert(isStrided(type) &&
- "Non-strided layout maps must have been normalized away");
+ if (!isStrided(type)) {
+ emitError(
+ UnknownLoc::get(type.getContext()),
+ "conversion to strided form failed either due to non-strided layout "
+ "maps (which should have been normalized away) or other reasons");
+ return {};
+ }
Type elementType = convertType(type.getElementType());
if (!elementType)
More information about the Mlir-commits
mailing list