Skip to content

Commit 5ceaeed

Browse files
committed
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
1 parent 6272f87 commit 5ceaeed

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp gpuFuncOp, OpAdaptor adaptor,
4343
}
4444

4545
// Rewrite the original GPU function to an LLVM function.
46-
auto funcType = typeConverter->convertType(gpuFuncOp.getFunctionType())
47-
.template cast<LLVM::LLVMPointerType>()
48-
.getElementType();
46+
auto convertedType = typeConverter->convertType(gpuFuncOp.getFunctionType());
47+
if (!convertedType)
48+
return failure();
49+
auto funcType =
50+
convertedType.template cast<LLVM::LLVMPointerType>().getElementType();
4951

5052
// Remap proper input types.
5153
TypeConverter::SignatureConversion signatureConversion(

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ Type LLVMTypeConverter::convertFunctionType(FunctionType type) {
199199
SignatureConversion conversion(type.getNumInputs());
200200
Type converted =
201201
convertFunctionSignature(type, /*isVariadic=*/false, conversion);
202+
if (!converted)
203+
return {};
202204
return LLVM::LLVMPointerType::get(converted);
203205
}
204206

@@ -298,8 +300,13 @@ LLVMTypeConverter::convertFunctionTypeCWrapper(FunctionType type) {
298300
SmallVector<Type, 5>
299301
LLVMTypeConverter::getMemRefDescriptorFields(MemRefType type,
300302
bool unpackAggregates) {
301-
assert(isStrided(type) &&
302-
"Non-strided layout maps must have been normalized away");
303+
if (!isStrided(type)) {
304+
emitError(
305+
UnknownLoc::get(type.getContext()),
306+
"conversion to strided form failed either due to non-strided layout "
307+
"maps (which should have been normalized away) or other reasons");
308+
return {};
309+
}
303310

304311
Type elementType = convertType(type.getElementType());
305312
if (!elementType)

0 commit comments

Comments
 (0)