Skip to content

Commit 24849c9

Browse files
committed
[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
1 parent d36b96a commit 24849c9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -8325,7 +8325,8 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
83258325

83268326
ArgStringList Features;
83278327
SmallVector<StringRef> FeatureArgs;
8328-
getTargetFeatures(TC->getDriver(), TC->getTriple(), Args, Features, false);
8328+
getTargetFeatures(TC->getDriver(), TC->getTriple(), TCArgs, Features,
8329+
false);
83298330
llvm::copy_if(Features, std::back_inserter(FeatureArgs),
83308331
[](StringRef Arg) { return !Arg.startswith("-target"); });
83318332

clang/test/Driver/openmp-offload-gpu-new.c

+6
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,9 @@
120120
// RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-FEATURES %s
121121

122122
// CHECK-LTO-FEATURES: clang-offload-packager{{.*}}--image={{.*}}feature=+ptx{{[0-9]+}}
123+
124+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=sm_52 -nogpulib \
125+
// RUN: -Xopenmp-target=nvptx64-nvidia-cuda --cuda-feature=+ptx64 -foffload-lto %s 2>&1 \
126+
// RUN: | FileCheck --check-prefix=CHECK-SET-FEATURES %s
127+
128+
// CHECK-SET-FEATURES: clang-offload-packager{{.*}}--image={{.*}}feature=+ptx64

0 commit comments

Comments
 (0)