[flang-commits] [clang] [flang] [Flang-new][OpenMP] Add offload related flags for AMDGPU (PR #96742)
Dominik Adamski via flang-commits
flang-commits at lists.llvm.org
Wed Jun 26 01:08:59 PDT 2024
https://github.com/DominikAdamski created https://github.com/llvm/llvm-project/pull/96742
Flang-new needs to add `mlink-builtin-bitcode` objects to properly support offload code generation for AMD GPU.
fcuda-is-device flag is not used by Flang currently. In the future it will be needed for Flang equivalent function: `AMDGPUTargetCodeGenInfo::getGlobalVarAddressSpace`.
>From 80d46755e741cb9daa743574a3a4bfb580e0ad06 Mon Sep 17 00:00:00 2001
From: Dominik Adamski <dominik.adamski at amd.com>
Date: Fri, 21 Jun 2024 18:03:53 +0200
Subject: [PATCH] [Flang-new][OpenMP] Add offload related flags for AMDGPU
Flang-new needs to add mlink-builtin-bitcode objects
to properly support offload code generation for AMD GPU.
fcuda-is-device flag is not used by Flang currently.
In the future it will be needed for Flang equivalent function:
AMDGPUTargetCodeGenInfo::getGlobalVarAddressSpace.
---
clang/include/clang/Driver/Options.td | 4 ++--
clang/lib/Driver/ToolChains/Flang.cpp | 3 +++
flang/test/Driver/omp-driver-offload.f90 | 8 ++++++++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index dd55838dcf384..612d5793232ce 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8016,7 +8016,7 @@ def source_date_epoch : Separate<["-"], "source-date-epoch">,
// CUDA Options
//===----------------------------------------------------------------------===//
-let Visibility = [CC1Option] in {
+let Visibility = [CC1Option, FC1Option] in {
def fcuda_is_device : Flag<["-"], "fcuda-is-device">,
HelpText<"Generate code for CUDA device">,
@@ -8031,7 +8031,7 @@ def fno_cuda_host_device_constexpr : Flag<["-"], "fno-cuda-host-device-constexpr
HelpText<"Don't treat unattributed constexpr functions as __host__ __device__.">,
MarshallingInfoNegativeFlag<LangOpts<"CUDAHostDeviceConstexpr">>;
-} // let Visibility = [CC1Option]
+} // let Visibility = [CC1Option, FC1Option]
//===----------------------------------------------------------------------===//
// OpenMP Options
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..2679f284c5016 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -333,6 +333,9 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
StringRef Val = A->getValue();
CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
}
+
+ const ToolChain &TC = getToolChain();
+ TC.addClangTargetOptions(Args, CmdArgs, Action::OffloadKind::OFK_OpenMP);
}
void Flang::addTargetOptions(const ArgList &Args,
diff --git a/flang/test/Driver/omp-driver-offload.f90 b/flang/test/Driver/omp-driver-offload.f90
index 6fb4f4eeeeca1..b8afbe65961dc 100644
--- a/flang/test/Driver/omp-driver-offload.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -227,3 +227,11 @@
! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm"
! FORCE-USM-OFFLOAD-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa"
! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm"
+
+! RUN: %flang -### -v --target=x86_64-unknown-linux-gnu -fopenmp \
+! RUN: --offload-arch=gfx900 \
+! RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
+! RUN: | FileCheck --check-prefix=MLINK-BUILTIN-BITCODE %s
+! MLINK-BUILTIN-BITCODE: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! MLINK-BUILTIN-BITCODE-SAME: "-fcuda-is-device"
+! MLINK-BUILTIN-BITCODE-SAME: "-mlink-builtin-bitcode" {{.*Inputs.*rocm.*amdgcn.*bitcode.*}}oclc_isa_version_900.bc
More information about the flang-commits
mailing list