[clang] 2266f4a - [Flang][Driver][OpenMP] Enable options for selecting offloading phases in flang
Sergio Afonso via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 12 07:00:03 PDT 2023
Author: Sergio Afonso
Date: 2023-04-12T14:59:37+01:00
New Revision: 2266f4a3b38f4b59d313cdd2a9209952afb29d14
URL: https://github.com/llvm/llvm-project/commit/2266f4a3b38f4b59d313cdd2a9209952afb29d14
DIFF: https://github.com/llvm/llvm-project/commit/2266f4a3b38f4b59d313cdd2a9209952afb29d14.diff
LOG: [Flang][Driver][OpenMP] Enable options for selecting offloading phases in flang
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.
Differential Revision: https://reviews.llvm.org/D147941
Added:
flang/test/Driver/omp-driver-offload.f90
Modified:
clang/include/clang/Driver/Options.td
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
Removed:
flang/test/Driver/omp-frontend-forwarding.f90
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 0e3c7b708071f..7a2d9bf2a3915 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2735,11 +2735,11 @@ def offload_new_driver : Flag<["--"], "offload-new-driver">, Flags<[CC1Option]>,
MarshallingInfoFlag<LangOpts<"OffloadingNewDriver">>, HelpText<"Use the new driver for offloading compilation.">;
def no_offload_new_driver : Flag<["--"], "no-offload-new-driver">, Flags<[CC1Option]>, Group<f_Group>,
HelpText<"Don't Use the new driver for offloading compilation.">;
-def offload_device_only : Flag<["--"], "offload-device-only">,
+def offload_device_only : Flag<["--"], "offload-device-only">, Flags<[FlangOption]>,
HelpText<"Only compile for the offloading device.">;
-def offload_host_only : Flag<["--"], "offload-host-only">,
+def offload_host_only : Flag<["--"], "offload-host-only">, Flags<[FlangOption]>,
HelpText<"Only compile for the offloading host.">;
-def offload_host_device : Flag<["--"], "offload-host-device">,
+def offload_host_device : Flag<["--"], "offload-host-device">, Flags<[FlangOption]>,
HelpText<"Only compile for the offloading host.">;
def cuda_device_only : Flag<["--"], "cuda-device-only">, Alias<offload_device_only>,
HelpText<"Compile CUDA code for device only">;
diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 1a5fb4e996294..c365fbf16de35 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -69,6 +69,9 @@
! CHECK-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
! CHECK-NEXT: -module-dir <dir> Put MODULE files in <dir>
! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros
+! CHECK-NEXT: --offload-device-only Only compile for the offloading device.
+! CHECK-NEXT: --offload-host-device Only compile for the offloading host.
+! CHECK-NEXT: --offload-host-only Only compile for the offloading host.
! CHECK-NEXT: -o <file> Write output to <file>
! CHECK-NEXT: -pedantic Warn on language extensions
! CHECK-NEXT: -print-effective-triple Print the effective target triple
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 84707791a2e32..25871db048911 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -65,6 +65,9 @@
! HELP-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
! HELP-NEXT: -module-dir <dir> Put MODULE files in <dir>
! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
+! HELP-NEXT: --offload-device-only Only compile for the offloading device.
+! HELP-NEXT: --offload-host-device Only compile for the offloading host.
+! HELP-NEXT: --offload-host-only Only compile for the offloading host.
! HELP-NEXT: -o <file> Write output to <file>
! HELP-NEXT: -pedantic Warn on language extensions
! HELP-NEXT: -print-effective-triple Print the effective target triple
diff --git a/flang/test/Driver/omp-frontend-forwarding.f90 b/flang/test/Driver/omp-driver-offload.f90
similarity index 69%
rename from flang/test/Driver/omp-frontend-forwarding.f90
rename to flang/test/Driver/omp-driver-offload.f90
index ef4875ce2fae8..ec107261d4c2b 100644
--- a/flang/test/Driver/omp-frontend-forwarding.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -7,6 +7,42 @@
! CHECK-OPENMP: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}}.f90"
! CHECK-OPENMP-NOT: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
+! Test regular -fopenmp with offload, and invocation filtering options
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
+
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-device \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
+
+! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "nvptx64-nvidia-cuda"
+! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-only \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST
+
+! OFFLOAD-HOST: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-HOST-NOT: "-triple" "amdgcn-amd-amdhsa"
+! OFFLOAD-HOST-NOT: "-triple" "nvptx64-nvidia-cuda"
+! OFFLOAD-HOST-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+
+! RUN: %flang -S -### %s -o %t 2>&1 \
+! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-device-only \
+! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: | FileCheck %s --check-prefix=OFFLOAD-DEVICE
+
+! OFFLOAD-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "nvptx64-nvidia-cuda"
+! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+
! Test regular -fopenmp with offload for basic fopenmp-is-device flag addition and correct fopenmp
! RUN: %flang -### -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP-IS-DEVICE %s
! CHECK-OPENMP-IS-DEVICE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
More information about the cfe-commits
mailing list