aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorIvan Tadeu Ferreira Antunes Filho <antunesi@google.com>2023-04-04 09:57:53 -0700
committerTeresa Johnson <tejohnson@google.com>2023-04-04 11:24:51 -0700
commit73fd9d310fff4d7d2b95e0509aafdf28bd3c713c (patch)
tree4e2ca6a50f12c40734fbaeb033514d4c2f2bd664 /llvm/lib/LTO/LTO.cpp
parenta401e10f12ba555eefc3da607fa5168603caa9c6 (diff)
downloadllvm-73fd9d310fff4d7d2b95e0509aafdf28bd3c713c.zip
llvm-73fd9d310fff4d7d2b95e0509aafdf28bd3c713c.tar.gz
llvm-73fd9d310fff4d7d2b95e0509aafdf28bd3c713c.tar.bz2
[lld] Support separate native object file path in --thinlto-prefix-replace
Currently, the --thinlto-prefix-replace="oldpath;newpath" option is used during distributed ThinLTO thin links to specify the mapping of the input bitcode object files' directory tree (oldpath) to the directory tree (newpath) used for both: 1) the output files of the thin link itself (the .thinlto.bc index files and the optional .imports files) 2) the specified object file paths written to the response file given in the --thinlto-index-only=${response} option, which is used by the final native link and must match the paths of the native object files that will be produced by ThinLTO backend compiles. This patch expands the --thinlto-prefix-replace option to allow a separate directory tree mapping to be specified for the object file paths written to the response file (number 2 above). This is important to support builds and build systems where the same output directory may not be written by multiple build actions (e.g. the thin link and the ThinLTO backend compiles). The new format is: --thinlto-prefix-replace="origpath;outpath[;objpath]" This replaces the origpath directory tree of the thin link input files with outpath when writing the thin link index and imports outputs (number 1 above). If objpath is specified it replaces origpath of the input files with objpath when writing the response file (number 2 above), otherwise it falls back to the old behavior of using outpath for this as well. Reviewed By: tejohnson, MaskRay Differential Revision: https://reviews.llvm.org/D144596
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 4d6a620..ff57f30 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1422,18 +1422,20 @@ std::string lto::getThinLTOOutputFile(const std::string &Path,
namespace {
class WriteIndexesThinBackend : public ThinBackendProc {
- std::string OldPrefix, NewPrefix;
+ std::string OldPrefix, NewPrefix, NativeObjectPrefix;
raw_fd_ostream *LinkedObjectsFile;
public:
WriteIndexesThinBackend(
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
- std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles,
+ std::string OldPrefix, std::string NewPrefix,
+ std::string NativeObjectPrefix, bool ShouldEmitImportsFiles,
raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite)
: ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
OnWrite, ShouldEmitImportsFiles),
OldPrefix(OldPrefix), NewPrefix(NewPrefix),
+ NativeObjectPrefix(NativeObjectPrefix),
LinkedObjectsFile(LinkedObjectsFile) {}
Error start(
@@ -1446,8 +1448,13 @@ public:
std::string NewModulePath =
getThinLTOOutputFile(std::string(ModulePath), OldPrefix, NewPrefix);
- if (LinkedObjectsFile)
- *LinkedObjectsFile << NewModulePath << '\n';
+ if (LinkedObjectsFile) {
+ std::string ObjectPrefix =
+ NativeObjectPrefix.empty() ? NewPrefix : NativeObjectPrefix;
+ std::string LinkedObjectsFilePath = getThinLTOOutputFile(
+ std::string(ModulePath), OldPrefix, ObjectPrefix);
+ *LinkedObjectsFile << LinkedObjectsFilePath << '\n';
+ }
if (auto E = emitFiles(ImportList, ModulePath, NewModulePath))
return E;
@@ -1466,14 +1473,15 @@ public:
} // end anonymous namespace
ThinBackend lto::createWriteIndexesThinBackend(
- std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles,
+ std::string OldPrefix, std::string NewPrefix,
+ std::string NativeObjectPrefix, bool ShouldEmitImportsFiles,
raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite) {
return [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache) {
return std::make_unique<WriteIndexesThinBackend>(
Conf, CombinedIndex, ModuleToDefinedGVSummaries, OldPrefix, NewPrefix,
- ShouldEmitImportsFiles, LinkedObjectsFile, OnWrite);
+ NativeObjectPrefix, ShouldEmitImportsFiles, LinkedObjectsFile, OnWrite);
};
}