diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-12-09 13:28:42 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2023-12-09 13:28:42 +0000 |
| commit | b1c73532ee8997fe5dfbeb7d223027bdf99758a0 (patch) | |
| tree | 7d6e51c294ab6719475d660217aa0c0ad0526292 /llvm/lib/ProfileData/InstrProfWriter.cpp | |
| parent | 7fa27ce4a07f19b07799a767fc29416f3b625afb (diff) | |
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
| -rw-r--r-- | llvm/lib/ProfileData/InstrProfWriter.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index b74d5c3862d8..595c9aa1adc1 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -49,9 +49,9 @@ namespace llvm { class ProfOStream { public: ProfOStream(raw_fd_ostream &FD) - : IsFDOStream(true), OS(FD), LE(FD, support::little) {} + : IsFDOStream(true), OS(FD), LE(FD, llvm::endianness::little) {} ProfOStream(raw_string_ostream &STR) - : IsFDOStream(false), OS(STR), LE(STR, support::little) {} + : IsFDOStream(false), OS(STR), LE(STR, llvm::endianness::little) {} uint64_t tell() { return OS.tell(); } void write(uint64_t V) { LE.write<uint64_t>(V); } @@ -80,7 +80,8 @@ public: std::string &Data = SOStream.str(); // with flush for (int K = 0; K < NItems; K++) { for (int I = 0; I < P[K].N; I++) { - uint64_t Bytes = endian::byte_swap<uint64_t, little>(P[K].D[I]); + uint64_t Bytes = + endian::byte_swap<uint64_t, llvm::endianness::little>(P[K].D[I]); Data.replace(P[K].Pos + I * sizeof(uint64_t), sizeof(uint64_t), (const char *)&Bytes, sizeof(uint64_t)); } @@ -106,7 +107,7 @@ public: using hash_value_type = uint64_t; using offset_type = uint64_t; - support::endianness ValueProfDataEndianness = support::little; + llvm::endianness ValueProfDataEndianness = llvm::endianness::little; InstrProfSummaryBuilder *SummaryBuilder; InstrProfSummaryBuilder *CSSummaryBuilder; @@ -120,7 +121,7 @@ public: EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); offset_type N = K.size(); LE.write<offset_type>(N); @@ -131,6 +132,8 @@ public: M += sizeof(uint64_t); // The function hash M += sizeof(uint64_t); // The size of the Counts vector M += ProfRecord.Counts.size() * sizeof(uint64_t); + M += sizeof(uint64_t); // The size of the Bitmap vector + M += ProfRecord.BitmapBytes.size() * sizeof(uint64_t); // Value data M += ValueProfData::getSize(ProfileData.second); @@ -147,7 +150,7 @@ public: void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); for (const auto &ProfileData : *V) { const InstrProfRecord &ProfRecord = ProfileData.second; if (NamedInstrProfRecord::hasCSFlagInHash(ProfileData.first)) @@ -160,6 +163,10 @@ public: for (uint64_t I : ProfRecord.Counts) LE.write<uint64_t>(I); + LE.write<uint64_t>(ProfRecord.BitmapBytes.size()); + for (uint64_t I : ProfRecord.BitmapBytes) + LE.write<uint64_t>(I); + // Write value data std::unique_ptr<ValueProfData> VDataPtr = ValueProfData::serializeFrom(ProfileData.second); @@ -182,8 +189,7 @@ InstrProfWriter::InstrProfWriter(bool Sparse, InstrProfWriter::~InstrProfWriter() { delete InfoObj; } // Internal interface for testing purpose only. -void InstrProfWriter::setValueProfDataEndianness( - support::endianness Endianness) { +void InstrProfWriter::setValueProfDataEndianness(llvm::endianness Endianness) { InfoObj->ValueProfDataEndianness = Endianness; } @@ -380,6 +386,8 @@ bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) { const InstrProfRecord &IPR = Func.second; if (llvm::any_of(IPR.Counts, [](uint64_t Count) { return Count > 0; })) return true; + if (llvm::any_of(IPR.BitmapBytes, [](uint8_t Byte) { return Byte > 0; })) + return true; } return false; } @@ -703,6 +711,17 @@ void InstrProfWriter::writeRecordInText(StringRef Name, uint64_t Hash, for (uint64_t Count : Func.Counts) OS << Count << "\n"; + if (Func.BitmapBytes.size() > 0) { + OS << "# Num Bitmap Bytes:\n$" << Func.BitmapBytes.size() << "\n"; + OS << "# Bitmap Byte Values:\n"; + for (uint8_t Byte : Func.BitmapBytes) { + OS << "0x"; + OS.write_hex(Byte); + OS << "\n"; + } + OS << "\n"; + } + uint32_t NumValueKinds = Func.getNumValueKinds(); if (!NumValueKinds) { OS << "\n"; @@ -722,7 +741,7 @@ void InstrProfWriter::writeRecordInText(StringRef Name, uint64_t Hash, std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S); for (uint32_t I = 0; I < ND; I++) { if (VK == IPVK_IndirectCallTarget) - OS << Symtab.getFuncNameOrExternalSymbol(VD[I].Value) << ":" + OS << Symtab.getFuncOrVarNameIfDefined(VD[I].Value) << ":" << VD[I].Count << "\n"; else OS << VD[I].Value << ":" << VD[I].Count << "\n"; @@ -743,6 +762,8 @@ Error InstrProfWriter::writeText(raw_fd_ostream &OS) { if (static_cast<bool>(ProfileKind & InstrProfKind::FunctionEntryInstrumentation)) OS << "# Always instrument the function entry block\n:entry_first\n"; + if (static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage)) + OS << "# Instrument block coverage\n:single_byte_coverage\n"; InstrProfSymtab Symtab; using FuncPair = detail::DenseMapPair<uint64_t, InstrProfRecord>; @@ -790,7 +811,7 @@ void InstrProfWriter::writeTextTemporalProfTraceData(raw_fd_ostream &OS, for (auto &Trace : TemporalProfTraces) { OS << "# Weight:\n" << Trace.Weight << "\n"; for (auto &NameRef : Trace.FunctionNameRefs) - OS << Symtab.getFuncName(NameRef) << ","; + OS << Symtab.getFuncOrVarName(NameRef) << ","; OS << "\n"; } OS << "\n"; |
