[clang] [CLANG][DRIVER] Resolve Argument Visibility and Duplication Issue for Cuda ToolChain (PR #86807)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 07:34:52 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Jefferson Le Quellec (jle-quel)
<details>
<summary>Changes</summary>
# Description
This PR makes the argument `-Xcuda-ptxas` visible to the driver in cl-mode.
Furthermore, it has been noticed that the arguments are being passed twice to `ptxas`.
This also has been fixed by filtering out the arguments before appending them to the new `DAL` created by `CudaToolChain::TranslateArgs`.
---
Full diff: https://github.com/llvm/llvm-project/pull/86807.diff
3 Files Affected:
- (modified) clang/include/clang/Driver/Options.td (+2-1)
- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+4-1)
- (modified) clang/test/Driver/cuda-external-tools.cu (+8)
``````````diff
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 29066ea14280c2..a5e132dc48a3ef 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1001,7 +1001,8 @@ def : Joined<["-"], "Xclang=">, Group<CompileOnly_Group>,
def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">,
HelpText<"Pass <arg> to fatbinary invocation">, MetaVarName<"<arg>">;
def Xcuda_ptxas : Separate<["-"], "Xcuda-ptxas">,
- HelpText<"Pass <arg> to the ptxas assembler">, MetaVarName<"<arg>">;
+ HelpText<"Pass <arg> to the ptxas assembler">, MetaVarName<"<arg>">,
+ Visibility<[ClangOption, CLOption]>;
def Xopenmp_target : Separate<["-"], "Xopenmp-target">, Group<CompileOnly_Group>,
HelpText<"Pass <arg> to the target offloading toolchain.">, MetaVarName<"<arg>">;
def Xopenmp_target_EQ : JoinedAndSeparate<["-"], "Xopenmp-target=">, Group<CompileOnly_Group>,
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 5f0b516e1a1a08..6634e6d818b33e 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -990,7 +990,10 @@ CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
}
for (Arg *A : Args) {
- DAL->append(A);
+ // Make sure flags are not duplicated.
+ if (!llvm::is_contained(*DAL, A)) {
+ DAL->append(A);
+ }
}
if (!BoundArch.empty()) {
diff --git a/clang/test/Driver/cuda-external-tools.cu b/clang/test/Driver/cuda-external-tools.cu
index 946e144fce38fb..d9564d026b4faa 100644
--- a/clang/test/Driver/cuda-external-tools.cu
+++ b/clang/test/Driver/cuda-external-tools.cu
@@ -86,6 +86,12 @@
// RUN: -Xcuda-fatbinary -bar1 -Xcuda-ptxas -foo2 -Xcuda-fatbinary -bar2 %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK,SM35,PTXAS-EXTRA,FATBINARY-EXTRA %s
+// Check -Xcuda-ptxas with clang-cl
+// RUN: %clang_cl -### -c -Xcuda-ptxas -foo1 \
+// RUN: --offload-arch=sm_35 --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
+// RUN: -Xcuda-ptxas -foo2 %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHECK,SM35,PTXAS-EXTRA %s
+
// MacOS spot-checks
// RUN: %clang -### --target=x86_64-apple-macosx -O0 -c %s 2>&1 \
// RUN: --offload-arch=sm_35 --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
@@ -140,6 +146,8 @@
// CHECK-SAME: "[[PTXFILE]]"
// PTXAS-EXTRA-SAME: "-foo1"
// PTXAS-EXTRA-SAME: "-foo2"
+// CHECK-NOT: "-foo1"
+// CHECK-NOT: "-foo2"
// RDC-SAME: "-c"
// CHECK-NOT: "-c"
``````````
</details>
https://github.com/llvm/llvm-project/pull/86807
More information about the cfe-commits
mailing list