;
42RocmInstallationDetector::findSPACKPackage(
constCandidate &Cand,
43StringRef PackageName) {
47std::string Prefix = Twine(PackageName +
"-"+ Cand.SPACKReleaseStr).str();
49 for(llvm::vfs::directory_iterator
File= D.
getVFS().dir_begin(Cand.Path, EC),
51 File!= FileEnd && !EC;
File.increment(EC)) {
52llvm::StringRef
FileName= llvm::sys::path::filename(
File->path());
53 if(
FileName.starts_with(Prefix)) {
55 if(SubDirs.size() > 1)
59 if(SubDirs.size() == 1) {
60 autoPackagePath = Cand.Path;
61llvm::sys::path::append(PackagePath, SubDirs[0]);
64 if(SubDirs.size() == 0 && Verbose) {
65llvm::errs() <<
"SPACK package "<< Prefix <<
" not found at "<< Cand.Path
70 if(SubDirs.size() > 1 && Verbose) {
71llvm::errs() <<
"Cannot use SPACK package "<< Prefix <<
" at "<< Cand.Path
72<<
" due to multiple installations for the same version\n";
77voidRocmInstallationDetector::scanLibDevicePath(llvm::StringRef
Path) {
78assert(!
Path.empty());
80 constStringRef Suffix(
".bc");
81 constStringRef Suffix2(
".amdgcn.bc");
84 for(llvm::vfs::directory_iterator LI = D.
getVFS().dir_begin(
Path, EC), LE;
85!EC && LI != LE; LI = LI.increment(EC)) {
86StringRef FilePath = LI->path();
87StringRef
FileName= llvm::sys::path::filename(FilePath);
93BaseName =
FileName.drop_back(Suffix2.size());
94 else if(
FileName.ends_with(Suffix))
95BaseName =
FileName.drop_back(Suffix.size());
97 constStringRef ABIVersionPrefix =
"oclc_abi_version_";
98 if(BaseName ==
"ocml") {
100}
else if(BaseName ==
"ockl") {
102}
else if(BaseName ==
"opencl") {
104}
else if(BaseName ==
"hip") {
106}
else if(BaseName ==
"asanrtl") {
108}
else if(BaseName ==
"oclc_finite_only_off") {
109FiniteOnly.Off = FilePath;
110}
else if(BaseName ==
"oclc_finite_only_on") {
111FiniteOnly.On = FilePath;
112}
else if(BaseName ==
"oclc_daz_opt_on") {
113DenormalsAreZero.On = FilePath;
114}
else if(BaseName ==
"oclc_daz_opt_off") {
115DenormalsAreZero.Off = FilePath;
116}
else if(BaseName ==
"oclc_correctly_rounded_sqrt_on") {
117CorrectlyRoundedSqrt.On = FilePath;
118}
else if(BaseName ==
"oclc_correctly_rounded_sqrt_off") {
119CorrectlyRoundedSqrt.Off = FilePath;
120}
else if(BaseName ==
"oclc_unsafe_math_on") {
121UnsafeMath.On = FilePath;
122}
else if(BaseName ==
"oclc_unsafe_math_off") {
123UnsafeMath.Off = FilePath;
124}
else if(BaseName ==
"oclc_wavefrontsize64_on") {
125WavefrontSize64.On = FilePath;
126}
else if(BaseName ==
"oclc_wavefrontsize64_off") {
127WavefrontSize64.Off = FilePath;
128}
else if(BaseName.starts_with(ABIVersionPrefix)) {
129 unsignedABIVersionNumber;
130 if(BaseName.drop_front(ABIVersionPrefix.size())
131.getAsInteger(
0, ABIVersionNumber))
133ABIVersionMap[ABIVersionNumber] = FilePath.str();
137 constStringRef DeviceLibPrefix =
"oclc_isa_version_";
138 if(!BaseName.starts_with(DeviceLibPrefix))
141StringRef IsaVersionNumber =
142BaseName.drop_front(DeviceLibPrefix.size());
144llvm::Twine GfxName = Twine(
"gfx") + IsaVersionNumber;
147std::make_pair(GfxName.toStringRef(Tmp), FilePath.str()));
154boolRocmInstallationDetector::parseHIPVersionFile(llvm::StringRef
V) {
156 V.split(VersionParts,
'\n');
157 unsignedMajor = ~0
U;
158 unsignedMinor = ~0
U;
159 for(
autoPart : VersionParts) {
160 autoSplits = Part.rtrim().split(
'=');
161 if(Splits.first ==
"HIP_VERSION_MAJOR") {
162 if(Splits.second.getAsInteger(0, Major))
164}
else if(Splits.first ==
"HIP_VERSION_MINOR") {
165 if(Splits.second.getAsInteger(0, Minor))
167}
else if(Splits.first ==
"HIP_VERSION_PATCH")
168VersionPatch = Splits.second.str();
170 if(Major == ~0
U|| Minor == ~0
U)
172VersionMajorMinor = llvm::VersionTuple(Major, Minor);
174(Twine(Major) +
"."+ Twine(Minor) +
"."+ VersionPatch).str();
181RocmInstallationDetector::getInstallationPathCandidates() {
184 if(!ROCmSearchDirs.empty())
185 returnROCmSearchDirs;
187 autoDoPrintROCmSearchDirs = [&]() {
188 if(PrintROCmSearchDirs)
189 for(
autoCand : ROCmSearchDirs) {
190llvm::errs() <<
"ROCm installation search path";
192llvm::errs() <<
" (Spack "<< Cand.SPACKReleaseStr <<
")";
193llvm::errs() <<
": "<< Cand.Path <<
'\n';
199 if(!RocmPathArg.empty()) {
200ROCmSearchDirs.emplace_back(RocmPathArg.str());
201DoPrintROCmSearchDirs();
202 returnROCmSearchDirs;
203}
else if(std::optional<std::string> RocmPathEnv =
204llvm::sys::Process::GetEnv(
"ROCM_PATH")) {
205 if(!RocmPathEnv->empty()) {
206ROCmSearchDirs.emplace_back(std::move(*RocmPathEnv));
207DoPrintROCmSearchDirs();
208 returnROCmSearchDirs;
213StringRef InstallDir = D.
Dir;
218 autoDeduceROCmPath = [](StringRef ClangPath) {
220StringRef ParentDir = llvm::sys::path::parent_path(ClangPath);
221StringRef ParentName = llvm::sys::path::filename(ParentDir);
224 if(ParentName ==
"bin") {
225ParentDir = llvm::sys::path::parent_path(ParentDir);
226ParentName = llvm::sys::path::filename(ParentDir);
234 if(ParentName.starts_with(
"llvm-amdgpu-")) {
236ParentName.drop_front(strlen(
"llvm-amdgpu-")).split(
'-');
237 autoSPACKReleaseStr = SPACKPostfix.first;
238 if(!SPACKReleaseStr.empty()) {
239ParentDir = llvm::sys::path::parent_path(ParentDir);
240 returnCandidate(ParentDir.str(),
true,
247 if(ParentName ==
"llvm"|| ParentName.starts_with(
"aomp"))
248ParentDir = llvm::sys::path::parent_path(ParentDir);
250 returnCandidate(ParentDir.str(),
true);
255ROCmSearchDirs.emplace_back(DeduceROCmPath(InstallDir));
261 autoParentPath = llvm::sys::path::parent_path(RealClangPath);
262 if(ParentPath != InstallDir)
263ROCmSearchDirs.emplace_back(DeduceROCmPath(ParentPath));
266 autoClangRoot = llvm::sys::path::parent_path(InstallDir);
267 autoRealClangRoot = llvm::sys::path::parent_path(ParentPath);
268ROCmSearchDirs.emplace_back(ClangRoot.str(),
true);
269 if(RealClangRoot != ClangRoot)
270ROCmSearchDirs.emplace_back(RealClangRoot.str(),
true);
274ROCmSearchDirs.emplace_back(D.
SysRoot+
"/opt/rocm",
279std::string LatestROCm;
280llvm::VersionTuple LatestVer;
282 autoGetROCmVersion = [](StringRef DirName) {
283llvm::VersionTuple
V;
284std::string VerStr = DirName.drop_front(strlen(
"rocm-")).str();
287std::replace(VerStr.begin(), VerStr.end(),
'-',
'.');
291 for(llvm::vfs::directory_iterator
294 File!= FileEnd && !EC;
File.increment(EC)) {
295llvm::StringRef
FileName= llvm::sys::path::filename(
File->path());
296 if(!
FileName.starts_with(
"rocm-"))
298 if(LatestROCm.empty()) {
300LatestVer = GetROCmVersion(LatestROCm);
303 autoVer = GetROCmVersion(
FileName);
304 if(LatestVer < Ver) {
309 if(!LatestROCm.empty())
310ROCmSearchDirs.emplace_back(D.
SysRoot+
"/opt/"+ LatestROCm,
313ROCmSearchDirs.emplace_back(D.
SysRoot+
"/usr/local",
315ROCmSearchDirs.emplace_back(D.
SysRoot+
"/usr",
318DoPrintROCmSearchDirs();
319 returnROCmSearchDirs;
323 const Driver&
D,
constllvm::Triple &HostTriple,
324 constllvm::opt::ArgList &Args,
boolDetectHIPRuntime,
boolDetectDeviceLib)
326Verbose = Args.hasArg(options::OPT_v);
327RocmPathArg = Args.getLastArgValue(clang::driver::options::OPT_rocm_path_EQ);
328PrintROCmSearchDirs =
329Args.hasArg(clang::driver::options::OPT_print_rocm_search_dirs);
330RocmDeviceLibPathArg =
331Args.getAllArgValues(clang::driver::options::OPT_rocm_device_lib_path_EQ);
332HIPPathArg = Args.getLastArgValue(clang::driver::options::OPT_hip_path_EQ);
334Args.getLastArgValue(clang::driver::options::OPT_hipstdpar_path_EQ);
335HasHIPStdParLibrary =
336!HIPStdParPathArg.empty() &&
D.getVFS().exists(HIPStdParPathArg +
337 "/hipstdpar_lib.hpp");
338HIPRocThrustPathArg =
339Args.getLastArgValue(clang::driver::options::OPT_hipstdpar_thrust_path_EQ);
340HasRocThrustLibrary = !HIPRocThrustPathArg.empty() &&
341 D.getVFS().exists(HIPRocThrustPathArg +
"/thrust");
343Args.getLastArgValue(clang::driver::options::OPT_hipstdpar_prim_path_EQ);
344HasRocPrimLibrary = !HIPRocPrimPathArg.empty() &&
345 D.getVFS().exists(HIPRocPrimPathArg +
"/rocprim");
347 if(
auto*A = Args.getLastArg(clang::driver::options::OPT_hip_version_EQ)) {
348HIPVersionArg = A->getValue();
349 unsignedMajor = ~0
U;
350 unsignedMinor = ~0
U;
352HIPVersionArg.split(Parts,
'.');
354Parts[0].getAsInteger(0, Major);
355 if(Parts.size() > 1)
356Parts[1].getAsInteger(0, Minor);
357 if(Parts.size() > 2)
358VersionPatch = Parts[2].str();
359 if(VersionPatch.empty())
361 if(Major != ~0
U&& Minor == ~0
U)
363 if(Major == ~0
U|| Minor == ~0
U)
364 D.Diag(diag::err_drv_invalid_value)
365<< A->getAsString(Args) << HIPVersionArg;
367VersionMajorMinor = llvm::VersionTuple(Major, Minor);
369(Twine(Major) +
"."+ Twine(Minor) +
"."+ VersionPatch).str();
371VersionPatch = DefaultVersionPatch;
373llvm::VersionTuple(DefaultVersionMajor, DefaultVersionMinor);
374DetectedVersion = (Twine(DefaultVersionMajor) +
"."+
375Twine(DefaultVersionMinor) +
"."+ VersionPatch)
379 if(DetectHIPRuntime)
386assert(LibDevicePath.empty());
388 if(!RocmDeviceLibPathArg.empty())
389LibDevicePath = RocmDeviceLibPathArg[RocmDeviceLibPathArg.size() - 1];
390 else if(std::optional<std::string> LibPathEnv =
391llvm::sys::Process::GetEnv(
"HIP_DEVICE_LIB_PATH"))
392LibDevicePath = std::move(*LibPathEnv);
395 if(!LibDevicePath.empty()) {
399 if(!FS.exists(LibDevicePath))
402scanLibDevicePath(LibDevicePath);
403HasDeviceLibrary = allGenericLibsValid() && !LibDeviceMap.empty();
408 autoCheckDeviceLib = [&](StringRef
Path,
boolStrictChecking) {
409 boolCheckLibDevice = (!NoBuiltinLibs || StrictChecking);
410 if(CheckLibDevice && !FS.exists(
Path))
413scanLibDevicePath(
Path);
415 if(!NoBuiltinLibs) {
417 if(!allGenericLibsValid())
422 if(LibDeviceMap.empty())
430llvm::sys::path::append(LibDevicePath, CLANG_INSTALL_LIBDIR_BASENAME,
431 "amdgcn",
"bitcode");
432HasDeviceLibrary = CheckDeviceLib(LibDevicePath,
true);
433 if(HasDeviceLibrary)
438 auto&ROCmDirs = getInstallationPathCandidates();
439 for(
const auto&Candidate : ROCmDirs) {
440LibDevicePath = Candidate.Path;
441llvm::sys::path::append(LibDevicePath,
"amdgcn",
"bitcode");
442HasDeviceLibrary = CheckDeviceLib(LibDevicePath, Candidate.StrictChecking);
443 if(HasDeviceLibrary)
450 if(!HIPPathArg.empty())
451HIPSearchDirs.emplace_back(HIPPathArg.str());
452 else if(std::optional<std::string> HIPPathEnv =
453llvm::sys::Process::GetEnv(
"HIP_PATH")) {
454 if(!HIPPathEnv->empty())
455HIPSearchDirs.emplace_back(std::move(*HIPPathEnv));
457 if(HIPSearchDirs.empty())
458HIPSearchDirs.append(getInstallationPathCandidates());
461 for(
const auto&Candidate : HIPSearchDirs) {
462InstallPath = Candidate.Path;
463 if(InstallPath.empty() || !FS.exists(InstallPath))
467 autoSPACKPath = findSPACKPackage(Candidate,
"hip");
468InstallPath = SPACKPath.empty() ? InstallPath : SPACKPath;
470BinPath = InstallPath;
471llvm::sys::path::append(BinPath,
"bin");
472IncludePath = InstallPath;
473llvm::sys::path::append(IncludePath,
"include");
474LibPath = InstallPath;
475llvm::sys::path::append(LibPath,
"lib");
476SharePath = InstallPath;
477llvm::sys::path::append(SharePath,
"share");
480 SmallString<0>ParentSharePath = llvm::sys::path::parent_path(InstallPath);
481llvm::sys::path::append(ParentSharePath,
"share");
484 constTwine &
c=
"",
constTwine &d =
"") {
486llvm::sys::path::append(newpath, a,
b,
c, d);
490std::vector<SmallString<0>> VersionFilePaths = {
491 Append(SharePath,
"hip",
"version"),
492InstallPath != D.
SysRoot+
"/usr/local" 493?
Append(ParentSharePath,
"hip",
"version")
495 Append(BinPath,
".hipVersion")};
497 for(
const auto&VersionFilePath : VersionFilePaths) {
498 if(VersionFilePath.empty())
500llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
501FS.getBufferForFile(VersionFilePath);
504 if(HIPVersionArg.empty() && VersionFile)
505 if(parseHIPVersionFile((*VersionFile)->getBuffer()))
508HasHIPRuntime =
true;
513 if(!Candidate.StrictChecking) {
514HasHIPRuntime =
true;
518HasHIPRuntime =
false;
523OS <<
"Found HIP installation: "<< InstallPath <<
", version " 524<< DetectedVersion <<
'\n';
528ArgStringList &CC1Args)
const{
529 boolUsesRuntimeWrapper = VersionMajorMinor > llvm::VersionTuple(3, 5) &&
530!DriverArgs.hasArg(options::OPT_nohipwrapperinc);
531 boolHasHipStdPar = DriverArgs.hasArg(options::OPT_hipstdpar);
533 if(!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
548 if(UsesRuntimeWrapper)
549llvm::sys::path::append(
P,
"include",
"cuda_wrappers");
550CC1Args.push_back(
"-internal-isystem");
551CC1Args.push_back(DriverArgs.MakeArgString(
P));
554 const autoHandleHipStdPar = [=, &DriverArgs, &CC1Args]() {
559 if(!HIPStdParPathArg.empty() ||
560!FS.exists(Inc +
"/thrust/system/hip/hipstdpar/hipstdpar_lib.hpp")) {
561D.
Diag(diag::err_drv_no_hipstdpar_lib);
564 if(!HasRocThrustLibrary && !FS.exists(Inc +
"/thrust")) {
565D.
Diag(diag::err_drv_no_hipstdpar_thrust_lib);
568 if(!HasRocPrimLibrary && !FS.exists(Inc +
"/rocprim")) {
569D.
Diag(diag::err_drv_no_hipstdpar_prim_lib);
572 const char*ThrustPath;
573 if(HasRocThrustLibrary)
574ThrustPath = DriverArgs.MakeArgString(HIPRocThrustPathArg);
576ThrustPath = DriverArgs.MakeArgString(Inc +
"/thrust");
578 const char*HIPStdParPath;
580HIPStdParPath = DriverArgs.MakeArgString(HIPStdParPathArg);
582HIPStdParPath = DriverArgs.MakeArgString(StringRef(ThrustPath) +
583 "/system/hip/hipstdpar");
585 const char*PrimPath;
586 if(HasRocPrimLibrary)
587PrimPath = DriverArgs.MakeArgString(HIPRocPrimPathArg);
589PrimPath = DriverArgs.MakeArgString(
getIncludePath() +
"/rocprim");
591CC1Args.append({
"-idirafter", ThrustPath,
"-idirafter", PrimPath,
592 "-idirafter", HIPStdParPath,
"-include",
593 "hipstdpar_lib.hpp"});
596 if(DriverArgs.hasArg(options::OPT_nogpuinc)) {
604D.
Diag(diag::err_drv_no_hip_runtime);
608CC1Args.push_back(
"-idirafter");
610 if(UsesRuntimeWrapper)
611CC1Args.append({
"-include",
"__clang_hip_runtime_wrapper.h"});
620 const char*LinkingOutput)
const{
621std::string
Linker= getToolChain().GetLinkerPath();
622ArgStringList CmdArgs;
623 if(!Args.hasArg(options::OPT_r)) {
624CmdArgs.push_back(
"--no-undefined");
625CmdArgs.push_back(
"-shared");
629Args.AddAllArgs(CmdArgs, options::OPT_L);
630getToolChain().AddFilePathLibArgs(Args, CmdArgs);
632 if(
C.getDriver().isUsingLTO()) {
633 addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
635}
else if(Args.hasArg(options::OPT_mcpu_EQ)) {
636CmdArgs.push_back(Args.MakeArgString(
637 "-plugin-opt=mcpu="+
639Args.getLastArgValue(options::OPT_mcpu_EQ))));
643std::vector<StringRef> Features;
646 if(!Features.empty()) {
648Args.MakeArgString(
"-plugin-opt=-mattr="+ llvm::join(Features,
",")));
651 if(Args.hasArg(options::OPT_stdlib))
652CmdArgs.append({
"-lc",
"-lm"});
653 if(Args.hasArg(options::OPT_startfiles)) {
654std::optional<std::string> IncludePath = getToolChain().getStdlibPath();
656IncludePath =
"/lib";
658llvm::sys::path::append(
P,
"crt1.o");
659CmdArgs.push_back(Args.MakeArgString(
P));
662CmdArgs.push_back(
"-o");
664 C.addCommand(std::make_unique<Command>(
666CmdArgs, Inputs, Output));
670 constllvm::Triple &Triple,
671 constllvm::opt::ArgList &Args,
672std::vector<StringRef> &Features) {
676 if(Args.hasArg(options::OPT_mcpu_EQ))
677TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ);
678 else if(Args.hasArg(options::OPT_march_EQ))
679TargetID = Args.getLastArgValue(options::OPT_march_EQ);
680 if(!TargetID.empty()) {
681llvm::StringMap<bool> FeatureMap;
682 autoOptionalGpuArch =
parseTargetID(Triple, TargetID, &FeatureMap);
683 if(OptionalGpuArch) {
684StringRef GpuArch = *OptionalGpuArch;
690 autoPos = FeatureMap.find(Feature);
691 if(Pos == FeatureMap.end())
693Features.push_back(Args.MakeArgStringRef(
694(Twine(Pos->second ?
"+":
"-") + Feature).str()));
699 if(Args.hasFlag(options::OPT_mwavefrontsize64,
700options::OPT_mno_wavefrontsize64,
false))
701Features.push_back(
"+wavefrontsize64");
703 if(Args.hasFlag(options::OPT_mamdgpu_precise_memory_op,
704options::OPT_mno_amdgpu_precise_memory_op,
false))
705Features.push_back(
"+precise-memory");
708options::OPT_m_amdgpu_Features_Group);
716{{options::OPT_O,
"3"}, {options::OPT_cl_std_EQ,
"CL1.2"}}) {
732DerivedArgList *DAL =
738DAL =
newDerivedArgList(Args.getBaseArgs());
744Arg *LastMCPUArg = DAL->getLastArg(options::OPT_mcpu_EQ);
745 if(LastMCPUArg && StringRef(LastMCPUArg->getValue()) ==
"native") {
746DAL->eraseArg(options::OPT_mcpu_EQ);
750<< llvm::Triple::getArchTypeName(
getArch())
751<< llvm::toString(GPUsOrErr.takeError()) <<
"-mcpu";
753 auto&GPUs = *GPUsOrErr;
754 if(GPUs.size() > 1) {
756<< llvm::Triple::getArchTypeName(
getArch())
757<< llvm::join(GPUs,
", ") <<
"-mcpu";
759DAL->AddJoinedArg(
nullptr, Opts.getOption(options::OPT_mcpu_EQ),
760Args.MakeArgString(GPUs.front()));
766 if(Args.getLastArgValue(options::OPT_x) !=
"cl")
770 if(Args.hasArg(options::OPT_c) && Args.hasArg(options::OPT_emit_llvm)) {
771DAL->AddFlagArg(
nullptr, Opts.getOption(
getTriple().isArch64Bit()
773: options::OPT_m32));
777 if(!Args.hasArg(options::OPT_O, options::OPT_O0, options::OPT_O4,
779DAL->AddJoinedArg(
nullptr, Opts.getOption(options::OPT_O),
787llvm::AMDGPU::GPUKind Kind) {
790 if(Kind == llvm::AMDGPU::GK_NONE)
793 const unsignedArchAttr = llvm::AMDGPU::getArchAttrAMDGCN(Kind);
797 const boolBothDenormAndFMAFast =
798(ArchAttr & llvm::AMDGPU::FEATURE_FAST_FMA_F32) &&
799(ArchAttr & llvm::AMDGPU::FEATURE_FAST_DENORMAL_F32);
800 return!BothDenormAndFMAFast;
804 constllvm::opt::ArgList &DriverArgs,
const JobAction&JA,
805 constllvm::fltSemantics *FPType)
const{
807 if(!FPType || FPType != &llvm::APFloat::IEEEsingle())
808 returnllvm::DenormalMode::getIEEE();
813 autoKind = llvm::AMDGPU::parseArchAMDGCN(Arch);
814 if(FPType && FPType == &llvm::APFloat::IEEEsingle() &&
815DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
816options::OPT_fno_gpu_flush_denormals_to_zero,
818 returnllvm::DenormalMode::getPreserveSign();
820 returnllvm::DenormalMode::getIEEE();
823 constStringRef GpuArch =
getGPUArch(DriverArgs);
824 autoKind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
828 boolDAZ = DriverArgs.hasArg(options::OPT_cl_denorms_are_zero) ||
833 returnDAZ ? llvm::DenormalMode::getPreserveSign() :
834llvm::DenormalMode::getIEEE();
838llvm::AMDGPU::GPUKind Kind) {
839 const unsignedArchAttr = llvm::AMDGPU::getArchAttrAMDGCN(Kind);
840 boolHasWave32 = (ArchAttr & llvm::AMDGPU::FEATURE_WAVE32);
842 return!HasWave32 || DriverArgs.hasFlag(
843options::OPT_mwavefrontsize64, options::OPT_mno_wavefrontsize64,
false);
855 constllvm::opt::ArgList &DriverArgs,
856llvm::opt::ArgStringList &CC1Args,
860 if(!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
861options::OPT_fvisibility_ms_compat)) {
862CC1Args.push_back(
"-fvisibility=hidden");
863CC1Args.push_back(
"-fapply-global-visibility-to-externs");
870CC1Args.push_back(
"-Werror=atomic-alignment");
876 getTriple(), DriverArgs.getLastArgValue(options::OPT_mcpu_EQ));
881StringRef TargetID = DriverArgs.getLastArgValue(options::OPT_mcpu_EQ);
882 if(TargetID.empty())
883 return{std::nullopt, std::nullopt, std::nullopt};
885llvm::StringMap<bool> FeatureMap;
887 if(!OptionalGpuArch)
888 return{TargetID.str(), std::nullopt, std::nullopt};
890 return{TargetID.str(), OptionalGpuArch->str(), FeatureMap};
894 constllvm::opt::ArgList &DriverArgs)
const{
896 if(PTID.OptionalTargetID && !PTID.OptionalGPUArch) {
898<< *PTID.OptionalTargetID;
906 if(Arg *A = Args.getLastArg(options::OPT_amdgpu_arch_tool_EQ))
907Program = A->getValue();
913 returnStdoutOrErr.takeError();
916 for(StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(),
"\n"))
918GPUArchs.push_back(Arch.str());
920 if(GPUArchs.empty())
921 returnllvm::createStringError(std::error_code(),
922 "No AMD GPU detected in the system");
924 returnstd::move(GPUArchs);
928 constllvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
931DeviceOffloadingKind);
936DriverArgs.hasArg(options::OPT_nostdlib))
939 if(DriverArgs.hasArg(options::OPT_nogpulib))
943 constStringRef GpuArch =
getGPUArch(DriverArgs);
944 autoKind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
945 constStringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
953std::tuple<bool, const SanitizerArgs> GPUSan(
954DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
955options::OPT_fno_gpu_sanitize,
true),
958 boolWave64 =
isWave64(DriverArgs, Kind);
962 boolDAZ = DriverArgs.hasArg(options::OPT_cl_denorms_are_zero) ||
964 boolFiniteOnly = DriverArgs.hasArg(options::OPT_cl_finite_math_only);
967DriverArgs.hasArg(options::OPT_cl_unsafe_math_optimizations);
968 boolFastRelaxedMath = DriverArgs.hasArg(options::OPT_cl_fast_relaxed_math);
970DriverArgs.hasArg(options::OPT_cl_fp32_correctly_rounded_divide_sqrt);
978DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
979FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan,
false));
981 for(
auto[BCFile, Internalize] : BCLibs) {
983CC1Args.push_back(
"-mlink-builtin-bitcode");
985CC1Args.push_back(
"-mlink-bitcode-file");
986CC1Args.push_back(DriverArgs.MakeArgString(BCFile));
991StringRef GPUArch, StringRef LibDeviceFile,
993 if(!hasDeviceLibrary()) {
994 D.Diag(diag::err_drv_no_rocm_device_lib) << 0;
997 if(LibDeviceFile.empty()) {
998 D.Diag(diag::err_drv_no_rocm_device_lib) << 1 << GPUArch;
1001 if(ABIVer.
requiresLibrary() && getABIVersionPath(ABIVer).empty()) {
1002 D.Diag(diag::err_drv_no_rocm_device_lib) << 2 << ABIVer.
toString();
1010 constllvm::opt::ArgList &DriverArgs, StringRef LibDeviceFile,
boolWave64,
1011 boolDAZ,
boolFiniteOnly,
boolUnsafeMathOpt,
boolFastRelaxedMath,
1013 conststd::tuple<bool, const SanitizerArgs> &GPUSan,
1014 boolisOpenMP =
false)
const{
1017 autoGPUSanEnabled = [GPUSan]() {
returnstd::get<bool>(GPUSan); };
1019 boolInternalize =
true) {
1021BCLibs.emplace_back(BCLib);
1023 autoAddSanBCLibs = [&]() {
1024 if(GPUSanEnabled()) {
1025 autoSanArgs = std::get<const SanitizerArgs>(GPUSan);
1026 if(SanArgs.needsAsanRt())
1027AddBCLib(getAsanRTLPath(),
false);
1032AddBCLib(getOCMLPath());
1034AddBCLib(getOCKLPath());
1035 else if(GPUSanEnabled() && isOpenMP)
1036AddBCLib(getOCKLPath(),
false);
1037AddBCLib(getDenormalsAreZeroPath(DAZ));
1038AddBCLib(getUnsafeMathPath(UnsafeMathOpt || FastRelaxedMath));
1039AddBCLib(getFiniteOnlyPath(FiniteOnly || FastRelaxedMath));
1040AddBCLib(getCorrectlyRoundedSqrtPath(CorrectSqrt));
1041AddBCLib(getWavefrontSize64Path(Wave64));
1042AddBCLib(LibDeviceFile);
1043 autoABIVerPath = getABIVersionPath(ABIVer);
1044 if(!ABIVerPath.empty())
1045AddBCLib(ABIVerPath);
1052 conststd::string &GPUArch,
1053 boolisOpenMP)
const{
1054 autoKind = llvm::AMDGPU::parseArchAMDGCN(GPUArch);
1055 constStringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
1067std::tuple<bool, const SanitizerArgs> GPUSan(
1068DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
1069options::OPT_fno_gpu_sanitize,
true),
1071 boolDAZ = DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
1072options::OPT_fno_gpu_flush_denormals_to_zero,
1074 boolFiniteOnly = DriverArgs.hasFlag(
1075options::OPT_ffinite_math_only, options::OPT_fno_finite_math_only,
false);
1076 boolUnsafeMathOpt =
1077DriverArgs.hasFlag(options::OPT_funsafe_math_optimizations,
1078options::OPT_fno_unsafe_math_optimizations,
false);
1079 boolFastRelaxedMath = DriverArgs.hasFlag(options::OPT_ffast_math,
1080options::OPT_fno_fast_math,
false);
1081 boolCorrectSqrt = DriverArgs.hasFlag(
1082options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
1083options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt,
true);
1084 boolWave64 =
isWave64(DriverArgs, Kind);
1087DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
1088FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, isOpenMP);
1092 const ToolChain&TC,
constllvm::opt::ArgList &DriverArgs,
1093StringRef TargetID,
constllvm::opt::Arg *A)
const{
1095 if(TargetID.empty())
1097Option O = A->getOption();
1098 if(!O.matches(options::OPT_fsanitize_EQ))
1101 if(!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
1102options::OPT_fno_gpu_sanitize,
true))
1109 if(K != SanitizerKind::Address)
1112llvm::StringMap<bool> FeatureMap;
1115assert(OptionalGpuArch &&
"Invalid Target ID");
1116(void)OptionalGpuArch;
1117 auto Loc= FeatureMap.find(
"xnack");
1118 if(
Loc== FeatureMap.end() || !
Loc->second) {
1120clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
1121<< A->getAsString(DriverArgs) << TargetID <<
"xnack+";
static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)
__device__ __2f16 float c
const char * getOffloadingArch() const
OffloadKind getOffloadingDeviceKind() const
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
DiagnosticsEngine & getDiags() const
const char * getClangProgramPath() const
Get the path to the main clang executable.
DiagnosticBuilder Diag(unsigned DiagID) const
const llvm::opt::OptTable & getOpts() const
std::string ResourceDir
The path to the compiler resource directory.
llvm::vfs::FileSystem & getVFS() const
std::string Dir
The path the driver executable was in, as invoked from the command line.
InputInfo - Wrapper for information about an input source.
const char * getFilename() const
StringRef getIncludePath() const
Get the detected path to Rocm's bin directory.
llvm::SmallVector< ToolChain::BitCodeLibraryInfo, 12 > getCommonBitcodeLibs(const llvm::opt::ArgList &DriverArgs, StringRef LibDeviceFile, bool Wave64, bool DAZ, bool FiniteOnly, bool UnsafeMathOpt, bool FastRelaxedMath, bool CorrectSqrt, DeviceLibABIVersion ABIVer, const std::tuple< bool, const SanitizerArgs > &GPUSan, bool isOpenMP) const
Get file paths of default bitcode libraries common to AMDGPU based toolchains.
RocmInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args, bool DetectHIPRuntime=true, bool DetectDeviceLib=false)
bool checkCommonBitcodeLibs(StringRef GPUArch, StringRef LibDeviceFile, DeviceLibABIVersion ABIVer) const
Check file paths of default bitcode libraries common to AMDGPU based toolchains.
bool hasHIPStdParLibrary() const
Check whether we detected a valid HIP STDPAR Acceleration library.
bool hasHIPRuntime() const
Check whether we detected a valid HIP runtime.
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
void detectDeviceLibrary()
void print(raw_ostream &OS) const
Print information about the detected ROCm installation.
The JSON file list parser is used to communicate input to InstallAPI.
std::optional< llvm::StringRef > parseTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch, llvm::StringMap< bool > *FeatureMap)
Parse a target ID to get processor and feature map.
llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch)
Get processor name from target ID.
llvm::SmallVector< llvm::StringRef, 4 > getAllPossibleTargetIDFeatures(const llvm::Triple &T, llvm::StringRef Processor)
Get all feature strings that can be used in target ID for Processor.
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
Parse a single value from a -fsanitize= or -fno-sanitize= value list.
ABI version of device library.
static DeviceLibABIVersion fromCodeObjectVersion(unsigned CodeObjectVersion)
bool requiresLibrary()
Whether ABI version bc file is requested.
static constexpr ResponseFileSupport AtFileCurCP()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4