[MLIR][LLVM] Don't use void return type in `getCallableResults`.
authorJohannes de Fine Licht <johannes.definelicht@nextsilicon.com>
Thu, 19 Jan 2023 08:52:08 +0000 (09:52 +0100)
committerTobias Gysi <tobias.gysi@nextsilicon.com>
Thu, 19 Jan 2023 09:01:22 +0000 (10:01 +0100)
In the LLVM IR dialect, `LLVMVoidType` is used to model the return type
of LLVM IR functions with no return value. This is inconsistent with
MLIR APIs, which expect a function with no return value to have an
empty return type. Handle this special case in `LLVMFuncOp` to avoid
mismatches between the number of return values and return types between
caller and callee.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D141676

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

index a97073e..88eacda 100644 (file)
@@ -1520,8 +1520,14 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
     /// is external, returns null.
     Region *getCallableRegion();
 
-    /// Returns the callable result type, which is the function return type.
-    ArrayRef<Type> getCallableResults() { return getFunctionType().getReturnTypes(); }
+    /// Returns the callable result type, which is the single function return
+    /// type if it is not void, or an empty array if the function's return type
+    /// is void, as void is not assignable to a value.
+    ArrayRef<Type> getCallableResults() {
+      if (getFunctionType().getReturnType().isa<LLVM::LLVMVoidType>())
+        return {};
+      return getFunctionType().getReturnTypes();
+    }
 
   }];