From 71cb689661ab107986a3773571ab9985d6c47114 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 26 Apr 2023 20:43:11 -0700 Subject: [PATCH] [LTO] Change getThinLTOOutputFile to take StringRef --- lld/COFF/LTO.cpp | 5 ++--- lld/ELF/LTO.cpp | 5 ++--- lld/MachO/LTO.cpp | 5 ++--- llvm/include/llvm/LTO/LTO.h | 5 ++--- llvm/lib/LTO/LTO.cpp | 13 ++++++------- llvm/tools/llvm-lto/llvm-lto.cpp | 7 +++---- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp index fb3ba2c..cca14be 100644 --- a/lld/COFF/LTO.cpp +++ b/lld/COFF/LTO.cpp @@ -55,9 +55,8 @@ static std::unique_ptr openFile(StringRef file) { } std::string BitcodeCompiler::getThinLTOOutputFile(StringRef path) { - return lto::getThinLTOOutputFile( - std::string(path), std::string(ctx.config.thinLTOPrefixReplaceOld), - std::string(ctx.config.thinLTOPrefixReplaceNew)); + return lto::getThinLTOOutputFile(path, ctx.config.thinLTOPrefixReplaceOld, + ctx.config.thinLTOPrefixReplaceNew); } lto::Config BitcodeCompiler::createConfig() { diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 8b5c23e..f16abc1 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -67,9 +67,8 @@ static std::unique_ptr openLTOOutputFile(StringRef file) { } static std::string getThinLTOOutputFile(StringRef modulePath) { - return lto::getThinLTOOutputFile( - std::string(modulePath), std::string(config->thinLTOPrefixReplaceOld), - std::string(config->thinLTOPrefixReplaceNew)); + return lto::getThinLTOOutputFile(modulePath, config->thinLTOPrefixReplaceOld, + config->thinLTOPrefixReplaceNew); } static lto::Config createConfig() { diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp index 481ac94..a2d3934 100644 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -46,9 +46,8 @@ static std::unique_ptr openFile(StringRef file) { } static std::string getThinLTOOutputFile(StringRef modulePath) { - return lto::getThinLTOOutputFile( - std::string(modulePath), std::string(config->thinLTOPrefixReplaceOld), - std::string(config->thinLTOPrefixReplaceNew)); + return lto::getThinLTOOutputFile(modulePath, config->thinLTOPrefixReplaceOld, + config->thinLTOPrefixReplaceNew); } static lto::Config createConfig() { diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h index 97ab7c4..dabc367 100644 --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -78,9 +78,8 @@ namespace lto { /// Given the original \p Path to an output file, replace any path /// prefix matching \p OldPrefix with \p NewPrefix. Also, create the /// resulting directory if it does not yet exist. -std::string getThinLTOOutputFile(const std::string &Path, - const std::string &OldPrefix, - const std::string &NewPrefix); +std::string getThinLTOOutputFile(StringRef Path, StringRef OldPrefix, + StringRef NewPrefix); /// Setup optimization remarks. Expected> setupLLVMOptimizationRemarks( diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 15b6e22..fee09fc 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1404,11 +1404,10 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism, // Given the original \p Path to an output file, replace any path // prefix matching \p OldPrefix with \p NewPrefix. Also, create the // resulting directory if it does not yet exist. -std::string lto::getThinLTOOutputFile(const std::string &Path, - const std::string &OldPrefix, - const std::string &NewPrefix) { +std::string lto::getThinLTOOutputFile(StringRef Path, StringRef OldPrefix, + StringRef NewPrefix) { if (OldPrefix.empty() && NewPrefix.empty()) - return Path; + return std::string(Path); SmallString<128> NewPath(Path); llvm::sys::path::replace_path_prefix(NewPath, OldPrefix, NewPrefix); StringRef ParentPath = llvm::sys::path::parent_path(NewPath.str()); @@ -1447,13 +1446,13 @@ public: MapVector &ModuleMap) override { StringRef ModulePath = BM.getModuleIdentifier(); std::string NewModulePath = - getThinLTOOutputFile(std::string(ModulePath), OldPrefix, NewPrefix); + getThinLTOOutputFile(ModulePath, OldPrefix, NewPrefix); if (LinkedObjectsFile) { std::string ObjectPrefix = NativeObjectPrefix.empty() ? NewPrefix : NativeObjectPrefix; - std::string LinkedObjectsFilePath = getThinLTOOutputFile( - std::string(ModulePath), OldPrefix, ObjectPrefix); + std::string LinkedObjectsFilePath = + getThinLTOOutputFile(ModulePath, OldPrefix, ObjectPrefix); *LinkedObjectsFile << LinkedObjectsFilePath << '\n'; } diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index 79e9d93..51921d4 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -516,11 +516,10 @@ static void getThinLTOOldAndNewPrefix(std::string &OldPrefix, /// Given the original \p Path to an output file, replace any path /// prefix matching \p OldPrefix with \p NewPrefix. Also, create the /// resulting directory if it does not yet exist. -static std::string getThinLTOOutputFile(const std::string &Path, - const std::string &OldPrefix, - const std::string &NewPrefix) { +static std::string getThinLTOOutputFile(StringRef Path, StringRef OldPrefix, + StringRef NewPrefix) { if (OldPrefix.empty() && NewPrefix.empty()) - return Path; + return std::string(Path); SmallString<128> NewPath(Path); llvm::sys::path::replace_path_prefix(NewPath, OldPrefix, NewPrefix); StringRef ParentPath = llvm::sys::path::parent_path(NewPath.str()); -- 2.7.4