[PATCH] D80760: [JitRunner] add support for i32 output

Stephen Neuendorffer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 14:20:02 PDT 2020


stephenneuendorffer created this revision.
Herald added subscribers: llvm-commits, jurahul, Kayjukh, frgossen, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.

Depends on D80609 <https://reviews.llvm.org/D80609>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80760

Files:
  mlir/lib/ExecutionEngine/JitRunner.cpp


Index: mlir/lib/ExecutionEngine/JitRunner.cpp
===================================================================
--- mlir/lib/ExecutionEngine/JitRunner.cpp
+++ mlir/lib/ExecutionEngine/JitRunner.cpp
@@ -54,7 +54,7 @@
   llvm::cl::opt<std::string> mainFuncType{
       "entry-point-result",
       llvm::cl::desc("Textual description of the function type to be called"),
-      llvm::cl::value_desc("f32 | void"), llvm::cl::init("f32")};
+      llvm::cl::value_desc("f32 | i32 | void"), llvm::cl::init("f32")};
 
   llvm::cl::OptionCategory optFlags{"opt-like flags"};
 
@@ -199,10 +199,38 @@
   return Error::success();
 }
 
-/// Entry point for all CPU runners. Expects the common argc/argv arguments for
-/// standard C++ main functions and an mlirTransformer.
-/// The latter is applied after parsing the input into MLIR IR and before
-/// passing the MLIR module to the ExecutionEngine.
+static Error compileAndExecuteSingleIntReturnFunction(
+    ModuleOp module, StringRef entryPoint,
+    std::function<llvm::Error(llvm::Module *)> transformer) {
+  auto mainFunction = module.lookupSymbol<LLVM::LLVMFuncOp>(entryPoint);
+  if (!mainFunction || mainFunction.isExternal())
+    return make_string_error("entry point not found");
+
+  if (mainFunction.getType().getFunctionNumParams() != 0)
+    return make_string_error("function inputs not supported");
+
+  if (!mainFunction.getType().getFunctionResultType().isIntegerTy())
+    return make_string_error("only single llvm.i32 function result supported");
+
+  int res;
+  struct {
+    void *data;
+  } data;
+  data.data = &res;
+  if (auto error =
+          compileAndExecute(module, entryPoint, transformer, (void **)&data))
+    return error;
+
+  // Intentional printing of the output so we can test.
+  llvm::outs() << res << '\n';
+
+  return Error::success();
+}
+
+// Entry point for all CPU runners. Expects the common argc/argv arguments for
+// standard C++ main functions and an mlirTransformer.
+// The latter is applied after parsing the input into MLIR IR and before passing
+// the MLIR module to the ExecutionEngine.
 int mlir::JitRunnerMain(
     int argc, char **argv,
     function_ref<LogicalResult(mlir::ModuleOp)> mlirTransformer) {
@@ -266,7 +294,12 @@
       Error (*)(Options &, ModuleOp, StringRef,
                 std::function<llvm::Error(llvm::Module *)>);
   auto compileAndExecuteFn =
+<<<<<<< HEAD:mlir/lib/ExecutionEngine/JitRunner.cpp
       llvm::StringSwitch<CompileAndExecuteFnT>(options.mainFuncType.getValue())
+=======
+      llvm::StringSwitch<CompileAndExecuteFnT>(mainFuncType.getValue())
+          .Case("i32", compileAndExecuteSingleIntReturnFunction)
+>>>>>>> 124f2402e0d... [JitRunner] add support for i32 output:mlir/lib/Support/JitRunner.cpp
           .Case("f32", compileAndExecuteSingleFloatReturnFunction)
           .Case("void", compileAndExecuteVoidFunction)
           .Default(nullptr);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80760.267040.patch
Type: text/x-patch
Size: 2909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200528/1cceaf11/attachment.bin>


More information about the llvm-commits mailing list