Skip to content

[ThinLTO] Re-commit termination handling #8840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,47 @@ void ThinLTOCodeGenerator::run() {
}
});
}

WrittenObjects.wait(AllModules);

{
if (CacheLogging)
CacheLogOS.applyLocked([&](raw_ostream &OS) {
OS << "Waiting for outstanding cache requests...\n";
});
ScopedDurationTimer T([&](double Seconds) {
if (CacheLogging)
CacheLogOS.applyLocked([&](raw_ostream &OS) {
OS << "Handled outstanding cache requests in "
<< llvm::format("%.6fs", Seconds) << "\n";
});
});
auto Start = std::chrono::steady_clock::now();
auto CacheTimeout = DeterministicCheck
? std::chrono::milliseconds::max()
: std::chrono::milliseconds(5000);

if (!HandledCacheReads.waitFor(CacheTimeout, AllModules)) {
// If we were unable to finish all cache reads in time, just request
// their cancellation (we already have all objects written) and don't
// bother writing to the cache (that would probably be even slower
// than reading form it).
GetCancelTok->requestCancellation();
} else {
auto Now = std::chrono::steady_clock::now();
auto RemainingCacheTimeout = CacheTimeout - (Now - Start);
// If we finished all cache reads in time, request writes.
if (!HandledCacheWrites.waitFor(RemainingCacheTimeout, AllModules)) {
// If we were unable to finish all cache writes in time, request
// their cancellation. We don't want to hold up the link any longer.
PutCancelTok->requestCancellation();
}
}

if (DeterministicCheck)
for (int count : ModulesOrdering)
(void)Infos[count].Entry->areLoadedAndWrittenResultsIdentical();
}
}

pruneCache(CacheOptions.Path, CacheOptions.Policy, ProducedBinaries);
Expand Down