LLVM 24.0.0git
BBAddrMapYAML.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares the YAML representation of BB address maps
11/// (SHT_LLVM_BB_ADDR_MAP / .llvm_bb_addr_map). The types here are
12/// format-agnostic so they can be reused by ELFYAML and COFFYAML.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_OBJECTYAML_BBADDRMAPYAML_H
17#define LLVM_OBJECTYAML_BBADDRMAPYAML_H
18
20
21namespace llvm {
22
23namespace yaml {
25}
26
27namespace BBAddrMapYAML {
28
30 struct BBEntry {
32 llvm::yaml::Hex64 AddressOffset;
33 llvm::yaml::Hex64 Size;
34 llvm::yaml::Hex64 Metadata;
35 std::optional<std::vector<llvm::yaml::Hex64>> CallsiteEndOffsets;
36 std::optional<llvm::yaml::Hex64> Hash;
37 };
39 llvm::yaml::Hex16 Feature;
40 std::optional<llvm::yaml::Hex64> FuncGUID;
41
42 struct BBRangeEntry {
43 llvm::yaml::Hex64 BaseAddress;
44 std::optional<uint64_t> NumBlocks;
45 std::optional<std::vector<BBEntry>> BBEntries;
46 };
47
48 std::optional<uint64_t> NumBBRanges;
49 std::optional<std::vector<BBRangeEntry>> BBRanges;
50
51 llvm::yaml::Hex64 getFunctionAddress() const {
52 if (!BBRanges || BBRanges->empty())
53 return 0;
54 return BBRanges->front().BaseAddress;
55 }
56
57 // Returns if any BB entries have non-empty callsite offsets.
59 if (!BBRanges)
60 return false;
61 for (const BBRangeEntry &BBR : *BBRanges) {
62 if (!BBR.BBEntries)
63 continue;
64 for (const BBEntry &BBE : *BBR.BBEntries)
65 if (BBE.CallsiteEndOffsets && !BBE.CallsiteEndOffsets->empty())
66 return true;
67 }
68 return false;
69 }
70};
71
73 struct PGOBBEntry {
76 llvm::yaml::Hex32 BrProb;
77 std::optional<uint32_t> PostLinkBrFreq;
78 };
79 std::optional<uint64_t> BBFreq;
80 std::optional<uint32_t> PostLinkBBFreq;
81 std::optional<std::vector<SuccessorEntry>> Successors;
82 };
83 std::optional<uint64_t> FuncEntryCount;
84 std::optional<std::vector<PGOBBEntry>> PGOBBEntries;
85};
86
87/// Encodes the BBAddrMap payload into \p CBA. \p AddressSize must be 4 or 8.
88/// If non-null, \p PGOAnalyses must have the same length as \p Entries.
90 const std::vector<PGOAnalysisMapEntry> *PGOAnalyses,
92 llvm::endianness Endian, unsigned AddressSize);
93
94/// Decodes the BBAddrMap payload in \p Content into \p Entries and
95/// \p PGOAnalyses. \p AddressSize must be 4 or 8. Returns an error for an
96/// unsupported version or feature. Leaves both outputs untouched if \p Content
97/// cannot be fully decoded.
99 ArrayRef<uint8_t> Content, llvm::endianness Endian, unsigned AddressSize,
100 std::optional<std::vector<BBAddrMapEntry>> &Entries,
101 std::optional<std::vector<PGOAnalysisMapEntry>> &PGOAnalyses);
102
103} // end namespace BBAddrMapYAML
104} // end namespace llvm
105
114
115namespace llvm {
116namespace yaml {
117
118template <> struct MappingTraits<BBAddrMapYAML::BBAddrMapEntry> {
119 LLVM_ABI static void mapping(IO &IO, BBAddrMapYAML::BBAddrMapEntry &E);
120};
121
122template <> struct MappingTraits<BBAddrMapYAML::BBAddrMapEntry::BBRangeEntry> {
123 LLVM_ABI static void mapping(IO &IO,
124 BBAddrMapYAML::BBAddrMapEntry::BBRangeEntry &E);
125};
126
127template <> struct MappingTraits<BBAddrMapYAML::BBAddrMapEntry::BBEntry> {
128 LLVM_ABI static void mapping(IO &IO,
129 BBAddrMapYAML::BBAddrMapEntry::BBEntry &E);
130};
131
132template <> struct MappingTraits<BBAddrMapYAML::PGOAnalysisMapEntry> {
133 LLVM_ABI static void mapping(IO &IO, BBAddrMapYAML::PGOAnalysisMapEntry &E);
134};
135
136template <>
137struct MappingTraits<BBAddrMapYAML::PGOAnalysisMapEntry::PGOBBEntry> {
138 LLVM_ABI static void
139 mapping(IO &IO, BBAddrMapYAML::PGOAnalysisMapEntry::PGOBBEntry &E);
140};
141
142template <>
143struct MappingTraits<
144 BBAddrMapYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry> {
145 LLVM_ABI static void
146 mapping(IO &IO,
147 BBAddrMapYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry &E);
148};
149
150} // end namespace yaml
151} // end namespace llvm
152
153#endif // LLVM_OBJECTYAML_BBADDRMAPYAML_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
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.
endianness
Definition bit.h:71
std::optional< std::vector< llvm::yaml::Hex64 > > CallsiteEndOffsets
std::optional< llvm::yaml::Hex64 > Hash
std::optional< std::vector< BBEntry > > BBEntries
std::optional< llvm::yaml::Hex64 > FuncGUID
std::optional< std::vector< BBRangeEntry > > BBRanges
llvm::yaml::Hex64 getFunctionAddress() const
std::optional< uint64_t > NumBBRanges
std::optional< std::vector< SuccessorEntry > > Successors
std::optional< uint64_t > FuncEntryCount
std::optional< std::vector< PGOBBEntry > > PGOBBEntries
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63