LLVM 20.0.0git
|
#include "llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h"
Public Member Functions | |
SampleProfileLoaderBaseImpl (std::string Name, std::string RemapName, IntrusiveRefCntPtr< vfs::FileSystem > FS) | |
void | dump () |
Protected Member Functions | |
~SampleProfileLoaderBaseImpl ()=default | |
Function & | getFunction (FunctionT &F) |
const BasicBlockT * | getEntryBB (const FunctionT *F) |
PredRangeT | getPredecessors (BasicBlockT *BB) |
SuccRangeT | getSuccessors (BasicBlockT *BB) |
unsigned | getFunctionLoc (FunctionT &Func) |
Get the line number for the function header. | |
virtual ErrorOr< uint64_t > | getInstWeight (const InstructionT &Inst) |
Get the weight for an instruction. | |
ErrorOr< uint64_t > | getInstWeightImpl (const InstructionT &Inst) |
virtual ErrorOr< uint64_t > | getProbeWeight (const InstructionT &Inst) |
ErrorOr< uint64_t > | getBlockWeight (const BasicBlockT *BB) |
Compute the weight of a basic block. | |
virtual const FunctionSamples * | findFunctionSamples (const InstructionT &I) const |
Get the FunctionSamples for an instruction. | |
void | printEdgeWeight (raw_ostream &OS, Edge E) |
Print the weight of edge E on stream OS . | |
void | printBlockWeight (raw_ostream &OS, const BasicBlockT *BB) const |
Print the weight of block BB on stream OS . | |
void | printBlockEquivalence (raw_ostream &OS, const BasicBlockT *BB) |
Print the equivalence class of block BB on stream OS . | |
bool | computeBlockWeights (FunctionT &F) |
Compute and store the weights of every basic block. | |
void | findEquivalenceClasses (FunctionT &F) |
Find equivalence classes. | |
void | findEquivalencesFor (BasicBlockT *BB1, ArrayRef< BasicBlockT * > Descendants, PostDominatorTreeT *DomTree) |
Find equivalence classes for the given block. | |
void | propagateWeights (FunctionT &F) |
Propagate weights into edges. | |
void | applyProfi (FunctionT &F, BlockEdgeMap &Successors, BlockWeightMap &SampleBlockWeights, BlockWeightMap &BlockWeights, EdgeWeightMap &EdgeWeights) |
uint64_t | visitEdge (Edge E, unsigned *NumUnknownEdges, Edge *UnknownEdge) |
Visit the given edge to decide if it has a valid weight. | |
void | buildEdges (FunctionT &F) |
Build in/out edge lists for each basic block in the CFG. | |
bool | propagateThroughEdges (FunctionT &F, bool UpdateBlockCount) |
Propagate weights through incoming/outgoing edges. | |
void | clearFunctionData (bool ResetDT=true) |
Clear all the per-function data used to load samples and propagate weights. | |
void | computeDominanceAndLoopInfo (FunctionT &F) |
bool | computeAndPropagateWeights (FunctionT &F, const DenseSet< GlobalValue::GUID > &InlinedGUIDs) |
Generate branch weight metadata for all branches in F . | |
void | initWeightPropagation (FunctionT &F, const DenseSet< GlobalValue::GUID > &InlinedGUIDs) |
void | finalizeWeightPropagation (FunctionT &F, const DenseSet< GlobalValue::GUID > &InlinedGUIDs) |
void | emitCoverageRemarks (FunctionT &F) |
void | computeDominanceAndLoopInfo (MachineFunction &F) |
void | computeDominanceAndLoopInfo (Function &F) |
Protected Attributes | |
DenseMap< const DILocation *, const FunctionSamples * > | DILocation2SampleMap |
BlockWeightMap | BlockWeights |
Map basic blocks to their computed weights. | |
EdgeWeightMap | EdgeWeights |
Map edges to their computed weights. | |
SmallPtrSet< const BasicBlockT *, 32 > | VisitedBlocks |
Set of visited blocks during propagation. | |
SmallSet< Edge, 32 > | VisitedEdges |
Set of visited edges during propagation. | |
EquivalenceClassMap | EquivalenceClass |
Equivalence classes for block weights. | |
DominatorTreePtrT | DT |
Dominance, post-dominance and loop information. | |
PostDominatorTreePtrT | PDT |
LoopInfoPtrT | LI |
BlockEdgeMap | Predecessors |
Predecessors for each basic block in the CFG. | |
BlockEdgeMap | Successors |
Successors for each basic block in the CFG. | |
SampleCoverageTracker | CoverageTracker |
Profile coverage tracker. | |
std::unique_ptr< SampleProfileReader > | Reader |
Profile reader object. | |
std::map< SampleContext, FunctionSamples > | OutlineFunctionSamples |
Synthetic samples created by duplicating the samples of inlined functions from the original profile as if they were top level sample profiles. | |
std::unique_ptr< PseudoProbeManager > | ProbeManager |
FunctionSamples * | Samples = nullptr |
Samples collected for the body of this function. | |
std::string | Filename |
Name of the profile file to load. | |
std::string | RemappingFilename |
Name of the profile remapping file to load. | |
IntrusiveRefCntPtr< vfs::FileSystem > | FS |
VirtualFileSystem to load profile files from. | |
ProfileSummaryInfo * | PSI = nullptr |
Profile Summary Info computed from sample profile. | |
OptRemarkEmitterT * | ORE = nullptr |
Optimization Remark Emitter used to emit diagnostic remarks. | |
Friends | |
class | SampleCoverageTracker |
Definition at line 175 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::BasicBlockT = typename afdo_detail::IRTraits<BT>::BasicBlockT |
Definition at line 185 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::BlockEdgeMap = DenseMap<const BasicBlockT *, SmallVector<const BasicBlockT *, 8> > |
Definition at line 209 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::BlockFrequencyInfoT = typename afdo_detail::IRTraits<BT>::BlockFrequencyInfoT |
Definition at line 186 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::BlockWeightMap = DenseMap<const BasicBlockT *, uint64_t> |
Definition at line 204 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::BT = std::remove_pointer_t<NodeRef> |
Definition at line 183 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::DominatorTreePtrT = typename afdo_detail::IRTraits<BT>::DominatorTreePtrT |
Definition at line 191 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::Edge = std::pair<const BasicBlockT *, const BasicBlockT *> |
Definition at line 207 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::EdgeWeightMap = DenseMap<Edge, uint64_t> |
Definition at line 208 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::EquivalenceClassMap = DenseMap<const BasicBlockT *, const BasicBlockT *> |
Definition at line 205 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::FunctionT = typename afdo_detail::IRTraits<BT>::FunctionT |
Definition at line 188 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::InstructionT = typename afdo_detail::IRTraits<BT>::InstructionT |
Definition at line 184 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::LoopInfoPtrT = typename afdo_detail::IRTraits<BT>::LoopInfoPtrT |
Definition at line 190 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::LoopT = typename afdo_detail::IRTraits<BT>::LoopT |
Definition at line 189 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::NodeRef = typename GraphTraits<FT *>::NodeRef |
Definition at line 182 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::OptRemarkAnalysisT = typename afdo_detail::IRTraits<BT>::OptRemarkAnalysisT |
Definition at line 199 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::OptRemarkEmitterT = typename afdo_detail::IRTraits<BT>::OptRemarkEmitterT |
Definition at line 197 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::PostDominatorTreePtrT = typename afdo_detail::IRTraits<BT>::PostDominatorTreePtrT |
Definition at line 193 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::PostDominatorTreeT = typename afdo_detail::IRTraits<BT>::PostDominatorTreeT |
Definition at line 195 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::PredRangeT = typename afdo_detail::IRTraits<BT>::PredRangeT |
Definition at line 201 of file SampleProfileLoaderBaseImpl.h.
using llvm::SampleProfileLoaderBaseImpl< FT >::SuccRangeT = typename afdo_detail::IRTraits<BT>::SuccRangeT |
Definition at line 202 of file SampleProfileLoaderBaseImpl.h.
|
inline |
Definition at line 177 of file SampleProfileLoaderBaseImpl.h.
|
protecteddefault |
|
protected |
Definition at line 973 of file SampleProfileLoaderBaseImpl.h.
References F.
|
protected |
Build in/out edge lists for each basic block in the CFG.
We are interested in unique edges. If a block B1 has multiple edges to another block B2, we only add a single B1->B2 edge.
Definition at line 878 of file SampleProfileLoaderBaseImpl.h.
References llvm::SmallPtrSetImplBase::clear(), F, llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm_unreachable.
|
protected |
Clear all the per-function data used to load samples and propagate weights.
Definition at line 337 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Generate branch weight metadata for all branches in F
.
Branch weights are computed out of instruction samples using a propagation heuristic. Propagation proceeds in 3 phases:
1- Assignment of block weights. All the basic blocks in the function are initial assigned the same weight as their most frequently executed instruction.
2- Creation of equivalence classes. Since samples may be missing from blocks, we can fill in the gaps by setting the weights of all the blocks in the same equivalence class to the same weight. To compute the concept of equivalence, we use dominance and loop information. Two blocks B1 and B2 are in the same equivalence class if B1 dominates B2, B2 post-dominates B1 and both are in the same loop.
3- Propagation of block weights into edges. This uses a simple propagation heuristic. The following rules are applied to every block BB in the CFG:
Since this propagation is not guaranteed to finalize for every CFG, we only allow it to proceed for a limited number of iterations (controlled by -sample-profile-max-propagate-iterations).
FIXME: Try to replace this propagation heuristic with a scheme that is guaranteed to finalize. A work-list approach similar to the standard value propagation algorithm used by SSA-CCP might work here.
F | The function to query. |
F
was modified. Returns false, otherwise. Definition at line 1027 of file SampleProfileLoaderBaseImpl.h.
References F, and llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::size().
|
protected |
Compute and store the weights of every basic block.
This populates the BlockWeights map by computing the weights of every basic block in the CFG.
F | The function to query. |
Definition at line 534 of file SampleProfileLoaderBaseImpl.h.
References llvm::dbgs(), F, llvm::ErrorOr< T >::get(), and LLVM_DEBUG.
|
protected |
Definition at line 641 of file SampleProfile.cpp.
References F.
|
protected |
|
protected |
Definition at line 202 of file MIRSampleProfile.cpp.
|
inline |
Definition at line 180 of file SampleProfileLoaderBaseImpl.h.
References llvm::SampleProfileLoaderBaseImpl< FT >::Reader.
|
protected |
Definition at line 1097 of file SampleProfileLoaderBaseImpl.h.
References llvm::DS_Warning, F, getFunction(), llvm::SampleProfileRecordCoverage, llvm::SampleProfileSampleCoverage, and llvm::Total.
|
protected |
Definition at line 1077 of file SampleProfileLoaderBaseImpl.h.
References F, getFunction(), llvm::Function::PCT_Real, llvm::SampleProfileUseProfi, and llvm::Function::setEntryCount().
|
protected |
Find equivalence classes.
Since samples may be missing from blocks, we can fill in the gaps by setting the weights of all the blocks in the same equivalence class to the same weight. To compute the concept of equivalence, we use dominance and loop information. Two blocks B1 and B2 are in the same equivalence class if B1 dominates B2, B2 post-dominates B1 and both are in the same loop.
F | The function to query. |
Definition at line 641 of file SampleProfileLoaderBaseImpl.h.
References llvm::SmallVectorImpl< T >::clear(), llvm::dbgs(), F, and LLVM_DEBUG.
|
protected |
Find equivalence classes for the given block.
This finds all the blocks that are guaranteed to execute the same number of times as BB1
. To do this, it traverses all the descendants of BB1
in the dominator or post-dominator tree.
A block BB2 will be in the same equivalence class as BB1
if the following holds:
1- BB1
is a descendant of BB2 in the opposite tree. So, if BB2 is a descendant of BB1
in the dominator tree, then BB2 should dominate BB1 in the post-dominator tree.
2- Both BB2 and BB1
must be in the same loop.
For every block BB2 that meets those two requirements, we set BB2's equivalence class to BB1
.
BB1 | Block to check. |
Descendants | Descendants of BB1 in either the dom or pdom tree. |
DomTree | Opposite dominator tree. If Descendants is filled with blocks from BB1's dominator tree, then this is the post-dominator tree, and vice versa. |
Definition at line 597 of file SampleProfileLoaderBaseImpl.h.
|
protectedvirtual |
Get the FunctionSamples for an instruction.
The FunctionSamples of an instruction Inst
is the inlined instance in which that instruction is coming from. We traverse the inline stack of that instruction, and match it with the tree nodes in the profile.
Inst | Instruction to query. |
Definition at line 560 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Compute the weight of a basic block.
The weight of basic block BB
is the maximum weight of all the instructions in BB.
BB | The basic block to query. |
BB
. Definition at line 514 of file SampleProfileLoaderBaseImpl.h.
References I.
|
inlineprotected |
Definition at line 219 of file SampleProfileLoaderBaseImpl.h.
References F.
|
inlineprotected |
Definition at line 216 of file SampleProfileLoaderBaseImpl.h.
References F.
|
protected |
Get the line number for the function header.
This looks up function F
in the current compilation unit and retrieves the line number where the function is defined. This is line 0 for all the samples read from the profile file. Every line number is relative to this line.
F | Function object to query. |
F
is defined. If it returns 0, it means that there is no debug information available for F
. Definition at line 1139 of file SampleProfileLoaderBaseImpl.h.
References llvm::DS_Warning, F, getFunction(), and llvm::NoWarnSampleUnused.
|
protectedvirtual |
Get the weight for an instruction.
The "weight" of an instruction Inst
is the number of samples collected on that instruction at runtime. To retrieve it, we need to compute the line number of Inst
relative to the start of its function. We use HeaderLineno to compute the offset. We then look up the samples collected for Inst
using BodySamples.
Inst | Instruction to query. |
Inst
. Definition at line 402 of file SampleProfileLoaderBaseImpl.h.
References llvm::sampleprof::FunctionSamples::ProfileIsProbeBased.
|
protected |
Definition at line 410 of file SampleProfileLoaderBaseImpl.h.
References llvm::dbgs(), DEBUG_TYPE, llvm::EnableFSDiscriminator, llvm::DILocation::getBaseDiscriminator(), llvm::DebugLoc::getLine(), llvm::sampleprof::FunctionSamples::getOffset(), LLVM_DEBUG, and llvm::Remark.
|
inlineprotected |
Definition at line 222 of file SampleProfileLoaderBaseImpl.h.
|
protectedvirtual |
Definition at line 454 of file SampleProfileLoaderBaseImpl.h.
References assert(), llvm::dbgs(), DEBUG_TYPE, llvm::extractProbe(), llvm::format(), LLVM_DEBUG, llvm::sampleprof::FunctionSamples::ProfileIsProbeBased, and llvm::Remark.
|
inlineprotected |
Definition at line 225 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Definition at line 1049 of file SampleProfileLoaderBaseImpl.h.
References F, getFunction(), llvm::Function::PCT_Real, llvm::SampleProfileUseProfi, and llvm::Function::setEntryCount().
|
protected |
Print the equivalence class of block BB
on stream OS
.
OS | Stream to emit the output to. |
BB | Block to print. |
Definition at line 369 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Print the weight of block BB
on stream OS
.
OS | Stream to emit the output to. |
BB | Block to print. |
Definition at line 381 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Print the weight of edge E
on stream OS
.
OS | Stream to emit the output to. |
E | Edge to print. |
Definition at line 359 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Propagate weights through incoming/outgoing edges.
If the weight of a basic block is known, and there is only one edge with an unknown weight, we can calculate the weight of that edge.
Similarly, if all the edges have a known count, we can calculate the count of the basic block, if needed.
F | Function to process. |
UpdateBlockCount | Whether we should update basic block counts that has already been annotated. |
Definition at line 728 of file SampleProfileLoaderBaseImpl.h.
References llvm::dbgs(), E, F, and LLVM_DEBUG.
|
protected |
Propagate weights into edges.
The following rules are applied to every block BB in the CFG:
Definition at line 918 of file SampleProfileLoaderBaseImpl.h.
References F, llvm::ErrorOr< T >::get(), I, llvm::SampleProfileMaxPropagateIterations, and llvm::SampleProfileUseProfi.
|
protected |
Visit the given edge to decide if it has a valid weight.
If E
has not been visited before, we copy to UnknownEdge
and increment the count of unknown edges.
E | Edge to visit. |
NumUnknownEdges | Current number of unknown edges. |
UnknownEdge | Set if E has not been visited before. |
Definition at line 702 of file SampleProfileLoaderBaseImpl.h.
References E.
|
friend |
Definition at line 214 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Map basic blocks to their computed weights.
The weight of a basic block is defined to be the maximum of all the instruction weights in that block.
Definition at line 269 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Profile coverage tracker.
Definition at line 303 of file SampleProfileLoaderBaseImpl.h.
|
mutableprotected |
Definition at line 235 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Dominance, post-dominance and loop information.
Definition at line 292 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Map edges to their computed weights.
Edge weights are computed by propagating basic block weights in SampleProfile::propagateWeights.
Definition at line 275 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Equivalence classes for block weights.
Two blocks BB1 and BB2 are in the same equivalence class if they dominate and post-dominate each other, and they are in the same loop nest. When this happens, the two blocks are guaranteed to execute the same number of times.
Definition at line 289 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Name of the profile file to load.
Definition at line 320 of file SampleProfileLoaderBaseImpl.h.
|
protected |
VirtualFileSystem to load profile files from.
Definition at line 326 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Definition at line 294 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Optimization Remark Emitter used to emit diagnostic remarks.
Definition at line 332 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Synthetic samples created by duplicating the samples of inlined functions from the original profile as if they were top level sample profiles.
Use std::map because insertion may happen while its content is referenced.
Definition at line 311 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Definition at line 293 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Predecessors for each basic block in the CFG.
Definition at line 297 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Definition at line 314 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Profile Summary Info computed from sample profile.
Definition at line 329 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Profile reader object.
Definition at line 306 of file SampleProfileLoaderBaseImpl.h.
Referenced by llvm::SampleProfileLoaderBaseImpl< FT >::dump().
|
protected |
Name of the profile remapping file to load.
Definition at line 323 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Samples collected for the body of this function.
Definition at line 317 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Successors for each basic block in the CFG.
Definition at line 300 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Set of visited blocks during propagation.
Definition at line 278 of file SampleProfileLoaderBaseImpl.h.
|
protected |
Set of visited edges during propagation.
Definition at line 281 of file SampleProfileLoaderBaseImpl.h.