Author: Yaxun (Sam) Liu Date: 2026-08-13T10:10:42-04:00 New Revision: 088864db1798f23c309f548d7275260e8a0e7f67
URL: https://github.com/llvm/llvm-project/commit/088864db1798f23c309f548d7275260e8a0e7f67 DIFF: https://github.com/llvm/llvm-project/commit/088864db1798f23c309f548d7275260e8a0e7f67.diff LOG: [Clang][Driver] Accept `--offload-jobs` without parallel work (#214310) Clang reported `--offload-jobs` as unused when an active offload compilation had no device work that could run in parallel. CMake tests compiler options with `-Werror`, so this warning made HIP/offload 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. An offload compilation with fewer jobs, including zero or one, is valid and should not produce an unused argument warning. A normal C++ compilation without offloading still reports the option as unused; CMake should probe it using a HIP/offload compilation. Claim and validate the option whenever offloading is active, independently of whether parallel device jobs are found. Keep job discovery responsible only for marking work that can run in parallel. Added: Modified: clang/lib/Driver/Driver.cpp clang/test/Driver/offload-parallel-device-cc1.cu Removed: ################################################################################ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index d4719f37e5b4d..39691538c355a 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5518,18 +5518,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 { @@ -5633,6 +5628,8 @@ void Driver::BuildJobs(Compilation &C) const { J.InProcess = false; markOffloadDeviceCC1JobsForParallelExecution(C); + if (C.getActiveOffloadKinds() != Action::OFK_None) + 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..ff68770926aa1 100644 --- a/clang/test/Driver/offload-parallel-device-cc1.cu +++ b/clang/test/Driver/offload-parallel-device-cc1.cu @@ -2,6 +2,11 @@ // REQUIRES: nvptx-registered-target, lld // RUN: rm -rf %t && mkdir -p %t +// RUN: not %clang -x c++ --offload-jobs=1 -Werror -fsyntax-only %s 2>&1 | \ +// RUN: FileCheck -check-prefix=NOOFFLOAD %s +// NOOFFLOAD: argument unused during compilation: '--offload-jobs=1' +// 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 \ @@ -18,5 +23,5 @@ // RUN: --cuda-device-only -S %s 2>&1 | FileCheck -check-prefix=INVJOBS %s // INVJOBS: clang: error: invalid integral value '0x4' in '--offload-jobs=0x4' -// Empty source file. RUN lines are execution smoke tests for the driver -// path that runs independent offload device cc1 jobs through --offload-jobs. +// Empty source file. RUN lines test --offload-jobs with and without +// independent offload device cc1 jobs. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
