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).
Will enabling Ofast require more changes in the flang frontend? If yes, it is OK to support it in another patch later.