LLVM  15.0.0git
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
llvm::BlockFrequencyInfoImplBase Class Reference

Base class for BlockFrequencyInfoImpl. More...

#include "llvm/Analysis/BlockFrequencyInfoImpl.h"

Collaboration diagram for llvm::BlockFrequencyInfoImplBase:
Collaboration graph


struct  BlockNode
 Representative of a block. More...
struct  Distribution
 Distribution of unscaled probability weight. More...
struct  FrequencyData
 Stats about a block itself. More...
struct  LoopData
 Data about a loop. More...
struct  Weight
 Unscaled probability weight. More...
struct  WorkingData
 Index of loop information. More...

Public Types

using Scaled64 = ScaledNumber< uint64_t >
using BlockMass = bfi_detail::BlockMass

Public Member Functions

virtual ~BlockFrequencyInfoImplBase ()=default
 Virtual destructor. More...
bool addLoopSuccessorsToDist (const LoopData *OuterLoop, LoopData &Loop, Distribution &Dist)
 Add all edges out of a packaged loop to the distribution. More...
bool addToDist (Distribution &Dist, const LoopData *OuterLoop, const BlockNode &Pred, const BlockNode &Succ, uint64_t Weight)
 Add an edge to the distribution. More...
iterator_range< std::list< LoopData >::iterator > analyzeIrreducible (const bfi_detail::IrreducibleGraph &G, LoopData *OuterLoop, std::list< LoopData >::iterator Insert)
 Analyze irreducible SCCs. More...
void updateLoopWithIrreducible (LoopData &OuterLoop)
 Update a loop after packaging irreducible SCCs inside of it. More...
void distributeMass (const BlockNode &Source, LoopData *OuterLoop, Distribution &Dist)
 Distribute mass according to a distribution. More...
void computeLoopScale (LoopData &Loop)
 Compute the loop scale for a loop. More...
void adjustLoopHeaderMass (LoopData &Loop)
 Adjust the mass of all headers in an irreducible loop. More...
void distributeIrrLoopHeaderMass (Distribution &Dist)
void packageLoop (LoopData &Loop)
 Package up a loop. More...
void unwrapLoops ()
 Unwrap loops. More...
void finalizeMetrics ()
 Finalize frequency metrics. More...
void clear ()
 Clear all memory. More...
virtual std::string getBlockName (const BlockNode &Node) const
std::string getLoopName (const LoopData &Loop) const
virtual raw_ostreamprint (raw_ostream &OS) const
void dump () const
Scaled64 getFloatingBlockFreq (const BlockNode &Node) const
BlockFrequency getBlockFreq (const BlockNode &Node) const
Optional< uint64_tgetBlockProfileCount (const Function &F, const BlockNode &Node, bool AllowSynthetic=false) const
Optional< uint64_tgetProfileCountFromFreq (const Function &F, uint64_t Freq, bool AllowSynthetic=false) const
bool isIrrLoopHeader (const BlockNode &Node)
void setBlockFreq (const BlockNode &Node, uint64_t Freq)
raw_ostreamprintBlockFreq (raw_ostream &OS, const BlockNode &Node) const
raw_ostreamprintBlockFreq (raw_ostream &OS, const BlockFrequency &Freq) const
uint64_t getEntryFreq () const

Public Attributes

std::vector< FrequencyDataFreqs
 Data about each block. This is used downstream. More...
SparseBitVector IsIrrLoopHeader
 Whether each block is an irreducible loop header. More...
std::vector< WorkingDataWorking
 Loop data: see initializeLoops(). More...
std::list< LoopDataLoops
 Indexed information about loops. More...

Detailed Description

Base class for BlockFrequencyInfoImpl.

BlockFrequencyInfoImplBase has supporting data structures and some algorithms for BlockFrequencyInfoImplBase. Only algorithms that depend on the block type (or that call such algorithms) are skipped here.

Nevertheless, the majority of the overall algorithm documentation lives with BlockFrequencyInfoImpl. See there for details.

Definition at line 179 of file BlockFrequencyInfoImpl.h.

Member Typedef Documentation

◆ BlockMass

Definition at line 182 of file BlockFrequencyInfoImpl.h.

◆ Scaled64

Definition at line 181 of file BlockFrequencyInfoImpl.h.

Constructor & Destructor Documentation

◆ ~BlockFrequencyInfoImplBase()

virtual llvm::BlockFrequencyInfoImplBase::~BlockFrequencyInfoImplBase ( )

Virtual destructor.

Need a virtual destructor to mask the compiler warning about getBlockName().

Member Function Documentation

◆ addLoopSuccessorsToDist()

