[Alignment][NFC] Value::getPointerAlignment returns MaybeAlign
[llvm-core.git] / lib / Analysis / LazyBranchProbabilityInfo.cpp
blobe727de468a0d235a6482c5a7c68d81cefc33ae6d
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"
21 using namespace llvm;
23 #define DEBUG_TYPE "lazy-branch-prob"
25 INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
26 "Lazy Branch Probability Analysis", true, true)
27 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
28 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
29 INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
30 "Lazy Branch Probability Analysis", true, true)
32 char LazyBranchProbabilityInfoPass::ID = 0;
34 LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass()
35 : FunctionPass(ID) {
36 initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry());
39 void LazyBranchProbabilityInfoPass::print(raw_ostream &OS,
40 const Module *) const {
41 LBPI->getCalculated().print(OS);
44 void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
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.addRequired<DominatorTreeWrapperPass>();
49 AU.addRequired<LoopInfoWrapperPass>();
50 AU.addRequired<TargetLibraryInfoWrapperPass>();
51 AU.setPreservesAll();
54 void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); }
56 bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) {
57 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
58 TargetLibraryInfo &TLI =
59 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
60 LBPI = std::make_unique<LazyBranchProbabilityInfo>(&F, &LI, &TLI);
61 return false;
64 void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
65 AU.addRequired<LazyBranchProbabilityInfoPass>();
66 AU.addRequired<LoopInfoWrapperPass>();
67 AU.addRequired<TargetLibraryInfoWrapperPass>();
70 void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {
71 INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass);
72 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
73 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass);