This is an archive of the discontinued LLVM Phabricator instance.

[flang][driver] Add support for `--target`/`--triple`
ClosedPublic

Authored by awarzynski on Feb 21 2022, 5:19 AM.

Details

Summary

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-ffective-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.

Diff Detail

Event Timeline

awarzynski created this revision.Feb 21 2022, 5:19 AM
Herald added a project: Restricted Project. · View Herald Transcript
awarzynski requested review of this revision.Feb 21 2022, 5:19 AM

Add TargetOptions.h (that I forgot to add earlier)

rovka added a comment.Feb 22 2022, 7:36 PM

Nit: Should we also have a test for print-effective-triple?

Otherwise LGTM, although I'm not sure that -emit-llvm is necessarily something we'd want flang users to be exposed to.

flang/include/flang/Frontend/TargetOptions.h
21

https://reviews.llvm.org/D117809

There was a discussion that -emit-llvm is considered a mistake.

@MaskRay

Add a test for --print-effective-triple

Thank you both for taking a look!

Nit: Should we also have a test for print-effective-triple?

Added.

I'm not sure that -emit-llvm is necessarily something we'd want flang users to be exposed to.

Hm, but that's what clang does and we probably want to keep flang-new and clang consistent. And we can't hide -emit-llvm without hiding it in clangas well (so HelpHidden is not really an option).

https://reviews.llvm.org/D117809

There was a discussion that -emit-llvm is considered a mistake.

Which comment are you referring to specifically? Also, -emit-llvm is something that Flang inherits from Clang. I'm merely making it available in flang-new rather than re-defining it.

https://reviews.llvm.org/D117809

There was a discussion that -emit-llvm is considered a mistake.

Which comment are you referring to specifically? Also, -emit-llvm is something that Flang inherits from Clang. I'm merely making it available in flang-new rather than re-defining it.

Following clang's precedent with regard to spelling the option -emit-llvm seems to both follow the principle of least surprise and most obvious for sharing common code.

schweitz added inline comments.Feb 23 2022, 8:35 AM
clang/include/clang/Driver/Options.td
4833–4849

Is this comment something left over from edits?

awarzynski added inline comments.Feb 23 2022, 8:44 AM
clang/include/clang/Driver/Options.td
4833–4849

This is intentional (there's already a precedent in this file).

The nesting of let statements in this file can be very confusing. Also, some let blocks are really large. I think that adding such comments helps to separate them visually.

Rebase on top of main

This revision was not accepted when it landed; it landed in state Needs Review.Feb 25 2022, 1:45 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.

Thank you all for taking a look!

I've just realised this: "This revision was not accepted when it landed; it landed in state Needs Review." Just to clarify, I merged this as two reviewers accepted this in comments (with "LGTM"). Also, I believe that I addressed all your comments. If you feel otherwise, I'm happy to re-open the discussion.