[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / Analysis / LazyBlockFrequencyInfo.cpp
blob636baf82eedffab91e8951154e48d5796cdc5035
1 //===- LazyBlockFrequencyInfo.cpp - Lazy Block Frequency Analysis ---------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This is an alternative analysis pass to BlockFrequencyInfoWrapperPass. The
10 // difference is that with this pass the block frequencies are not computed when
11 // the analysis pass is executed but rather when the BFI result is explicitly
12 // requested by the analysis client.
14 //===----------------------------------------------------------------------===//
16 #include "llvm/Analysis/LazyBlockFrequencyInfo.h"
17 #include "llvm/Analysis/LazyBranchProbabilityInfo.h"
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/IR/Dominators.h"
20 #include "llvm/InitializePasses.h"
22 using namespace llvm;
24 #define DEBUG_TYPE "lazy-block-freq"
26 INITIALIZE_PASS_BEGIN(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
27 "Lazy Block Frequency Analysis", true, true)
28 INITIALIZE_PASS_DEPENDENCY(LazyBPIPass)
29 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
30 INITIALIZE_PASS_END(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
31 "Lazy Block Frequency Analysis", true, true)
33 char LazyBlockFrequencyInfoPass::ID = 0;
35 LazyBlockFrequencyInfoPass::LazyBlockFrequencyInfoPass() : FunctionPass(ID) {
36 initializeLazyBlockFrequencyInfoPassPass(*PassRegistry::getPassRegistry());
39 void LazyBlockFrequencyInfoPass::print(raw_ostream &OS, const Module *) const {
40 LBFI.getCalculated().print(OS);
43 void LazyBlockFrequencyInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
44 LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
45 // We require DT so it's available when LI is available. The LI updating code
46 // asserts that DT is also present so if we don't make sure that we have DT
47 // here, that assert will trigger.
48 AU.addRequiredTransitive<DominatorTreeWrapperPass>();
49 AU.addRequiredTransitive<LoopInfoWrapperPass>();
50 AU.setPreservesAll();
53 void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
55 bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
56 auto &BPIPass = getAnalysis<LazyBranchProbabilityInfoPass>();
57 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
58 LBFI.setAnalysis(&F, &BPIPass, &LI);
59 return false;
62 void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
63 LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
64 AU.addRequiredTransitive<LazyBlockFrequencyInfoPass>();
65 AU.addRequiredTransitive<LoopInfoWrapperPass>();
68 void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
69 initializeLazyBPIPassPass(Registry);
70 INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
71 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);