1//===- BlockFrequencyInfo.h - Block Frequency Analysis ----------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// Loops should be simplified before this analysis. 11//===----------------------------------------------------------------------===// 13#ifndef LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H 14#define LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H 27classBranchProbabilityInfo;
31template <
class BlockT>
classBlockFrequencyInfoImpl;
35/// BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to 36/// estimate IR basic block frequencies. 40 std::unique_ptr<ImplType> BFI;
52 /// Handle invalidation explicitly. 60 /// getblockFreq - Return block frequency. Return 0 if we don't have the 61 /// information. Please note that initial frequency is equal to ENTRY_FREQ. It 62 /// means that we should not rely on the value itself, but only on the 63 /// comparison to the other block frequencies. We do this to avoid using of 67 /// Returns the estimated profile count of \p BB. 68 /// This computes the relative block frequency of \p BB and multiplies it by 69 /// the enclosing function's count (if available) and returns the value. 70 std::optional<uint64_t>
73 /// Returns the estimated profile count of \p Freq. 74 /// This uses the frequency \p Freq and multiplies it by 75 /// the enclosing function's count (if available) and returns the value. 78 /// Returns true if \p BB is an irreducible loop header 79 /// block. Otherwise false. 82// Set the frequency of the given basic block. 85 /// Set the frequency of \p ReferenceBB to \p Freq and scale the frequencies 86 /// of the blocks in \p BlocksToScale such that their frequencies relative 87 /// to \p ReferenceBB remain unchanged. 91 /// calculate - compute block frequency info for the given function. 99// Compare to the other BFI and verify they match. 103/// Print the block frequency @p Freq relative to the current functions entry 104/// frequency. Returns a Printable object that can be piped via `<<` to a 108/// Convenience function equivalent to calling 109/// `printBlockFreq(BFI, BFI.getBlocakFreq(&BB))`. 112/// Analysis pass which computes \c BlockFrequencyInfo. 120 /// Provide the result type for this analysis pass. 123 /// Run the analysis pass over a function and produce BFI. 127/// Printer pass for the \c BlockFrequencyInfo results. 140/// Legacy analysis pass which computes \c BlockFrequencyInfo. 160}
// end namespace llvm 162#endif// LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
LLVM Basic Block Representation.
Analysis pass which computes BlockFrequencyInfo.
Result run(Function &F, FunctionAnalysisManager &AM)
Run the analysis pass over a function and produce BFI.
Shared implementation for block frequency analysis.
Legacy analysis pass which computes BlockFrequencyInfo.
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
~BlockFrequencyInfoWrapperPass() override
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
BlockFrequencyInfo & getBFI()
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
BlockFrequencyInfoWrapperPass()
const BlockFrequencyInfo & getBFI() const
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
bool isIrrLoopHeader(const BasicBlock *BB)
Returns true if BB is an irreducible loop header block.
void calculate(const Function &F, const BranchProbabilityInfo &BPI, const LoopInfo &LI)
calculate - compute block frequency info for the given function.
std::optional< uint64_t > getProfileCountFromFreq(BlockFrequency Freq) const
Returns the estimated profile count of Freq.
void setBlockFreq(const BasicBlock *BB, BlockFrequency Freq)
const Function * getFunction() const
std::optional< uint64_t > getBlockProfileCount(const BasicBlock *BB, bool AllowSynthetic=false) const
Returns the estimated profile count of BB.
BlockFrequencyInfo & operator=(const BlockFrequencyInfo &)=delete
void view(StringRef="BlockFrequencyDAGs") const
Pop up a ghostview window with the current block frequency propagation rendered using dot.
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, BlockFrequency Freq, SmallPtrSetImpl< BasicBlock * > &BlocksToScale)
Set the frequency of ReferenceBB to Freq and scale the frequencies of the blocks in BlocksToScale suc...
const BranchProbabilityInfo * getBPI() const
BlockFrequency getEntryFreq() const
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
void print(raw_ostream &OS) const
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
void verifyMatch(BlockFrequencyInfo &Other) const
BlockFrequencyInfo(const BlockFrequencyInfo &)=delete
Printer pass for the BlockFrequencyInfo results.
BlockFrequencyPrinterPass(raw_ostream &OS)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Analysis providing branch probability information.
FunctionPass class - This class is used to implement most global optimizations.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
Simple wrapper around std::function<void(raw_ostream&)>.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
Printable printBlockFreq(const BlockFrequencyInfo &BFI, BlockFrequency Freq)
Print the block frequency Freq relative to the current functions entry frequency.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
A CRTP mix-in to automatically provide informational APIs needed for passes.