diff options
author | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2022-02-21 11:51:32 +0000 |
---|---|---|
committer | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2022-02-25 09:38:10 +0000 |
commit | 2e9439e4891c3d427c0fed477b54f3da2ff8ec28 (patch) | |
tree | 476f53b367f6c8eb24a5468b06de191657203c71 /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | 6114491441700cc8a614d284407e9a6e9bf74751 (diff) | |
download | llvm-2e9439e4891c3d427c0fed477b54f3da2ff8ec28.zip llvm-2e9439e4891c3d427c0fed477b54f3da2ff8ec28.tar.gz llvm-2e9439e4891c3d427c0fed477b54f3da2ff8ec28.tar.bz2 |
[flang][driver] Add support for `--target`/`--triple`
This patch adds support for:
* `--target` in the compiler driver (`flang-new`)
* `--triple` in the frontend driver (`flang-new -fc1`)
The semantics of these flags are inherited from `clangDriver`, i.e.
consistent with `clang --target` and `clang -cc1 --triple`,
respectively.
A new structure is defined, `TargetOptions`, that will hold various
Frontend options related to the target. Currently, this is mostly a
placeholder that contains the target triple. In the future, it will be
used for storing e.g. the CPU to tune for or the target features to
enable.
Additionally, the following target/triple related options are enabled
[*]: `-print-effective-triple`, `-print-target-triple`. Definitions in
Options.td are updated accordingly and, to facilated testing,
`-emit-llvm` is added to the list of options available in `flang-new`
(previously it was only enabled in `flang-new -fc1`).
[*] These options were actually available before (like all other options
defined in `clangDriver`), but not included in `flang-new --help`.
Before this change, `flang-new` would just use `native` for defining the
target, so these options were of little value.
Differential Revision: https://reviews.llvm.org/D120246
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 7507b00..32888bd 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -9,6 +9,7 @@ #include "flang/Frontend/CompilerInvocation.h" #include "flang/Common/Fortran-features.h" #include "flang/Frontend/PreprocessorOptions.h" +#include "flang/Frontend/TargetOptions.h" #include "flang/Semantics/semantics.h" #include "flang/Version.inc" #include "clang/Basic/AllDiagnostics.h" @@ -88,6 +89,15 @@ bool Fortran::frontend::ParseDiagnosticArgs(clang::DiagnosticOptions &opts, return true; } +/// Parses all target input arguments and populates the target +/// options accordingly. +/// +/// \param [in] opts The target options instance to update +/// \param [in] args The list of input arguments (from the compiler invocation) +static void ParseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) { + opts.triple = args.getLastArgValue(clang::driver::options::OPT_triple); +} + // Tweak the frontend configuration based on the frontend action static void setUpFrontendBasedOnAction(FrontendOptions &opts) { assert(opts.programAction != Fortran::frontend::InvalidAction && @@ -563,6 +573,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res, } success &= ParseFrontendArgs(res.frontendOpts(), args, diags); + ParseTargetArgs(res.targetOpts(), args); parsePreprocessorArgs(res.preprocessorOpts(), args); success &= parseSemaArgs(res, args, diags); success &= parseDialectArgs(res, args, diags); |