CUDA: Avoid unnecessary allocation and GetLinkLanguage()

There's no reason to allocate the cmNinjaLinkLineDeviceComputer on the heap.
We can also assume the link language as CUDA in cmLocalGenerator::GetDeviceLinkFlags().
This commit is contained in:
Raul Tambre
2021-11-06 13:35:04 +02:00
parent 5b0693411e
commit cf7e68087d
3 changed files with 11 additions and 15 deletions
+3 -5
View File
@@ -1410,25 +1410,23 @@ std::vector<BT<std::string>> cmLocalGenerator::GetStaticLibraryFlags(
} }
void cmLocalGenerator::GetDeviceLinkFlags( void cmLocalGenerator::GetDeviceLinkFlags(
cmLinkLineComputer* linkLineComputer, const std::string& config, cmLinkLineComputer& linkLineComputer, const std::string& config,
std::string& linkLibs, std::string& linkFlags, std::string& frameworkPath, std::string& linkLibs, std::string& linkFlags, std::string& frameworkPath,
std::string& linkPath, cmGeneratorTarget* target) std::string& linkPath, cmGeneratorTarget* target)
{ {
cmGeneratorTarget::DeviceLinkSetter setter(*target); cmGeneratorTarget::DeviceLinkSetter setter(*target);
cmComputeLinkInformation* pcli = target->GetLinkInformation(config); cmComputeLinkInformation* pcli = target->GetLinkInformation(config);
const std::string linkLanguage =
linkLineComputer->GetLinkerLanguage(target, config);
if (pcli) { if (pcli) {
// Compute the required device link libraries when // Compute the required device link libraries when
// resolving gpu lang device symbols // resolving gpu lang device symbols
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath, this->OutputLinkLibraries(pcli, &linkLineComputer, linkLibs, frameworkPath,
linkPath); linkPath);
} }
std::vector<std::string> linkOpts; std::vector<std::string> linkOpts;
target->GetLinkOptions(linkOpts, config, linkLanguage); target->GetLinkOptions(linkOpts, config, "CUDA");
// LINK_OPTIONS are escaped. // LINK_OPTIONS are escaped.
this->AppendCompileOptions(linkFlags, linkOpts); this->AppendCompileOptions(linkFlags, linkOpts);
} }
+1 -1
View File
@@ -496,7 +496,7 @@ public:
/** Fill out these strings for the given target. Libraries to link, /** Fill out these strings for the given target. Libraries to link,
* flags, and linkflags. */ * flags, and linkflags. */
void GetDeviceLinkFlags(cmLinkLineComputer* linkLineComputer, void GetDeviceLinkFlags(cmLinkLineComputer& linkLineComputer,
const std::string& config, std::string& linkLibs, const std::string& config, std::string& linkLibs,
std::string& linkFlags, std::string& frameworkPath, std::string& linkFlags, std::string& frameworkPath,
std::string& linkPath, cmGeneratorTarget* target); std::string& linkPath, cmGeneratorTarget* target);
+7 -9
View File
@@ -855,16 +855,14 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement(
vars["TARGET_FILE"] = vars["TARGET_FILE"] =
localGen.ConvertToOutputFormat(output, cmOutputConverter::SHELL); localGen.ConvertToOutputFormat(output, cmOutputConverter::SHELL);
std::unique_ptr<cmLinkLineComputer> linkLineComputer( cmNinjaLinkLineDeviceComputer linkLineComputer(
new cmNinjaLinkLineDeviceComputer( this->GetLocalGenerator(),
this->GetLocalGenerator(), this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), globalGen);
this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), linkLineComputer.SetUseNinjaMulti(globalGen->IsMultiConfig());
globalGen));
linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig());
localGen.GetDeviceLinkFlags(linkLineComputer.get(), config, localGen.GetDeviceLinkFlags(linkLineComputer, config, vars["LINK_LIBRARIES"],
vars["LINK_LIBRARIES"], vars["LINK_FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath,
frameworkPath, linkPath, genTarget); genTarget);
this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars); this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars);