Skip to content

Commit b063e88

Browse files
jhuber6mahesh-attarde
authored andcommitted
[Clang][NFC] Move GPU include directory to proper place (llvm#160608)
Summary: This should be handled in the toolchain, not in the middle of clang.
1 parent d124e96 commit b063e88

File tree

11 files changed

+41
-35
lines changed

11 files changed

+41
-35
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,16 @@ void AMDGPUToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
882882
CC1Args.push_back("-Werror=atomic-alignment");
883883
}
884884

885+
void AMDGPUToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
886+
ArgStringList &CC1Args) const {
887+
if (DriverArgs.hasArg(options::OPT_nostdinc) ||
888+
DriverArgs.hasArg(options::OPT_nostdlibinc))
889+
return;
890+
891+
if (std::optional<std::string> Path = getStdlibIncludePath())
892+
addSystemInclude(DriverArgs, CC1Args, *Path);
893+
}
894+
885895
StringRef
886896
AMDGPUToolChain::getGPUArch(const llvm::opt::ArgList &DriverArgs) const {
887897
return getProcessorFromTargetID(

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
7979
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
8080
llvm::opt::ArgStringList &CC1Args,
8181
Action::OffloadKind DeviceOffloadKind) const override;
82+
void
83+
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
84+
llvm::opt::ArgStringList &CC1Args) const override;
8285

8386
/// Return whether denormals should be flushed, and treated as 0 by default
8487
/// for the subtarget.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,26 +1109,15 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11091109
if (!Args.hasArg(options::OPT_nostdinc) &&
11101110
Args.hasFlag(options::OPT_offload_inc, options::OPT_no_offload_inc,
11111111
true) &&
1112-
!Args.hasArg(options::OPT_nobuiltininc)) {
1113-
// Without an offloading language we will include these headers directly.
1114-
// Offloading languages will instead only use the declarations stored in
1115-
// the resource directory at clang/lib/Headers/llvm_libc_wrappers.
1116-
if (getToolChain().getTriple().isGPU() &&
1117-
C.getActiveOffloadKinds() == Action::OFK_None) {
1118-
SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
1119-
llvm::sys::path::append(P, "include");
1120-
llvm::sys::path::append(P, getToolChain().getTripleString());
1121-
CmdArgs.push_back("-internal-isystem");
1122-
CmdArgs.push_back(Args.MakeArgString(P));
1123-
} else if (C.getActiveOffloadKinds() == Action::OFK_OpenMP) {
1124-
// TODO: CUDA / HIP include their own headers for some common functions
1125-
// implemented here. We'll need to clean those up so they do not conflict.
1126-
SmallString<128> P(D.ResourceDir);
1127-
llvm::sys::path::append(P, "include");
1128-
llvm::sys::path::append(P, "llvm_libc_wrappers");
1129-
CmdArgs.push_back("-internal-isystem");
1130-
CmdArgs.push_back(Args.MakeArgString(P));
1131-
}
1112+
!Args.hasArg(options::OPT_nobuiltininc) &&
1113+
(C.getActiveOffloadKinds() == Action::OFK_OpenMP)) {
1114+
// TODO: CUDA / HIP include their own headers for some common functions
1115+
// implemented here. We'll need to clean those up so they do not conflict.
1116+
SmallString<128> P(D.ResourceDir);
1117+
llvm::sys::path::append(P, "include");
1118+
llvm::sys::path::append(P, "llvm_libc_wrappers");
1119+
CmdArgs.push_back("-internal-isystem");
1120+
CmdArgs.push_back(Args.MakeArgString(P));
11321121
}
11331122

11341123
// Add system include arguments for all targets but IAMCU.

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,16 @@ void NVPTXToolChain::addClangTargetOptions(
778778
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
779779
Action::OffloadKind DeviceOffloadingKind) const {}
780780

781+
void NVPTXToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
782+
ArgStringList &CC1Args) const {
783+
if (DriverArgs.hasArg(options::OPT_nostdinc) ||
784+
DriverArgs.hasArg(options::OPT_nostdlibinc))
785+
return;
786+
787+
if (std::optional<std::string> Path = getStdlibIncludePath())
788+
addSystemInclude(DriverArgs, CC1Args, *Path);
789+
}
790+
781791
bool NVPTXToolChain::supportsDebugInfoOption(const llvm::opt::Arg *A) const {
782792
const Option &O = A->getOption();
783793
return (O.matches(options::OPT_gN_Group) &&

clang/lib/Driver/ToolChains/Cuda.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class LLVM_LIBRARY_VISIBILITY NVPTXToolChain : public ToolChain {
9292
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
9393
llvm::opt::ArgStringList &CC1Args,
9494
Action::OffloadKind DeviceOffloadKind) const override;
95+
void
96+
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
97+
llvm::opt::ArgStringList &CC1Args) const override;
9598

9699
// Never try to use the integrated assembler with CUDA; always fork out to
97100
// ptxas.

clang/test/Driver/Inputs/basic_gpu_tree/bin/keep

Whitespace-only changes.

clang/test/Driver/Inputs/basic_gpu_tree/include/amdgcn-amd-amdhsa/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/basic_gpu_tree/include/nvptx64-nvidia-cuda/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/basic_gpu_tree/lib/amdgcn-amd-amdhsa/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/basic_gpu_tree/lib/nvptx64-nvidia-cuda/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)