bool BlockFrequencyInfoImplBase::addLoopSuccessorsToDist ( const LoopData OuterLoop,
LoopData Loop,
Distribution Dist 

Add all edges out of a packaged loop to the distribution.

Adds all edges from LocalLoopHead to Dist. Calls addToDist() to add each successor edge.

true unless there's an irreducible backedge.

Definition at line 373 of file BlockFrequencyInfoImpl.cpp.

References llvm::LoopBase< BlockT, LoopT >::getHeader(), and I.

◆ addToDist()

bool BlockFrequencyInfoImplBase::addToDist ( Distribution Dist,
const LoopData OuterLoop,
const BlockNode Pred,
const BlockNode Succ,
uint64_t  Weight 

Add an edge to the distribution.

Adds an edge to Succ to Dist. If LoopHead.isValid(), then whether the edge is local/exit/backedge is in the context of LoopHead. Otherwise, every edge should be a local edge (since all the loops are packaged up).

true unless aborted due to an irreducible backedge.

Definition at line 311 of file BlockFrequencyInfoImpl.cpp.

◆ adjustLoopHeaderMass()

void BlockFrequencyInfoImplBase::adjustLoopHeaderMass ( LoopData Loop)

Adjust the mass of all headers in an irreducible loop.

Initially, irreducible loops are assumed to distribute their mass equally among its headers. This can lead to wrong frequency estimates since some headers may be executed more frequently than others.

This adjusts header mass distribution so it matches the weights of the backedges going into each of the loop headers.

Definition at line 835 of file BlockFrequencyInfoImpl.cpp.

References llvm::BlockFrequencyInfoImplBase::Distribution::addLocal(), assert(), D, llvm::dbgs(), debugAssign(), llvm::bfi_detail::getBlockName(), llvm::bfi_detail::BlockMass::getFull(), H, LLVM_DEBUG, llvm::RISCVFenceField::W, and llvm::BlockFrequencyInfoImplBase::Distribution::Weights.

◆ analyzeIrreducible()

iterator_range< std::list< LoopData >::iterator > BlockFrequencyInfoImplBase::analyzeIrreducible ( const bfi_detail::IrreducibleGraph G,
LoopData OuterLoop,
std::list< LoopData >::iterator  Insert 

Analyze irreducible SCCs.

Separate irreducible SCCs from G, which is an explicit graph of OuterLoop (or the top-level function, if OuterLoop is nullptr). Insert them into Loops before Insert.

the LoopData nodes representing the irreducible SCCs.

Definition at line 804 of file BlockFrequencyInfoImpl.cpp.

References assert(), createIrreducibleLoop(), G, I, Insert, Loops, llvm::make_range(), and llvm::scc_begin().

◆ clear()

void BlockFrequencyInfoImplBase::clear ( )

Clear all memory.

Definition at line 291 of file BlockFrequencyInfoImpl.cpp.

References Loops.

Referenced by llvm::BlockFrequencyInfoImpl< BT >::calculate().

◆ computeLoopScale()

void BlockFrequencyInfoImplBase::computeLoopScale ( LoopData Loop)

◆ distributeIrrLoopHeaderMass()

void BlockFrequencyInfoImplBase::distributeIrrLoopHeaderMass ( Distribution Dist)

◆ distributeMass()

void BlockFrequencyInfoImplBase::distributeMass ( const BlockNode Source,
LoopData OuterLoop,
Distribution Dist 

Distribute mass according to a distribution.

Distributes the mass in Source according to Dist. If LoopHead.isValid(), backedges and exits are stored in its entry in Loops.

Mass is distributed in parallel from two copies of the source mass.

Definition at line 446 of file BlockFrequencyInfoImpl.cpp.

References assert(), llvm::BlockFrequencyInfoImplBase::LoopData::BackedgeMass, D, llvm::dbgs(), debugAssign(), llvm::BlockFrequencyInfoImplBase::LoopData::Exits, llvm::BlockFrequencyInfoImplBase::LoopData::getHeaderIndex(), llvm::bfi_detail::BlockMass::getMass(), LLVM_DEBUG, llvm::Sched::Source, llvm::RISCVFenceField::W, and llvm::BlockFrequencyInfoImplBase::Distribution::Weights.

◆ dump()

void llvm::BlockFrequencyInfoImplBase::dump ( ) const

Definition at line 520 of file BlockFrequencyInfoImpl.h.

References llvm::dbgs(), and print().

◆ finalizeMetrics()

void BlockFrequencyInfoImplBase::finalizeMetrics ( )

Finalize frequency metrics.

Calculates final frequencies and cleans up no-longer-needed data structures.

Definition at line 551 of file BlockFrequencyInfoImpl.cpp.

References cleanup(), convertFloatingToInteger(), llvm::dump(), LLVM_DEBUG, llvm::max(), llvm::min(), and Scaled.

◆ getBlockFreq()

BlockFrequency BlockFrequencyInfoImplBase::getBlockFreq ( const BlockNode Node) const

◆ getBlockName()

std::string BlockFrequencyInfoImplBase::getBlockName ( const BlockNode Node) const

Definition at line 636 of file BlockFrequencyInfoImpl.cpp.

◆ getBlockProfileCount()

Optional< uint64_t > BlockFrequencyInfoImplBase::getBlockProfileCount ( const Function F,
const BlockNode Node,
bool  AllowSynthetic = false 
) const

◆ getEntryFreq()

uint64_t llvm::BlockFrequencyInfoImplBase::getEntryFreq ( ) const

Definition at line 539 of file BlockFrequencyInfoImpl.h.

References assert(), and Freqs.

◆ getFloatingBlockFreq()

Scaled64 BlockFrequencyInfoImplBase::getFloatingBlockFreq ( const BlockNode Node) const

◆ getLoopName()

std::string BlockFrequencyInfoImplBase::getLoopName ( const LoopData Loop) const

◆ getProfileCountFromFreq()

Optional< uint64_t > BlockFrequencyInfoImplBase::getProfileCountFromFreq ( const Function F,
uint64_t  Freq,
bool  AllowSynthetic = false 
) const

◆ isIrrLoopHeader()

bool BlockFrequencyInfoImplBase::isIrrLoopHeader ( const BlockNode Node)

◆ packageLoop()

void BlockFrequencyInfoImplBase::packageLoop ( LoopData Loop)

Package up a loop.

Definition at line 421 of file BlockFrequencyInfoImpl.cpp.

References llvm::dbgs(), llvm::bfi_detail::getBlockName(), LLVM_DEBUG, and M.

◆ print()

virtual raw_ostream& llvm::BlockFrequencyInfoImplBase::print ( raw_ostream OS) const

Definition at line 519 of file BlockFrequencyInfoImpl.h.

Referenced by dump().

◆ printBlockFreq() [1/2]

raw_ostream & BlockFrequencyInfoImplBase::printBlockFreq ( raw_ostream OS,
const BlockFrequency Freq 
) const

Definition at line 652 of file BlockFrequencyInfoImpl.cpp.

References llvm::BlockFrequency::getFrequency().

◆ printBlockFreq() [2/2]

raw_ostream & BlockFrequencyInfoImplBase::printBlockFreq ( raw_ostream OS,
const BlockNode Node 
) const

◆ setBlockFreq()

void BlockFrequencyInfoImplBase::setBlockFreq ( const BlockNode Node,
uint64_t  Freq 

◆ unwrapLoops()

void BlockFrequencyInfoImplBase::unwrapLoops ( )

Unwrap loops.

Definition at line 542 of file BlockFrequencyInfoImpl.cpp.

References Loops, Scaled, llvm::bfi_detail::BlockMass::toScaled(), and unwrapLoop().

◆ updateLoopWithIrreducible()

void BlockFrequencyInfoImplBase::updateLoopWithIrreducible ( LoopData OuterLoop)

Update a loop after packaging irreducible SCCs inside of it.

Update OuterLoop. Before finding irreducible control flow, it was partway through computeMassInLoop(), so LoopData::Exits and LoopData::BackedgeMass need to be reset. Also, nodes that were packaged up need to be removed from OuterLoop::Nodes.

Definition at line 824 of file BlockFrequencyInfoImpl.cpp.

References llvm::BlockFrequencyInfoImplBase::LoopData::BackedgeMass, llvm::SmallVectorImpl< T >::clear(), E, llvm::SmallVectorImpl< T >::erase(), llvm::BlockFrequencyInfoImplBase::LoopData::Exits, llvm::bfi_detail::BlockMass::getEmpty(), I, llvm::BlockFrequencyInfoImplBase::LoopData::Nodes, and llvm::RISCVFenceField::O.

Member Data Documentation

◆ Freqs

std::vector<FrequencyData> llvm::BlockFrequencyInfoImplBase::Freqs

Data about each block. This is used downstream.

Definition at line 421 of file BlockFrequencyInfoImpl.h.

Referenced by getEntryFreq().

◆ IsIrrLoopHeader

SparseBitVector llvm::BlockFrequencyInfoImplBase::IsIrrLoopHeader

Whether each block is an irreducible loop header.

This is used downstream.

Definition at line 425 of file BlockFrequencyInfoImpl.h.

◆ Loops

std::list<LoopData> llvm::BlockFrequencyInfoImplBase::Loops

Indexed information about loops.

Definition at line 431 of file BlockFrequencyInfoImpl.h.

◆ Working

std::vector<WorkingData> llvm::BlockFrequencyInfoImplBase::Working

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