[clang] Remove Linux search paths on Windows (PR #113628)
David Salinas via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 24 17:03:04 PDT 2024
https://github.com/david-salinas created https://github.com/llvm/llvm-project/pull/113628
Change-Id: Ia0b44eb1069fa631a6d5156cf5881c978e23b62d
>From 2bcd8608ca1e00893692f1d1f8b1734204abbd15 Mon Sep 17 00:00:00 2001
From: David Salinas <david.salinas at amd.com>
Date: Tue, 22 Oct 2024 18:58:47 +0000
Subject: [PATCH] Remove Linux search paths on Windows
Change-Id: Ia0b44eb1069fa631a6d5156cf5881c978e23b62d
---
clang/lib/Driver/Driver.cpp | 6 ++--
clang/lib/Driver/ToolChains/AMDGPU.cpp | 34 ++++++++++++++------
clang/lib/Driver/ToolChains/AMDGPU.h | 2 +-
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp | 2 +-
clang/lib/Driver/ToolChains/HIPAMD.cpp | 9 +++++-
clang/lib/Driver/ToolChains/MSVC.cpp | 5 +++
clang/lib/Driver/ToolChains/ROCm.h | 12 +++++++
clang/test/Driver/rocm-detect-linux.hip | 9 ++++++
clang/test/Driver/rocm-detect-windows.hip | 9 ++++++
9 files changed, 72 insertions(+), 16 deletions(-)
create mode 100644 clang/test/Driver/rocm-detect-linux.hip
create mode 100644 clang/test/Driver/rocm-detect-windows.hip
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9878a9dad78d40..2be0d04d1c5ddf 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6440,7 +6440,7 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
TC = std::make_unique<toolchains::NVPTXToolChain>(*this, Target, Args);
break;
case llvm::Triple::AMDHSA:
- TC = std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args);
+ TC = std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args, Target.isWindowsMSVCEnvironment());
break;
case llvm::Triple::AMDPAL:
case llvm::Triple::Mesa3D:
@@ -6582,8 +6582,8 @@ const ToolChain &Driver::getOffloadingDeviceToolChain(
TC = std::make_unique<toolchains::HIPAMDToolChain>(*this, Target,
HostTC, Args);
else if (Target.getArch() == llvm::Triple::spirv64 &&
- Target.getVendor() == llvm::Triple::UnknownVendor &&
- Target.getOS() == llvm::Triple::UnknownOS)
+ Target.getVendor() == llvm::Triple::UnknownVendor &&
+ Target.getOS() == llvm::Triple::UnknownOS)
TC = std::make_unique<toolchains::HIPSPVToolChain>(*this, Target,
HostTC, Args);
break;
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 2c85d21ebd738c..c6ff2717d9853b 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -306,15 +306,18 @@ RocmInstallationDetector::getInstallationPathCandidates() {
LatestVer = Ver;
}
}
+
+ if (!isHostWindows()) {
if (!LatestROCm.empty())
ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
/*StrictChecking=*/true);
- ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
- /*StrictChecking=*/true);
- ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
- /*StrictChecking=*/true);
-
+ ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
+ /*StrictChecking=*/true);
+ ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
+ /*StrictChecking=*/true);
+ }
+
DoPrintROCmSearchDirs();
return ROCmSearchDirs;
}
@@ -376,10 +379,15 @@ RocmInstallationDetector::RocmInstallationDetector(
.str();
}
- if (DetectHIPRuntime)
- detectHIPRuntime();
- if (DetectDeviceLib)
- detectDeviceLibrary();
+ // Windows needs to exclude linux style paths from the list of paths to search,
+ // so delay these detection functions until after the constructor
+ if (!isHostWindows() && !HostTriple.isWindowsMSVCEnvironment()) {
+ if (DetectHIPRuntime)
+ detectHIPRuntime();
+ if (DetectDeviceLib)
+ detectDeviceLibrary();
+ }
+
}
void RocmInstallationDetector::detectDeviceLibrary() {
@@ -835,8 +843,11 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList &DriverArgs,
/// ROCM Toolchain
ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
- const ArgList &Args)
+ const ArgList &Args, bool isHostTCMSVC)
: AMDGPUToolChain(D, Triple, Args) {
+ RocmInstallation->setHostWindows(isHostTCMSVC);
+ if (isHostTCMSVC)
+ RocmInstallation->init(true, false);
RocmInstallation->detectDeviceLibrary();
}
@@ -1048,6 +1059,9 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true);
bool Wave64 = isWave64(DriverArgs, Kind);
+ /* SALINASif (getTriple().isWindowsMSVCEnvironment())
+ RocmInstallation->init(true,true); */
+
return RocmInstallation->getCommonBitcodeLibs(
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index a9b4552a1f91a4..db08529f955168 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -135,7 +135,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
public:
ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
- const llvm::opt::ArgList &Args);
+ const llvm::opt::ArgList &Args, bool isHostTCMSVC);
void
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 3f0b3f2d86b3ed..892db0dbc776df 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -33,7 +33,7 @@ AMDGPUOpenMPToolChain::AMDGPUOpenMPToolChain(const Driver &D,
const llvm::Triple &Triple,
const ToolChain &HostTC,
const ArgList &Args)
- : ROCMToolChain(D, Triple, Args), HostTC(HostTC) {
+ : ROCMToolChain(D, Triple, Args, HostTC.getTriple().isWindowsMSVCEnvironment()), HostTC(HostTC) {
// Lookup binaries into the driver directory, this is used to
// discover the 'amdgpu-arch' executable.
getProgramPaths().push_back(getDriver().Dir);
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index bae05cc0bb7353..bea8e6e2df6406 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -213,7 +213,14 @@ void AMDGCN::Linker::ConstructJob(Compilation &C, const JobAction &JA,
HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const ArgList &Args)
- : ROCMToolChain(D, Triple, Args), HostTC(HostTC) {
+ : ROCMToolChain(D, Triple, Args, HostTC.getTriple().isWindowsMSVCEnvironment()),
+ HostTC(HostTC) {
+ if (HostTC.getTriple().isWindowsMSVCEnvironment()) {
+ RocmInstallation->setHostWindows(true);
+ RocmInstallation->init(true, false);
+ }
+
+
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index 80799d1e715f07..e149717fb101fa 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -425,6 +425,11 @@ MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
RocmInstallation(D, Triple, Args) {
+
+ // Tell the ROCm installation detector that Host is Windows before trying to find HIPRT or Device Libs
+ RocmInstallation->setHostWindows(true);
+ RocmInstallation->init();
+
getProgramPaths().push_back(getDriver().Dir);
std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
diff --git a/clang/lib/Driver/ToolChains/ROCm.h b/clang/lib/Driver/ToolChains/ROCm.h
index dceb0ab0366933..a8868ade1c3f14 100644
--- a/clang/lib/Driver/ToolChains/ROCm.h
+++ b/clang/lib/Driver/ToolChains/ROCm.h
@@ -80,6 +80,7 @@ class RocmInstallationDetector {
bool HasHIPStdParLibrary = false;
bool HasRocThrustLibrary = false;
bool HasRocPrimLibrary = false;
+ bool IsHostMSVC = false;
// Default version if not detected or specified.
const unsigned DefaultVersionMajor = 3;
@@ -193,6 +194,10 @@ class RocmInstallationDetector {
/// Check whether we detected a valid HIP STDPAR Acceleration library.
bool hasHIPStdParLibrary() const { return HasHIPStdParLibrary; }
+ /// Check whether the target triple is for Windows.
+ bool isHostWindows() const { return IsHostMSVC; }
+ void setHostWindows(bool val) { IsHostMSVC=val; }
+
/// Print information about the detected ROCm installation.
void print(raw_ostream &OS) const;
@@ -272,6 +277,13 @@ class RocmInstallationDetector {
return Loc->second;
}
+ void init(bool DetectHIPRuntime=true, bool DetectDeviceLib=false) {
+ if (DetectHIPRuntime)
+ detectHIPRuntime();
+ if (DetectDeviceLib)
+ detectDeviceLibrary();
+ }
+
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
diff --git a/clang/test/Driver/rocm-detect-linux.hip b/clang/test/Driver/rocm-detect-linux.hip
new file mode 100644
index 00000000000000..dc602f59ac15ec
--- /dev/null
+++ b/clang/test/Driver/rocm-detect-linux.hip
@@ -0,0 +1,9 @@
+// REQUIRES: system-linux
+
+// Test to ensure that on Windows, we do not include linux sesrch paths
+// RUN: %clang -### -nogpulib -nogpuinc \
+// RUN: --print-rocm-search-dirs %s 2>&1 \
+// RUN: | FileCheck %s --dump-input-context 100
+
+// CHECK: ROCm installation search path: {{/usr/local}}
+// CHECK: ROCm installation search path: {{/usr}}
diff --git a/clang/test/Driver/rocm-detect-windows.hip b/clang/test/Driver/rocm-detect-windows.hip
new file mode 100644
index 00000000000000..b9c76dfd27859b
--- /dev/null
+++ b/clang/test/Driver/rocm-detect-windows.hip
@@ -0,0 +1,9 @@
+// REQUIRES: system-windows
+
+// Test to ensure that on Windows, we do not include linux sesrch paths
+// RUN: %clang -### -nogpulib -nogpuinc \
+// RUN: --print-rocm-search-dirs %s 2>&1 \
+// RUN: | FileCheck %s --dump-input-context 100
+
+// CHECK-NOT: ROCm installation search path: {{/usr/local}}
+// CHECK-NOT: ROCm installation search path: {{/usr}}
\ No newline at end of file
More information about the cfe-commits
mailing list