@@ -2227,7 +2227,13 @@ LLVM_DUMP_METHOD void SourceManager::dump() const {
22272227 }
22282228}
22292229
2230- static std::string NumberToHumanString (uint64_t Number) {
2230+ // 123 -> "123".
2231+ // 1234 -> "1.23k".
2232+ // 123456 -> "123.46k".
2233+ // 1234567 -> "1.23M".
2234+ // 1234567890 -> "1.23G".
2235+ // 1234567890123 -> "1.23T".
2236+ static std::string humanizeNumber (uint64_t Number) {
22312237 static constexpr std::array<std::pair<uint64_t , char >, 4 > Units = {
22322238 {{1'000'000'000'000UL , ' T' },
22332239 {1'000'000'000UL , ' G' },
@@ -2318,27 +2324,27 @@ void SourceManager::noteSLocAddressSpaceUsage(
23182324 int UsagePercent = static_cast <int >(100.0 * double (LocalUsage + LoadedUsage) /
23192325 MaxLoadedOffset);
23202326 Diag.Report (SourceLocation (), diag::note_total_sloc_usage)
2321- << LocalUsage << NumberToHumanString (LocalUsage) << LoadedUsage
2322- << NumberToHumanString (LoadedUsage) << (LocalUsage + LoadedUsage)
2323- << NumberToHumanString (LocalUsage + LoadedUsage) << UsagePercent;
2327+ << LocalUsage << humanizeNumber (LocalUsage) << LoadedUsage
2328+ << humanizeNumber (LoadedUsage) << (LocalUsage + LoadedUsage)
2329+ << humanizeNumber (LocalUsage + LoadedUsage) << UsagePercent;
23242330
23252331 // Produce notes on sloc address space usage for each file with a high usage.
23262332 uint64_t ReportedSize = 0 ;
23272333 for (auto &[Entry, FileInfo] :
23282334 llvm::make_range (SortedUsage.begin (), SortedEnd)) {
23292335 Diag.Report (FileInfo.Loc , diag::note_file_sloc_usage)
23302336 << FileInfo.Inclusions << FileInfo.DirectSize
2331- << NumberToHumanString (FileInfo.DirectSize )
2337+ << humanizeNumber (FileInfo.DirectSize )
23322338 << (FileInfo.TotalSize - FileInfo.DirectSize )
2333- << NumberToHumanString (FileInfo.TotalSize - FileInfo.DirectSize );
2339+ << humanizeNumber (FileInfo.TotalSize - FileInfo.DirectSize );
23342340 ReportedSize += FileInfo.TotalSize ;
23352341 }
23362342
23372343 // Describe any remaining usage not reported in the per-file usage.
23382344 if (ReportedSize != CountedSize) {
23392345 Diag.Report (SourceLocation (), diag::note_file_misc_sloc_usage)
23402346 << (SortedUsage.end () - SortedEnd) << CountedSize - ReportedSize
2341- << NumberToHumanString (CountedSize - ReportedSize);
2347+ << humanizeNumber (CountedSize - ReportedSize);
23422348 }
23432349}
23442350
0 commit comments