[PATCH] D128752: [CUDA] Stop adding CUDA features twice

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 12:24:09 PDT 2022


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tra, yaxunl.
Herald added subscribers: mattd, carlosgalvezp.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

We currently call the `addNVPTXFeatures` function in two places, inside
of the CUDA Toolchain and inside of Clang in the standard entry point.
We normally add features to the job in Clang, so the call inside of the
CUDA toolchain is redundant and results in `+ptx` features being added.
Since we remove this call, we no longer will have a cached CUDA
installation so we will usually create it twice.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128752

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h


Index: clang/lib/Driver/ToolChains/Cuda.h
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.h
+++ clang/lib/Driver/ToolChains/Cuda.h
@@ -126,8 +126,7 @@
 
 void getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
                             const llvm::opt::ArgList &Args,
-                            std::vector<StringRef> &Features,
-                            Optional<clang::CudaVersion> Version = None);
+                            std::vector<StringRef> &Features);
 
 } // end namespace NVPTX
 } // end namespace tools
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -636,23 +636,20 @@
 
 void NVPTX::getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
                                    const llvm::opt::ArgList &Args,
-                                   std::vector<StringRef> &Features,
-                                   Optional<clang::CudaVersion> Version) {
+                                   std::vector<StringRef> &Features) {
   if (Args.hasArg(options::OPT_cuda_feature_EQ)) {
     StringRef PtxFeature =
         Args.getLastArgValue(options::OPT_cuda_feature_EQ, "+ptx42");
     Features.push_back(Args.MakeArgString(PtxFeature));
     return;
-  } else if (!Version) {
-    CudaInstallationDetector CudaInstallation(D, Triple, Args);
-    Version = CudaInstallation.version();
   }
+  CudaInstallationDetector CudaInstallation(D, Triple, Args);
 
   // New CUDA versions often introduce new instructions that are only supported
   // by new PTX version, so we need to raise PTX level to enable them in NVPTX
   // back-end.
   const char *PtxFeature = nullptr;
-  switch (*Version) {
+  switch (CudaInstallation.version()) {
 #define CASE_CUDA_VERSION(CUDA_VER, PTX_VER)                                   \
   case CudaVersion::CUDA_##CUDA_VER:                                           \
     PtxFeature = "+ptx" #PTX_VER;                                              \
@@ -746,11 +743,6 @@
 
   clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
 
-  std::vector<StringRef> Features;
-  NVPTX::getNVPTXTargetFeatures(getDriver(), getTriple(), DriverArgs, Features,
-                                CudaInstallationVersion);
-  for (StringRef PtxFeature : Features)
-    CC1Args.append({"-target-feature", DriverArgs.MakeArgString(PtxFeature)});
   if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
                          options::OPT_fno_cuda_short_ptr, false))
     CC1Args.append({"-mllvm", "--nvptx-short-ptr"});


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128752.440720.patch
Type: text/x-patch
Size: 2710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220628/2698d04b/attachment.bin>


More information about the cfe-commits mailing list