Skip to content

Commit 803e393

Browse files
David Salinasdavid-salinas
authored andcommitted
Remove Linux path names in ROCm search paths on Windows
When target triple indicates we are on Windows, do not add linux paths to search path in ROCm Installation Detection. Change-Id: I18effb8c20252de3d84ea37ef562124695c5a570
1 parent 845dee3 commit 803e393

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,23 +306,25 @@ RocmInstallationDetector::getInstallationPathCandidates() {
306306
LatestVer = Ver;
307307
}
308308
}
309-
if (!LatestROCm.empty())
310-
ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
311-
/*StrictChecking=*/true);
309+
if (!isHostWindows()) {
310+
if (!LatestROCm.empty())
311+
ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
312+
/*StrictChecking=*/true);
312313

313-
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
314-
/*StrictChecking=*/true);
315-
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
316-
/*StrictChecking=*/true);
314+
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
315+
/*StrictChecking=*/true);
316+
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
317+
/*StrictChecking=*/true);
318+
}
317319

318320
DoPrintROCmSearchDirs();
319321
return ROCmSearchDirs;
320322
}
321323

322324
RocmInstallationDetector::RocmInstallationDetector(
323-
const Driver &D, const llvm::Triple &HostTriple,
325+
const Driver &D, const llvm::Triple &TargetTriple,
324326
const llvm::opt::ArgList &Args, bool DetectHIPRuntime, bool DetectDeviceLib)
325-
: D(D) {
327+
: D(D), TargetTriple(TargetTriple) {
326328
Verbose = Args.hasArg(options::OPT_v);
327329
RocmPathArg = Args.getLastArgValue(clang::driver::options::OPT_rocm_path_EQ);
328330
PrintROCmSearchDirs =
@@ -820,8 +822,10 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList &DriverArgs,
820822

821823
/// ROCM Toolchain
822824
ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
823-
const ArgList &Args)
825+
const ArgList &Args, bool isHostTCMSVC)
824826
: AMDGPUToolChain(D, Triple, Args) {
827+
RocmInstallation->setHostWindows(isHostTCMSVC);
828+
825829
RocmInstallation->detectDeviceLibrary();
826830
}
827831

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
129129
class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
130130
public:
131131
ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
132-
const llvm::opt::ArgList &Args);
132+
const llvm::opt::ArgList &Args, bool isHostTCMSVC=false);
133133
void
134134
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
135135
llvm::opt::ArgStringList &CC1Args,

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void AMDGCN::Linker::ConstructJob(Compilation &C, const JobAction &JA,
250250

251251
HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
252252
const ToolChain &HostTC, const ArgList &Args)
253-
: ROCMToolChain(D, Triple, Args), HostTC(HostTC) {
253+
: ROCMToolChain(D, Triple, Args, HostTC.getTriple().isWindowsMSVCEnvironment()), HostTC(HostTC) {
254254
// Lookup binaries into the driver directory, this is used to
255255
// discover the clang-offload-bundler executable.
256256
getProgramPaths().push_back(getDriver().Dir);

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
428428
const ArgList &Args)
429429
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
430430
RocmInstallation(D, Triple, Args) {
431+
432+
RocmInstallation->setHostWindows(true);
433+
431434
getProgramPaths().push_back(getDriver().Dir);
432435

433436
std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
@@ -453,6 +456,7 @@ MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
453456
llvm::findVCToolChainViaSetupConfig(getVFS(), VCToolsVersion,
454457
VCToolChainPath, VSLayout) ||
455458
llvm::findVCToolChainViaRegistry(VCToolChainPath, VSLayout);
459+
456460
}
457461

458462
Tool *MSVCToolChain::buildLinker() const {

clang/lib/Driver/ToolChains/ROCm.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class RocmInstallationDetector {
8080
bool HasHIPStdParLibrary = false;
8181
bool HasRocThrustLibrary = false;
8282
bool HasRocPrimLibrary = false;
83+
bool IsHostMSVC = false;
8384

8485
// Default version if not detected or specified.
8586
const unsigned DefaultVersionMajor = 3;
@@ -111,6 +112,8 @@ class RocmInstallationDetector {
111112
// Wheter -nogpulib is specified.
112113
bool NoBuiltinLibs = false;
113114

115+
llvm::Triple TargetTriple;
116+
114117
// Paths
115118
SmallString<0> InstallPath;
116119
SmallString<0> BinPath;
@@ -166,7 +169,7 @@ class RocmInstallationDetector {
166169
StringRef PackageName);
167170

168171
public:
169-
RocmInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
172+
RocmInstallationDetector(const Driver &D, const llvm::Triple &TargetTriple,
170173
const llvm::opt::ArgList &Args,
171174
bool DetectHIPRuntime = true,
172175
bool DetectDeviceLib = false);
@@ -193,6 +196,10 @@ class RocmInstallationDetector {
193196
/// Check whether we detected a valid HIP STDPAR Acceleration library.
194197
bool hasHIPStdParLibrary() const { return HasHIPStdParLibrary; }
195198

199+
/// Check whether the target triple is for Windows.
200+
bool isHostWindows() const { return IsHostMSVC; }
201+
void setHostWindows(bool val) { IsHostMSVC=val; }
202+
196203
/// Print information about the detected ROCm installation.
197204
void print(raw_ostream &OS) const;
198205

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// REQUIRES: system-windows
2+
3+
// Test to ensure that on Windows, we do not include linux sesrch paths
4+
// RUN: %clang -### -nogpulib -nogpuinc \
5+
// RUN: --print-rocm-search-dirs %s 2>&1 \
6+
// RUN: | FileCheck %s
7+
8+
// CHECK-NOT: ROCm installation search path: {{/usr/local}}
9+
// CHECK-NOT: ROCm installation search path: {{/usr}}

0 commit comments

Comments
 (0)