diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -95,6 +95,12 @@ EmbedBitcode } BitcodeEmbed; + enum OffloadMode { + OffloadHostDevice, + OffloadHost, + OffloadDevice, + } Offload; + /// Header unit mode set by -fmodule-header={user,system}. ModuleHeaderMode CXX20HeaderType; @@ -391,6 +397,9 @@ bool embedBitcodeInObject() const { return (BitcodeEmbed == EmbedBitcode); } bool embedBitcodeMarkerOnly() const { return (BitcodeEmbed == EmbedMarker); } + bool offloadHostOnly() const { return Offload == OffloadHost; } + bool offloadDeviceOnly() const { return Offload == OffloadDevice; } + /// Compute the desired OpenMP runtime from the flags provided. OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -192,13 +192,14 @@ IntrusiveRefCntPtr VFS) : Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode), SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), - CXX20HeaderType(HeaderMode_None), ModulesModeCXX20(false), - LTOMode(LTOK_None), ClangExecutable(ClangExecutable), - SysRoot(DEFAULT_SYSROOT), DriverTitle(Title), CCCPrintBindings(false), - CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false), - CCGenDiagnostics(false), CCPrintProcessStats(false), - TargetTriple(TargetTriple), Saver(Alloc), CheckInputsExist(true), - ProbePrecompiled(true), SuppressMissingInputWarning(false) { + Offload(OffloadHostDevice), CXX20HeaderType(HeaderMode_None), + ModulesModeCXX20(false), LTOMode(LTOK_None), + ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT), + DriverTitle(Title), CCCPrintBindings(false), CCPrintOptions(false), + CCPrintHeaders(false), CCLogDiagnostics(false), CCGenDiagnostics(false), + CCPrintProcessStats(false), TargetTriple(TargetTriple), Saver(Alloc), + CheckInputsExist(true), ProbePrecompiled(true), + SuppressMissingInputWarning(false) { // Provide a sane fallback if no VFS is specified. if (!this->VFS) this->VFS = llvm::vfs::getRealFileSystem(); @@ -1284,6 +1285,17 @@ .Default(SaveTempsCwd); } + if (const Arg *A = Args.getLastArg(options::OPT_offload_host_only, + options::OPT_offload_device_only, + options::OPT_offload_host_device)) { + if (A->getOption().matches(options::OPT_offload_host_only)) + Offload = OffloadHost; + else if (A->getOption().matches(options::OPT_offload_device_only)) + Offload = OffloadDevice; + else + Offload = OffloadHostDevice; + } + setLTOMode(Args); // Process -fembed-bitcode= flags. @@ -2933,15 +2945,8 @@ ? C.getSingleOffloadToolChain() : C.getSingleOffloadToolChain()); - Arg *PartialCompilationArg = Args.getLastArg( - options::OPT_offload_host_only, options::OPT_offload_device_only, - options::OPT_offload_host_device); - CompileHostOnly = - PartialCompilationArg && PartialCompilationArg->getOption().matches( - options::OPT_offload_host_only); - CompileDeviceOnly = - PartialCompilationArg && PartialCompilationArg->getOption().matches( - options::OPT_offload_device_only); + CompileHostOnly = C.getDriver().offloadHostOnly(); + CompileDeviceOnly = C.getDriver().offloadDeviceOnly(); EmitLLVM = Args.getLastArg(options::OPT_emit_llvm); EmitAsm = Args.getLastArg(options::OPT_S); FixedCUID = Args.getLastArgValue(options::OPT_cuid_EQ); @@ -4270,11 +4275,6 @@ // Claim ignored clang-cl options. Args.ClaimAllArgs(options::OPT_cl_ignored_Group); - - // Claim --offload-host-only and --offload-compile-host-device, which may be - // passed to non-CUDA compilations and should not trigger warnings there. - Args.ClaimAllArgs(options::OPT_offload_host_only); - Args.ClaimAllArgs(options::OPT_offload_host_device); } /// Returns the canonical name for the offloading architecture when using a HIP @@ -4393,18 +4393,10 @@ llvm::opt::DerivedArgList &Args, const InputTy &Input, Action *HostAction) const { - const Arg *Mode = Args.getLastArg(options::OPT_offload_host_only, - options::OPT_offload_device_only, - options::OPT_offload_host_device); - const bool HostOnly = - Mode && Mode->getOption().matches(options::OPT_offload_host_only); - const bool DeviceOnly = - Mode && Mode->getOption().matches(options::OPT_offload_device_only); - // Don't build offloading actions if explicitly disabled or we do not have a // valid source input and compile action to embed it in. If preprocessing only // ignore embedding. - if (HostOnly || !types::isSrcFile(Input.first) || + if (offloadHostOnly() || !types::isSrcFile(Input.first) || !(isa(HostAction) || getFinalPhase(Args) == phases::Preprocess)) return HostAction; @@ -4492,7 +4484,7 @@ } } - if (DeviceOnly) + if (offloadDeviceOnly()) return C.MakeAction(DDeps, types::TY_Nothing); Action *OffloadPackager = diff --git a/clang/test/Driver/cuda-unused-arg-warning.cu b/clang/test/Driver/cuda-unused-arg-warning.cu deleted file mode 100644 --- a/clang/test/Driver/cuda-unused-arg-warning.cu +++ /dev/null @@ -1,28 +0,0 @@ -// Tests that we trigger unused-arg warnings on CUDA flags appropriately. - -// REQUIRES: x86-registered-target -// REQUIRES: nvptx-registered-target - -// --cuda-host-only and --cuda-compile-host-device should never trigger an -// unused arg warning. -// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -c %s 2>&1 | \ -// RUN: FileCheck %s -// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -x c -c %s 2>&1 | \ -// RUN: FileCheck %s -// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device -c %s 2>&1 | \ -// RUN: FileCheck %s -// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device -x c -c %s 2>&1 | \ -// RUN: FileCheck %s - -// --cuda-device-only should warn during non-CUDA compilation. -// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only -x c -c %s 2>&1 | \ -// RUN: FileCheck -check-prefix UNUSED-WARNING %s - -// --cuda-device-only should not produce warning compiling CUDA files -// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only -c %s 2>&1 | \ -// RUN: FileCheck -check-prefix NO-UNUSED-WARNING %s - -// CHECK-NOT: warning: argument unused during compilation: '--cuda-host-only' -// CHECK-NOT: warning: argument unused during compilation: '--cuda-compile-host-device' -// UNUSED-WARNING: warning: argument unused during compilation: '--cuda-device-only' -// NO-UNUSED-WARNING-NOT: warning: argument unused during compilation: '--cuda-device-only'