[clang] 24849c9 - [Clang] Fix the wrong features being derivec in the offload packager

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 8 14:26:27 PDT 2022


Author: Joseph Huber
Date: 2022-07-08T17:26:20-04:00
New Revision: 24849c9eb504cad5b17f16ed23a88dab92882d5d

URL: https://github.com/llvm/llvm-project/commit/24849c9eb504cad5b17f16ed23a88dab92882d5d
DIFF: https://github.com/llvm/llvm-project/commit/24849c9eb504cad5b17f16ed23a88dab92882d5d.diff

LOG: [Clang] Fix the wrong features being derivec in the offload packager

The offload packager embeds the features in the offloading binary when
performing LTO. This had an incorrect interaction with the
`--cuda-feature` option because we weren't deriving the features from
the CUDA toolchain arguments when it was being specified. This patch
fixes this so the features are correctly overrideen when using this
argument.

However, this brings up a question of how best to handle conflicting
target features. The user could compile many libraries with different
features, in this case we do not know which one to pick. This was not
previously a problem when we simply passed the features in from the CUDA
installation at link-link because we just defaulted to whatever was
current on the system.

Reviewed By: ye-luo

Differential Revision: https://reviews.llvm.org/D129393

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/openmp-offload-gpu-new.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 2c4d39343183c..bc29dd8107a60 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8325,7 +8325,8 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
 
     ArgStringList Features;
     SmallVector<StringRef> FeatureArgs;
-    getTargetFeatures(TC->getDriver(), TC->getTriple(), Args, Features, false);
+    getTargetFeatures(TC->getDriver(), TC->getTriple(), TCArgs, Features,
+                      false);
     llvm::copy_if(Features, std::back_inserter(FeatureArgs),
                   [](StringRef Arg) { return !Arg.startswith("-target"); });
 

diff  --git a/clang/test/Driver/openmp-offload-gpu-new.c b/clang/test/Driver/openmp-offload-gpu-new.c
index a59952a90e29e..9a421059a68fd 100644
--- a/clang/test/Driver/openmp-offload-gpu-new.c
+++ b/clang/test/Driver/openmp-offload-gpu-new.c
@@ -120,3 +120,9 @@
 // RUN:     -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-FEATURES %s
 
 // CHECK-LTO-FEATURES: clang-offload-packager{{.*}}--image={{.*}}feature=+ptx{{[0-9]+}}
+
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=sm_52 -nogpulib \
+// RUN:     -Xopenmp-target=nvptx64-nvidia-cuda --cuda-feature=+ptx64 -foffload-lto %s 2>&1 \
+// RUN:    | FileCheck --check-prefix=CHECK-SET-FEATURES %s
+
+// CHECK-SET-FEATURES: clang-offload-packager{{.*}}--image={{.*}}feature=+ptx64


        


More information about the cfe-commits mailing list