Skip to content

Commit c869225

Browse files
author
David Salinas
committed
Remove Linux search paths on Windows
Change-Id: Ia0b44eb1069fa631a6d5156cf5881c978e23b62d
1 parent 7b9f988 commit c869225

File tree

11 files changed

+72
-22
lines changed

11 files changed

+72
-22
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6440,7 +6440,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
64406440
TC = std::make_unique<toolchains::NVPTXToolChain>(*this, Target, Args);
64416441
break;
64426442
case llvm::Triple::AMDHSA:
6443-
TC = std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args);
6443+
TC = std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args,
6444+
Target.isOSWindows());
64446445
break;
64456446
case llvm::Triple::AMDPAL:
64466447
case llvm::Triple::Mesa3D:

clang/lib/Driver/ToolChains/AMDGPU.cpp

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

313-
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
314-
/*StrictChecking=*/true);
315-
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
316-
/*StrictChecking=*/true);
310+
if (!isHostWindows()) {
311+
if (!LatestROCm.empty())
312+
ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
313+
/*StrictChecking=*/true);
317314

315+
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
316+
/*StrictChecking=*/true);
317+
ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
318+
/*StrictChecking=*/true);
319+
}
318320
DoPrintROCmSearchDirs();
319321
return ROCmSearchDirs;
320322
}
@@ -375,11 +377,6 @@ RocmInstallationDetector::RocmInstallationDetector(
375377
Twine(DefaultVersionMinor) + "." + VersionPatch)
376378
.str();
377379
}
378-
379-
if (DetectHIPRuntime)
380-
detectHIPRuntime();
381-
if (DetectDeviceLib)
382-
detectDeviceLibrary();
383380
}
384381

385382
void RocmInstallationDetector::detectDeviceLibrary() {
@@ -699,10 +696,12 @@ void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
699696

700697
/// AMDGPU Toolchain
701698
AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
702-
const ArgList &Args)
699+
const ArgList &Args, bool isHostTCMSVC)
703700
: Generic_ELF(D, Triple, Args),
704701
OptionsDefault(
705702
{{options::OPT_O, "3"}, {options::OPT_cl_std_EQ, "CL1.2"}}) {
703+
if (!isHostTCMSVC)
704+
RocmInstallation->init();
706705
// Check code object version options. Emit warnings for legacy options
707706
// and errors for the last invalid code object version options.
708707
// It is done here to avoid repeated warning or error messages for
@@ -835,8 +834,11 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList &DriverArgs,
835834

836835
/// ROCM Toolchain
837836
ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
838-
const ArgList &Args)
839-
: AMDGPUToolChain(D, Triple, Args) {
837+
const ArgList &Args, bool isHostTCMSVC)
838+
: AMDGPUToolChain(D, Triple, Args, isHostTCMSVC) {
839+
RocmInstallation->setHostWindows(isHostTCMSVC);
840+
if (isHostTCMSVC)
841+
RocmInstallation->init(true, false);
840842
RocmInstallation->detectDeviceLibrary();
841843
}
842844

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
5959

6060
public:
6161
AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
62-
const llvm::opt::ArgList &Args);
62+
const llvm::opt::ArgList &Args, bool isHostTCMSVC = false);
6363
unsigned GetDefaultDwarfVersion() const override { return 5; }
6464

6565
bool IsMathErrnoDefault() const override { return false; }
@@ -135,7 +135,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
135135
class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
136136
public:
137137
ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
138-
const llvm::opt::ArgList &Args);
138+
const llvm::opt::ArgList &Args, bool isHostTCMSVC);
139139
void
140140
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
141141
llvm::opt::ArgStringList &CC1Args,

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ AMDGPUOpenMPToolChain::AMDGPUOpenMPToolChain(const Driver &D,
3333
const llvm::Triple &Triple,
3434
const ToolChain &HostTC,
3535
const ArgList &Args)
36-
: ROCMToolChain(D, Triple, Args), HostTC(HostTC) {
36+
: ROCMToolChain(D, Triple, Args, HostTC.getTriple().isOSWindows()),
37+
HostTC(HostTC) {
3738
// Lookup binaries into the driver directory, this is used to
3839
// discover the 'amdgpu-arch' executable.
3940
getProgramPaths().push_back(getDriver().Dir);

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,9 @@ Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
30603060
: ToolChain(D, Triple, Args), GCCInstallation(D),
30613061
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {
30623062
getProgramPaths().push_back(getDriver().Dir);
3063+
llvm::Triple TargetTriple(D.getTargetTriple());
3064+
if (!TargetTriple.isOSWindows())
3065+
RocmInstallation->init();
30633066
}
30643067

30653068
Generic_GCC::~Generic_GCC() {}

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,14 @@ void AMDGCN::Linker::ConstructJob(Compilation &C, const JobAction &JA,
213213

214214
HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
215215
const ToolChain &HostTC, const ArgList &Args)
216-
: ROCMToolChain(D, Triple, Args), HostTC(HostTC) {
216+
: ROCMToolChain(D, Triple, Args, HostTC.getTriple().isOSWindows()),
217+
HostTC(HostTC) {
218+
if (HostTC.getTriple().isWindowsMSVCEnvironment()) {
219+
RocmInstallation->setHostWindows(true);
220+
}
221+
222+
RocmInstallation->init(true, false);
223+
217224
// Lookup binaries into the driver directory, this is used to
218225
// discover the clang-offload-bundler executable.
219226
getProgramPaths().push_back(getDriver().Dir);

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
425425
const ArgList &Args)
426426
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
427427
RocmInstallation(D, Triple, Args) {
428+
429+
// Tell the ROCm installation detector that Host is Windows before trying to
430+
// find HIPRT or Device Libs
431+
RocmInstallation->setHostWindows(true);
432+
RocmInstallation->init();
433+
428434
getProgramPaths().push_back(getDriver().Dir);
429435

430436
std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;

clang/lib/Driver/ToolChains/ROCm.h

Lines changed: 12 additions & 0 deletions
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;
@@ -193,6 +194,10 @@ class RocmInstallationDetector {
193194
/// Check whether we detected a valid HIP STDPAR Acceleration library.
194195
bool hasHIPStdParLibrary() const { return HasHIPStdParLibrary; }
195196

197+
/// Check whether the target triple is for Windows.
198+
bool isHostWindows() const { return IsHostMSVC; }
199+
void setHostWindows(bool val) { IsHostMSVC = val; }
200+
196201
/// Print information about the detected ROCm installation.
197202
void print(raw_ostream &OS) const;
198203

@@ -272,6 +277,13 @@ class RocmInstallationDetector {
272277
return Loc->second;
273278
}
274279

280+
void init(bool DetectHIPRuntime = true, bool DetectDeviceLib = false) {
281+
if (DetectHIPRuntime)
282+
detectHIPRuntime();
283+
if (DetectDeviceLib)
284+
detectDeviceLibrary();
285+
}
286+
275287
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
276288
llvm::opt::ArgStringList &CC1Args) const;
277289

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// REQUIRES: target={{.*-linux.*}}
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: ROCm installation search path: {{/usr/local}}
9+
// CHECK: ROCm installation search path: {{/usr}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// REQUIRES: target={{.*-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)