|
LLVM 24.0.0git
|
Base class for BlockFrequencyInfoImpl. More...
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
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 Attributes | |
| std::vector< FrequencyData > | Freqs |
| Data about each block. This is used downstream. | |
| SparseBitVector | IsIrrLoopHeader |
| Whether each block is an irreducible loop header. | |
| std::vector< WorkingData > | Working |
| Loop data: see initializeLoops(). | |
| std::list< LoopData > | Loops |
| Indexed information about loops. | |
| bool | TopContainsIrreducible = false |
| Has an irreducible SCC outside every loop. | |
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.
Definition at line 180 of file BlockFrequencyInfoImpl.h.
Definition at line 179 of file BlockFrequencyInfoImpl.h.
|
virtualdefault |
Virtual destructor.
Need a virtual destructor to mask the compiler warning about getBlockName().
References addLoopSuccessorsToDist(), addToDist(), adjustLoopHeaderMass(), analyzeIrreducible(), clear(), computeLoopScale(), distributeIrrLoopHeaderMass(), distributeMass(), finalizeMetrics(), G, getLoopName(), packageLoop(), and unwrapLoops().
| 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().
| 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().
| 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().
| 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.
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().
| void BlockFrequencyInfoImplBase::clear | ( | ) |
Clear all memory.
Definition at line 292 of file BlockFrequencyInfoImpl.cpp.
References Freqs, IsIrrLoopHeader, Loops, TopContainsIrreducible, and Working.
Referenced by llvm::BlockFrequencyInfoImpl< BT >::calculate(), cleanup(), and ~BlockFrequencyInfoImplBase().
| void BlockFrequencyInfoImplBase::computeLoopScale | ( | LoopData & | Loop | ) |
Compute the loop scale for a loop.
Definition at line 372 of file BlockFrequencyInfoImpl.cpp.
References llvm::dbgs(), llvm::bfi_detail::BlockMass::getFull(), getLoopName(), llvm::ScaledNumber< DigitsT >::inverse(), llvm::bfi_detail::BlockMass::isEmpty(), LLVM_DEBUG, and llvm::bfi_detail::BlockMass::toScaled().
Referenced by ~BlockFrequencyInfoImplBase().
| void BlockFrequencyInfoImplBase::distributeIrrLoopHeaderMass | ( | Distribution & | Dist | ) |
Definition at line 794 of file BlockFrequencyInfoImpl.cpp.
References assert(), D(), debugAssign(), llvm::bfi_detail::BlockMass::getFull(), LLVM_DEBUG, llvm::BlockFrequencyInfoImplBase::Weight::Local, llvm::BlockFrequencyInfoImplBase::Distribution::Weights, and Working.
Referenced by ~BlockFrequencyInfoImplBase().
| 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 432 of file BlockFrequencyInfoImpl.cpp.
References assert(), llvm::BlockFrequencyInfoImplBase::Weight::Backedge, llvm::BlockFrequencyInfoImplBase::LoopData::BackedgeMass, D(), llvm::dbgs(), debugAssign(), llvm::BlockFrequencyInfoImplBase::Weight::Exit, llvm::BlockFrequencyInfoImplBase::LoopData::Exits, llvm::BlockFrequencyInfoImplBase::LoopData::getHeaderIndex(), LLVM_DEBUG, llvm::BlockFrequencyInfoImplBase::Weight::Local, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::BlockFrequencyInfoImplBase::Distribution::Weights, and Working.
Referenced by ~BlockFrequencyInfoImplBase().
|
inline |
Definition at line 515 of file BlockFrequencyInfoImpl.h.
References llvm::dbgs(), and print().
Referenced by llvm::BlockFrequencyInfoImpl< BasicBlock >::print().
| 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().
| BlockFrequency BlockFrequencyInfoImplBase::getBlockFreq | ( | const BlockNode & | Node | ) | const |
Definition at line 550 of file BlockFrequencyInfoImpl.cpp.
References llvm::CheckBFIUnknownBlockQueries, Freqs, llvm::bfi_detail::getBlockName(), Msg, llvm::report_fatal_error(), and llvm::raw_svector_ostream::str().
Referenced by llvm::BlockFrequencyInfoImpl< BasicBlock >::getBlockFreq(), and getBlockProfileCount().
Definition at line 610 of file BlockFrequencyInfoImpl.cpp.
Referenced by convertFloatingToInteger(), createIrreducibleLoop(), debugAssign(), and unwrapLoop().
| std::optional< uint64_t > BlockFrequencyInfoImplBase::getBlockProfileCount | ( | const Function & | F, |
| const BlockNode & | Node ) const |
Definition at line 566 of file BlockFrequencyInfoImpl.cpp.
References F, getBlockFreq(), and getProfileCountFromFreq().
Referenced by llvm::BlockFrequencyInfoImpl< BasicBlock >::getBlockProfileCount(), and llvm::BlockFrequencyInfoImpl< BT >::print().
|
inline |
Definition at line 528 of file BlockFrequencyInfoImpl.h.
References assert(), Freqs, and llvm::Integer.
Referenced by llvm::BlockFrequencyInfoImpl< BasicBlock >::calculate(), and getProfileCountFromFreq().
Definition at line 596 of file BlockFrequencyInfoImpl.cpp.
References Freqs, and llvm::ScaledNumber< uint64_t >::getZero().
Referenced by llvm::BlockFrequencyInfoImpl< BasicBlock >::getFloatingBlockFreq().
Definition at line 615 of file BlockFrequencyInfoImpl.cpp.
References llvm::bfi_detail::getBlockName(), and llvm::LoopBase< BlockT, LoopT >::getHeader().
Referenced by computeLoopScale(), packageLoop(), unwrapLoop(), and ~BlockFrequencyInfoImplBase().
| std::optional< uint64_t > BlockFrequencyInfoImplBase::getProfileCountFromFreq | ( | const Function & | F, |
| BlockFrequency | Freq ) const |
Definition at line 572 of file BlockFrequencyInfoImpl.cpp.
References F, getEntryFreq(), llvm::BlockFrequency::getFrequency(), llvm::APInt::getLimitedValue(), llvm::APInt::lshr(), and llvm::APInt::udiv().
Referenced by getBlockProfileCount(), and llvm::BlockFrequencyInfoImpl< BasicBlock >::getProfileCountFromFreq().
Definition at line 589 of file BlockFrequencyInfoImpl.cpp.
References IsIrrLoopHeader.
Referenced by llvm::BlockFrequencyInfoImpl< BasicBlock >::isIrrLoopHeader().
| 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().
|
inlinevirtual |
Reimplemented in llvm::BlockFrequencyInfoImpl< BT >, llvm::BlockFrequencyInfoImpl< BasicBlock >, and llvm::BlockFrequencyInfoImpl< MachineBasicBlock >.
Definition at line 514 of file BlockFrequencyInfoImpl.h.
| void BlockFrequencyInfoImplBase::setBlockFreq | ( | const BlockNode & | Node, |
| BlockFrequency | Freq ) |
Definition at line 602 of file BlockFrequencyInfoImpl.cpp.
References assert(), Freqs, and llvm::BlockFrequency::getFrequency().
Referenced by llvm::BlockFrequencyInfoImpl< BT >::setBlockFreq().
| void BlockFrequencyInfoImplBase::unwrapLoops | ( | ) |
Unwrap loops.
Definition at line 529 of file BlockFrequencyInfoImpl.cpp.
References Freqs, Loops, Scaled, llvm::bfi_detail::BlockMass::toScaled(), unwrapLoop(), and Working.
Referenced by llvm::BlockFrequencyInfoImpl< BT >::calculate(), and ~BlockFrequencyInfoImplBase().
| std::vector<FrequencyData> llvm::BlockFrequencyInfoImplBase::Freqs |
Data about each block. This is used downstream.
Definition at line 425 of file BlockFrequencyInfoImpl.h.
Referenced by cleanup(), clear(), convertFloatingToInteger(), getBlockFreq(), getEntryFreq(), getFloatingBlockFreq(), llvm::BlockFrequencyInfoImpl< BT >::setBlockFreq(), setBlockFreq(), unwrapLoop(), unwrapLoops(), and llvm::BlockFrequencyInfoImpl< BT >::verifyMatch().
| 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().
| 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().
| bool llvm::BlockFrequencyInfoImplBase::TopContainsIrreducible = false |
Has an irreducible SCC outside every loop.
Definition at line 438 of file BlockFrequencyInfoImpl.h.
Referenced by clear().
| std::vector<WorkingData> llvm::BlockFrequencyInfoImplBase::Working |
Loop data: see initializeLoops().
Definition at line 432 of file BlockFrequencyInfoImpl.h.
Referenced by addToDist(), adjustLoopHeaderMass(), clear(), createIrreducibleLoop(), distributeIrrLoopHeaderMass(), distributeMass(), packageLoop(), unwrapLoop(), and unwrapLoops().