diff --git a/bolt/lib/Profile/Heatmap.cpp b/bolt/lib/Profile/Heatmap.cpp --- a/bolt/lib/Profile/Heatmap.cpp +++ b/bolt/lib/Profile/Heatmap.cpp @@ -17,6 +17,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include +#include #include #include @@ -141,7 +142,8 @@ Range[NumRanges - 1] = std::max((uint64_t)NumRanges, MaxValue); // Print scaled value - auto printValue = [&](uint64_t Value, bool ResetColor = false) { + auto printValue = [&](uint64_t Value, char Character, + bool ResetColor = false) { assert(Value && "should only print positive values"); for (unsigned I = 0; I < sizeof(Range) / sizeof(Range[0]); ++I) { if (Value <= Range[I]) { @@ -150,9 +152,9 @@ } } if (Value <= Range[0]) - OS << 'o'; + OS << static_cast(std::tolower(Character)); else - OS << 'O'; + OS << static_cast(std::toupper(Character)); if (ResetColor) changeColor(DefaultColor); @@ -193,17 +195,31 @@ for (unsigned I = 5; I > 0; --I) printHeader(I); + auto SectionStart = TextSections.begin(); uint64_t PrevAddress = 0; for (auto MI = Map.begin(), ME = Map.end(); MI != ME; ++MI) { const std::pair &Entry = *MI; uint64_t Address = Entry.first * BucketSize; + char Character = 'o'; + + // Check if address is in the current or any later section. + auto Section = std::find_if( + SectionStart, TextSections.end(), [&](const SectionNameAndRange &S) { + return Address >= S.BeginAddress && Address < S.EndAddress; + }); + if (Section != TextSections.end()) { + // Shift the section forward (if SectionStart is different from Section). + // This works, because TextSections is sorted by start address. + SectionStart = Section; + Character = 'a' + ((Section - TextSections.begin()) % 26); + } if (PrevAddress) fillRange(PrevAddress, Address); else startLine(Address); - printValue(Entry.second); + printValue(Entry.second, Character); PrevAddress = Address; }