[PATCH] D100609: [Offload][OpenMP][CUDA] Allow fembed-bitcode for device offload
Johannes Doerfert via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 15 16:53:36 PDT 2021
jdoerfert created this revision.
jdoerfert added a reviewer: tra.
Herald added subscribers: guansong, yaxunl.
Herald added a reviewer: bollu.
jdoerfert requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.
This is a fix for the problem reported here:
https://lists.llvm.org/pipermail/llvm-dev/2021-March/149529.html
That is, the target information was missing when we embedded bitcode and
that caused the NVPTX backend to fail.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100609
Files:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/embed-bitcode-nvptx.cu
Index: clang/test/Driver/embed-bitcode-nvptx.cu
===================================================================
--- /dev/null
+++ clang/test/Driver/embed-bitcode-nvptx.cu
@@ -0,0 +1,8 @@
+// RUN: %clang -Xclang -triple -Xclang nvptx64 -S -Xclang -target-feature -Xclang +ptx70 -fembed-bitcode=all --cuda-device-only -nocudalib -nocudainc %s -o - | FileCheck %s
+// REQUIRES: nvptx-registered-target
+//
+// CHECK:.global .align 1 .b8 llvm_$_embedded_$_module[
+
+__device__ void foo(int mask) {
+ __nvvm_bar_warp_sync(mask);
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4295,6 +4295,9 @@
// Select the appropriate action.
RewriteKind rewriteKind = RK_None;
+ bool isDeviceOffloadAction = !(JA.isDeviceOffloading(Action::OFK_None) ||
+ JA.isDeviceOffloading(Action::OFK_Host));
+
// If CollectArgsForIntegratedAssembler() isn't called below, claim the args
// it claims when not running an assembler. Otherwise, clang would emit
// "argument unused" warnings for assembler flags when e.g. adding "-E" to
@@ -4401,9 +4404,6 @@
CmdArgs.push_back("-emit-llvm-uselists");
// Device-side jobs do not support LTO.
- bool isDeviceOffloadAction = !(JA.isDeviceOffloading(Action::OFK_None) ||
- JA.isDeviceOffloading(Action::OFK_Host));
-
if (D.isUsingLTO() && !isDeviceOffloadAction) {
Args.AddLastArg(CmdArgs, options::OPT_flto, options::OPT_flto_EQ);
CmdArgs.push_back("-flto-unit");
@@ -4436,7 +4436,15 @@
// Add flags implied by -fembed-bitcode.
Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
// Disable all llvm IR level optimizations.
- CmdArgs.push_back("-disable-llvm-passes");
+ if (!isDeviceOffloadAction) {
+ CmdArgs.push_back("-disable-llvm-passes");
+ } else {
+ std::string CPU = getCPUName(Args, Triple, /*FromAs*/ false);
+ if (!CPU.empty()) {
+ CmdArgs.push_back("-target-cpu");
+ CmdArgs.push_back(Args.MakeArgString(CPU));
+ }
+ }
// Render target options.
TC.addClangTargetOptions(Args, CmdArgs, JA.getOffloadingDeviceKind());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100609.337947.patch
Type: text/x-patch
Size: 2308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210415/029703b8/attachment-0001.bin>
More information about the cfe-commits
mailing list