diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 3f2058a5d4650..ceeb4c5e7c424 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -148,7 +148,8 @@ def pedantic_Group : OptionGroup<"">, Group, DocFlatten; def offload_Group : OptionGroup<"">, Group, - DocName<"Common Offloading options">; + DocName<"Common Offloading options">, + Visibility<[ClangOption, CLOption]>; def opencl_Group : OptionGroup<"">, Group, DocName<"OpenCL options">; @@ -157,13 +158,16 @@ def sycl_Group : OptionGroup<"">, Group, DocName<"SYCL options">; def cuda_Group : OptionGroup<"">, Group, - DocName<"CUDA options">; + DocName<"CUDA options">, + Visibility<[ClangOption, CLOption]>; def hip_Group : OptionGroup<"">, Group, - DocName<"HIP options">; + DocName<"HIP options">, + Visibility<[ClangOption, CLOption]>; def m_Group : OptionGroup<"">, Group, - DocName<"Target-dependent compilation options">; + DocName<"Target-dependent compilation options">, + Visibility<[ClangOption, CLOption]>; // Feature groups - these take command line options that correspond directly to // target specific features and can be translated directly from command line @@ -5164,14 +5168,16 @@ def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules" def prebind : Flag<["-"], "prebind">; def preload : Flag<["-"], "preload">; def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">, - HelpText<"Print the full library path of ">, MetaVarName<"">; + HelpText<"Print the full library path of ">, MetaVarName<"">, + Visibility<[ClangOption, CLOption]>; def print_ivar_layout : Flag<["-"], "print-ivar-layout">, Visibility<[ClangOption, CC1Option]>, HelpText<"Enable Objective-C Ivar layout bitmap print trace">, MarshallingInfoFlag>; def print_libgcc_file_name : Flag<["-", "--"], "print-libgcc-file-name">, HelpText<"Print the library path for the currently used compiler runtime " - "library (\"libgcc.a\" or \"libclang_rt.builtins.*.a\")">; + "library (\"libgcc.a\" or \"libclang_rt.builtins.*.a\")">, + Visibility<[ClangOption, CLOption]>; def print_multi_directory : Flag<["-", "--"], "print-multi-directory">; def print_multi_lib : Flag<["-", "--"], "print-multi-lib">; def print_multi_flags : Flag<["-", "--"], "print-multi-flags-experimental">, @@ -5180,27 +5186,34 @@ def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">, Flags<[Unsupported]>; def print_target_triple : Flag<["-", "--"], "print-target-triple">, HelpText<"Print the normalized target triple">, - Visibility<[ClangOption, FlangOption]>; + Visibility<[ClangOption, FlangOption, CLOption]>; def print_effective_triple : Flag<["-", "--"], "print-effective-triple">, HelpText<"Print the effective target triple">, - Visibility<[ClangOption, FlangOption]>; + Visibility<[ClangOption, FlangOption, CLOption]>; // GCC --disable-multiarch, GCC --enable-multiarch (upstream and Debian // specific) have different behaviors. We choose not to support the option. def : Flag<["-", "--"], "print-multiarch">, Flags<[Unsupported]>; def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">, - HelpText<"Print the full program path of ">, MetaVarName<"">; + HelpText<"Print the full program path of ">, MetaVarName<"">, + Visibility<[ClangOption, CLOption]>; def print_resource_dir : Flag<["-", "--"], "print-resource-dir">, - HelpText<"Print the resource directory pathname">; + HelpText<"Print the resource directory pathname">, + Visibility<[ClangOption, CLOption]>; def print_search_dirs : Flag<["-", "--"], "print-search-dirs">, - HelpText<"Print the paths used for finding libraries and programs">; + HelpText<"Print the paths used for finding libraries and programs">, + Visibility<[ClangOption, CLOption]>; def print_targets : Flag<["-", "--"], "print-targets">, - HelpText<"Print the registered targets">; + HelpText<"Print the registered targets">, + Visibility<[ClangOption, CLOption]>; def print_rocm_search_dirs : Flag<["-", "--"], "print-rocm-search-dirs">, - HelpText<"Print the paths used for finding ROCm installation">; + HelpText<"Print the paths used for finding ROCm installation">, + Visibility<[ClangOption, CLOption]>; def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">, - HelpText<"Print the directory pathname containing clangs runtime libraries">; + HelpText<"Print the directory pathname containing clangs runtime libraries">, + Visibility<[ClangOption, CLOption]>; def print_diagnostic_options : Flag<["-", "--"], "print-diagnostic-options">, - HelpText<"Print all of Clang's warning options">; + HelpText<"Print all of Clang's warning options">, + Visibility<[ClangOption, CLOption]>; def private__bundle : Flag<["-"], "private_bundle">; def pthreads : Flag<["-"], "pthreads">; defm pthread : BoolOption<"", "pthread", @@ -5227,7 +5240,7 @@ def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, Alias; def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group; -def rtlib_EQ : Joined<["-", "--"], "rtlib=">, +def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, CLOption]>, HelpText<"Compiler runtime library to use">; def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, Flags<[NoArgumentUnused]>, HelpText<"Add -rpath with architecture-specific resource directory to the linker flags. " @@ -5393,7 +5406,7 @@ def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">, MarshallingInfoFlag>; def x : JoinedOrSeparate<["-"], "x">, Flags<[NoXarchOption]>, - Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option, CLOption]>, HelpText<"Treat subsequent input files as having type ">, MetaVarName<"">; def y : Joined<["-"], "y">; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 77328e1f99e50..f5fd900a6447f 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2589,8 +2589,11 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, Diag(clang::diag::note_drv_t_option_is_global); } + // CUDA/HIP and their preprocessor expansions can be accepted by CL mode. // Warn -x after last input file has no effect - if (!IsCLMode()) { + auto LastXArg = Args.getLastArgValue(options::OPT_x); + const llvm::StringSet<> ValidXArgs = {"cuda", "hip", "cui", "hipi"}; + if (!IsCLMode() || ValidXArgs.find(LastXArg) != ValidXArgs.end()) { Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x); Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT); if (LastXArg && LastInputArg && diff --git a/clang/test/Driver/cl-offload.cu b/clang/test/Driver/cl-offload.cu new file mode 100644 index 0000000000000..aa5c096338110 --- /dev/null +++ b/clang/test/Driver/cl-offload.cu @@ -0,0 +1,27 @@ +// RUN: %clang_cl -### --offload-arch=sm_35 -fgpu-rdc \ +// RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda \ +// RUN: /Wall -x cuda %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CUDA + +// RUN: %clang_cl -### --offload-arch=gfx1010 -fgpu-rdc --hip-link \ +// RUN: --rocm-path=%S/Inputs/rocm /Wall -x hip %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=HIP + +// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda" "-aux-triple" "x86_64-pc-windows-msvc" +// CUDA-SAME: "-Weverything" +// CUDA: ptxas +// CUDA: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "nvptx64-nvidia-cuda" +// CUDA-SAME: "-Weverything" +// CUDA: link + +// HIP: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "amdgcn-amd-amdhsa" +// HIP-SAME: "-Weverything" +// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-pc-windows-msvc" +// HIP-SAME: "-Weverything" +// HIP: {{lld.* "-flavor" "gnu" "-m" "elf64_amdgpu"}} +// HIP: {{link.* "amdhip64.lib"}} + +// CMake uses this option when finding packages for HIP, so +// make sure it does not cause error. + +// RUN: %clang_cl --print-libgcc-file-name