diff options
author | Mingming Liu <mingmingl@google.com> | 2024-05-20 08:55:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-20 08:55:31 -0700 |
commit | e33db249b53fb70dce62db3ebd82d42239bd1d9d (patch) | |
tree | b4c8ec5c69cfd321ab3b285bf6a06520e4dddd8d /llvm/lib/LTO/LTOBackend.cpp | |
parent | 8b22bb8a62a259e35ccc49fb2f50077a2772cf2f (diff) | |
download | llvm-e33db249b53fb70dce62db3ebd82d42239bd1d9d.zip llvm-e33db249b53fb70dce62db3ebd82d42239bd1d9d.tar.gz llvm-e33db249b53fb70dce62db3ebd82d42239bd1d9d.tar.bz2 |
Reland "[ThinLTO] Populate declaration import status except for distributed ThinLTO under a default-off new option" (#92718)
The original PR is reviewed in
https://github.com/llvm/llvm-project/pull/88024, and this PR adds one
line (https://github.com/llvm/llvm-project/pull/92718/commits/b9f04d199dec4f3c221d981dcb91e55298d0693f)
to fix test
Limit to one thread for in-process ThinLTO to test `LLVM_DEBUG` log.
- This should fix build bot failure like
https://lab.llvm.org/buildbot/#/builders/259/builds/4727 and
https://lab.llvm.org/buildbot/#/builders/9/builds/43876
- I could repro the failure and see interleaved log messages by using
`-thinlto-threads=all`
**Original Commit Message:**
The goal is to populate `declaration` import status if a new flag
`-import-declaration` is on.
* For in-process ThinLTO, the `declaration` status is visible to backend
`function-import` pass, so `FunctionImporter::importFunctions` should
read the import status and be no-op for declaration summaries.
Basically, the postlink pipeline is updated to keep its current behavior
(import definitions), but not updated to handle `declaration` summaries.
Two use cases ([better call-graph
sort](https://discourse.llvm.org/t/rfc-for-better-call-graph-sort-build-a-more-complete-call-graph-by-adding-more-indirect-call-edges/74029#support-cross-module-function-declaration-import-5)
or [cross-module
auto-init](https://github.com/llvm/llvm-project/pull/87597#discussion_r1556067195))
would use this bit differently.
* For distributed ThinLTO, the `declaration` status is not serialized to
bitcode. As discussed, https://github.com/llvm/llvm-project/pull/87600
will do this.
Diffstat (limited to 'llvm/lib/LTO/LTOBackend.cpp')
-rw-r--r-- | llvm/lib/LTO/LTOBackend.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 21aed79..76223e8 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -720,7 +720,14 @@ bool lto::initImportList(const Module &M, if (Summary->modulePath() == M.getModuleIdentifier()) continue; // Add an entry to provoke importing by thinBackend. - ImportList[Summary->modulePath()].insert(GUID); + // Try emplace the entry first. If an entry with the same key already + // exists, set the value to 'std::min(existing-value, new-value)' to make + // sure a definition takes precedence over a declaration. + auto [Iter, Inserted] = ImportList[Summary->modulePath()].try_emplace( + GUID, Summary->importType()); + + if (!Inserted) + Iter->second = std::min(Iter->second, Summary->importType()); } } return true; |