[all-commits] [llvm/llvm-project] 02fb5b: [flang][driver] Define the default frontend driver...

Andrzej WarzyƄski via All-commits all-commits at lists.llvm.org
Wed May 4 05:02:27 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 02fb5b771d7ff130eff6c3ee5ac1c7cbdfb5dc63
      https://github.com/llvm/llvm-project/commit/02fb5b771d7ff130eff6c3ee5ac1c7cbdfb5dc63
  Author: Andrzej Warzynski <andrzej.warzynski at arm.com>
  Date:   2022-05-04 (Wed, 04 May 2022)

  Changed paths:
    M flang/lib/Frontend/CompilerInvocation.cpp
    M flang/lib/Frontend/FrontendActions.cpp
    M flang/unittests/Frontend/FrontendActionTest.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list