22 raw_ostream &Out, std::optional<unsigned> VersionOverride)
32 llvm::arrayRefFromStringRef(
Name));
35 auto DescribeRecord = [&](
unsigned RecordID,
StringRef Name) {
37 Data.push_back(RecordID);
55void PGOCtxProfileWriter::writeCounters(
const ContextNode &Node) {
59 for (
uint32_t I = 0U;
I < Node.counters_size(); ++
I)
67void PGOCtxProfileWriter::writeImpl(std::optional<uint32_t> CallerIndex,
77 for (
const auto *Subcontext =
Node.subContexts()[
I]; Subcontext;
78 Subcontext = Subcontext->next())
79 writeImpl(
I, *Subcontext);
84 writeImpl(std::nullopt, RootNode);
89struct DeserializableCtx {
92 std::vector<std::vector<DeserializableCtx>> Callsites;
96createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
97 const std::vector<DeserializableCtx> &DCList);
102createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
103 const DeserializableCtx &DC,
106 DC.Callsites.size());
107 auto *Mem = Nodes.emplace_back(std::make_unique<
char[]>(AllocSize)).get();
108 std::memset(Mem, 0, AllocSize);
110 DC.Callsites.size(), Next);
111 std::memcpy(Ret->counters(), DC.Counters.data(),
112 sizeof(
uint64_t) * DC.Counters.size());
114 Ret->subContexts()[
I] = createNode(Nodes, DCList);
120createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
121 const std::vector<DeserializableCtx> &DCList) {
123 for (
const auto &DC : DCList)
133 return Mapper && Mapper.
map(
"Guid", R.Guid) &&
134 Mapper.
map(
"Counters", R.Counters) &&
143 return P.takeError();
146 std::vector<DeserializableCtx> DCList;
147 if (!fromJSON(*
P, DCList, R))
150 std::vector<std::unique_ptr<char[]>> Nodes;
155 for (
const auto &DC : DCList) {
156 auto *TopList = createNode(Nodes, DC);
159 "Unexpected error converting internal structure to ctx profile");
160 Writer.
write(*TopList);
This file supports working with JSON data.
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)
Helper for mapping JSON objects onto protocol structs.
bool map(StringLiteral Prop, T &Out)
Maps a property to a field.
bool mapOptional(StringLiteral Prop, T &Out)
Maps a property to a field, if it exists.
The root is the trivial Path to the root value.
A "cursor" marking a position within a Value.
A Value is an JSON value of unknown type.
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
llvm::Expected< Value > parse(llvm::StringRef JSON)
Parses the provided JSON source, or returns a ParseError.
bool fromJSON(const Value &E, std::string &Out, Path P)
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 createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Error createCtxProfFromJSON(StringRef Profile, raw_ostream &Out)