LLVM: llvm::SampleProfileLoaderBaseImpl< FT > Class Template Reference (original) (raw)

#include "[llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h](SampleProfileLoaderBaseImpl%5F8h%5Fsource.html)"

Public Types
using NodeRef = typename GraphTraits<FT *>::NodeRef
using BT = std::remove_pointer_t<NodeRef>
using InstructionT = typename afdo_detail::IRTraits<BT>::InstructionT
using BasicBlockT = typename afdo_detail::IRTraits<BT>::BasicBlockT
using BlockFrequencyInfoT
using FunctionT = typename afdo_detail::IRTraits<BT>::FunctionT
using LoopT = typename afdo_detail::IRTraits<BT>::LoopT
using LoopInfoPtrT = typename afdo_detail::IRTraits<BT>::LoopInfoPtrT
using DominatorTreePtrT
using PostDominatorTreePtrT
using PostDominatorTreeT
using OptRemarkEmitterT
using OptRemarkAnalysisT
using PredRangeT = typename afdo_detail::IRTraits<BT>::PredRangeT
using SuccRangeT = typename afdo_detail::IRTraits<BT>::SuccRangeT
using BlockWeightMap = DenseMap<const BasicBlockT *, uint64_t>
using EquivalenceClassMap
using Edge = std::pair<const BasicBlockT *, const BasicBlockT *>
using EdgeWeightMap = DenseMap<Edge, uint64_t>
using BlockEdgeMap
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

template
class llvm::SampleProfileLoaderBaseImpl< FT >

Definition at line 176 of file SampleProfileLoaderBaseImpl.h.

BasicBlockT

BlockEdgeMap

BlockFrequencyInfoT

BlockWeightMap

BT

DominatorTreePtrT

Edge

EdgeWeightMap

EquivalenceClassMap

FunctionT

InstructionT

LoopInfoPtrT

LoopT

NodeRef

OptRemarkAnalysisT

OptRemarkEmitterT

PostDominatorTreePtrT

PostDominatorTreeT

PredRangeT

SuccRangeT

~SampleProfileLoaderBaseImpl()

applyProfi()

buildEdges()

clearFunctionData()

Clear all the per-function data used to load samples and propagate weights.

Definition at line 338 of file SampleProfileLoaderBaseImpl.h.

References BlockWeights, CoverageTracker, DT, EdgeWeights, EquivalenceClass, LI, PDT, Predecessors, Successors, VisitedBlocks, and VisitedEdges.

computeAndPropagateWeights()

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.

Parameters

Returns

true if F was modified. Returns false, otherwise.

Definition at line 1031 of file SampleProfileLoaderBaseImpl.h.

References Changed, computeBlockWeights(), F, finalizeWeightPropagation(), initWeightPropagation(), propagateWeights(), and llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::size().

computeBlockWeights()

computeDominanceAndLoopInfo() [1/3]

computeDominanceAndLoopInfo() [2/3]

computeDominanceAndLoopInfo() [3/3]

dump()

emitCoverageRemarks()

finalizeWeightPropagation()

findEquivalenceClasses()

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.

Parameters

Definition at line 642 of file SampleProfileLoaderBaseImpl.h.

References BlockWeights, llvm::SmallVectorImpl< T >::clear(), llvm::dbgs(), DT, EquivalenceClass, F, findEquivalencesFor(), LLVM_DEBUG, PDT, printBlockEquivalence(), and printBlockWeight().

Referenced by initWeightPropagation().

findEquivalencesFor()

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.

Parameters

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 598 of file SampleProfileLoaderBaseImpl.h.

References BlockWeights, EquivalenceClass, getEntryBB(), LI, Samples, and VisitedBlocks.

Referenced by findEquivalenceClasses().

findFunctionSamples()

getBlockWeight()

getEntryBB()

getFunction()

getFunctionLoc()

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.

Parameters

Returns

the line number where F is defined. If it returns 0, it means that there is no debug information available for F.

Definition at line 1143 of file SampleProfileLoaderBaseImpl.h.

References llvm::DS_Warning, F, getFunction(), and llvm::NoWarnSampleUnused.

Referenced by emitCoverageRemarks().

getInstWeight()

getInstWeightImpl()

Definition at line 411 of file SampleProfileLoaderBaseImpl.h.

References CoverageTracker, llvm::dbgs(), DEBUG_TYPE, llvm::EnableFSDiscriminator, findFunctionSamples(), FS, llvm::DILocation::getBaseDiscriminator(), llvm::DebugLoc::getLine(), llvm::sampleprof::FunctionSamples::getOffset(), LLVM_DEBUG, ORE, and llvm::Remark.

Referenced by getInstWeight().

getPredecessors()

getProbeWeight()

Definition at line 455 of file SampleProfileLoaderBaseImpl.h.

References assert(), CoverageTracker, llvm::dbgs(), DEBUG_TYPE, llvm::extractProbe(), findFunctionSamples(), llvm::format(), FS, LLVM_DEBUG, ORE, llvm::sampleprof::FunctionSamples::ProfileIsProbeBased, llvm::Remark, and Samples.

Referenced by getInstWeight().

getSuccessors()

initWeightPropagation()

printBlockEquivalence()

printBlockWeight()

printEdgeWeight()

propagateThroughEdges()

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.

Parameters

F Function to process.
UpdateBlockCount Whether we should update basic block counts that has already been annotated.

Returns

True if new weights were assigned to edges or blocks.

Definition at line 728 of file SampleProfileLoaderBaseImpl.h.

References BlockWeights, Changed, llvm::dbgs(), E(), EdgeWeights, EquivalenceClass, F, LLVM_DEBUG, Predecessors, printBlockWeight(), printEdgeWeight(), Successors, VisitedBlocks, VisitedEdges, and visitEdge().

Referenced by propagateWeights().

propagateWeights()

Propagate weights into edges.

The following rules are applied to every block BB in the CFG:

Definition at line 922 of file SampleProfileLoaderBaseImpl.h.

References applyProfi(), BlockWeights, Changed, EdgeWeights, F, llvm::ErrorOr< T >::get(), getBlockWeight(), I, LI, propagateThroughEdges(), llvm::SampleProfileMaxPropagateIterations, llvm::SampleProfileUseProfi, Successors, and VisitedEdges.

Referenced by computeAndPropagateWeights().

visitEdge()

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.

Parameters

E Edge to visit.
NumUnknownEdges Current number of unknown edges.
UnknownEdge Set if E has not been visited before.

Returns

E's weight, if known. Otherwise, return 0.

Definition at line 702 of file SampleProfileLoaderBaseImpl.h.

References E(), EdgeWeights, and VisitedEdges.

Referenced by propagateThroughEdges().

SampleCoverageTracker

BlockWeights

CoverageTracker

DILocation2SampleMap

DT

EdgeWeights

EquivalenceClass

Filename

FS

LI

ORE

OutlineFunctionSamples

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 312 of file SampleProfileLoaderBaseImpl.h.

PDT

Predecessors

ProbeManager

PSI

Reader

RemappingFilename

Samples

Successors

VisitedBlocks

VisitedEdges


The documentation for this class was generated from the following file: