Skip to content

Commit 38e87e8

Browse files
committed
[mlir][llvm] Improve LLVM IR import error handling.
Instead of exiting in the middle of the import handle errors more gracefully by printing an error message and returning failure. The revision handles and tests the import of unsupported instructions, values, constants, and intrinsics. Depends on D139404 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D139405
1 parent 77ab728 commit 38e87e8

File tree

5 files changed

+223
-135
lines changed

5 files changed

+223
-135
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,13 @@ class LLVM_IntrOpBase<Dialect dialect, string opName, string enumName,
373373
# !if(!gt(numResults, 0), "$res = inst;", "");
374374

375375
string mlirBuilder = [{
376+
FailureOr<SmallVector<Value>> mlirOperands = convertValues(llvmOperands);
377+
if (failed(mlirOperands))
378+
return failure();
376379
SmallVector<Type> resultTypes =
377380
}] # !if(!gt(numResults, 0), "{$_resultType};", "{};") # [{
378381
Operation *op = $_builder.create<$_qualCppClassName>(
379-
$_location,
380-
resultTypes,
381-
convertValues(llvmOperands));
382+
$_location, resultTypes, *mlirOperands);
382383
}] # !if(!gt(numResults, 0), "$res = op->getResult(0);", "(void)op;");
383384
}
384385

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,10 @@ def LLVM_ReturnOp : LLVM_TerminatorOp<"return", [Pure, ReturnLike]> {
810810
builder.CreateRetVoid();
811811
}];
812812
string mlirBuilder = [{
813-
$_builder.create<LLVM::ReturnOp>($_location, convertValues(llvmOperands));
813+
FailureOr<SmallVector<Value>> mlirOperands = convertValues(llvmOperands);
814+
if (failed(mlirOperands))
815+
return failure();
816+
$_builder.create<LLVM::ReturnOp>($_location, *mlirOperands);
814817
}];
815818
}
816819

0 commit comments

Comments
 (0)