25 IO &
IO, BBAddrMapYAML::BBAddrMapEntry &
E) {
35 IO &
IO, BBAddrMapYAML::BBAddrMapEntry::BBRangeEntry &
E) {
42 IO &
IO, BBAddrMapYAML::BBAddrMapEntry::BBEntry &
E) {
53 IO &
IO, BBAddrMapYAML::PGOAnalysisMapEntry &
E) {
60 IO &
IO, BBAddrMapYAML::PGOAnalysisMapEntry::PGOBBEntry &
E) {
68 BBAddrMapYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry>::
70 BBAddrMapYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry &
E) {
82 const std::vector<PGOAnalysisMapEntry> *PGOAnalyses,
85 assert((AddressSize == 4 || AddressSize == 8) &&
"invalid address size");
90 <<
static_cast<int>(
E.Version)
91 <<
"; encoding using the most recent version";
105 if (!FeatureOrErr->FuncGUID &&
E.FuncGUID.has_value())
107 <<
") does not support function GUID.";
108 if (FeatureOrErr->FuncGUID ||
E.FuncGUID.has_value())
109 CBA.
write<
uint64_t>(
E.FuncGUID.value_or(llvm::yaml::Hex64(0)), Endian);
110 bool MultiBBRangeFeatureEnabled = FeatureOrErr->MultiBBRange;
112 MultiBBRangeFeatureEnabled ||
113 (
E.NumBBRanges.has_value() &&
E.NumBBRanges.value() != 1) ||
114 (
E.BBRanges &&
E.BBRanges->size() != 1);
115 if (MultiBBRange && !MultiBBRangeFeatureEnabled)
117 <<
") does not support multiple BB ranges.";
122 E.NumBBRanges.value_or(
E.BBRanges ?
E.BBRanges->size() : 0);
128 bool EmitCallsiteEndOffsets =
129 FeatureOrErr->CallsiteEndOffsets ||
E.hasAnyCallsiteEndOffsets();
132 if (AddressSize == 8)
143 if (!BBR.
BBEntries || FeatureOrErr->OmitBBEntries)
150 if (EmitCallsiteEndOffsets) {
151 size_t NumCallsiteEndOffsets =
161 if (FeatureOrErr->BBHash || BBE.
Hash.has_value()) {
163 BBE.
Hash.has_value() ? BBE.
Hash.value() : llvm::yaml::Hex64(0);
178 const auto &PGOBBEntries = PGOEntry.
PGOBBEntries.value();
179 if (TotalNumBlocks != PGOBBEntries.size()) {
181 "BBEntries in the BB address map.\n"
182 <<
"Mismatch on function with address: "
183 <<
E.getFunctionAddress();
187 for (
const auto &PGOBBE : PGOBBEntries) {
190 if (FeatureOrErr->PostLinkCfg || PGOBBE.PostLinkBBFreq.has_value())
192 if (PGOBBE.Successors) {
194 for (
const auto &[ID,
BrProb, PostLinkBrFreq] : *PGOBBE.Successors) {
197 if (FeatureOrErr->PostLinkCfg || PostLinkBrFreq.has_value())
207 std::optional<std::vector<BBAddrMapEntry>> &Entries,
208 std::optional<std::vector<PGOAnalysisMapEntry>> &PGOAnalyses) {
209 assert((AddressSize == 4 || AddressSize == 8) &&
"invalid address size");
212 std::vector<BBAddrMapEntry> DecodedEntries;
213 bool HasAnyPGOAnalysisMapEntry =
false;
214 std::vector<PGOAnalysisMapEntry> DecodedPGOAnalyses;
219 while (Cur && Cur.
tell() < Content.
size()) {
224 "invalid SHT_LLVM_BB_ADDR_MAP section version: " +
232 return FeatureOrErr.takeError();
233 std::optional<llvm::yaml::Hex64> FuncGUID;
234 if (FeatureOrErr->FuncGUID)
235 FuncGUID =
Data.getU64(Cur);
236 if (FeatureOrErr->MultiBBRange) {
237 NumBBRanges =
Data.getULEB128(Cur);
240 NumBlocks =
Data.getULEB128(Cur);
242 std::vector<BBAddrMapEntry::BBRangeEntry> BBRanges;
244 for (
uint64_t BBRangeN = 0; Cur && BBRangeN != NumBBRanges; ++BBRangeN) {
245 if (FeatureOrErr->MultiBBRange) {
246 BaseAddress =
Data.getUnsigned(Cur, AddressSize);
247 NumBlocks =
Data.getULEB128(Cur);
252 std::vector<BBAddrMapEntry::BBEntry> BBEntries;
254 for (
uint64_t BlockIndex = 0; Cur && BlockIndex < NumBlocks;
258 std::optional<std::vector<llvm::yaml::Hex64>> CallsiteEndOffsets;
259 if (FeatureOrErr->CallsiteEndOffsets) {
261 CallsiteEndOffsets = std::vector<llvm::yaml::Hex64>(NumCallsites, 0);
269 std::optional<llvm::yaml::Hex64> Hash;
270 if (FeatureOrErr->BBHash)
271 Hash =
Data.getU64(Cur);
275 TotalNumBlocks += BBEntries.size();
276 BBRanges.push_back({BaseAddress, {}, BBEntries});
278 DecodedEntries.push_back(
279 {
Version, Feature, FuncGUID, {}, std::move(BBRanges)});
282 if (FeatureOrErr->hasPGOAnalysis()) {
283 HasAnyPGOAnalysisMapEntry =
true;
285 if (FeatureOrErr->FuncEntryCount)
288 if (FeatureOrErr->hasPGOAnalysisBBData()) {
289 auto &PGOBBEntries = PGOAnalysis.
PGOBBEntries.emplace();
290 for (
uint64_t BlockIndex = 0; Cur && BlockIndex < TotalNumBlocks;
292 auto &PGOBBEntry = PGOBBEntries.emplace_back();
293 if (FeatureOrErr->BBFreq) {
294 PGOBBEntry.BBFreq =
Data.getULEB128(Cur);
295 if (FeatureOrErr->PostLinkCfg)
296 PGOBBEntry.PostLinkBBFreq =
Data.getULEB128(Cur);
301 if (FeatureOrErr->BrProb) {
302 auto &SuccEntries = PGOBBEntry.Successors.emplace();
304 for (
uint64_t SuccIdx = 0; Cur && SuccIdx < SuccCount; ++SuccIdx) {
307 std::optional<uint32_t> PostLinkBrFreq;
308 if (FeatureOrErr->PostLinkCfg)
309 PostLinkBrFreq =
Data.getULEB128(Cur);
310 SuccEntries.push_back({ID,
BrProb, PostLinkBrFreq});
322 Entries = std::move(DecodedEntries);
323 if (HasAnyPGOAnalysisMapEntry)
324 PGOAnalyses = std::move(DecodedPGOAnalyses);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares the YAML representation of BB address maps (SHT_LLVM_BB_ADDR_MAP / ....
This file declares common types and utilities for basic-block address maps.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines ContiguousBlobAccumulator, the size-limited output buffer shared by the yaml2obj em...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
void write(const char *Ptr, size_t Size)
LLVM_ABI unsigned writeULEB128(uint64_t Val)
void mapOptional(StringRef Key, T &Val)
void * getContext() const
void mapRequired(StringRef Key, T &Val)
LLVM_ABI Error decodePayload(ArrayRef< uint8_t > Content, llvm::endianness Endian, unsigned AddressSize, std::optional< std::vector< BBAddrMapEntry > > &Entries, std::optional< std::vector< PGOAnalysisMapEntry > > &PGOAnalyses)
Decodes the BBAddrMap payload in Content into Entries and PGOAnalyses.
LLVM_ABI void encodePayload(ArrayRef< BBAddrMapEntry > Entries, const std::vector< PGOAnalysisMapEntry > *PGOAnalyses, yaml::ContiguousBlobAccumulator &CBA, llvm::endianness Endian, unsigned AddressSize)
Encodes the BBAddrMap payload into CBA.
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
void consumeError(Error Err)
Consume a Error without doing anything.
llvm::yaml::Hex64 Metadata
std::optional< std::vector< llvm::yaml::Hex64 > > CallsiteEndOffsets
std::optional< llvm::yaml::Hex64 > Hash
llvm::yaml::Hex64 AddressOffset
std::optional< std::vector< BBEntry > > BBEntries
std::optional< uint64_t > NumBlocks
llvm::yaml::Hex64 BaseAddress
std::optional< uint64_t > FuncEntryCount
std::optional< std::vector< PGOBBEntry > > PGOBBEntries
static Expected< Features > decode(uint16_t Val)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.