diff options
author | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2022-04-07 09:47:23 +0000 |
---|---|---|
committer | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2022-04-14 09:40:31 +0000 |
commit | 6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce (patch) | |
tree | 9d696f12500ac390d43e7c2628ae1f2833a9e7d8 /flang/lib/FrontendTool | |
parent | 04a3f3f167dbf90fb11524c00af5313c2b135ad3 (diff) | |
download | llvm-6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce.zip llvm-6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce.tar.gz llvm-6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce.tar.bz2 |
[flang][driver] Add support for `-mmlir`
The semantics of `-mmlir` are identical to `-mllvm`. The only notable
difference is that `-mmlir` options should be forwarded to MLIR rather
than LLVM.
Note that MLIR llvm::cl options are lazily constructed on demand (see
the definition of options in PassManagerOptions.cpp). This means that:
* MLIR global options are only visible when explicitly initialised and
displayed only when using `-mmlir --help`,
* Flang and LLVM global options are always visible and displayed when
using either `-mllvm -help` or `-mmlir --help`.
In other words, `-mmlir --help` is a superset of `-mllvm --help`. This is not
ideal, but we'd need to refactor all option definitions in Flang and
LLVM to improve this. I suggesting leaving this for later.
Differential Revision: https://reviews.llvm.org/D123297
Diffstat (limited to 'flang/lib/FrontendTool')
-rw-r--r-- | flang/lib/FrontendTool/CMakeLists.txt | 1 | ||||
-rw-r--r-- | flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/flang/lib/FrontendTool/CMakeLists.txt b/flang/lib/FrontendTool/CMakeLists.txt index 1a29f4a..0753313 100644 --- a/flang/lib/FrontendTool/CMakeLists.txt +++ b/flang/lib/FrontendTool/CMakeLists.txt @@ -11,6 +11,7 @@ add_flang_library(flangFrontendTool flangFrontend clangBasic clangDriver + MLIRPass LINK_COMPONENTS Option diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 04e00e5..bc2bf1d 100644 --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -19,6 +19,8 @@ #include "llvm/Option/Option.h" #include "llvm/Support/BuryPointer.h" #include "llvm/Support/CommandLine.h" +#include "mlir/IR/MLIRContext.h" +#include "mlir/Pass/PassManager.h" namespace Fortran::frontend { @@ -150,6 +152,21 @@ bool ExecuteCompilerInvocation(CompilerInstance *flang) { llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get()); } + // Honor -mmlir. This should happen AFTER plugins have been loaded! + if (!flang->frontendOpts().mlirArgs.empty()) { + mlir::registerMLIRContextCLOptions(); + mlir::registerPassManagerCLOptions(); + unsigned numArgs = flang->frontendOpts().mlirArgs.size(); + auto args = std::make_unique<const char *[]>(numArgs + 2); + args[0] = "flang (MLIR option parsing)"; + + for (unsigned i = 0; i != numArgs; ++i) + args[i + 1] = flang->frontendOpts().mlirArgs[i].c_str(); + + args[numArgs + 1] = nullptr; + llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get()); + } + // If there were errors in processing arguments, don't do anything else. if (flang->diagnostics().hasErrorOccurred()) { return false; |