LLVM 19.0.0git
PGOCtxProfWriter.cpp
Go to the documentation of this file.
1//===- PGOCtxProfWriter.cpp - Contextual Instrumentation profile writer ---===//
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// Write a contextual profile to bitstream.
10//
11//===----------------------------------------------------------------------===//
12
15
16using namespace llvm;
17using namespace llvm::ctx_profile;
18
19void PGOCtxProfileWriter::writeCounters(const ContextNode &Node) {
22 Writer.EmitVBR(Node.counters_size(), VBREncodingBits);
23 for (uint32_t I = 0U; I < Node.counters_size(); ++I)
24 Writer.EmitVBR64(Node.counters()[I], VBREncodingBits);
25}
26
27// recursively write all the subcontexts. We do need to traverse depth first to
28// model the context->subcontext implicitly, and since this captures call
29// stacks, we don't really need to be worried about stack overflow and we can
30// keep the implementation simple.
31void PGOCtxProfileWriter::writeImpl(std::optional<uint32_t> CallerIndex,
32 const ContextNode &Node) {
36 if (CallerIndex)
38 SmallVector<uint64_t, 1>{*CallerIndex});
39 writeCounters(Node);
40 for (uint32_t I = 0U; I < Node.callsites_size(); ++I)
41 for (const auto *Subcontext = Node.subContexts()[I]; Subcontext;
42 Subcontext = Subcontext->next())
43 writeImpl(I, *Subcontext);
44 Writer.ExitBlock();
45}
46
48 writeImpl(std::nullopt, RootNode);
49}
#define I(x, y, z)
Definition: MD5.cpp:58
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 EmitVBR(uint32_t Val, unsigned NumBits)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
static constexpr unsigned VBREncodingBits
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.
Definition: SmallVector.h:1209
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ ContextNodeBlockID