2017-03-03 02:07:34 +01:00
|
|
|
//===- SampleProfReader.h - Read LLVM sample profile data -------*- C++ -*-===//
|
2014-09-09 14:40:50 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-09-09 14:40:50 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains definitions needed for reading sample profiles.
|
|
|
|
//
|
2015-10-14 20:36:30 +02:00
|
|
|
// NOTE: If you are making changes to this file format, please remember
|
|
|
|
// to document them in the Clang documentation at
|
|
|
|
// tools/clang/docs/UsersManual.rst.
|
|
|
|
//
|
|
|
|
// Text format
|
|
|
|
// -----------
|
|
|
|
//
|
|
|
|
// Sample profiles are written as ASCII text. The file is divided into
|
|
|
|
// sections, which correspond to each of the functions executed at runtime.
|
|
|
|
// Each section has the following format
|
|
|
|
//
|
|
|
|
// function1:total_samples:total_head_samples
|
|
|
|
// offset1[.discriminator]: number_of_samples [fn1:num fn2:num ... ]
|
|
|
|
// offset2[.discriminator]: number_of_samples [fn3:num fn4:num ... ]
|
|
|
|
// ...
|
|
|
|
// offsetN[.discriminator]: number_of_samples [fn5:num fn6:num ... ]
|
|
|
|
// offsetA[.discriminator]: fnA:num_of_total_samples
|
|
|
|
// offsetA1[.discriminator]: number_of_samples [fn7:num fn8:num ... ]
|
|
|
|
// ...
|
2020-12-16 21:54:50 +01:00
|
|
|
// !CFGChecksum: num
|
2015-10-14 20:36:30 +02:00
|
|
|
//
|
2020-12-16 21:54:50 +01:00
|
|
|
// This is a nested tree in which the indentation represents the nesting level
|
2015-10-14 20:36:30 +02:00
|
|
|
// of the inline stack. There are no blank lines in the file. And the spacing
|
|
|
|
// within a single line is fixed. Additional spaces will result in an error
|
|
|
|
// while reading the file.
|
|
|
|
//
|
|
|
|
// Any line starting with the '#' character is completely ignored.
|
|
|
|
//
|
|
|
|
// Inlined calls are represented with indentation. The Inline stack is a
|
|
|
|
// stack of source locations in which the top of the stack represents the
|
|
|
|
// leaf function, and the bottom of the stack represents the actual
|
|
|
|
// symbol to which the instruction belongs.
|
|
|
|
//
|
|
|
|
// Function names must be mangled in order for the profile loader to
|
|
|
|
// match them in the current translation unit. The two numbers in the
|
|
|
|
// function header specify how many total samples were accumulated in the
|
|
|
|
// function (first number), and the total number of samples accumulated
|
|
|
|
// in the prologue of the function (second number). This head sample
|
|
|
|
// count provides an indicator of how frequently the function is invoked.
|
|
|
|
//
|
2020-12-16 21:54:50 +01:00
|
|
|
// There are three types of lines in the function body.
|
2015-10-14 20:36:30 +02:00
|
|
|
//
|
|
|
|
// * Sampled line represents the profile information of a source location.
|
|
|
|
// * Callsite line represents the profile information of a callsite.
|
2020-12-16 21:54:50 +01:00
|
|
|
// * Metadata line represents extra metadata of the function.
|
2015-10-14 20:36:30 +02:00
|
|
|
//
|
|
|
|
// Each sampled line may contain several items. Some are optional (marked
|
|
|
|
// below):
|
|
|
|
//
|
|
|
|
// a. Source line offset. This number represents the line number
|
|
|
|
// in the function where the sample was collected. The line number is
|
|
|
|
// always relative to the line where symbol of the function is
|
|
|
|
// defined. So, if the function has its header at line 280, the offset
|
|
|
|
// 13 is at line 293 in the file.
|
|
|
|
//
|
|
|
|
// Note that this offset should never be a negative number. This could
|
|
|
|
// happen in cases like macros. The debug machinery will register the
|
|
|
|
// line number at the point of macro expansion. So, if the macro was
|
|
|
|
// expanded in a line before the start of the function, the profile
|
|
|
|
// converter should emit a 0 as the offset (this means that the optimizers
|
|
|
|
// will not be able to associate a meaningful weight to the instructions
|
|
|
|
// in the macro).
|
|
|
|
//
|
|
|
|
// b. [OPTIONAL] Discriminator. This is used if the sampled program
|
|
|
|
// was compiled with DWARF discriminator support
|
|
|
|
// (http://wiki.dwarfstd.org/index.php?title=Path_Discriminators).
|
|
|
|
// DWARF discriminators are unsigned integer values that allow the
|
|
|
|
// compiler to distinguish between multiple execution paths on the
|
|
|
|
// same source line location.
|
|
|
|
//
|
|
|
|
// For example, consider the line of code ``if (cond) foo(); else bar();``.
|
|
|
|
// If the predicate ``cond`` is true 80% of the time, then the edge
|
|
|
|
// into function ``foo`` should be considered to be taken most of the
|
|
|
|
// time. But both calls to ``foo`` and ``bar`` are at the same source
|
|
|
|
// line, so a sample count at that line is not sufficient. The
|
|
|
|
// compiler needs to know which part of that line is taken more
|
|
|
|
// frequently.
|
|
|
|
//
|
|
|
|
// This is what discriminators provide. In this case, the calls to
|
|
|
|
// ``foo`` and ``bar`` will be at the same line, but will have
|
|
|
|
// different discriminator values. This allows the compiler to correctly
|
|
|
|
// set edge weights into ``foo`` and ``bar``.
|
|
|
|
//
|
|
|
|
// c. Number of samples. This is an integer quantity representing the
|
|
|
|
// number of samples collected by the profiler at this source
|
|
|
|
// location.
|
|
|
|
//
|
|
|
|
// d. [OPTIONAL] Potential call targets and samples. If present, this
|
|
|
|
// line contains a call instruction. This models both direct and
|
|
|
|
// number of samples. For example,
|
|
|
|
//
|
|
|
|
// 130: 7 foo:3 bar:2 baz:7
|
|
|
|
//
|
|
|
|
// The above means that at relative line offset 130 there is a call
|
|
|
|
// instruction that calls one of ``foo()``, ``bar()`` and ``baz()``,
|
|
|
|
// with ``baz()`` being the relatively more frequently called target.
|
|
|
|
//
|
|
|
|
// Each callsite line may contain several items. Some are optional.
|
|
|
|
//
|
|
|
|
// a. Source line offset. This number represents the line number of the
|
|
|
|
// callsite that is inlined in the profiled binary.
|
|
|
|
//
|
|
|
|
// b. [OPTIONAL] Discriminator. Same as the discriminator for sampled line.
|
|
|
|
//
|
|
|
|
// c. Number of samples. This is an integer quantity representing the
|
|
|
|
// total number of samples collected for the inlined instance at this
|
|
|
|
// callsite
|
|
|
|
//
|
2020-12-16 21:54:50 +01:00
|
|
|
// Metadata line can occur in lines with one indent only, containing extra
|
|
|
|
// information for the top-level function. Furthermore, metadata can only
|
|
|
|
// occur after all the body samples and callsite samples.
|
|
|
|
// Each metadata line may contain a particular type of metadata, marked by
|
|
|
|
// the starting characters annotated with !. We process each metadata line
|
|
|
|
// independently, hence each metadata line has to form an independent piece
|
|
|
|
// of information that does not require cross-line reference.
|
|
|
|
// We support the following types of metadata:
|
|
|
|
//
|
|
|
|
// a. CFG Checksum (a.k.a. function hash):
|
|
|
|
// !CFGChecksum: 12345
|
|
|
|
//
|
2015-10-14 20:36:30 +02:00
|
|
|
//
|
|
|
|
// Binary format
|
|
|
|
// -------------
|
|
|
|
//
|
|
|
|
// This is a more compact encoding. Numbers are encoded as ULEB128 values
|
|
|
|
// and all strings are encoded in a name table. The file is organized in
|
|
|
|
// the following sections:
|
|
|
|
//
|
|
|
|
// MAGIC (uint64_t)
|
|
|
|
// File identifier computed by function SPMagic() (0x5350524f463432ff)
|
|
|
|
//
|
|
|
|
// VERSION (uint32_t)
|
|
|
|
// File format version number computed by SPVersion()
|
|
|
|
//
|
2016-02-19 04:15:33 +01:00
|
|
|
// SUMMARY
|
|
|
|
// TOTAL_COUNT (uint64_t)
|
|
|
|
// Total number of samples in the profile.
|
|
|
|
// MAX_COUNT (uint64_t)
|
|
|
|
// Maximum value of samples on a line.
|
2016-03-29 01:14:29 +02:00
|
|
|
// MAX_FUNCTION_COUNT (uint64_t)
|
|
|
|
// Maximum number of samples at function entry (head samples).
|
2016-02-19 04:15:33 +01:00
|
|
|
// NUM_COUNTS (uint64_t)
|
|
|
|
// Number of lines with samples.
|
|
|
|
// NUM_FUNCTIONS (uint64_t)
|
|
|
|
// Number of functions with samples.
|
|
|
|
// NUM_DETAILED_SUMMARY_ENTRIES (size_t)
|
|
|
|
// Number of entries in detailed summary
|
|
|
|
// DETAILED_SUMMARY
|
|
|
|
// A list of detailed summary entry. Each entry consists of
|
|
|
|
// CUTOFF (uint32_t)
|
|
|
|
// Required percentile of total sample count expressed as a fraction
|
|
|
|
// multiplied by 1000000.
|
|
|
|
// MIN_COUNT (uint64_t)
|
|
|
|
// The minimum number of samples required to reach the target
|
|
|
|
// CUTOFF.
|
|
|
|
// NUM_COUNTS (uint64_t)
|
|
|
|
// Number of samples to get to the desrired percentile.
|
|
|
|
//
|
2015-10-14 20:36:30 +02:00
|
|
|
// NAME TABLE
|
|
|
|
// SIZE (uint32_t)
|
|
|
|
// Number of entries in the name table.
|
|
|
|
// NAMES
|
|
|
|
// A NUL-separated list of SIZE strings.
|
|
|
|
//
|
|
|
|
// FUNCTION BODY (one for each uninlined function body present in the profile)
|
2015-10-16 20:54:35 +02:00
|
|
|
// HEAD_SAMPLES (uint64_t) [only for top-level functions]
|
|
|
|
// Total number of samples collected at the head (prologue) of the
|
|
|
|
// function.
|
|
|
|
// NOTE: This field should only be present for top-level functions
|
|
|
|
// (i.e., not inlined into any caller). Inlined function calls
|
|
|
|
// have no prologue, so they don't need this.
|
2015-10-14 20:36:30 +02:00
|
|
|
// NAME_IDX (uint32_t)
|
|
|
|
// Index into the name table indicating the function name.
|
2015-10-15 18:36:21 +02:00
|
|
|
// SAMPLES (uint64_t)
|
2015-10-14 20:36:30 +02:00
|
|
|
// Total number of samples collected in this function.
|
|
|
|
// NRECS (uint32_t)
|
|
|
|
// Total number of sampling records this function's profile.
|
|
|
|
// BODY RECORDS
|
|
|
|
// A list of NRECS entries. Each entry contains:
|
|
|
|
// OFFSET (uint32_t)
|
|
|
|
// Line offset from the start of the function.
|
|
|
|
// DISCRIMINATOR (uint32_t)
|
|
|
|
// Discriminator value (see description of discriminators
|
|
|
|
// in the text format documentation above).
|
|
|
|
// SAMPLES (uint64_t)
|
|
|
|
// Number of samples collected at this location.
|
|
|
|
// NUM_CALLS (uint32_t)
|
|
|
|
// Number of non-inlined function calls made at this location. In the
|
|
|
|
// case of direct calls, this number will always be 1. For indirect
|
|
|
|
// calls (virtual functions and function pointers) this will
|
|
|
|
// represent all the actual functions called at runtime.
|
|
|
|
// CALL_TARGETS
|
|
|
|
// A list of NUM_CALLS entries for each called function:
|
|
|
|
// NAME_IDX (uint32_t)
|
|
|
|
// Index into the name table with the callee name.
|
|
|
|
// SAMPLES (uint64_t)
|
|
|
|
// Number of samples collected at the call site.
|
|
|
|
// NUM_INLINED_FUNCTIONS (uint32_t)
|
|
|
|
// Number of callees inlined into this function.
|
|
|
|
// INLINED FUNCTION RECORDS
|
|
|
|
// A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined
|
|
|
|
// callees.
|
|
|
|
// OFFSET (uint32_t)
|
|
|
|
// Line offset from the start of the function.
|
|
|
|
// DISCRIMINATOR (uint32_t)
|
|
|
|
// Discriminator value (see description of discriminators
|
|
|
|
// in the text format documentation above).
|
|
|
|
// FUNCTION BODY
|
|
|
|
// A FUNCTION BODY entry describing the inlined function.
|
2014-09-09 14:40:50 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2017-03-03 02:07:34 +01:00
|
|
|
|
2014-09-09 14:40:50 +02:00
|
|
|
#ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H
|
|
|
|
#define LLVM_PROFILEDATA_SAMPLEPROFREADER_H
|
|
|
|
|
[SampleFDO] Enhance profile remapping support for searching inline instance
and indirect call promotion candidate.
Profile remapping is a feature to match a function in the module with its
profile in sample profile if the function name and the name in profile look
different but are equivalent using given remapping rules. This is a useful
feature to keep the performance stable by specifying some remapping rules
when sampleFDO targets are going through some large scale function signature
change.
However, currently profile remapping support is only valid for outline
function profile in SampleFDO. It cannot match a callee with an inline
instance profile if they have different but equivalent names. We found
that without the support for inline instance profile, remapping is less
effective for some large scale change.
To add that support, before any remapping lookup happens, all the names
in the profile will be inserted into remapper and the Key to the name
mapping will be recorded in a map called NameMap in the remapper. During
name lookup, a Key will be returned for the given name and it will be used
to extract an equivalent name in the profile from NameMap. So with the help
of the NameMap, we can translate any given name to an equivalent name in
the profile if it exists. Whenever we try to match a name in the module to
a name in the profile, we will try the match with the original name first,
and if it doesn't match, we will use the equivalent name got from remapper
to try the match for another time. In this way, the patch can enhance the
profile remapping support for searching inline instance and searching
indirect call promotion candidate.
In a planned large scale change of int64 type (long long) to int64_t (long),
we found the performance of a google internal benchmark degraded by 2% if
nothing was done. If existing profile remapping was enabled, the performance
degradation dropped to 1.2%. If the profile remapping with the current patch
was enabled, the performance degradation further dropped to 0.14% (Note the
experiment was done before searching indirect call promotion candidate was
added. We hope with the remapping support of searching indirect call promotion
candidate, the degradation can drop to 0% in the end. It will be evaluated
post commit).
Differential Revision: https://reviews.llvm.org/D86332
2020-08-25 07:59:20 +02:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2017-03-03 02:07:34 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-09-09 14:40:50 +02:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2017-03-03 02:07:34 +01:00
|
|
|
#include "llvm/IR/ProfileSummary.h"
|
2017-11-03 21:57:10 +01:00
|
|
|
#include "llvm/ProfileData/GCOV.h"
|
2014-10-30 19:00:06 +01:00
|
|
|
#include "llvm/ProfileData/SampleProf.h"
|
2014-11-01 01:56:55 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2014-10-30 19:00:06 +01:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2018-10-10 23:31:01 +02:00
|
|
|
#include "llvm/Support/SymbolRemappingReader.h"
|
2017-03-03 02:07:34 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
|
|
|
#include <vector>
|
2014-09-09 14:40:50 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2017-03-03 02:07:34 +01:00
|
|
|
class raw_ostream;
|
2021-01-06 15:04:37 +01:00
|
|
|
class Twine;
|
2017-03-03 02:07:34 +01:00
|
|
|
|
2014-09-09 14:40:50 +02:00
|
|
|
namespace sampleprof {
|
|
|
|
|
2019-10-19 00:35:20 +02:00
|
|
|
class SampleProfileReader;
|
|
|
|
|
|
|
|
/// SampleProfileReaderItaniumRemapper remaps the profile data from a
|
|
|
|
/// sample profile data reader, by applying a provided set of equivalences
|
|
|
|
/// between components of the symbol names in the profile.
|
|
|
|
class SampleProfileReaderItaniumRemapper {
|
|
|
|
public:
|
|
|
|
SampleProfileReaderItaniumRemapper(std::unique_ptr<MemoryBuffer> B,
|
|
|
|
std::unique_ptr<SymbolRemappingReader> SRR,
|
|
|
|
SampleProfileReader &R)
|
|
|
|
: Buffer(std::move(B)), Remappings(std::move(SRR)), Reader(R) {
|
|
|
|
assert(Remappings && "Remappings cannot be nullptr");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a remapper from the given remapping file. The remapper will
|
|
|
|
/// be used for profile read in by Reader.
|
|
|
|
static ErrorOr<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
|
|
|
|
create(const std::string Filename, SampleProfileReader &Reader,
|
|
|
|
LLVMContext &C);
|
|
|
|
|
|
|
|
/// Create a remapper from the given Buffer. The remapper will
|
|
|
|
/// be used for profile read in by Reader.
|
|
|
|
static ErrorOr<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
|
|
|
|
create(std::unique_ptr<MemoryBuffer> &B, SampleProfileReader &Reader,
|
|
|
|
LLVMContext &C);
|
|
|
|
|
|
|
|
/// Apply remappings to the profile read by Reader.
|
|
|
|
void applyRemapping(LLVMContext &Ctx);
|
|
|
|
|
|
|
|
bool hasApplied() { return RemappingApplied; }
|
|
|
|
|
|
|
|
/// Insert function name into remapper.
|
|
|
|
void insert(StringRef FunctionName) { Remappings->insert(FunctionName); }
|
|
|
|
|
|
|
|
/// Query whether there is equivalent in the remapper which has been
|
|
|
|
/// inserted.
|
|
|
|
bool exist(StringRef FunctionName) {
|
|
|
|
return Remappings->lookup(FunctionName);
|
|
|
|
}
|
|
|
|
|
[SampleFDO] Enhance profile remapping support for searching inline instance
and indirect call promotion candidate.
Profile remapping is a feature to match a function in the module with its
profile in sample profile if the function name and the name in profile look
different but are equivalent using given remapping rules. This is a useful
feature to keep the performance stable by specifying some remapping rules
when sampleFDO targets are going through some large scale function signature
change.
However, currently profile remapping support is only valid for outline
function profile in SampleFDO. It cannot match a callee with an inline
instance profile if they have different but equivalent names. We found
that without the support for inline instance profile, remapping is less
effective for some large scale change.
To add that support, before any remapping lookup happens, all the names
in the profile will be inserted into remapper and the Key to the name
mapping will be recorded in a map called NameMap in the remapper. During
name lookup, a Key will be returned for the given name and it will be used
to extract an equivalent name in the profile from NameMap. So with the help
of the NameMap, we can translate any given name to an equivalent name in
the profile if it exists. Whenever we try to match a name in the module to
a name in the profile, we will try the match with the original name first,
and if it doesn't match, we will use the equivalent name got from remapper
to try the match for another time. In this way, the patch can enhance the
profile remapping support for searching inline instance and searching
indirect call promotion candidate.
In a planned large scale change of int64 type (long long) to int64_t (long),
we found the performance of a google internal benchmark degraded by 2% if
nothing was done. If existing profile remapping was enabled, the performance
degradation dropped to 1.2%. If the profile remapping with the current patch
was enabled, the performance degradation further dropped to 0.14% (Note the
experiment was done before searching indirect call promotion candidate was
added. We hope with the remapping support of searching indirect call promotion
candidate, the degradation can drop to 0% in the end. It will be evaluated
post commit).
Differential Revision: https://reviews.llvm.org/D86332
2020-08-25 07:59:20 +02:00
|
|
|
/// Return the equivalent name in the profile for \p FunctionName if
|
|
|
|
/// it exists.
|
|
|
|
Optional<StringRef> lookUpNameInProfile(StringRef FunctionName);
|
2019-10-19 00:35:20 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// The buffer holding the content read from remapping file.
|
|
|
|
std::unique_ptr<MemoryBuffer> Buffer;
|
|
|
|
std::unique_ptr<SymbolRemappingReader> Remappings;
|
[SampleFDO] Enhance profile remapping support for searching inline instance
and indirect call promotion candidate.
Profile remapping is a feature to match a function in the module with its
profile in sample profile if the function name and the name in profile look
different but are equivalent using given remapping rules. This is a useful
feature to keep the performance stable by specifying some remapping rules
when sampleFDO targets are going through some large scale function signature
change.
However, currently profile remapping support is only valid for outline
function profile in SampleFDO. It cannot match a callee with an inline
instance profile if they have different but equivalent names. We found
that without the support for inline instance profile, remapping is less
effective for some large scale change.
To add that support, before any remapping lookup happens, all the names
in the profile will be inserted into remapper and the Key to the name
mapping will be recorded in a map called NameMap in the remapper. During
name lookup, a Key will be returned for the given name and it will be used
to extract an equivalent name in the profile from NameMap. So with the help
of the NameMap, we can translate any given name to an equivalent name in
the profile if it exists. Whenever we try to match a name in the module to
a name in the profile, we will try the match with the original name first,
and if it doesn't match, we will use the equivalent name got from remapper
to try the match for another time. In this way, the patch can enhance the
profile remapping support for searching inline instance and searching
indirect call promotion candidate.
In a planned large scale change of int64 type (long long) to int64_t (long),
we found the performance of a google internal benchmark degraded by 2% if
nothing was done. If existing profile remapping was enabled, the performance
degradation dropped to 1.2%. If the profile remapping with the current patch
was enabled, the performance degradation further dropped to 0.14% (Note the
experiment was done before searching indirect call promotion candidate was
added. We hope with the remapping support of searching indirect call promotion
candidate, the degradation can drop to 0% in the end. It will be evaluated
post commit).
Differential Revision: https://reviews.llvm.org/D86332
2020-08-25 07:59:20 +02:00
|
|
|
// Map remapping key to the name in the profile. By looking up the
|
|
|
|
// key in the remapper, a given new name can be mapped to the
|
|
|
|
// cannonical name using the NameMap.
|
|
|
|
DenseMap<SymbolRemappingReader::Key, StringRef> NameMap;
|
2019-10-19 00:35:20 +02:00
|
|
|
// The Reader the remapper is servicing.
|
|
|
|
SampleProfileReader &Reader;
|
|
|
|
// Indicate whether remapping has been applied to the profile read
|
|
|
|
// by Reader -- by calling applyRemapping.
|
|
|
|
bool RemappingApplied = false;
|
|
|
|
};
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Sample-based profile reader.
|
2014-09-09 14:40:50 +02:00
|
|
|
///
|
|
|
|
/// Each profile contains sample counts for all the functions
|
|
|
|
/// executed. Inside each function, statements are annotated with the
|
|
|
|
/// collected samples on all the instructions associated with that
|
|
|
|
/// statement.
|
|
|
|
///
|
|
|
|
/// For this to produce meaningful data, the program needs to be
|
|
|
|
/// compiled with some debug information (at minimum, line numbers:
|
|
|
|
/// -gline-tables-only). Otherwise, it will be impossible to match IR
|
|
|
|
/// instructions to the line numbers collected by the profiler.
|
|
|
|
///
|
|
|
|
/// From the profile file, we are interested in collecting the
|
|
|
|
/// following information:
|
|
|
|
///
|
|
|
|
/// * A list of functions included in the profile (mangled names).
|
|
|
|
///
|
|
|
|
/// * For each function F:
|
|
|
|
/// 1. The total number of samples collected in F.
|
|
|
|
///
|
|
|
|
/// 2. The samples collected at each line in F. To provide some
|
|
|
|
/// protection against source code shuffling, line numbers should
|
|
|
|
/// be relative to the start of the function.
|
|
|
|
///
|
2014-10-30 19:00:06 +01:00
|
|
|
/// The reader supports two file formats: text and binary. The text format
|
|
|
|
/// is useful for debugging and testing, while the binary format is more
|
2015-09-17 02:17:24 +02:00
|
|
|
/// compact and I/O efficient. They can both be used interchangeably.
|
2014-09-09 14:40:50 +02:00
|
|
|
class SampleProfileReader {
|
|
|
|
public:
|
2018-06-12 00:40:43 +02:00
|
|
|
SampleProfileReader(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
|
|
|
|
SampleProfileFormat Format = SPF_None)
|
|
|
|
: Profiles(0), Ctx(C), Buffer(std::move(B)), Format(Format) {}
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2017-03-03 02:07:34 +01:00
|
|
|
virtual ~SampleProfileReader() = default;
|
2014-09-09 14:40:50 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read and validate the file header.
|
2014-10-30 19:00:06 +01:00
|
|
|
virtual std::error_code readHeader() = 0;
|
|
|
|
|
2019-10-19 00:35:20 +02:00
|
|
|
/// The interface to read sample profiles from the associated file.
|
|
|
|
std::error_code read() {
|
|
|
|
if (std::error_code EC = readImpl())
|
|
|
|
return EC;
|
|
|
|
if (Remapper)
|
|
|
|
Remapper->applyRemapping(Ctx);
|
2020-03-03 22:19:32 +01:00
|
|
|
FunctionSamples::UseMD5 = useMD5();
|
2019-10-19 00:35:20 +02:00
|
|
|
return sampleprof_error::success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The implementaion to read sample profiles from the associated file.
|
|
|
|
virtual std::error_code readImpl() = 0;
|
2014-09-09 14:40:50 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Print the profile for \p FName on stream \p OS.
|
2014-11-01 01:56:55 +01:00
|
|
|
void dumpFunctionProfile(StringRef FName, raw_ostream &OS = dbgs());
|
2014-09-09 14:40:50 +02:00
|
|
|
|
2019-10-09 23:36:03 +02:00
|
|
|
virtual void collectFuncsFrom(const Module &M) {}
|
2018-09-14 22:52:59 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Print all the profiles on stream \p OS.
|
2014-11-01 01:56:55 +01:00
|
|
|
void dump(raw_ostream &OS = dbgs());
|
2014-09-09 14:40:50 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return the samples collected for function \p F.
|
2014-09-09 14:40:50 +02:00
|
|
|
FunctionSamples *getSamplesFor(const Function &F) {
|
2019-03-14 14:56:49 +01:00
|
|
|
// The function name may have been updated by adding suffix. Call
|
|
|
|
// a helper to (optionally) strip off suffixes so that we can
|
|
|
|
// match against the original function name in the profile.
|
|
|
|
StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
|
|
|
|
return getSamplesFor(CanonName);
|
2018-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2019-11-25 08:31:02 +01:00
|
|
|
/// Return the samples collected for function \p F, create empty
|
|
|
|
/// FunctionSamples if it doesn't exist.
|
|
|
|
FunctionSamples *getOrCreateSamplesFor(const Function &F) {
|
|
|
|
std::string FGUID;
|
|
|
|
StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
|
2020-03-03 22:19:32 +01:00
|
|
|
CanonName = getRepInFormat(CanonName, useMD5(), FGUID);
|
2019-11-25 08:31:02 +01:00
|
|
|
return &Profiles[CanonName];
|
|
|
|
}
|
|
|
|
|
2018-10-10 23:31:01 +02:00
|
|
|
/// Return the samples collected for function \p F.
|
|
|
|
virtual FunctionSamples *getSamplesFor(StringRef Fname) {
|
2018-06-12 00:40:43 +02:00
|
|
|
std::string FGUID;
|
2020-03-03 22:19:32 +01:00
|
|
|
Fname = getRepInFormat(Fname, useMD5(), FGUID);
|
2018-10-10 23:31:01 +02:00
|
|
|
auto It = Profiles.find(Fname);
|
|
|
|
if (It != Profiles.end())
|
|
|
|
return &It->second;
|
[SampleFDO] Enhance profile remapping support for searching inline instance
and indirect call promotion candidate.
Profile remapping is a feature to match a function in the module with its
profile in sample profile if the function name and the name in profile look
different but are equivalent using given remapping rules. This is a useful
feature to keep the performance stable by specifying some remapping rules
when sampleFDO targets are going through some large scale function signature
change.
However, currently profile remapping support is only valid for outline
function profile in SampleFDO. It cannot match a callee with an inline
instance profile if they have different but equivalent names. We found
that without the support for inline instance profile, remapping is less
effective for some large scale change.
To add that support, before any remapping lookup happens, all the names
in the profile will be inserted into remapper and the Key to the name
mapping will be recorded in a map called NameMap in the remapper. During
name lookup, a Key will be returned for the given name and it will be used
to extract an equivalent name in the profile from NameMap. So with the help
of the NameMap, we can translate any given name to an equivalent name in
the profile if it exists. Whenever we try to match a name in the module to
a name in the profile, we will try the match with the original name first,
and if it doesn't match, we will use the equivalent name got from remapper
to try the match for another time. In this way, the patch can enhance the
profile remapping support for searching inline instance and searching
indirect call promotion candidate.
In a planned large scale change of int64 type (long long) to int64_t (long),
we found the performance of a google internal benchmark degraded by 2% if
nothing was done. If existing profile remapping was enabled, the performance
degradation dropped to 1.2%. If the profile remapping with the current patch
was enabled, the performance degradation further dropped to 0.14% (Note the
experiment was done before searching indirect call promotion candidate was
added. We hope with the remapping support of searching indirect call promotion
candidate, the degradation can drop to 0% in the end. It will be evaluated
post commit).
Differential Revision: https://reviews.llvm.org/D86332
2020-08-25 07:59:20 +02:00
|
|
|
|
|
|
|
if (Remapper) {
|
|
|
|
if (auto NameInProfile = Remapper->lookUpNameInProfile(Fname)) {
|
|
|
|
auto It = Profiles.find(*NameInProfile);
|
|
|
|
if (It != Profiles.end())
|
|
|
|
return &It->second;
|
|
|
|
}
|
|
|
|
}
|
SamplePGO ThinLTO ICP fix for local functions.
Summary:
In SamplePGO, if the profile is collected from non-LTO binary, and used to drive ThinLTO, the indirect call promotion may fail because ThinLTO adjusts local function names to avoid conflicts. There are two places of where the mismatch can happen:
1. thin-link prepends SourceFileName to front of FuncName to build the GUID (GlobalValue::getGlobalIdentifier). Unlike instrumentation FDO, SamplePGO does not use the PGOFuncName scheme and therefore the indirect call target profile data contains a hash of the OriginalName.
2. backend compiler promotes some local functions to global and appends .llvm.{$ModuleHash} to the end of the FuncName to derive PromotedFunctionName
This patch tries at the best effort to find the GUID from the original local function name (in profile), and use that in ICP promotion, and in SamplePGO matching that happens in the backend after importing/inlining:
1. in thin-link, it builds the map from OriginalName to GUID so that when thin-link reads in indirect call target profile (represented by OriginalName), it knows which GUID to import.
2. in backend compiler, if sample profile reader cannot find a profile match for PromotedFunctionName, it will try to find if there is a match for OriginalFunctionName.
3. in backend compiler, we build symbol table entry for OriginalFunctionName and pointer to the same symbol of PromotedFunctionName, so that ICP can find the correct target to promote.
Reviewers: mehdi_amini, tejohnson
Reviewed By: tejohnson
Subscribers: llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D30754
llvm-svn: 297757
2017-03-14 18:33:01 +01:00
|
|
|
return nullptr;
|
2014-09-09 14:40:50 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return all the profiles.
|
2014-11-01 01:56:55 +01:00
|
|
|
StringMap<FunctionSamples> &getProfiles() { return Profiles; }
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Report a parse error message.
|
2021-01-06 15:04:37 +01:00
|
|
|
void reportError(int64_t LineNumber, const Twine &Msg) const {
|
2014-10-30 21:19:19 +01:00
|
|
|
Ctx.diagnose(DiagnosticInfoSampleProfile(Buffer->getBufferIdentifier(),
|
|
|
|
LineNumber, Msg));
|
2014-09-09 14:40:50 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Create a sample profile reader appropriate to the file format.
|
2019-10-19 00:35:20 +02:00
|
|
|
/// Create a remapper underlying if RemapFilename is not empty.
|
2014-11-03 01:51:45 +01:00
|
|
|
static ErrorOr<std::unique_ptr<SampleProfileReader>>
|
2019-10-19 00:35:20 +02:00
|
|
|
create(const std::string Filename, LLVMContext &C,
|
|
|
|
const std::string RemapFilename = "");
|
2014-09-09 14:40:50 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Create a sample profile reader from the supplied memory buffer.
|
2019-10-19 00:35:20 +02:00
|
|
|
/// Create a remapper underlying if RemapFilename is not empty.
|
2015-12-10 18:21:42 +01:00
|
|
|
static ErrorOr<std::unique_ptr<SampleProfileReader>>
|
2019-10-19 00:35:20 +02:00
|
|
|
create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
|
|
|
|
const std::string RemapFilename = "");
|
2015-12-10 18:21:42 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return the profile summary.
|
2019-10-19 00:35:20 +02:00
|
|
|
ProfileSummary &getSummary() const { return *(Summary.get()); }
|
|
|
|
|
|
|
|
MemoryBuffer *getBuffer() const { return Buffer.get(); }
|
2016-02-19 04:15:33 +01:00
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
/// \brief Return the profile format.
|
2019-10-19 00:35:20 +02:00
|
|
|
SampleProfileFormat getFormat() const { return Format; }
|
2018-06-12 00:40:43 +02:00
|
|
|
|
2020-12-16 21:54:50 +01:00
|
|
|
/// Whether input profile is based on pseudo probes.
|
|
|
|
bool profileIsProbeBased() const { return ProfileIsProbeBased; }
|
|
|
|
|
|
|
|
/// Whether input profile is fully context-sensitive
|
[CSSPGO] Infrastructure for context-sensitive Sample PGO and Inlining
This change adds the context-senstive sample PGO infracture described in CSSPGO RFC (https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s). It introduced an abstraction between input profile and profile loader that queries input profile for functions. Specifically, there's now the notion of base profile and context profile, and they are managed by the new SampleContextTracker for adjusting and merging profiles based on inline decisions. It works with top-down profiled guided inliner in profile loader (https://reviews.llvm.org/D70655) for better inlining with specialization and better post-inline profile fidelity. In the future, we can also expose this infrastructure to CGSCC inliner in order for it to take advantage of context-sensitive profile. This change is the consumption part of context-sensitive profile (The generation part is in this stack: https://reviews.llvm.org/D89707). We've seen good results internally in conjunction with Pseudo-probe (https://reviews.llvm.org/D86193). Pacthes for integration with Pseudo-probe coming up soon.
Currently the new infrastructure kick in when input profile contains the new context-sensitive profile; otherwise it's no-op and does not affect existing AutoFDO.
**Interface**
There're two sets of interfaces for query and tracking respectively exposed from SampleContextTracker. For query, now instead of simply getting a profile from input for a function, we can explicitly query base profile or context profile for given call path of a function. For tracking, there're separate APIs for marking context profile as inlined, or promoting and merging not inlined context profile.
- Query base profile (`getBaseSamplesFor`)
Base profile is the merged synthetic profile for function's CFG profile from any outstanding (not inlined) context. We can query base profile by function.
- Query context profile (`getContextSamplesFor`)
Context profile is a function's CFG profile for a given calling context. We can query context profile by context string.
- Track inlined context profile (`markContextSamplesInlined`)
When a function is inlined for given calling context, we need to mark the context profile for that context as inlined. This is to make sure we don't include inlined context profile when synthesizing base profile for that inlined function.
- Track not-inlined context profile (`promoteMergeContextSamplesTree`)
When a function is not inlined for given calling context, we need to promote the context profile tree so the not inlined context becomes top-level context. This preserve the sub-context under that function so later inline decision for that not inlined function will still have context profile for its call tree. Note that profile will be merged if needed when promoting a context profile tree if any of the node already exists at its promoted destination.
**Implementation**
Implementation-wise, `SampleContext` is created as abstraction for context. Currently it's a string for call path, and we can later optimize it to something more efficient, e.g. context id. Each `SampleContext` also has a `ContextState` indicating whether it's raw context profile from input, whether it's inlined or merged, whether it's synthetic profile created by compiler. Each `FunctionSamples` now has a `SampleContext` that tells whether it's base profile or context profile, and for context profile what is the context and state.
On top of the above context representation, a custom trie tree is implemented to track and manager context profiles. Specifically, `SampleContextTracker` is implemented that encapsulates a trie tree with `ContextTireNode` as node. Each node of the trie tree represents a frame in calling context, thus the path from root to a node represents a valid calling context. We also track `FunctionSamples` for each node, so this trie tree can serve efficient query for context profile. Accordingly, context profile tree promotion now becomes moving a subtree to be under the root of entire tree, and merge nodes for subtree if this move encounters existing nodes.
**Integration**
`SampleContextTracker` is now also integrated with AutoFDO, `SampleProfileReader` and `SampleProfileLoader`. When we detected input profile contains context-sensitive profile, `SampleContextTracker` will be used to track profiles, and all profile query will go to `SampleContextTracker` instead of `SampleProfileReader` automatically. Tracking APIs are called automatically for each inline decision from `SampleProfileLoader`.
Differential Revision: https://reviews.llvm.org/D90125
2020-03-24 07:50:41 +01:00
|
|
|
bool profileIsCS() const { return ProfileIsCS; }
|
|
|
|
|
2019-08-31 04:27:26 +02:00
|
|
|
virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList() {
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
[SampleFDO] Minimize performance impact when profile-sample-accurate
is enabled.
We can save memory and reduce binary size significantly by enabling
ProfileSampleAccurate. However when ProfileSampleAccurate is true,
function without sample will be regarded as cold and this could
potentially cause performance regression.
To minimize the potential negative performance impact, we want to be
a little conservative here saying if a function shows up in the profile,
no matter as outline instance, inline instance or call targets, treat
the function as not being cold. This will handle the cases such as most
callsites of a function are inlined in sampled binary (thus outline copy
don't get any sample) but not inlined in current build (because of source
code drift, imprecise debug information, or the callsites are all cold
individually but not cold accumulatively...), so that the outline function
showing up as cold in sampled binary will actually not be cold after current
build. After the change, such function will be treated as not cold even
profile-sample-accurate is enabled.
At the same time we lower the hot criteria of callsiteIsHot check when
profile-sample-accurate is enabled. callsiteIsHot is used to determined
whether a callsite is hot and qualified for early inlining. When
profile-sample-accurate is enabled, functions without profile will be
regarded as cold and much less inlining will happen in CGSCC inlining pass,
so we can worry less about size increase and be aggressive to allow more
early inlining to happen for warm callsites and it is helpful for performance
overall.
Differential Revision: https://reviews.llvm.org/D67561
llvm-svn: 372232
2019-09-18 18:06:28 +02:00
|
|
|
/// It includes all the names that have samples either in outline instance
|
|
|
|
/// or inline instance.
|
|
|
|
virtual std::vector<StringRef> *getNameTable() { return nullptr; }
|
2019-09-21 19:23:55 +02:00
|
|
|
virtual bool dumpSectionInfo(raw_ostream &OS = dbgs()) { return false; };
|
[SampleFDO] Minimize performance impact when profile-sample-accurate
is enabled.
We can save memory and reduce binary size significantly by enabling
ProfileSampleAccurate. However when ProfileSampleAccurate is true,
function without sample will be regarded as cold and this could
potentially cause performance regression.
To minimize the potential negative performance impact, we want to be
a little conservative here saying if a function shows up in the profile,
no matter as outline instance, inline instance or call targets, treat
the function as not being cold. This will handle the cases such as most
callsites of a function are inlined in sampled binary (thus outline copy
don't get any sample) but not inlined in current build (because of source
code drift, imprecise debug information, or the callsites are all cold
individually but not cold accumulatively...), so that the outline function
showing up as cold in sampled binary will actually not be cold after current
build. After the change, such function will be treated as not cold even
profile-sample-accurate is enabled.
At the same time we lower the hot criteria of callsiteIsHot check when
profile-sample-accurate is enabled. callsiteIsHot is used to determined
whether a callsite is hot and qualified for early inlining. When
profile-sample-accurate is enabled, functions without profile will be
regarded as cold and much less inlining will happen in CGSCC inlining pass,
so we can worry less about size increase and be aggressive to allow more
early inlining to happen for warm callsites and it is helpful for performance
overall.
Differential Revision: https://reviews.llvm.org/D67561
llvm-svn: 372232
2019-09-18 18:06:28 +02:00
|
|
|
|
2020-03-03 22:19:32 +01:00
|
|
|
/// Return whether names in the profile are all MD5 numbers.
|
|
|
|
virtual bool useMD5() { return false; }
|
|
|
|
|
2021-01-06 08:24:43 +01:00
|
|
|
/// Don't read profile without context if the flag is set. This is only meaningful
|
|
|
|
/// for ExtBinary format.
|
|
|
|
virtual void setSkipFlatProf(bool Skip) {}
|
|
|
|
|
[SampleFDO] Enhance profile remapping support for searching inline instance
and indirect call promotion candidate.
Profile remapping is a feature to match a function in the module with its
profile in sample profile if the function name and the name in profile look
different but are equivalent using given remapping rules. This is a useful
feature to keep the performance stable by specifying some remapping rules
when sampleFDO targets are going through some large scale function signature
change.
However, currently profile remapping support is only valid for outline
function profile in SampleFDO. It cannot match a callee with an inline
instance profile if they have different but equivalent names. We found
that without the support for inline instance profile, remapping is less
effective for some large scale change.
To add that support, before any remapping lookup happens, all the names
in the profile will be inserted into remapper and the Key to the name
mapping will be recorded in a map called NameMap in the remapper. During
name lookup, a Key will be returned for the given name and it will be used
to extract an equivalent name in the profile from NameMap. So with the help
of the NameMap, we can translate any given name to an equivalent name in
the profile if it exists. Whenever we try to match a name in the module to
a name in the profile, we will try the match with the original name first,
and if it doesn't match, we will use the equivalent name got from remapper
to try the match for another time. In this way, the patch can enhance the
profile remapping support for searching inline instance and searching
indirect call promotion candidate.
In a planned large scale change of int64 type (long long) to int64_t (long),
we found the performance of a google internal benchmark degraded by 2% if
nothing was done. If existing profile remapping was enabled, the performance
degradation dropped to 1.2%. If the profile remapping with the current patch
was enabled, the performance degradation further dropped to 0.14% (Note the
experiment was done before searching indirect call promotion candidate was
added. We hope with the remapping support of searching indirect call promotion
candidate, the degradation can drop to 0% in the end. It will be evaluated
post commit).
Differential Revision: https://reviews.llvm.org/D86332
2020-08-25 07:59:20 +02:00
|
|
|
SampleProfileReaderItaniumRemapper *getRemapper() { return Remapper.get(); }
|
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
protected:
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Map every function to its associated profile.
|
2014-09-09 14:40:50 +02:00
|
|
|
///
|
|
|
|
/// The profile of every function executed at runtime is collected
|
|
|
|
/// in the structure FunctionSamples. This maps function objects
|
|
|
|
/// to their corresponding profiles.
|
|
|
|
StringMap<FunctionSamples> Profiles;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// LLVM context used to emit diagnostics.
|
2014-10-30 19:00:06 +01:00
|
|
|
LLVMContext &Ctx;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Memory buffer holding the profile file.
|
2014-10-30 19:00:06 +01:00
|
|
|
std::unique_ptr<MemoryBuffer> Buffer;
|
2016-02-19 04:15:33 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Profile summary information.
|
2016-05-19 23:53:28 +02:00
|
|
|
std::unique_ptr<ProfileSummary> Summary;
|
2016-02-19 04:15:33 +01:00
|
|
|
|
2018-10-10 23:31:01 +02:00
|
|
|
/// Take ownership of the summary of this reader.
|
|
|
|
static std::unique_ptr<ProfileSummary>
|
|
|
|
takeSummary(SampleProfileReader &Reader) {
|
|
|
|
return std::move(Reader.Summary);
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Compute summary for this profile.
|
2016-02-19 04:15:33 +01:00
|
|
|
void computeSummary();
|
2018-06-12 00:40:43 +02:00
|
|
|
|
2019-10-19 00:35:20 +02:00
|
|
|
std::unique_ptr<SampleProfileReaderItaniumRemapper> Remapper;
|
|
|
|
|
2020-12-16 21:54:50 +01:00
|
|
|
/// \brief Whether samples are collected based on pseudo probes.
|
|
|
|
bool ProfileIsProbeBased = false;
|
|
|
|
|
2021-01-28 01:04:11 +01:00
|
|
|
/// Whether function profiles are context-sensitive.
|
[CSSPGO] Infrastructure for context-sensitive Sample PGO and Inlining
This change adds the context-senstive sample PGO infracture described in CSSPGO RFC (https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s). It introduced an abstraction between input profile and profile loader that queries input profile for functions. Specifically, there's now the notion of base profile and context profile, and they are managed by the new SampleContextTracker for adjusting and merging profiles based on inline decisions. It works with top-down profiled guided inliner in profile loader (https://reviews.llvm.org/D70655) for better inlining with specialization and better post-inline profile fidelity. In the future, we can also expose this infrastructure to CGSCC inliner in order for it to take advantage of context-sensitive profile. This change is the consumption part of context-sensitive profile (The generation part is in this stack: https://reviews.llvm.org/D89707). We've seen good results internally in conjunction with Pseudo-probe (https://reviews.llvm.org/D86193). Pacthes for integration with Pseudo-probe coming up soon.
Currently the new infrastructure kick in when input profile contains the new context-sensitive profile; otherwise it's no-op and does not affect existing AutoFDO.
**Interface**
There're two sets of interfaces for query and tracking respectively exposed from SampleContextTracker. For query, now instead of simply getting a profile from input for a function, we can explicitly query base profile or context profile for given call path of a function. For tracking, there're separate APIs for marking context profile as inlined, or promoting and merging not inlined context profile.
- Query base profile (`getBaseSamplesFor`)
Base profile is the merged synthetic profile for function's CFG profile from any outstanding (not inlined) context. We can query base profile by function.
- Query context profile (`getContextSamplesFor`)
Context profile is a function's CFG profile for a given calling context. We can query context profile by context string.
- Track inlined context profile (`markContextSamplesInlined`)
When a function is inlined for given calling context, we need to mark the context profile for that context as inlined. This is to make sure we don't include inlined context profile when synthesizing base profile for that inlined function.
- Track not-inlined context profile (`promoteMergeContextSamplesTree`)
When a function is not inlined for given calling context, we need to promote the context profile tree so the not inlined context becomes top-level context. This preserve the sub-context under that function so later inline decision for that not inlined function will still have context profile for its call tree. Note that profile will be merged if needed when promoting a context profile tree if any of the node already exists at its promoted destination.
**Implementation**
Implementation-wise, `SampleContext` is created as abstraction for context. Currently it's a string for call path, and we can later optimize it to something more efficient, e.g. context id. Each `SampleContext` also has a `ContextState` indicating whether it's raw context profile from input, whether it's inlined or merged, whether it's synthetic profile created by compiler. Each `FunctionSamples` now has a `SampleContext` that tells whether it's base profile or context profile, and for context profile what is the context and state.
On top of the above context representation, a custom trie tree is implemented to track and manager context profiles. Specifically, `SampleContextTracker` is implemented that encapsulates a trie tree with `ContextTireNode` as node. Each node of the trie tree represents a frame in calling context, thus the path from root to a node represents a valid calling context. We also track `FunctionSamples` for each node, so this trie tree can serve efficient query for context profile. Accordingly, context profile tree promotion now becomes moving a subtree to be under the root of entire tree, and merge nodes for subtree if this move encounters existing nodes.
**Integration**
`SampleContextTracker` is now also integrated with AutoFDO, `SampleProfileReader` and `SampleProfileLoader`. When we detected input profile contains context-sensitive profile, `SampleContextTracker` will be used to track profiles, and all profile query will go to `SampleContextTracker` instead of `SampleProfileReader` automatically. Tracking APIs are called automatically for each inline decision from `SampleProfileLoader`.
Differential Revision: https://reviews.llvm.org/D90125
2020-03-24 07:50:41 +01:00
|
|
|
bool ProfileIsCS = false;
|
|
|
|
|
2021-01-28 01:04:11 +01:00
|
|
|
/// Number of context-sensitive profiles.
|
|
|
|
uint32_t CSProfileCount = 0;
|
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
/// \brief The format of sample.
|
|
|
|
SampleProfileFormat Format = SPF_None;
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class SampleProfileReaderText : public SampleProfileReader {
|
|
|
|
public:
|
|
|
|
SampleProfileReaderText(std::unique_ptr<MemoryBuffer> B, LLVMContext &C)
|
2018-06-12 00:40:43 +02:00
|
|
|
: SampleProfileReader(std::move(B), C, SPF_Text) {}
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read and validate the file header.
|
2014-10-30 19:00:06 +01:00
|
|
|
std::error_code readHeader() override { return sampleprof_error::success; }
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read sample profiles from the associated file.
|
2019-10-19 00:35:20 +02:00
|
|
|
std::error_code readImpl() override;
|
2015-11-13 04:47:58 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return true if \p Buffer is in the format supported by this class.
|
2015-11-13 04:47:58 +01:00
|
|
|
static bool hasFormat(const MemoryBuffer &Buffer);
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class SampleProfileReaderBinary : public SampleProfileReader {
|
|
|
|
public:
|
2018-06-12 00:40:43 +02:00
|
|
|
SampleProfileReaderBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
|
|
|
|
SampleProfileFormat Format = SPF_None)
|
|
|
|
: SampleProfileReader(std::move(B), C, Format) {}
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read and validate the file header.
|
2018-09-14 22:52:59 +02:00
|
|
|
virtual std::error_code readHeader() override;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read sample profiles from the associated file.
|
2019-10-19 00:35:20 +02:00
|
|
|
std::error_code readImpl() override;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
[SampleFDO] Minimize performance impact when profile-sample-accurate
is enabled.
We can save memory and reduce binary size significantly by enabling
ProfileSampleAccurate. However when ProfileSampleAccurate is true,
function without sample will be regarded as cold and this could
potentially cause performance regression.
To minimize the potential negative performance impact, we want to be
a little conservative here saying if a function shows up in the profile,
no matter as outline instance, inline instance or call targets, treat
the function as not being cold. This will handle the cases such as most
callsites of a function are inlined in sampled binary (thus outline copy
don't get any sample) but not inlined in current build (because of source
code drift, imprecise debug information, or the callsites are all cold
individually but not cold accumulatively...), so that the outline function
showing up as cold in sampled binary will actually not be cold after current
build. After the change, such function will be treated as not cold even
profile-sample-accurate is enabled.
At the same time we lower the hot criteria of callsiteIsHot check when
profile-sample-accurate is enabled. callsiteIsHot is used to determined
whether a callsite is hot and qualified for early inlining. When
profile-sample-accurate is enabled, functions without profile will be
regarded as cold and much less inlining will happen in CGSCC inlining pass,
so we can worry less about size increase and be aggressive to allow more
early inlining to happen for warm callsites and it is helpful for performance
overall.
Differential Revision: https://reviews.llvm.org/D67561
llvm-svn: 372232
2019-09-18 18:06:28 +02:00
|
|
|
/// It includes all the names that have samples either in outline instance
|
|
|
|
/// or inline instance.
|
|
|
|
virtual std::vector<StringRef> *getNameTable() override { return &NameTable; }
|
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
protected:
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read a numeric value of type T from the profile.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// If an error occurs during decoding, a diagnostic message is emitted and
|
|
|
|
/// EC is set.
|
|
|
|
///
|
|
|
|
/// \returns the read value.
|
|
|
|
template <typename T> ErrorOr<T> readNumber();
|
2014-09-09 14:40:50 +02:00
|
|
|
|
2018-09-14 22:52:59 +02:00
|
|
|
/// Read a numeric value of type T from the profile. The value is saved
|
|
|
|
/// without encoded.
|
|
|
|
template <typename T> ErrorOr<T> readUnencodedNumber();
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read a string from the profile.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// If an error occurs during decoding, a diagnostic message is emitted and
|
|
|
|
/// EC is set.
|
|
|
|
///
|
|
|
|
/// \returns the read value.
|
|
|
|
ErrorOr<StringRef> readString();
|
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
/// Read the string index and check whether it overflows the table.
|
|
|
|
template <typename T> inline ErrorOr<uint32_t> readStringIndex(T &Table);
|
2015-10-14 00:48:46 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return true if we've reached the end of file.
|
2014-10-30 19:00:06 +01:00
|
|
|
bool at_eof() const { return Data >= End; }
|
|
|
|
|
2018-09-14 22:52:59 +02:00
|
|
|
/// Read the next function profile instance.
|
2019-10-09 23:36:03 +02:00
|
|
|
std::error_code readFuncProfile(const uint8_t *Start);
|
2018-09-14 22:52:59 +02:00
|
|
|
|
2015-10-09 19:54:24 +02:00
|
|
|
/// Read the contents of the given profile instance.
|
|
|
|
std::error_code readProfile(FunctionSamples &FProfile);
|
|
|
|
|
2019-08-23 21:05:30 +02:00
|
|
|
/// Read the contents of Magic number and Version number.
|
|
|
|
std::error_code readMagicIdent();
|
|
|
|
|
|
|
|
/// Read profile summary.
|
|
|
|
std::error_code readSummary();
|
|
|
|
|
|
|
|
/// Read the whole name table.
|
|
|
|
virtual std::error_code readNameTable();
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Points to the current location in the buffer.
|
2017-06-22 01:19:47 +02:00
|
|
|
const uint8_t *Data = nullptr;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Points to the end of the buffer.
|
2017-06-22 01:19:47 +02:00
|
|
|
const uint8_t *End = nullptr;
|
2015-10-14 00:48:46 +02:00
|
|
|
|
2019-08-23 21:05:30 +02:00
|
|
|
/// Function name table.
|
|
|
|
std::vector<StringRef> NameTable;
|
|
|
|
|
|
|
|
/// Read a string indirectly via the name table.
|
|
|
|
virtual ErrorOr<StringRef> readStringFromTable();
|
|
|
|
|
2016-02-19 04:15:33 +01:00
|
|
|
private:
|
|
|
|
std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
|
2018-06-12 00:40:43 +02:00
|
|
|
virtual std::error_code verifySPMagic(uint64_t Magic) = 0;
|
2019-08-23 21:05:30 +02:00
|
|
|
};
|
2016-02-19 04:15:33 +01:00
|
|
|
|
2019-08-23 21:05:30 +02:00
|
|
|
class SampleProfileReaderRawBinary : public SampleProfileReaderBinary {
|
|
|
|
private:
|
|
|
|
virtual std::error_code verifySPMagic(uint64_t Magic) override;
|
2018-06-12 00:40:43 +02:00
|
|
|
|
2019-08-23 21:05:30 +02:00
|
|
|
public:
|
|
|
|
SampleProfileReaderRawBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
|
|
|
|
SampleProfileFormat Format = SPF_Binary)
|
|
|
|
: SampleProfileReaderBinary(std::move(B), C, Format) {}
|
2018-06-12 00:40:43 +02:00
|
|
|
|
2019-08-23 21:05:30 +02:00
|
|
|
/// \brief Return true if \p Buffer is in the format supported by this class.
|
|
|
|
static bool hasFormat(const MemoryBuffer &Buffer);
|
2018-06-12 00:40:43 +02:00
|
|
|
};
|
|
|
|
|
2019-08-23 21:05:30 +02:00
|
|
|
/// SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase defines
|
|
|
|
/// the basic structure of the extensible binary format.
|
|
|
|
/// The format is organized in sections except the magic and version number
|
|
|
|
/// at the beginning. There is a section table before all the sections, and
|
|
|
|
/// each entry in the table describes the entry type, start, size and
|
|
|
|
/// attributes. The format in each section is defined by the section itself.
|
|
|
|
///
|
|
|
|
/// It is easy to add a new section while maintaining the backward
|
|
|
|
/// compatibility of the profile. Nothing extra needs to be done. If we want
|
|
|
|
/// to extend an existing section, like add cache misses information in
|
|
|
|
/// addition to the sample count in the profile body, we can add a new section
|
|
|
|
/// with the extension and retire the existing section, and we could choose
|
|
|
|
/// to keep the parser of the old section if we want the reader to be able
|
|
|
|
/// to read both new and old format profile.
|
|
|
|
///
|
|
|
|
/// SampleProfileReaderExtBinary/SampleProfileWriterExtBinary define the
|
|
|
|
/// commonly used sections of a profile in extensible binary format. It is
|
|
|
|
/// possible to define other types of profile inherited from
|
|
|
|
/// SampleProfileReaderExtBinaryBase/SampleProfileWriterExtBinaryBase.
|
|
|
|
class SampleProfileReaderExtBinaryBase : public SampleProfileReaderBinary {
|
2019-10-07 18:12:37 +02:00
|
|
|
private:
|
|
|
|
std::error_code decompressSection(const uint8_t *SecStart,
|
|
|
|
const uint64_t SecSize,
|
|
|
|
const uint8_t *&DecompressBuf,
|
|
|
|
uint64_t &DecompressBufSize);
|
|
|
|
|
|
|
|
BumpPtrAllocator Allocator;
|
|
|
|
|
2019-08-23 21:05:30 +02:00
|
|
|
protected:
|
|
|
|
std::vector<SecHdrTableEntry> SecHdrTable;
|
2020-12-14 23:49:20 +01:00
|
|
|
std::error_code readSecHdrTableEntry(uint32_t Idx);
|
2019-08-23 21:05:30 +02:00
|
|
|
std::error_code readSecHdrTable();
|
|
|
|
|
2020-12-16 21:54:50 +01:00
|
|
|
std::error_code readFuncMetadata();
|
2019-10-09 23:36:03 +02:00
|
|
|
std::error_code readFuncOffsetTable();
|
|
|
|
std::error_code readFuncProfiles();
|
2020-03-03 22:19:32 +01:00
|
|
|
std::error_code readMD5NameTable();
|
|
|
|
std::error_code readNameTableSec(bool IsMD5);
|
2020-10-16 00:17:28 +02:00
|
|
|
std::error_code readProfileSymbolList();
|
|
|
|
|
|
|
|
virtual std::error_code readHeader() override;
|
|
|
|
virtual std::error_code verifySPMagic(uint64_t Magic) override = 0;
|
|
|
|
virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size,
|
|
|
|
const SecHdrTableEntry &Entry);
|
|
|
|
// placeholder for subclasses to dispatch their own section readers.
|
|
|
|
virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry) = 0;
|
2020-12-03 21:19:25 +01:00
|
|
|
virtual ErrorOr<StringRef> readStringFromTable() override;
|
2020-10-16 00:17:28 +02:00
|
|
|
|
|
|
|
std::unique_ptr<ProfileSymbolList> ProfSymList;
|
2019-10-09 23:36:03 +02:00
|
|
|
|
|
|
|
/// The table mapping from function name to the offset of its FunctionSample
|
|
|
|
/// towards file start.
|
|
|
|
DenseMap<StringRef, uint64_t> FuncOffsetTable;
|
|
|
|
/// The set containing the functions to use when compiling a module.
|
|
|
|
DenseSet<StringRef> FuncsToUse;
|
|
|
|
/// Use all functions from the input profile.
|
|
|
|
bool UseAllFuncs = true;
|
2018-06-12 00:40:43 +02:00
|
|
|
|
2020-12-03 21:19:25 +01:00
|
|
|
/// Use fixed length MD5 instead of ULEB128 encoding so NameTable doesn't
|
|
|
|
/// need to be read in up front and can be directly accessed using index.
|
|
|
|
bool FixedLengthMD5 = false;
|
|
|
|
/// The starting address of NameTable containing fixed length MD5.
|
|
|
|
const uint8_t *MD5NameMemStart = nullptr;
|
|
|
|
|
2020-03-03 22:19:32 +01:00
|
|
|
/// If MD5 is used in NameTable section, the section saves uint64_t data.
|
|
|
|
/// The uint64_t data has to be converted to a string and then the string
|
|
|
|
/// will be used to initialize StringRef in NameTable.
|
|
|
|
/// Note NameTable contains StringRef so it needs another buffer to own
|
|
|
|
/// the string data. MD5StringBuf serves as the string buffer that is
|
|
|
|
/// referenced by NameTable (vector of StringRef). We make sure
|
|
|
|
/// the lifetime of MD5StringBuf is not shorter than that of NameTable.
|
|
|
|
std::unique_ptr<std::vector<std::string>> MD5StringBuf;
|
|
|
|
|
2021-01-06 08:24:43 +01:00
|
|
|
/// If SkipFlatProf is true, skip the sections with
|
|
|
|
/// SecFlagFlat flag.
|
|
|
|
bool SkipFlatProf = false;
|
|
|
|
|
2018-06-12 00:40:43 +02:00
|
|
|
public:
|
2020-10-16 00:17:28 +02:00
|
|
|
SampleProfileReaderExtBinaryBase(std::unique_ptr<MemoryBuffer> B,
|
|
|
|
LLVMContext &C, SampleProfileFormat Format)
|
|
|
|
: SampleProfileReaderBinary(std::move(B), C, Format) {}
|
2018-06-12 00:40:43 +02:00
|
|
|
|
2020-10-16 00:17:28 +02:00
|
|
|
/// Read sample profiles in extensible format from the associated file.
|
|
|
|
std::error_code readImpl() override;
|
2019-08-31 04:27:26 +02:00
|
|
|
|
2020-10-16 00:17:28 +02:00
|
|
|
/// Get the total size of all \p Type sections.
|
|
|
|
uint64_t getSectionSize(SecType Type);
|
|
|
|
/// Get the total size of header and all sections.
|
|
|
|
uint64_t getFileSize();
|
|
|
|
virtual bool dumpSectionInfo(raw_ostream &OS = dbgs()) override;
|
2019-10-09 23:36:03 +02:00
|
|
|
|
|
|
|
/// Collect functions with definitions in Module \p M.
|
|
|
|
void collectFuncsFrom(const Module &M) override;
|
2020-03-03 22:19:32 +01:00
|
|
|
|
|
|
|
/// Return whether names in the profile are all MD5 numbers.
|
2020-12-03 21:19:25 +01:00
|
|
|
virtual bool useMD5() override { return MD5StringBuf.get(); }
|
2020-10-16 00:17:28 +02:00
|
|
|
|
|
|
|
virtual std::unique_ptr<ProfileSymbolList> getProfileSymbolList() override {
|
|
|
|
return std::move(ProfSymList);
|
|
|
|
};
|
2021-01-06 08:24:43 +01:00
|
|
|
|
|
|
|
virtual void setSkipFlatProf(bool Skip) override { SkipFlatProf = Skip; }
|
2020-10-16 00:17:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class SampleProfileReaderExtBinary : public SampleProfileReaderExtBinaryBase {
|
|
|
|
private:
|
|
|
|
virtual std::error_code verifySPMagic(uint64_t Magic) override;
|
|
|
|
virtual std::error_code
|
|
|
|
readCustomSection(const SecHdrTableEntry &Entry) override {
|
|
|
|
return sampleprof_error::success;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
SampleProfileReaderExtBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,
|
|
|
|
SampleProfileFormat Format = SPF_Ext_Binary)
|
|
|
|
: SampleProfileReaderExtBinaryBase(std::move(B), C, Format) {}
|
|
|
|
|
|
|
|
/// \brief Return true if \p Buffer is in the format supported by this class.
|
|
|
|
static bool hasFormat(const MemoryBuffer &Buffer);
|
2018-06-12 00:40:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class SampleProfileReaderCompactBinary : public SampleProfileReaderBinary {
|
|
|
|
private:
|
|
|
|
/// Function name table.
|
|
|
|
std::vector<std::string> NameTable;
|
2018-09-14 22:52:59 +02:00
|
|
|
/// The table mapping from function name to the offset of its FunctionSample
|
|
|
|
/// towards file start.
|
|
|
|
DenseMap<StringRef, uint64_t> FuncOffsetTable;
|
|
|
|
/// The set containing the functions to use when compiling a module.
|
|
|
|
DenseSet<StringRef> FuncsToUse;
|
2019-08-13 19:56:08 +02:00
|
|
|
/// Use all functions from the input profile.
|
|
|
|
bool UseAllFuncs = true;
|
2018-06-12 00:40:43 +02:00
|
|
|
virtual std::error_code verifySPMagic(uint64_t Magic) override;
|
|
|
|
virtual std::error_code readNameTable() override;
|
|
|
|
/// Read a string indirectly via the name table.
|
|
|
|
virtual ErrorOr<StringRef> readStringFromTable() override;
|
2018-09-14 22:52:59 +02:00
|
|
|
virtual std::error_code readHeader() override;
|
|
|
|
std::error_code readFuncOffsetTable();
|
2018-06-12 00:40:43 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
SampleProfileReaderCompactBinary(std::unique_ptr<MemoryBuffer> B,
|
|
|
|
LLVMContext &C)
|
|
|
|
: SampleProfileReaderBinary(std::move(B), C, SPF_Compact_Binary) {}
|
|
|
|
|
|
|
|
/// \brief Return true if \p Buffer is in the format supported by this class.
|
|
|
|
static bool hasFormat(const MemoryBuffer &Buffer);
|
2018-09-14 22:52:59 +02:00
|
|
|
|
|
|
|
/// Read samples only for functions to use.
|
2019-10-19 00:35:20 +02:00
|
|
|
std::error_code readImpl() override;
|
2018-09-14 22:52:59 +02:00
|
|
|
|
|
|
|
/// Collect functions to be used when compiling Module \p M.
|
2019-10-09 23:36:03 +02:00
|
|
|
void collectFuncsFrom(const Module &M) override;
|
2020-03-03 22:19:32 +01:00
|
|
|
|
|
|
|
/// Return whether names in the profile are all MD5 numbers.
|
2020-03-31 09:41:36 +02:00
|
|
|
virtual bool useMD5() override { return true; }
|
2014-09-09 14:40:50 +02:00
|
|
|
};
|
|
|
|
|
2017-06-22 01:19:47 +02:00
|
|
|
using InlineCallStack = SmallVector<FunctionSamples *, 10>;
|
2015-09-17 02:17:24 +02:00
|
|
|
|
|
|
|
// Supported histogram types in GCC. Currently, we only need support for
|
|
|
|
// call target histograms.
|
|
|
|
enum HistType {
|
|
|
|
HIST_TYPE_INTERVAL,
|
|
|
|
HIST_TYPE_POW2,
|
|
|
|
HIST_TYPE_SINGLE_VALUE,
|
|
|
|
HIST_TYPE_CONST_DELTA,
|
|
|
|
HIST_TYPE_INDIR_CALL,
|
|
|
|
HIST_TYPE_AVERAGE,
|
|
|
|
HIST_TYPE_IOR,
|
|
|
|
HIST_TYPE_INDIR_CALL_TOPN
|
|
|
|
};
|
|
|
|
|
|
|
|
class SampleProfileReaderGCC : public SampleProfileReader {
|
|
|
|
public:
|
|
|
|
SampleProfileReaderGCC(std::unique_ptr<MemoryBuffer> B, LLVMContext &C)
|
2018-06-12 00:40:43 +02:00
|
|
|
: SampleProfileReader(std::move(B), C, SPF_GCC),
|
|
|
|
GcovBuffer(Buffer.get()) {}
|
2015-09-17 02:17:24 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read and validate the file header.
|
2015-09-17 02:17:24 +02:00
|
|
|
std::error_code readHeader() override;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read sample profiles from the associated file.
|
2019-10-19 00:35:20 +02:00
|
|
|
std::error_code readImpl() override;
|
2015-09-17 02:17:24 +02:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return true if \p Buffer is in the format supported by this class.
|
2015-09-17 02:17:24 +02:00
|
|
|
static bool hasFormat(const MemoryBuffer &Buffer);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::error_code readNameTable();
|
2015-10-08 21:40:37 +02:00
|
|
|
std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack,
|
|
|
|
bool Update, uint32_t Offset);
|
2015-09-17 02:17:24 +02:00
|
|
|
std::error_code readFunctionProfiles();
|
|
|
|
std::error_code skipNextWord();
|
|
|
|
template <typename T> ErrorOr<T> readNumber();
|
|
|
|
ErrorOr<StringRef> readString();
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Read the section tag and check that it's the same as \p Expected.
|
2015-09-17 02:17:24 +02:00
|
|
|
std::error_code readSectionTag(uint32_t Expected);
|
|
|
|
|
|
|
|
/// GCOV buffer containing the profile.
|
|
|
|
GCOVBuffer GcovBuffer;
|
|
|
|
|
|
|
|
/// Function names in this profile.
|
|
|
|
std::vector<std::string> Names;
|
|
|
|
|
|
|
|
/// GCOV tags used to separate sections in the profile file.
|
|
|
|
static const uint32_t GCOVTagAFDOFileNames = 0xaa000000;
|
|
|
|
static const uint32_t GCOVTagAFDOFunction = 0xac000000;
|
|
|
|
};
|
|
|
|
|
2017-03-03 02:07:34 +01:00
|
|
|
} // end namespace sampleprof
|
2014-09-09 14:40:50 +02:00
|
|
|
|
2017-03-03 02:07:34 +01:00
|
|
|
} // end namespace llvm
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2014-09-09 14:40:50 +02:00
|
|
|
#endif // LLVM_PROFILEDATA_SAMPLEPROFREADER_H
|