aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorAndrzej Warzynski <andrzej.warzynski@arm.com>2022-06-06 09:44:21 +0000
committerAndrzej Warzynski <andrzej.warzynski@arm.com>2022-06-27 10:06:14 +0000
commit869385b11c32032d02f5f24fcd21c694fb073850 (patch)
tree3c53524bb7124932109ccda3aa7ff5833028afe7 /flang/lib/Frontend/CompilerInvocation.cpp
parentbdfe556dd837007c5671f33384d26e9ea315db53 (diff)
downloadllvm-869385b11c32032d02f5f24fcd21c694fb073850.zip
llvm-869385b11c32032d02f5f24fcd21c694fb073850.tar.gz
llvm-869385b11c32032d02f5f24fcd21c694fb073850.tar.bz2
[flang][driver] Add support for `-O{0|1|2|3}`
This patch adds support for most common optimisation compiler flags: `-O{0|1|2|3}`. This is implemented in both the compiler and frontend drivers. At this point, these options are only used to configure the LLVM optimisation pipelines (aka middle-end). LLVM backend or MLIR/FIR optimisations are not supported yet. Previously, the middle-end pass manager was only required when generating LLVM bitcode (i.e. for `flang-new -c -emit-llvm <file>` or `flang-new -fc1 -emit-llvm-bc <file>`). With this change, it becomes required for all frontend actions that are represented as `CodeGenAction` and `CodeGenAction::executeAction` is refactored accordingly (in the spirit of better code re-use). Additionally, the `-fdebug-pass-manager` option is enabled to facilitate testing. This flag can be used to configure the pass manager to print the middle-end passes that are being run. Similar option exists in Clang and the semantics in Flang are identical. This option translates to extra configuration when setting up the pass manager. This is implemented in `CodeGenAction::runOptimizationPipeline`. This patch also adds some bolier plate code to manage code-gen options ("code-gen" refers to generating machine code in LLVM in this context). This was extracted from Clang. In Clang, it simplifies defining code-gen options and enables option marshalling. In Flang, option marshalling is not yet supported (we might do at some point), but being able to auto-generate some code with macros is beneficial. This will become particularly apparent when we start adding more options (at least in Clang, the list of code-gen options is rather long). Differential Revision: https://reviews.llvm.org/D128043
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index f665daf..f6fde9f 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -12,6 +12,7 @@
#include "flang/Frontend/CompilerInvocation.h"
#include "flang/Common/Fortran-features.h"
+#include "flang/Frontend/CodeGenOptions.h"
#include "flang/Frontend/PreprocessorOptions.h"
#include "flang/Frontend/TargetOptions.h"
#include "flang/Semantics/semantics.h"
@@ -20,6 +21,7 @@
#include "clang/Basic/DiagnosticDriver.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/OptionUtils.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
@@ -95,6 +97,18 @@ bool Fortran::frontend::parseDiagnosticArgs(clang::DiagnosticOptions &opts,
return true;
}
+static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
+ llvm::opt::ArgList &args,
+ clang::DiagnosticsEngine &diags) {
+ unsigned defaultOpt = llvm::CodeGenOpt::None;
+ opts.OptimizationLevel = clang::getLastArgIntValue(
+ args, clang::driver::options::OPT_O, defaultOpt, diags);
+
+ if (args.hasFlag(clang::driver::options::OPT_fdebug_pass_manager,
+ clang::driver::options::OPT_fno_debug_pass_manager, false))
+ opts.DebugPassManager = 1;
+}
+
/// Parses all target input arguments and populates the target
/// options accordingly.
///
@@ -616,6 +630,7 @@ bool CompilerInvocation::createFromArgs(
success &= parseFrontendArgs(res.getFrontendOpts(), args, diags);
parseTargetArgs(res.getTargetOpts(), args);
parsePreprocessorArgs(res.getPreprocessorOpts(), args);
+ parseCodeGenArgs(res.getCodeGenOpts(), args, diags);
success &= parseSemaArgs(res, args, diags);
success &= parseDialectArgs(res, args, diags);
success &= parseDiagArgs(res, args, diags);