Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / Analysis / LazyBranchProbabilityInfo.cpp
blob95de4949b21cfb8a5b14fa2d5085b73f3f5d9ba0
1 //===- LazyBranchProbabilityInfo.cpp - Lazy Branch Probability 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 BranchProbabilityInfoWrapperPass.
10 // The difference is that with this pass the branch probabilities are not
11 // computed when the analysis pass is executed but rather when the BPI results
12 // is explicitly requested by the analysis client.
14 //===----------------------------------------------------------------------===//
16 #include "llvm/Analysis/LazyBranchProbabilityInfo.h"
17 #include "llvm/Analysis/LoopInfo.h"
18 #include "llvm/Analysis/TargetLibraryInfo.h"
19 #include "llvm/IR/Dominators.h"
20 #include "llvm/InitializePasses.h"
22 using namespace llvm;
24 #define DEBUG_TYPE "lazy-branch-prob"
26 INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
27 "Lazy Branch Probability Analysis", true, true)
28 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
29 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
30 INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
31 "Lazy Branch Probability Analysis", true, true)
33 char LazyBranchProbabilityInfoPass::ID = 0;
35 LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass()
36 : FunctionPass(ID) {
37 initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry());
40 void LazyBranchProbabilityInfoPass::print(raw_ostream &OS,
41 const Module *) const {
42 LBPI->getCalculated().print(OS);
45 void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
46 // We require DT so it's available when LI is available. The LI updating code
47 // asserts that DT is also present so if we don't make sure that we have DT
48 // here, that assert will trigger.
49 AU.addRequiredTransitive<DominatorTreeWrapperPass>();
50 AU.addRequiredTransitive<LoopInfoWrapperPass>();
51 AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
52 AU.setPreservesAll();
55 void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); }
57 bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) {
58 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
59 TargetLibraryInfo &TLI =
60 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
61 LBPI = std::make_unique<LazyBranchProbabilityInfo>(&F, &LI, &TLI);
62 return false;
65 void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
66 AU.addRequiredTransitive<LazyBranchProbabilityInfoPass>();
67 AU.addRequiredTransitive<LoopInfoWrapperPass>();
68 AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
71 void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {
72 INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass);
73 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
74 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass);