Skip to content

[CUDA][HIP] add options --[no-]offload-inc #140106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,8 @@ multiclass BoolWOption<string flag_base, KeyPathAndMacro kpm,
// Works like BoolOption except without marshalling
multiclass BoolOptionWithoutMarshalling<string prefix = "", string spelling_base,
FlagDef flag1_base, FlagDef flag2_base,
BothFlags suffix = BothFlags<[]>> {
BothFlags suffix = BothFlags<[]>,
list<string> flag_prefix = ["-"]> {
defvar flag1 = FlagDefExpanded<ApplySuffix<flag1_base, suffix>.Result, prefix,
NAME, spelling_base>;

Expand All @@ -598,12 +599,12 @@ multiclass BoolOptionWithoutMarshalling<string prefix = "", string spelling_base

defvar implied = !if(flag1.CanBeImplied, flag1, flag2);

def flag1.RecordName : Flag<["-"], flag1.Spelling>, Flags<flag1.OptionFlags>,
def flag1.RecordName : Flag<flag_prefix, flag1.Spelling>, Flags<flag1.OptionFlags>,
Visibility<flag1.OptionVisibility>,
HelpText<flag1.Help>,
ImpliedByAnyOf<implied.ImpliedBy, implied.ValueAsCode>
{}
def flag2.RecordName : Flag<["-"], flag2.Spelling>, Flags<flag2.OptionFlags>,
def flag2.RecordName : Flag<flag_prefix, flag2.Spelling>, Flags<flag2.OptionFlags>,
Visibility<flag2.OptionVisibility>,
HelpText<flag2.Help>,
ImpliedByAnyOf<implied.ImpliedBy, implied.ValueAsCode>
Expand Down Expand Up @@ -5742,12 +5743,17 @@ def nobuiltininc : Flag<["-"], "nobuiltininc">,
Group<IncludePath_Group>,
HelpText<"Disable builtin #include directories only">,
MarshallingInfoNegativeFlag<HeaderSearchOpts<"UseBuiltinIncludes">>;
def nogpuinc : Flag<["-"], "nogpuinc">, Group<IncludePath_Group>,
HelpText<"Do not add include paths for CUDA/HIP and"
" do not include the default CUDA/HIP wrapper headers">;
defm offload_inc: BoolOptionWithoutMarshalling<"", "offload-inc",
PosFlag<SetTrue, [], [ClangOption], "Add include paths for CUDA/HIP and"
" include the default CUDA/HIP wrapper headers (default)">,
NegFlag<SetFalse, [], [ClangOption], "Do not add include paths for CUDA/HIP"
" and include the default CUDA/HIP wrapper headers">,
BothFlags<[]>, ["--"]>, Group<IncludePath_Group>;
def : Flag<["-"], "nogpuinc">, Alias<no_offload_inc>;

def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group<IncludePath_Group>,
HelpText<"Do not include the default HIP wrapper headers and include paths">;
def : Flag<["-"], "nocudainc">, Alias<nogpuinc>;
def : Flag<["-"], "nocudainc">, Alias<no_offload_inc>;
def no_offloadlib
: Flag<["--"], "no-offloadlib">,
MarshallingInfoFlag<LangOpts<"NoGPULib">>,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ void RocmInstallationDetector::AddHIPIncludeArgs(const ArgList &DriverArgs,
"hipstdpar_lib.hpp"});
};

if (DriverArgs.hasArg(options::OPT_nogpuinc)) {
if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
true)) {
if (HasHipStdPar)
HandleHipStdPar();

Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
// openmp_wrappers folder which contains alternative system headers.
if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&
!Args.hasArg(options::OPT_nostdinc) &&
!Args.hasArg(options::OPT_nogpuinc) &&
Args.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
true) &&
getToolChain().getTriple().isGPU()) {
if (!Args.hasArg(options::OPT_nobuiltininc)) {
// Add openmp_wrappers/* to our system include path. This lets us wrap
Expand Down Expand Up @@ -1120,7 +1121,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
// TODO: This should be moved to `AddClangSystemIncludeArgs` by passing the
// OffloadKind as an argument.
if (!Args.hasArg(options::OPT_nostdinc) &&
!Args.hasArg(options::OPT_nogpuinc) &&
Args.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
true) &&
!Args.hasArg(options::OPT_nobuiltininc)) {
// Without an offloading language we will include these headers directly.
// Offloading languages will instead only use the declarations stored in
Expand Down
10 changes: 7 additions & 3 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ void CudaInstallationDetector::AddCudaIncludeArgs(
CC1Args.push_back(DriverArgs.MakeArgString(P));
}

if (DriverArgs.hasArg(options::OPT_nogpuinc))
if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
true))
return;

if (!isValid()) {
Expand Down Expand Up @@ -928,7 +929,8 @@ llvm::DenormalMode CudaToolChain::getDefaultDenormalModeForType(
void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Check our CUDA version if we're going to include the CUDA headers.
if (!DriverArgs.hasArg(options::OPT_nogpuinc) &&
if (DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
true) &&
!DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
assert(!Arch.empty() && "Must have an explicit GPU arch.");
Expand Down Expand Up @@ -1001,7 +1003,9 @@ void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);

if (!DriverArgs.hasArg(options::OPT_nogpuinc) && CudaInstallation.isValid())
if (DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
true) &&
CudaInstallation.isValid())
CC1Args.append(
{"-internal-isystem",
DriverArgs.MakeArgString(CudaInstallation.getIncludePath())});
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/HIPSPV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ void HIPSPVToolChain::AddIAMCUIncludeArgs(const ArgList &Args,

void HIPSPVToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nogpuinc))
if (!DriverArgs.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
true))
return;

StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/hip-include-path.hip
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// RUN: -std=c++11 --rocm-path=%S/Inputs/rocm -nogpuinc -nogpulib %s 2>&1 \
// RUN: | FileCheck -check-prefixes=COMMON,CLANG,NOHIP %s

// RUN: %clang -c -### --target=x86_64-unknown-linux-gnu --cuda-gpu-arch=gfx900 \
// RUN: -std=c++11 --rocm-path=%S/Inputs/rocm --no-offload-inc -nogpulib --offload-inc %s 2>&1 \
// RUN: | FileCheck -check-prefixes=COMMON,CLANG,HIP %s

// COMMON-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
// CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
// NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
Expand Down
Loading