llvm-project/flang/lib
Andrzej Warzynski 02fb5b771d [flang][driver] Define the default frontend driver triple
*SUMMARY*
Currently, the frontend driver assumes that a target triple is either:
  * provided by the frontend itself (e.g. when lowering and generating
    code),
  * specified through the `-triple/-target` command line flags.

If `-triple/-target` is not used, the frontend will simply use the host
triple.

This is going to be insufficient when e.g. consuming an LLVM IR file
that has no triple specified (reading LLVM files is WIP, see D124667).
We shouldn't require the triple to be specified via the command line in
such situation. Instead, the frontend driver should contain a good
default, e.g.  the host triple.

This patch updates Flang's `CompilerInvocation` to do just that, i.e.
defines its default target triple. Similarly to Clang:
 * the default `CompilerInvocation` triple is set as the host triple,
 * the value specified with `-triple` takes precedence over the frontend
   driver default and the current module triple,
 * the frontend driver default takes precedence over the module triple.

*TESTS*
This change requires 2 unit tests to be updated. That's because relevant
frontend actions are updated to assume that there's always a valid
triple available in the current `CompilerInvocation`. This update is
required because the unit tests bypass the regular `CompilerInvocation`
set-up (in particular, they don't call
`CompilerInvocation::CreateFromArgs`). I've also taken the liberty to
disable the pre-precossor formatting in the affected unit tests as well
(it is not required).

No new tests are added. As `flang-new -fc1` does not support consuming
LLVM IR files just yet, it is not possible to compile an LLVM IR file
without a triple. More specifically, atm all LLVM IR files are generated
and stored internally and the driver makes sure that these contain a
valid target triple. This is about to change in D124667 (which adds
support for reading LLVM IR/BC files) and that's where tests for
exercising the default frontend driver triple will be added.

*WHAT DOES CLANG DO?*
For reference, the default target triple for Clang's
`CompilerInvocation` is set through option marshalling infra [1] in
Options.td. Please check the definition of the `-triple` flag:
```
def triple : Separate<["-"], "triple">,
  HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
  MarshallingInfoString<TargetOpts<"Triple">, "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
  AlwaysEmit, Normalizer<"normalizeTriple">;
```
Ideally, we should re-use the marshalling infra in Flang.

[1] https://clang.llvm.org/docs/InternalsManual.html#option-marshalling-infrastructure

Differential Revision: https://reviews.llvm.org/D124664
2022-05-04 12:01:53 +00:00
..
Common [flang] Use the Flang cmake-functions to add targets. 2020-04-16 15:51:30 +01:00
Decimal [flang] Accept "INFINITY" as real input 2022-04-25 12:12:10 -07:00
Evaluate [flang] Support FINDLOC/MAXLOC/MINLOC with scalar mask 2022-04-28 18:59:04 +09:00
Frontend [flang][driver] Define the default frontend driver triple 2022-05-04 12:01:53 +00:00
FrontendTool [flang][driver] NFC: Make code more in line with LLVM style 2022-04-27 09:20:07 +00:00
Lower [mlir][OpenMP] Restrict types for omp.parallel args 2022-05-02 14:17:34 +05:30
Optimizer [AsmParser] Introduce a new "Argument" abstraction + supporting logic 2022-04-29 12:19:34 -07:00
Parser [flang] Disambiguate F(X)=Y case where F is a function returning a pointer 2022-04-25 09:25:09 -07:00
Semantics [flang] Fix ICE for passing a label for non alternate return arguments 2022-05-04 12:32:33 +03:00
CMakeLists.txt [flang][driver] Delete `f18` (i.e. the old Flang driver) 2021-08-05 12:57:15 +00:00