Skip to content
Closed
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
24 changes: 14 additions & 10 deletions clang/lib/Driver/ToolChains/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,25 @@ RocmInstallationDetector::getInstallationPathCandidates() {
LatestVer = Ver;
}
}
if (!LatestROCm.empty())
ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
/*StrictChecking=*/true);
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;
}

RocmInstallationDetector::RocmInstallationDetector(
const Driver &D, const llvm::Triple &HostTriple,
const Driver &D, const llvm::Triple &TargetTriple,
const llvm::opt::ArgList &Args, bool DetectHIPRuntime, bool DetectDeviceLib)
: D(D) {
: D(D), TargetTriple(TargetTriple) {
Verbose = Args.hasArg(options::OPT_v);
RocmPathArg = Args.getLastArgValue(clang::driver::options::OPT_rocm_path_EQ);
PrintROCmSearchDirs =
Expand Down Expand Up @@ -835,8 +837,10 @@ 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);

RocmInstallation->detectDeviceLibrary();
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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=false);
void
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ 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) {
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/MSVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
RocmInstallation(D, Triple, Args) {

RocmInstallation->setHostWindows(true);

getProgramPaths().push_back(getDriver().Dir);

std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
Expand All @@ -450,6 +453,7 @@ MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
llvm::findVCToolChainViaSetupConfig(getVFS(), VCToolsVersion,
VCToolChainPath, VSLayout) ||
llvm::findVCToolChainViaRegistry(VCToolChainPath, VSLayout);

}

Tool *MSVCToolChain::buildLinker() const {
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Driver/ToolChains/ROCm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +112,8 @@ class RocmInstallationDetector {
// Wheter -nogpulib is specified.
bool NoBuiltinLibs = false;

llvm::Triple TargetTriple;

// Paths
SmallString<0> InstallPath;
SmallString<0> BinPath;
Expand Down Expand Up @@ -166,7 +169,7 @@ class RocmInstallationDetector {
StringRef PackageName);

public:
RocmInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
RocmInstallationDetector(const Driver &D, const llvm::Triple &TargetTriple,
const llvm::opt::ArgList &Args,
bool DetectHIPRuntime = true,
bool DetectDeviceLib = false);
Expand All @@ -193,6 +196,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;

Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/rocm-detect-windows.hip
Original file line number Diff line number Diff line change
@@ -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

// CHECK-NOT: ROCm installation search path: {{/usr/local}}
// CHECK-NOT: ROCm installation search path: {{/usr}}
Loading