Skip to content

Commit 5c29313

Browse files
committed
Reland "Revert "[HIP][Clang][Driver] Move BC preference logic into ROCm detection (llvm#149294)""
1 parent dc6f622 commit 5c29313

File tree

3 files changed

+14
-41
lines changed

3 files changed

+14
-41
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -720,46 +720,21 @@ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12>
720720
amdgpu::dlr::getCommonDeviceLibNames(
721721
const llvm::opt::ArgList &DriverArgs, const SanitizerArgs &SanArgs,
722722
const Driver &D, const std::string &GPUArch, bool isOpenMP,
723-
const RocmInstallationDetector &RocmInstallation) {
723+
const RocmInstallationDetector &RocmInstallation,
724+
const clang::driver::Action::OffloadKind DeviceOffloadingKind) {
724725
auto Kind = llvm::AMDGPU::parseArchAMDGCN(GPUArch);
725726
const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
726727

727728
StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
728729
auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
729730
getAMDGPUCodeObjectVersion(D, DriverArgs));
730-
bool noGPULib = DriverArgs.hasArg(options::OPT_offloadlib);
731-
if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile, ABIVer,
732-
noGPULib))
731+
if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
732+
ABIVer))
733733
return {};
734-
735-
// If --hip-device-lib is not set, add the default bitcode libraries.
736-
// TODO: There are way too many flags that change this. Do we need to check
737-
// them all?
738-
bool DAZ = DriverArgs.hasFlag(
739-
options::OPT_fgpu_flush_denormals_to_zero,
740-
options::OPT_fno_gpu_flush_denormals_to_zero,
741-
toolchains::AMDGPUToolChain::getDefaultDenormsAreZeroForTarget(Kind));
742-
bool FiniteOnly = DriverArgs.hasFlag(
743-
options::OPT_ffinite_math_only, options::OPT_fno_finite_math_only, false);
744-
bool UnsafeMathOpt =
745-
DriverArgs.hasFlag(options::OPT_funsafe_math_optimizations,
746-
options::OPT_fno_unsafe_math_optimizations, false);
747-
bool FastRelaxedMath = DriverArgs.hasFlag(options::OPT_ffast_math,
748-
options::OPT_fno_fast_math, false);
749-
bool CorrectSqrt = DriverArgs.hasFlag(
750-
options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
751-
options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true);
752-
bool Wave64 = toolchains::AMDGPUToolChain::isWave64(DriverArgs, Kind);
753-
754-
// GPU Sanitizer currently only supports ASan and is enabled through host
755-
// ASan.
756-
bool GPUSan = DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
757-
options::OPT_fno_gpu_sanitize, true) &&
758-
SanArgs.needsAsanRt();
759-
734+
760735
return RocmInstallation.getCommonBitcodeLibs(
761-
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
762-
FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, isOpenMP);
736+
DriverArgs, LibDeviceFile, GPUArch, DeviceOffloadingKind,
737+
SanArgs.needsAsanRt());
763738
}
764739

765740
/// AMDGPU Toolchain
@@ -1001,9 +976,8 @@ void ROCMToolChain::addClangTargetOptions(
1001976
StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
1002977
auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
1003978
getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
1004-
bool noGPULib = DriverArgs.hasArg(options::OPT_offloadlib);
1005979
if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
1006-
ABIVer, noGPULib))
980+
ABIVer))
1007981
return;
1008982

1009983
// Add the OpenCL specific bitcode library.
@@ -1026,15 +1000,13 @@ void ROCMToolChain::addClangTargetOptions(
10261000

10271001
bool RocmInstallationDetector::checkCommonBitcodeLibs(
10281002
StringRef GPUArch, StringRef LibDeviceFile,
1029-
DeviceLibABIVersion ABIVer, bool noGPULib) const {
1003+
DeviceLibABIVersion ABIVer) const {
10301004
if (!hasDeviceLibrary()) {
1031-
if (!noGPULib)
1032-
D.Diag(diag::err_drv_no_rocm_device_lib) << 0;
1005+
D.Diag(diag::err_drv_no_rocm_device_lib) << 0;
10331006
return false;
10341007
}
10351008
if (LibDeviceFile.empty()) {
1036-
if (!noGPULib)
1037-
D.Diag(diag::err_drv_no_rocm_device_lib) << 1 << GPUArch;
1009+
D.Diag(diag::err_drv_no_rocm_device_lib) << 1 << GPUArch;
10381010
return false;
10391011
}
10401012
if (ABIVer.requiresLibrary() && getABIVersionPath(ABIVer).empty()) {

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12>
4747
getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
4848
const SanitizerArgs &SanArgs, const Driver &D,
4949
const std::string &GPUArch, bool isOpenMP,
50-
const RocmInstallationDetector &RocmInstallation);
50+
const RocmInstallationDetector &RocmInstallation,
51+
const clang::driver::Action::OffloadKind DeviceOffloadingKind = Action::OFK_OpenMP);
5152

5253
const char *
5354
getCbslCommandArgs(Compilation &C, const llvm::opt::ArgList &Args,

clang/lib/Driver/ToolChains/ROCm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class RocmInstallationDetector {
203203
/// Check file paths of default bitcode libraries common to AMDGPU based
204204
/// toolchains. \returns false if there are invalid or missing files.
205205
bool checkCommonBitcodeLibs(StringRef GPUArch, StringRef LibDeviceFile,
206-
DeviceLibABIVersion ABIVer, bool noGPULib) const;
206+
DeviceLibABIVersion ABIVer) const;
207207

208208
/// Check whether we detected a valid HIP runtime.
209209
bool hasHIPRuntime() const { return HasHIPRuntime; }

0 commit comments

Comments
 (0)