[Mlir-commits] [mlir] [mlir-runner] Check entry function does not expect arguments (PR #136825)
Longsheng Mou
llvmlistbot at llvm.org
Tue May 13 04:27:06 PDT 2025
https://github.com/CoTinker updated https://github.com/llvm/llvm-project/pull/136825
>From 41d961310d23f43bd9cc70ff89488670a8001535 Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Wed, 23 Apr 2025 16:04:22 +0800
Subject: [PATCH 1/4] [mlir-runner] Check entry function not has inputs
This PR fixes a crash if entry function has inputs.
---
mlir/lib/ExecutionEngine/JitRunner.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/ExecutionEngine/JitRunner.cpp b/mlir/lib/ExecutionEngine/JitRunner.cpp
index cf462ddf6f17c..dc8af4e514dcd 100644
--- a/mlir/lib/ExecutionEngine/JitRunner.cpp
+++ b/mlir/lib/ExecutionEngine/JitRunner.cpp
@@ -222,9 +222,13 @@ static Error compileAndExecuteVoidFunction(
CompileAndExecuteConfig config, std::unique_ptr<llvm::TargetMachine> tm) {
auto mainFunction = dyn_cast_or_null<LLVM::LLVMFuncOp>(
SymbolTable::lookupSymbolIn(module, entryPoint));
- if (!mainFunction || mainFunction.empty())
+ if (!mainFunction || mainFunction.isExternal())
return makeStringError("entry point not found");
+ if (cast<LLVM::LLVMFunctionType>(mainFunction.getFunctionType())
+ .getNumParams() != 0)
+ return makeStringError("function inputs not supported");
+
auto resultType = dyn_cast<LLVM::LLVMVoidType>(
mainFunction.getFunctionType().getReturnType());
if (!resultType)
>From ccc09edeb7e71b246849a89e8632b8cbd42c006d Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Wed, 23 Apr 2025 16:05:59 +0800
Subject: [PATCH 2/4] add test
---
.../mlir-runner/verify-entry-point-result.mlir | 7 -------
mlir/test/mlir-runner/verify-entry-point.mlir | 17 +++++++++++++++++
2 files changed, 17 insertions(+), 7 deletions(-)
delete mode 100644 mlir/test/mlir-runner/verify-entry-point-result.mlir
create mode 100644 mlir/test/mlir-runner/verify-entry-point.mlir
diff --git a/mlir/test/mlir-runner/verify-entry-point-result.mlir b/mlir/test/mlir-runner/verify-entry-point-result.mlir
deleted file mode 100644
index ad46e0b5fe1bf..0000000000000
--- a/mlir/test/mlir-runner/verify-entry-point-result.mlir
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: not mlir-runner %s -e entry -entry-point-result=void 2>&1 | FileCheck %s
-
-// CHECK: Error: expected void function
-llvm.func @entry() -> (i32) {
- %0 = llvm.mlir.constant(0 : index) : i32
- llvm.return %0 : i32
-}
diff --git a/mlir/test/mlir-runner/verify-entry-point.mlir b/mlir/test/mlir-runner/verify-entry-point.mlir
new file mode 100644
index 0000000000000..9d166d1be7494
--- /dev/null
+++ b/mlir/test/mlir-runner/verify-entry-point.mlir
@@ -0,0 +1,17 @@
+// RUN: not mlir-runner %s -e entry_point -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-POINT
+// RUN: not mlir-runner %s -e entry_inputs -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-INPUTS
+// RUN: not mlir-runner %s -e entry_result -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT
+
+// CHECK-ENTRY-POINT: Error: entry point not found
+llvm.func @entry_point() -> ()
+
+// CHECK-ENTRY-INPUTS: Error: function inputs not supported
+llvm.func @entry_inputs(%arg0: i32) {
+ llvm.return
+}
+
+// CHECK-ENTRY-RESULT: Error: expected void function
+llvm.func @entry_result() -> (i32) {
+ %0 = llvm.mlir.constant(0 : index) : i32
+ llvm.return %0 : i32
+}
>From bf4b0d5e5ee98807c7f218bc20430db744f5e1ea Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Tue, 13 May 2025 19:25:17 +0800
Subject: [PATCH 3/4] change error message
---
mlir/lib/ExecutionEngine/JitRunner.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/ExecutionEngine/JitRunner.cpp b/mlir/lib/ExecutionEngine/JitRunner.cpp
index dc8af4e514dcd..2107df37d1997 100644
--- a/mlir/lib/ExecutionEngine/JitRunner.cpp
+++ b/mlir/lib/ExecutionEngine/JitRunner.cpp
@@ -227,7 +227,8 @@ static Error compileAndExecuteVoidFunction(
if (cast<LLVM::LLVMFunctionType>(mainFunction.getFunctionType())
.getNumParams() != 0)
- return makeStringError("function inputs not supported");
+ return makeStringError(
+ "JIT can't invoke a main function expecting arguments");
auto resultType = dyn_cast<LLVM::LLVMVoidType>(
mainFunction.getFunctionType().getReturnType());
@@ -278,7 +279,8 @@ Error compileAndExecuteSingleReturnFunction(
if (cast<LLVM::LLVMFunctionType>(mainFunction.getFunctionType())
.getNumParams() != 0)
- return makeStringError("function inputs not supported");
+ return makeStringError(
+ "JIT can't invoke a main function expecting arguments");
if (Error error = checkCompatibleReturnType<Type>(mainFunction))
return error;
>From 4f671de078855389fd7213daf0c5d499ff44532f Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Tue, 13 May 2025 19:26:56 +0800
Subject: [PATCH 4/4] update test
---
mlir/test/mlir-runner/verify-entry-point.mlir | 49 +++++++++++++++----
1 file changed, 40 insertions(+), 9 deletions(-)
diff --git a/mlir/test/mlir-runner/verify-entry-point.mlir b/mlir/test/mlir-runner/verify-entry-point.mlir
index 9d166d1be7494..c7165bd46302f 100644
--- a/mlir/test/mlir-runner/verify-entry-point.mlir
+++ b/mlir/test/mlir-runner/verify-entry-point.mlir
@@ -1,17 +1,48 @@
-// RUN: not mlir-runner %s -e entry_point -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-POINT
-// RUN: not mlir-runner %s -e entry_inputs -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-INPUTS
-// RUN: not mlir-runner %s -e entry_result -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT
+// RUN: not mlir-runner %s -e entry_point_void -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-POINT-VOID
+// RUN: not mlir-runner %s -e entry_inputs_void -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-INPUTS-VOID
+// RUN: not mlir-runner %s -e entry_result_void -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-VOID
+// RUN: not mlir-runner %s -e entry_point_i32 -entry-point-result=i32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-POINT-I32
+// RUN: not mlir-runner %s -e entry_inputs_i32 -entry-point-result=i32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-INPUTS-I32
+// RUN: not mlir-runner %s -e entry_result_i32 -entry-point-result=i32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-I32
+// RUN: not mlir-runner %s -e entry_result_i64 -entry-point-result=i64 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-I64
+// RUN: not mlir-runner %s -e entry_result_f32 -entry-point-result=f32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-F32
-// CHECK-ENTRY-POINT: Error: entry point not found
-llvm.func @entry_point() -> ()
+// CHECK-ENTRY-POINT-VOID: Error: entry point not found
+llvm.func @entry_point_void() -> ()
-// CHECK-ENTRY-INPUTS: Error: function inputs not supported
-llvm.func @entry_inputs(%arg0: i32) {
+// CHECK-ENTRY-INPUTS-VOID: Error: JIT can't invoke a main function expecting arguments
+llvm.func @entry_inputs_void(%arg0: i32) {
llvm.return
}
-// CHECK-ENTRY-RESULT: Error: expected void function
-llvm.func @entry_result() -> (i32) {
+// CHECK-ENTRY-RESULT-VOID: Error: expected void function
+llvm.func @entry_result_void() -> (i32) {
+ %0 = llvm.mlir.constant(0 : index) : i32
+ llvm.return %0 : i32
+}
+
+// CHECK-ENTRY-POINT-I32: Error: entry point not found
+llvm.func @entry_point_i32() -> (i32)
+
+// CHECK-ENTRY-INPUTS-I32: Error: JIT can't invoke a main function expecting arguments
+llvm.func @entry_inputs_i32(%arg0: i32) {
+ llvm.return
+}
+
+// CHECK-ENTRY-RESULT-I32: Error: only single i32 function result supported
+llvm.func @entry_result_i32() -> (i64) {
+ %0 = llvm.mlir.constant(0 : index) : i64
+ llvm.return %0 : i64
+}
+
+// CHECK-ENTRY-RESULT-I64: Error: only single i64 function result supported
+llvm.func @entry_result_i64() -> (i32) {
+ %0 = llvm.mlir.constant(0 : index) : i32
+ llvm.return %0 : i32
+}
+
+// CHECK-ENTRY-RESULT-F32: Error: only single f32 function result supported
+llvm.func @entry_result_f32() -> (i32) {
%0 = llvm.mlir.constant(0 : index) : i32
llvm.return %0 : i32
}
More information about the Mlir-commits
mailing list