llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Yaxun (Sam) Liu (yxsamliu)

<details>
<summary>Changes</summary>

Clang reported `--offload-jobs` as unused when an individual compilation
had no device work that could run in parallel. CMake tests compiler options
with `-Werror`, so this warning made option detection fail. It also caused
unnecessary build errors and CMake workarounds in projects targeting one or
several GPU architectures.

`--offload-jobs` sets the maximum number of parallel jobs, not a required
number. A compilation with fewer jobs, including zero or one, is valid and
should not produce an unused argument warning.

Claim and validate the option independently of whether parallel device jobs
are found. Keep job discovery responsible only for marking work that can run
in parallel.


---
Full diff: https://github.com/llvm/llvm-project/pull/214310.diff


2 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+1-5) 
- (modified) clang/test/Driver/offload-parallel-device-cc1.cu (+3) 


``````````diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 3b5d0c0aad981..81590a6fbc113 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5495,18 +5495,13 @@ static void claimAndDiagnoseOffloadJobs(const Driver 
&D, const ArgList &Args) {
 }
 
 static void markOffloadDeviceCC1JobsForParallelExecution(Compilation &C) {
-  bool FoundCandidate = false;
   for (auto &Job : C.getJobs()) {
     if (!isOffloadDeviceCC1JobCandidate(Job))
       continue;
 
     Job.setOffloadDeviceParallelJobGroup(
         getOffloadDeviceCC1ParallelJobGroup(Job));
-    FoundCandidate = true;
   }
-
-  if (FoundCandidate)
-    claimAndDiagnoseOffloadJobs(C.getDriver(), C.getArgs());
 }
 
 void Driver::BuildJobs(Compilation &C) const {
@@ -5610,6 +5605,7 @@ void Driver::BuildJobs(Compilation &C) const {
       J.InProcess = false;
 
   markOffloadDeviceCC1JobsForParallelExecution(C);
+  claimAndDiagnoseOffloadJobs(*this, C.getArgs());
 
   if (CCPrintProcessStats) {
     C.setPostCallback([=](const Command &Cmd, int Res) {
diff --git a/clang/test/Driver/offload-parallel-device-cc1.cu 
b/clang/test/Driver/offload-parallel-device-cc1.cu
index 3d8447b1cd4a8..1689825df196e 100644
--- a/clang/test/Driver/offload-parallel-device-cc1.cu
+++ b/clang/test/Driver/offload-parallel-device-cc1.cu
@@ -2,6 +2,9 @@
 // REQUIRES: nvptx-registered-target, lld
 
 // RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -x c++ --offload-jobs=1 -Werror -c %s -o %t/host.o
+// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --offload-arch=gfx900 --offload-jobs=1 -Werror -E %s -o %t/hip.i
 // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu \
 // RUN:   -nostdinc -nogpuinc -nohipwrapperinc -nogpulib \
 // RUN:   --offload-arch=gfx900 --offload-arch=gfx906 --offload-jobs=2 \

``````````

</details>


https://github.com/llvm/llvm-project/pull/214310
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to