File indexing completed on 2026-05-10 08:43:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef LLVM_ANALYSIS_LAZYBLOCKFREQUENCYINFO_H
0017 #define LLVM_ANALYSIS_LAZYBLOCKFREQUENCYINFO_H
0018
0019 #include "llvm/Analysis/BlockFrequencyInfo.h"
0020 #include "llvm/Analysis/LazyBranchProbabilityInfo.h"
0021 #include "llvm/Pass.h"
0022
0023 namespace llvm {
0024 class Function;
0025 class LoopInfo;
0026
0027
0028
0029
0030
0031 template <typename FunctionT, typename BranchProbabilityInfoPassT,
0032 typename LoopInfoT, typename BlockFrequencyInfoT>
0033 class LazyBlockFrequencyInfo {
0034 public:
0035 LazyBlockFrequencyInfo() = default;
0036
0037
0038 void setAnalysis(const FunctionT *F, BranchProbabilityInfoPassT *BPIPass,
0039 const LoopInfoT *LI) {
0040 this->F = F;
0041 this->BPIPass = BPIPass;
0042 this->LI = LI;
0043 }
0044
0045
0046 BlockFrequencyInfoT &getCalculated() {
0047 if (!Calculated) {
0048 assert(F && BPIPass && LI && "call setAnalysis");
0049 BFI.calculate(
0050 *F, BPIPassTrait<BranchProbabilityInfoPassT>::getBPI(BPIPass), *LI);
0051 Calculated = true;
0052 }
0053 return BFI;
0054 }
0055
0056 const BlockFrequencyInfoT &getCalculated() const {
0057 return const_cast<LazyBlockFrequencyInfo *>(this)->getCalculated();
0058 }
0059
0060 void releaseMemory() {
0061 BFI.releaseMemory();
0062 Calculated = false;
0063 setAnalysis(nullptr, nullptr, nullptr);
0064 }
0065
0066 private:
0067 BlockFrequencyInfoT BFI;
0068 bool Calculated = false;
0069 const FunctionT *F = nullptr;
0070 BranchProbabilityInfoPassT *BPIPass = nullptr;
0071 const LoopInfoT *LI = nullptr;
0072 };
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 class LazyBlockFrequencyInfoPass : public FunctionPass {
0098 private:
0099 LazyBlockFrequencyInfo<Function, LazyBranchProbabilityInfoPass, LoopInfo,
0100 BlockFrequencyInfo>
0101 LBFI;
0102
0103 public:
0104 static char ID;
0105
0106 LazyBlockFrequencyInfoPass();
0107
0108
0109 BlockFrequencyInfo &getBFI() { return LBFI.getCalculated(); }
0110
0111
0112 const BlockFrequencyInfo &getBFI() const { return LBFI.getCalculated(); }
0113
0114 void getAnalysisUsage(AnalysisUsage &AU) const override;
0115
0116
0117
0118 static void getLazyBFIAnalysisUsage(AnalysisUsage &AU);
0119
0120 bool runOnFunction(Function &F) override;
0121 void releaseMemory() override;
0122 void print(raw_ostream &OS, const Module *M) const override;
0123 };
0124
0125
0126 void initializeLazyBFIPassPass(PassRegistry &Registry);
0127 }
0128 #endif