diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -854,7 +854,7 @@ const StringRef GpuArch = getGPUArch(DriverArgs); auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch); const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind); - std::string LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch); + StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch); auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion( getAMDGPUCodeObjectVersion(getDriver(), DriverArgs)); if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile, @@ -946,7 +946,7 @@ auto Kind = llvm::AMDGPU::parseArchAMDGCN(GPUArch); const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind); - std::string LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch); + StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch); auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion( getAMDGPUCodeObjectVersion(getDriver(), DriverArgs)); if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile, diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp --- a/clang/lib/Driver/ToolChains/HIPAMD.cpp +++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp @@ -237,7 +237,7 @@ DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ); if (!MaxThreadsPerBlock.empty()) { std::string ArgStr = - std::string("--gpu-max-threads-per-block=") + MaxThreadsPerBlock.str(); + (Twine("--gpu-max-threads-per-block=") + MaxThreadsPerBlock).str(); CC1Args.push_back(DriverArgs.MakeArgStringRef(ArgStr)); } @@ -344,7 +344,7 @@ ArgStringList LibraryPaths; // Find in --hip-device-lib-path and HIP_LIBRARY_PATH. - for (auto Path : RocmInstallation.getRocmDeviceLibPathArg()) + for (StringRef Path : RocmInstallation.getRocmDeviceLibPathArg()) LibraryPaths.push_back(DriverArgs.MakeArgString(Path)); addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH"); @@ -354,7 +354,7 @@ if (!BCLibArgs.empty()) { llvm::for_each(BCLibArgs, [&](StringRef BCName) { StringRef FullName; - for (std::string LibraryPath : LibraryPaths) { + for (StringRef LibraryPath : LibraryPaths) { SmallString<128> Path(LibraryPath); llvm::sys::path::append(Path, BCName); FullName = Path; @@ -387,15 +387,15 @@ getDriver().Diag(DiagID); return {}; } else - BCLibs.push_back({AsanRTL.str(), /*ShouldInternalize=*/false}); + BCLibs.emplace_back(AsanRTL, /*ShouldInternalize=*/false); } // Add the HIP specific bitcode library. BCLibs.push_back(RocmInstallation.getHIPPath()); // Add common device libraries like ocml etc. - for (auto N : getCommonDeviceLibNames(DriverArgs, GpuArch.str())) - BCLibs.push_back(StringRef(N)); + for (StringRef N : getCommonDeviceLibNames(DriverArgs, GpuArch.str())) + BCLibs.emplace_back(N); // Add instrument lib. auto InstLib = diff --git a/clang/lib/Driver/ToolChains/ROCm.h b/clang/lib/Driver/ToolChains/ROCm.h --- a/clang/lib/Driver/ToolChains/ROCm.h +++ b/clang/lib/Driver/ToolChains/ROCm.h @@ -252,8 +252,11 @@ } /// Get libdevice file for given architecture - std::string getLibDeviceFile(StringRef Gpu) const { - return LibDeviceMap.lookup(Gpu); + StringRef getLibDeviceFile(StringRef Gpu) const { + auto Loc = LibDeviceMap.find(Gpu); + if (Loc == LibDeviceMap.end()) + return ""; + return Loc->second; } void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, @@ -263,7 +266,7 @@ void detectHIPRuntime(); /// Get the values for --rocm-device-lib-path arguments - std::vector getRocmDeviceLibPathArg() const { + const ArrayRef getRocmDeviceLibPathArg() const { return RocmDeviceLibPathArg; } @@ -273,7 +276,7 @@ /// Get the value for --hip-version argument StringRef getHIPVersionArg() const { return HIPVersionArg; } - std::string getHIPVersion() const { return DetectedVersion; } + StringRef getHIPVersion() const { return DetectedVersion; } }; } // end namespace driver