Skip to content

Commit e71e40b

Browse files
committed
[ThinLTO] Re-commit termination handling
1 parent 42203d4 commit e71e40b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

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

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

0 commit comments

Comments
 (0)