LLVM 24.0.0git
llvm::BlockFrequencyInfoImplBase Class Reference

Base class for BlockFrequencyInfoImpl. More...

#include "llvm/Analysis/BlockFrequencyInfoImpl.h"

Inheritance diagram for llvm::BlockFrequencyInfoImplBase:
[legend]

Classes

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.
void addLoopSuccessorsToDist (const LoopData *OuterLoop, LoopData &Loop, Distribution &Dist)
 Add all edges out of a packaged loop to the distribution.
void addToDist (Distribution &Dist, const LoopData *OuterLoop, const BlockNode &Pred, const BlockNode &Succ, uint64_t Weight)
 Add an edge to the distribution.
iterator_range< std::list< LoopData >::iteratoranalyzeIrreducible (const bfi_detail::IrreducibleGraph &G, LoopData *OuterLoop, std::list< LoopData >::iterator Insert)
 Analyze irreducible SCCs.
void distributeMass (const BlockNode &Source, LoopData *OuterLoop, Distribution &Dist)
 Distribute mass according to a distribution.
void computeLoopScale (LoopData &Loop)
 Compute the loop scale for a loop.
void adjustLoopHeaderMass (LoopData &Loop)
 Adjust the mass of all headers in an irreducible loop.
void distributeIrrLoopHeaderMass (Distribution &Dist)
void packageLoop (LoopData &Loop)
 Package up a loop.
void unwrapLoops ()
 Unwrap loops.
void finalizeMetrics ()
 Finalize frequency metrics.
void clear ()
 Clear all memory.
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
std::optional< uint64_tgetBlockProfileCount (const Function &F, const BlockNode &Node) const
std::optional< uint64_tgetProfileCountFromFreq (const Function &F, BlockFrequency Freq) const
bool isIrrLoopHeader (const BlockNode &Node)
void setBlockFreq (const BlockNode &Node, BlockFrequency Freq)
BlockFrequency getEntryFreq () const

Public Attributes

std::vector< FrequencyDataFreqs
 Data about each block. This is used downstream.
SparseBitVector IsIrrLoopHeader
 Whether each block is an irreducible loop header.
std::vector< WorkingDataWorking
 Loop data: see initializeLoops().
std::list< LoopDataLoops
 Indexed information about loops.
bool TopContainsIrreducible = false
 Has an irreducible SCC outside every loop.

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 177 of file BlockFrequencyInfoImpl.h.

Member Typedef Documentation

◆ BlockMass

◆ Scaled64

Constructor & Destructor Documentation

◆ ~BlockFrequencyInfoImplBase()

virtual llvm::BlockFrequencyInfoImplBase::~BlockFrequencyInfoImplBase ( )
virtualdefault

Member Function Documentation

◆ addLoopSuccessorsToDist()

void 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.

Definition at line 364 of file BlockFrequencyInfoImpl.cpp.

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

Referenced by ~BlockFrequencyInfoImplBase().

◆ addToDist()

void 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).

Definition at line 313 of file BlockFrequencyInfoImpl.cpp.

References llvm::BlockFrequencyInfoImplBase::Distribution::addBackedge(), llvm::BlockFrequencyInfoImplBase::Distribution::addExit(), llvm::BlockFrequencyInfoImplBase::Distribution::addLocal(), assert(), llvm::dbgs(), llvm::bfi_detail::getBlockName(), llvm::BlockFrequencyInfoImplBase::BlockNode::Index, llvm::BlockFrequencyInfoImplBase::LoopData::isHeader(), llvm::BlockFrequencyInfoImplBase::LoopData::isIrreducible(), LLVM_DEBUG, and Working.

Referenced by addLoopSuccessorsToDist(), and ~BlockFrequencyInfoImplBase().

◆ 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 757 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::BlockFrequencyInfoImplBase::Weight::Local, llvm::BlockFrequencyInfoImplBase::Distribution::Weights, and Working.

Referenced by ~BlockFrequencyInfoImplBase().

◆ 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.

Returns
the LoopData nodes representing the irreducible SCCs.

Definition at line 714 of file BlockFrequencyInfoImpl.cpp.

References assert(), createIrreducibleLoop(), llvm::SmallVectorImpl< T >::emplace_back(), G, I, Loops, llvm::make_range(), N, llvm::scc_begin(), llvm::BitVector::set(), and llvm::BitVector::test().

Referenced by ~BlockFrequencyInfoImplBase().

◆ clear()

void BlockFrequencyInfoImplBase::clear ( )

◆ computeLoopScale()

void BlockFrequencyInfoImplBase::computeLoopScale ( LoopData & Loop)

◆ distributeIrrLoopHeaderMass()

◆ distributeMass()

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

◆ dump()

void llvm::BlockFrequencyInfoImplBase::dump ( ) const
inline

Definition at line 515 of file BlockFrequencyInfoImpl.h.

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

Referenced by llvm::BlockFrequencyInfoImpl< BasicBlock >::print().

◆ finalizeMetrics()

void BlockFrequencyInfoImplBase::finalizeMetrics ( )

Finalize frequency metrics.

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

Definition at line 538 of file BlockFrequencyInfoImpl.cpp.

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

Referenced by llvm::BlockFrequencyInfoImpl< BT >::calculate(), and ~BlockFrequencyInfoImplBase().

◆ getBlockFreq()

◆ getBlockName()

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

◆ getBlockProfileCount()

std::optional< uint64_t > BlockFrequencyInfoImplBase::getBlockProfileCount ( const Function & F,
const BlockNode & Node ) const

◆ getEntryFreq()

BlockFrequency llvm::BlockFrequencyInfoImplBase::getEntryFreq ( ) const
inline

◆ getFloatingBlockFreq()

Scaled64 BlockFrequencyInfoImplBase::getFloatingBlockFreq ( const BlockNode & Node) const

◆ getLoopName()

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

◆ getProfileCountFromFreq()

◆ isIrrLoopHeader()

bool BlockFrequencyInfoImplBase::isIrrLoopHeader ( const BlockNode & Node)

◆ packageLoop()

void BlockFrequencyInfoImplBase::packageLoop ( LoopData & Loop)

Package up a loop.

Definition at line 407 of file BlockFrequencyInfoImpl.cpp.

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

Referenced by ~BlockFrequencyInfoImplBase().

◆ print()

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

◆ setBlockFreq()

void BlockFrequencyInfoImplBase::setBlockFreq ( const BlockNode & Node,
BlockFrequency Freq )

◆ unwrapLoops()

void BlockFrequencyInfoImplBase::unwrapLoops ( )

Member Data Documentation

◆ Freqs

◆ IsIrrLoopHeader

SparseBitVector llvm::BlockFrequencyInfoImplBase::IsIrrLoopHeader

Whether each block is an irreducible loop header.

This is used downstream.

Definition at line 429 of file BlockFrequencyInfoImpl.h.

Referenced by cleanup(), clear(), and isIrrLoopHeader().

◆ Loops

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

Indexed information about loops.

Definition at line 435 of file BlockFrequencyInfoImpl.h.

Referenced by analyzeIrreducible(), clear(), createIrreducibleLoop(), and unwrapLoops().

◆ TopContainsIrreducible

bool llvm::BlockFrequencyInfoImplBase::TopContainsIrreducible = false

Has an irreducible SCC outside every loop.

Definition at line 438 of file BlockFrequencyInfoImpl.h.

Referenced by clear().

◆ Working

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

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