Skip to content

Commit

Permalink
Fix regression due to test hip-version.hip
Browse files Browse the repository at this point in the history
Added RocmInstallationDetector to Darwin and MinGW.

Fixed duplicate ROCm detector in ROCm toolchain.
  • Loading branch information
yxsamliu committed Jul 11, 2020
1 parent 6e42a41 commit 5d2c3e0
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 9 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList &DriverArgs,
/// ROCM Toolchain
ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: AMDGPUToolChain(D, Triple, Args),
RocmInstallation(D, Triple, Args, /*DetectHIPRuntime=*/false,
/*DetectDeviceLib=*/true) {}
: AMDGPUToolChain(D, Triple, Args) {
RocmInstallation.detectDeviceLibrary();
}

void AMDGPUToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs,
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Driver/ToolChains/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
};

class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
protected:
RocmInstallationDetector RocmInstallation;

public:
ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
Expand Down
8 changes: 7 additions & 1 deletion clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
/// Darwin - Darwin tool chain for i386 and x86_64.
Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
: MachO(D, Triple, Args), TargetInitialized(false),
CudaInstallation(D, Triple, Args) {}
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {}

types::ID MachO::LookupTypeForExtension(StringRef Ext) const {
types::ID Ty = ToolChain::LookupTypeForExtension(Ext);
Expand Down Expand Up @@ -831,6 +831,11 @@ void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs,
CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
}

void Darwin::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
}

// This is just a MachO name translation routine and there's no
// way to join this into ARMTargetParser without breaking all
// other assumptions. Maybe MachO should consider standardising
Expand Down Expand Up @@ -2736,4 +2741,5 @@ SanitizerMask Darwin::getSupportedSanitizers() const {

void Darwin::printVerboseInfo(raw_ostream &OS) const {
CudaInstallation.print(OS);
RocmInstallation.print(OS);
}
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/Darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_DARWIN_H

#include "Cuda.h"
#include "ROCm.h"
#include "clang/Driver/DarwinSDKInfo.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
Expand Down Expand Up @@ -293,6 +294,7 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
mutable Optional<DarwinSDKInfo> SDKInfo;

CudaInstallationDetector CudaInstallation;
RocmInstallationDetector RocmInstallation;

private:
void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
Expand Down Expand Up @@ -475,6 +477,8 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {

void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;

bool UseObjCMixedDispatch() const override {
// This is only used with the non-fragile ABI and non-legacy dispatch.
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/FreeBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ void FreeBSD::AddCudaIncludeArgs(const ArgList &DriverArgs,
CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
}

void FreeBSD::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
}

Tool *FreeBSD::buildAssembler() const {
return new tools::freebsd::Assembler(*this);
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/FreeBSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
llvm::opt::ArgStringList &CmdArgs) const override;
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;

llvm::ExceptionHandling
GetExceptionModel(const llvm::opt::ArgList &Args) const override;
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Driver/ToolChains/HIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ HIPToolChain::HIPToolChain(const Driver &D, const llvm::Triple &Triple,
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
RocmInstallation.detectHIPRuntime();
}

void HIPToolChain::addClangTargetOptions(
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Driver/ToolChains/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ llvm::ErrorOr<std::string> toolchains::MinGW::findClangRelativeSysroot() {

toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args) {
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
RocmInstallation(D, Triple, Args) {
getProgramPaths().push_back(getDriver().getInstalledDir());

if (getDriver().SysRoot.size())
Expand Down Expand Up @@ -500,8 +501,14 @@ void toolchains::MinGW::AddCudaIncludeArgs(const ArgList &DriverArgs,
CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
}

void toolchains::MinGW::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
}

void toolchains::MinGW::printVerboseInfo(raw_ostream &OS) const {
CudaInstallation.print(OS);
RocmInstallation.print(OS);
}

// Include directories for various hosts:
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/MinGW.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "Cuda.h"
#include "Gnu.h"
#include "ROCm.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
#include "llvm/Support/ErrorOr.h"
Expand Down Expand Up @@ -81,6 +82,8 @@ class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {

void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;

void printVerboseInfo(raw_ostream &OS) const override;

Expand All @@ -91,6 +94,7 @@ class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {

private:
CudaInstallationDetector CudaInstallation;
RocmInstallationDetector RocmInstallation;

std::string Base;
std::string GccLibDir;
Expand Down
12 changes: 12 additions & 0 deletions clang/test/Driver/hip-version.hip
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
// RUN: %clang -v --rocm-path=%S/Inputs/rocm 2>&1 \
// RUN: | FileCheck -check-prefixes=FOUND %s

// RUN: %clang -v --rocm-path=%S/Inputs/rocm 2>&1 \
// RUN: -target amdgcn-amd-amdhsa \
// RUN: | FileCheck -check-prefixes=FOUND %s

// FOUND: Found HIP installation: {{.*Inputs.*rocm}}, version 3.6.20214-a2917cd

// When --rocm-path is set and .hipVersion is not found, use default version

// RUN: %clang -v --rocm-path=%S 2>&1 \
// RUN: | FileCheck -check-prefixes=DEFAULT %s

// RUN: %clang -v --rocm-path=%S 2>&1 \
// RUN: -target amdgcn-amd-amdhsa \
// RUN: | FileCheck -check-prefixes=DEFAULT %s

// DEFAULT: Found HIP installation: {{.*Driver}}, version 3.5.

// RUN: %clang -v --rocm-path=%S --hip-version=3.7.0 2>&1 \
// RUN: | FileCheck -check-prefixes=SPECIFIED %s

// RUN: %clang -v --rocm-path=%S --hip-version=3.7.0 2>&1 \
// RUN: -target amdgcn-amd-amdhsa \
// RUN: | FileCheck -check-prefixes=SPECIFIED %s

// SPECIFIED: Found HIP installation: {{.*Driver}}, version 3.7.0

// RUN: %clang -v --rocm-path=%S --hip-version=3.7 2>&1 \
Expand Down

0 comments on commit 5d2c3e0

Please sign in to comment.