Renato Golin 1b99e8ba48 [MLIR] Move JitRunner Options to header, pass to mlirTransformer
This allows the MLIR transformer to see the command line options and
make desicions based on them. No change upstream, but my use-case is to
look at the entry point name and type to make sure I can use them.

Differential Revision: https://reviews.llvm.org/D137861
2022-11-13 18:55:48 +00:00

76 lines
2.6 KiB
C++

//===- JitRunner.h - MLIR CPU Execution Driver Library ----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This is a library that provides a shared implementation for command line
// utilities that execute an MLIR file on the CPU by translating MLIR to LLVM
// IR before JIT-compiling and executing the latter.
//
// The translation can be customized by providing an MLIR to MLIR
// transformation.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_EXECUTIONENGINE_JITRUNNER_H
#define MLIR_EXECUTIONENGINE_JITRUNNER_H
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/Orc/Core.h"
namespace llvm {
class Module;
class LLVMContext;
namespace orc {
class MangleAndInterner;
} // namespace orc
} // namespace llvm
namespace mlir {
class DialectRegistry;
class Operation;
struct LogicalResult;
/// JitRunner command line options used by JitRunnerConfig methods
struct JitRunnerOptions {
/// The name of the main function
llvm::StringRef mainFuncName;
/// The type of the main function (as string, from cmd-line)
llvm::StringRef mainFuncType;
};
/// Configuration to override functionality of the JitRunner
struct JitRunnerConfig {
/// MLIR transformer applied after parsing the input into MLIR IR and before
/// passing the MLIR IR to the ExecutionEngine.
llvm::function_ref<LogicalResult(mlir::Operation *,
JitRunnerOptions &options)>
mlirTransformer = nullptr;
/// A custom function that is passed to ExecutionEngine. It processes MLIR and
/// creates an LLVM IR module.
llvm::function_ref<std::unique_ptr<llvm::Module>(Operation *,
llvm::LLVMContext &)>
llvmModuleBuilder = nullptr;
/// A callback to register symbols with ExecutionEngine at runtime.
llvm::function_ref<llvm::orc::SymbolMap(llvm::orc::MangleAndInterner)>
runtimesymbolMap = nullptr;
};
/// Entry point for all CPU runners. Expects the common argc/argv arguments for
/// standard C++ main functions. The supplied dialect registry is expected to
/// contain any registers that appear in the input IR, they will be loaded
/// on-demand by the parser.
int JitRunnerMain(int argc, char **argv, const DialectRegistry &registry,
JitRunnerConfig config = {});
} // namespace mlir
#endif // MLIR_EXECUTIONENGINE_JITRUNNER_H