[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
This commit is contained in:
Renato Golin 2022-11-12 21:48:54 +00:00
parent 6b9a79f9a2
commit 1b99e8ba48
4 changed files with 17 additions and 5 deletions

View File

@ -36,11 +36,21 @@ 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 *)> mlirTransformer =
nullptr;
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.

View File

@ -364,8 +364,9 @@ int mlir::JitRunnerMain(int argc, char **argv, const DialectRegistry &registry,
return 1;
}
JitRunnerOptions runnerOptions{options.mainFuncName, options.mainFuncType};
if (config.mlirTransformer)
if (failed(config.mlirTransformer(m.get())))
if (failed(config.mlirTransformer(m.get(), runnerOptions)))
return EXIT_FAILURE;
auto tmBuilderOrError = llvm::orc::JITTargetMachineBuilder::detectHost();

View File

@ -74,7 +74,8 @@ convertMLIRModule(Operation *op, llvm::LLVMContext &context) {
return mainModule;
}
static LogicalResult runMLIRPasses(Operation *module) {
static LogicalResult runMLIRPasses(Operation *module,
JitRunnerOptions &options) {
PassManager passManager(module->getContext(),
module->getName().getStringRef());
applyPassManagerCLOptions(passManager);

View File

@ -41,7 +41,7 @@
using namespace mlir;
static LogicalResult runMLIRPasses(Operation *op) {
static LogicalResult runMLIRPasses(Operation *op, JitRunnerOptions &options) {
auto module = dyn_cast<ModuleOp>(op);
if (!module)
return op->emitOpError("expected a 'builtin.module' op");