Skip to content

Commit 00751b5

Browse files
authored
Merge pull request #8839 from apple/jan_svoboda/thinlto-termination
[ThinLTO] Re-commit termination handling
2 parents 915b452 + 7fbd0e7 commit 00751b5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,47 @@ void ThinLTOCodeGenerator::run() {
20202020
}
20212021
});
20222022
}
2023+
2024+
WrittenObjects.wait(AllModules);
2025+
2026+
{
2027+
if (CacheLogging)
2028+
CacheLogOS.applyLocked([&](raw_ostream &OS) {
2029+
OS << "Waiting for outstanding cache requests...\n";
2030+
});
2031+
ScopedDurationTimer T([&](double Seconds) {
2032+
if (CacheLogging)
2033+
CacheLogOS.applyLocked([&](raw_ostream &OS) {
2034+
OS << "Handled outstanding cache requests in "
2035+
<< llvm::format("%.6fs", Seconds) << "\n";
2036+
});
2037+
});
2038+
auto Start = std::chrono::steady_clock::now();
2039+
auto CacheTimeout = DeterministicCheck
2040+
? std::chrono::milliseconds::max()
2041+
: std::chrono::milliseconds(5000);
2042+
2043+
if (!HandledCacheReads.waitFor(CacheTimeout, AllModules)) {
2044+
// If we were unable to finish all cache reads in time, just request
2045+
// their cancellation (we already have all objects written) and don't
2046+
// bother writing to the cache (that would probably be even slower
2047+
// than reading form it).
2048+
GetCancelTok->requestCancellation();
2049+
} else {
2050+
auto Now = std::chrono::steady_clock::now();
2051+
auto RemainingCacheTimeout = CacheTimeout - (Now - Start);
2052+
// If we finished all cache reads in time, request writes.
2053+
if (!HandledCacheWrites.waitFor(RemainingCacheTimeout, AllModules)) {
2054+
// If we were unable to finish all cache writes in time, request
2055+
// their cancellation. We don't want to hold up the link any longer.
2056+
PutCancelTok->requestCancellation();
2057+
}
2058+
}
2059+
2060+
if (DeterministicCheck)
2061+
for (int count : ModulesOrdering)
2062+
(void)Infos[count].Entry->areLoadedAndWrittenResultsIdentical();
2063+
}
20232064
}
20242065

20252066
pruneCache(CacheOptions.Path, CacheOptions.Policy, ProducedBinaries);

0 commit comments

Comments
 (0)