Page MenuHomePhabricator

[flang][driver] Define the default frontend driver triple

Authored by awarzynski on Apr 29 2022, 2:38 AM.



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

This is going to be insufficient when e.g. consuming an LLVM IR file
that has no triple specified (note: reading LLVM files is WIP). 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.

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.

For reference, the default target triple for Clang's
CompilerInvocation is set through option marshalling infra [1] in 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.


Diff Detail

Event Timeline

awarzynski created this revision.Apr 29 2022, 2:38 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 29 2022, 2:38 AM
awarzynski requested review of this revision.Apr 29 2022, 2:38 AM
ekieri accepted this revision.May 1 2022, 12:28 PM

LGTM, just a small suggestion: Could you add a note about the missing tests (that (and why) they are in D124667) to the commit message?


or above? Call is below, definition above.

This revision is now accepted and ready to land.May 1 2022, 12:28 PM
awarzynski updated this revision to Diff 426604.May 3 2022, 1:56 AM

Update the comment in "CompilerInvocation.cpp"

awarzynski edited the summary of this revision. (Show Details)May 3 2022, 2:01 AM
awarzynski edited the summary of this revision. (Show Details)

LGTM, just a small suggestion: Could you add a note about the missing tests (that (and why) they are in D124667) to the commit message?

Done, thanks for the suggestion!

Hopefully the commit message makes it clear. Ideally, I should've done a better job splitting this, D124665 and D124667 into testable units. It all started as one change :)


Thanks, I've clarified this.

ekieri added a comment.May 3 2022, 8:53 AM

Looks good, thanks!