26 raw_ostream &Out, std::optional<unsigned> VersionOverride)
36 llvm::arrayRefFromStringRef(
Name));
39 auto DescribeRecord = [&](
unsigned RecordID,
StringRef Name) {
41 Data.push_back(RecordID);
59void PGOCtxProfileWriter::writeCounters(
const ContextNode &Node) {
63 for (
uint32_t I = 0U;
I < Node.counters_size(); ++
I)
71void PGOCtxProfileWriter::writeImpl(std::optional<uint32_t> CallerIndex,
81 for (
const auto *Subcontext =
Node.subContexts()[
I]; Subcontext;
82 Subcontext = Subcontext->next())
83 writeImpl(
I, *Subcontext);
88 writeImpl(std::nullopt, RootNode);
93createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
94 const std::vector<SerializableCtxRepresentation> &DCList);
99createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
104 auto *Mem = Nodes.emplace_back(std::make_unique<
char[]>(AllocSize)).get();
105 std::memset(Mem, 0, AllocSize);
108 std::memcpy(Ret->counters(), DC.
Counters.data(),
111 Ret->subContexts()[
I] = createNode(Nodes, DCList);
118createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
119 const std::vector<SerializableCtxRepresentation> &DCList) {
121 for (
const auto &DC : DCList)
131 IO.mapRequired(
"Guid", SCR.
Guid);
132 IO.mapRequired(
"Counters", SCR.
Counters);
133 IO.mapOptional(
"Callsites", SCR.
Callsites);
139 std::vector<SerializableCtxRepresentation> DCList;
143 std::vector<std::unique_ptr<char[]>> Nodes;
148 for (
const auto &DC : DCList) {
149 auto *TopList = createNode(Nodes, DC);
152 "Unexpected error converting internal structure to ctx profile");
153 Writer.
write(*TopList);
This file supports working with JSON data.
#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.
Representation of the context node suitable for yaml / json serialization / deserialization.
std::vector< std::vector< SerializableCtxRepresentation > > Callsites
std::vector< uint64_t > Counters
static void mapping(yaml::IO &IO, SerializableCtxRepresentation &SCR)