This is an archive of the discontinued LLVM Phabricator instance.

[Flang][Driver][OpenMP] Enable options for selecting offloading phases in flang
ClosedPublic

Authored by skatrak on Apr 10 2023, 7:11 AM.

Details

Summary

This patch unlocks the "--offload-device-only", "--offload-host-only" and
"--offload-host-device" options available in Clang for use by the Flang driver.
These can be used to modify the behavior of the driver to select which
compilation invocations are triggered during OpenMP offloading.

Diff Detail

Event Timeline

skatrak created this revision.Apr 10 2023, 7:11 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
skatrak requested review of this revision.Apr 10 2023, 7:11 AM

Could you add tests that demonstrate what these options actually do?

Could you add tests that demonstrate what these options actually do?

Thank you for the quick review! These options just modify which flang-new -fc1 invocations are produced by the driver when compiling for device offloading. I have added tests that check that only the expected invocations are present, but if these tests are not what you'd expect I'd gladly make some more if you can explain a bit further what you had in mind.

Could you add tests that demonstrate what these options actually do?

Thank you for the quick review! These options just modify which flang-new -fc1 invocations are produced by the driver when compiling for device offloading. I have added tests that check that only the expected invocations are present, but if these tests are not what you'd expect I'd gladly make some more if you can explain a bit further what you had in mind.

Cheers!

These can be used to modify the behavior of the driver to select which compilation passes are triggered during OpenMP offloading.

In the context of LLVM, I would normally associate "pass" with something else. I'm not that familiar with offloading, so perhaps that's the language that people use? Personally, in the context of the driver I'd normally use the term "phase" rather than "pass".

This patch makes sense, though I'd like the following to be addressed before landing this:

  1. Where's the logic that implements what --offload-host-device? It looks like this is already implemented elsewhere and this patch simply "unlocks" (rather than "implements") this option for Flang.
  2. The name of "omp-frontend-forwarding.f90" is very misleading. "Forwarding" would mean flang-new --offload-host-only %s --> flang-new -fc1 --offload-host-only %s, but that's not what's happening here, is it?

For 1. you could just update the summary, and for 2. I suggest renaming "omp-frontend-forwarding.f90" as e.g. "omp-compiler-flag-expansion.f90". WDYT?

clang/include/clang/Driver/Options.td
2738

Why is CoreOption needed here? Wouldn't FlangOption be sufficient?

flang/test/Driver/omp-driver-offload.f90
14

[nit] You can reduce noise by using OFFLOAD-HOST-DEVICE instead of CHECK-OFFLOAD-HOST-DEVICE. I think that most people understand that these are CHECK prefixes anyway.

19

[nit] No harm in being a bit more verbose to communicate the intent a bit clearer :)

30

Shouldn't there be 2 driver invocation for the host, as in the the CHECK-OFFLOAD-HOST-DEVICE case?

skatrak updated this revision to Diff 512399.Apr 11 2023, 4:56 AM

Address reviewer's comments

skatrak retitled this revision from [Flang][Driver][OpenMP] Enable flags for filtering of offloading passes in flang to [Flang][Driver][OpenMP] Enable options for selecting offloading phases in flang.Apr 11 2023, 4:57 AM
skatrak edited the summary of this revision. (Show Details)
skatrak marked 4 inline comments as done.Apr 11 2023, 5:08 AM

In the context of LLVM, I would normally associate "pass" with something else. I'm not that familiar with offloading, so perhaps that's the language that people use? Personally, in the context of the driver I'd normally use the term "phase" rather than "pass".

This patch makes sense, though I'd like the following to be addressed before landing this:

  1. Where's the logic that implements what --offload-host-device? It looks like this is already implemented elsewhere and this patch simply "unlocks" (rather than "implements") this option for Flang.
  2. The name of "omp-frontend-forwarding.f90" is very misleading. "Forwarding" would mean flang-new --offload-host-only %s --> flang-new -fc1 --offload-host-only %s, but that's not what's happening here, is it?

For 1. you could just update the summary, and for 2. I suggest renaming "omp-frontend-forwarding.f90" as e.g. "omp-compiler-flag-expansion.f90". WDYT?

I updated the patch title and summary, and renamed the test file to something that I think represents better the contents of the test. Thank you again for the suggestions, let me know if there are any other improvements to make before landing this patch.

clang/include/clang/Driver/Options.td
2738

You're right, thanks for the comment.

flang/test/Driver/omp-driver-offload.f90
30

In this case only the first invocation would remain, but I added an additional OFFLOAD-HOST-NOT to make this behavior explicit

awarzynski accepted this revision.Apr 11 2023, 6:36 AM

LGTM, thanks for addressing my comments. I'd wait a day before landing this - just in case other reviewers have comments.

This revision is now accepted and ready to land.Apr 11 2023, 6:36 AM
This revision was automatically updated to reflect the committed changes.
skatrak marked 2 inline comments as done.