25 raw_ostream &Out, std::optional<unsigned> VersionOverride)
35 llvm::arrayRefFromStringRef(
Name));
38 auto DescribeRecord = [&](
unsigned RecordID,
StringRef Name) {
40 Data.push_back(RecordID);
58void PGOCtxProfileWriter::writeCounters(
const ContextNode &Node) {
62 for (
uint32_t I = 0U;
I < Node.counters_size(); ++
I)
70void PGOCtxProfileWriter::writeImpl(std::optional<uint32_t> CallerIndex,
80 for (
const auto *Subcontext =
Node.subContexts()[
I]; Subcontext;
81 Subcontext = Subcontext->next())
82 writeImpl(
I, *Subcontext);
87 writeImpl(std::nullopt, RootNode);
94struct SerializableCtxRepresentation {
97 std::vector<std::vector<SerializableCtxRepresentation>> Callsites;
101createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
102 const std::vector<SerializableCtxRepresentation> &DCList);
107createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
108 const SerializableCtxRepresentation &DC,
111 DC.Callsites.size());
112 auto *Mem = Nodes.emplace_back(std::make_unique<
char[]>(AllocSize)).get();
113 std::memset(Mem, 0, AllocSize);
115 DC.Callsites.size(), Next);
116 std::memcpy(Ret->counters(), DC.Counters.data(),
117 sizeof(
uint64_t) * DC.Counters.size());
119 Ret->subContexts()[
I] = createNode(Nodes, DCList);
126createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
127 const std::vector<SerializableCtxRepresentation> &DCList) {
129 for (
const auto &DC : DCList)
138 static void mapping(yaml::IO &IO, SerializableCtxRepresentation &SCR) {
139 IO.mapRequired(
"Guid", SCR.Guid);
140 IO.mapRequired(
"Counters", SCR.Counters);
141 IO.mapOptional(
"Callsites", SCR.Callsites);
147 std::vector<SerializableCtxRepresentation> DCList;
151 std::vector<std::unique_ptr<char[]>> Nodes;
156 for (
const auto &DC : DCList) {
157 auto *TopList = createNode(Nodes, DC);
160 "Unexpected error converting internal structure to ctx profile");
161 Writer.
write(*TopList);
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void EmitCode(unsigned Val)
EmitCode - Emit the specified code.
void EmitVBR64(uint64_t Val, unsigned NumBits)
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void EmitVBR(uint32_t Val, unsigned NumBits)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Write one or more ContextNodes to the provided raw_fd_stream.
static constexpr unsigned VBREncodingBits
static constexpr uint32_t CurrentVersion
static constexpr StringRef ContainerMagic
PGOCtxProfileWriter(raw_ostream &Out, std::optional< unsigned > VersionOverride=std::nullopt)
void write(const ctx_profile::ContextNode &)
static constexpr unsigned CodeLen
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static size_t getAllocSize(uint32_t NumCounters, uint32_t NumCallsites)
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ BLOCKINFO_CODE_BLOCKNAME
@ BLOCKINFO_CODE_SETRECORDNAME
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,...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Error createCtxProfFromYAML(StringRef Profile, raw_ostream &Out)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
static void mapping(yaml::IO &IO, SerializableCtxRepresentation &SCR)