26 cl::desc(
"Also write profiles with all-zero counters. "
27 "Intended for testing/debugging."));
30 raw_ostream &Out, std::optional<unsigned> VersionOverride,
43 llvm::arrayRefFromStringRef(
Name));
46 auto DescribeRecord = [&](
unsigned RecordID,
StringRef Name) {
48 Data.push_back(RecordID);
58 "TotalRootEntryCount");
108 if (!IncludeEmpty && (
Node.counters_size() > 0 &&
Node.entrycount() == 0))
111 writeGuid(
Node.guid());
113 writeCounters({
Node.counters(),
Node.counters_size()});
114 writeSubcontexts(
Node);
120 for (
const auto *Subcontext =
Node.subContexts()[
I]; Subcontext;
121 Subcontext = Subcontext->next())
122 writeNode(
I, *Subcontext);
144 writeGuid(RootNode.
guid());
149 for (
const auto *
P = Unhandled;
P;
P =
P->next())
150 writeFlat(
P->guid(),
P->counters(),
P->counters_size());
153 writeSubcontexts(RootNode);
161 writeCounters({Buffer,
Size});
169using SerializableFlatProfileRepresentation =
170 std::pair<ctx_profile::GUID, std::vector<uint64_t>>;
172struct SerializableCtxRepresentation {
175 std::vector<std::vector<SerializableCtxRepresentation>> Callsites;
178struct SerializableRootRepresentation :
public SerializableCtxRepresentation {
180 std::vector<SerializableFlatProfileRepresentation> Unhandled;
183struct SerializableProfileRepresentation {
184 std::vector<SerializableRootRepresentation> Contexts;
185 std::vector<SerializableFlatProfileRepresentation> FlatProfiles;
189createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
190 const std::vector<SerializableCtxRepresentation> &DCList);
195createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
196 const SerializableCtxRepresentation &DC,
199 DC.Callsites.size());
200 auto *Mem = Nodes.emplace_back(std::make_unique<
char[]>(AllocSize)).get();
201 std::memset(Mem, 0, AllocSize);
203 DC.Callsites.size(), Next);
204 std::memcpy(
Ret->counters(), DC.Counters.data(),
205 sizeof(
uint64_t) * DC.Counters.size());
214createNode(std::vector<std::unique_ptr<
char[]>> &Nodes,
215 const std::vector<SerializableCtxRepresentation> &DCList) {
217 for (
const auto &DC : DCList)
228 static void mapping(yaml::IO &IO, SerializableCtxRepresentation &SCR) {
229 IO.mapRequired(
"Guid", SCR.Guid);
230 IO.mapRequired(
"Counters", SCR.Counters);
231 IO.mapOptional(
"Callsites", SCR.Callsites);
236 static void mapping(yaml::IO &IO, SerializableRootRepresentation &R) {
238 IO.mapRequired(
"TotalRootEntryCount", R.TotalRootEntryCount);
239 IO.mapOptional(
"Unhandled", R.Unhandled);
244 static void mapping(yaml::IO &IO, SerializableProfileRepresentation &SPR) {
245 IO.mapOptional(
"Contexts", SPR.Contexts);
246 IO.mapOptional(
"FlatProfiles", SPR.FlatProfiles);
252 SerializableFlatProfileRepresentation &SFPR) {
253 IO.mapRequired(
"Guid", SFPR.first);
254 IO.mapRequired(
"Counters", SFPR.second);
260 SerializableProfileRepresentation SPR;
264 std::vector<std::unique_ptr<char[]>> Nodes;
270 if (!SPR.Contexts.empty()) {
272 for (
const auto &DC : SPR.Contexts) {
273 auto *TopList = createNode(Nodes, DC);
276 "Unexpected error converting internal structure to ctx profile");
279 for (
const auto &U : DC.Unhandled) {
280 SerializableCtxRepresentation Unhandled;
281 Unhandled.Guid = U.first;
282 Unhandled.Counters = U.second;
283 FirstUnhandled = createNode(Nodes, Unhandled, FirstUnhandled);
285 Writer.
writeContextual(*TopList, FirstUnhandled, DC.TotalRootEntryCount);
289 if (!SPR.FlatProfiles.empty()) {
static cl::opt< bool > IncludeEmptyOpt("ctx-prof-include-empty", cl::init(false), cl::desc("Also write profiles with all-zero counters. " "Intended for testing/debugging."))
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
void startFlatSection() override
void writeContextual(const ctx_profile::ContextNode &RootNode, const ctx_profile::ContextNode *Unhandled, uint64_t TotalRootEntryCount) override
static constexpr unsigned VBREncodingBits
static constexpr uint32_t CurrentVersion
PGOCtxProfileWriter(raw_ostream &Out, std::optional< unsigned > VersionOverride=std::nullopt, bool IncludeEmpty=false)
void endFlatSection() override
static constexpr StringRef ContainerMagic
static constexpr unsigned CodeLen
void startContextSection() override
void endContextSection() override
void writeFlat(ctx_profile::GUID Guid, const uint64_t *Buffer, size_t BufferSize) override
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).
uint64_t entrycount() const
static size_t getAllocSize(uint32_t NumCounters, uint32_t NumCallsites)
uint32_t counters_size() const
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.
@ C
The default llvm calling convention, compatible with C.
@ BLOCKINFO_CODE_BLOCKNAME
@ BLOCKINFO_CODE_SETRECORDNAME
initializer< Ty > init(const Ty &Val)
AstPtr createNode(ASTNode::Type T, Accessor A, ASTNode *Parent, llvm::StringMap< AstPtr > &Partials, llvm::StringMap< Lambda > &Lambdas, llvm::StringMap< SectionLambda > &SectionLambdas, EscapeMap &Escapes)
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.
LLVM_ABI Error createCtxProfFromYAML(StringRef Profile, raw_ostream &Out)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
@ FlatProfilesSectionBlockID
static void mapping(yaml::IO &IO, SerializableCtxRepresentation &SCR)
static void mapping(yaml::IO &IO, SerializableFlatProfileRepresentation &SFPR)
static void mapping(yaml::IO &IO, SerializableProfileRepresentation &SPR)
static void mapping(yaml::IO &IO, SerializableRootRepresentation &R)