LLVM  14.0.0git
LazyBranchProbabilityInfo.cpp
Go to the documentation of this file.
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.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/IR/Dominators.h"
20 #include "llvm/InitializePasses.h"
21 
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "lazy-branch-prob"
25 
27  "Lazy Branch Probability Analysis", true, true)
31  "Lazy Branch Probability Analysis", true, true)
32 
34 
36  : FunctionPass(ID) {
38 }
39 
41  const Module *) const {
42  LBPI->getCalculated().print(OS);
43 }
44 
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.
52  AU.setPreservesAll();
53 }
54 
56 
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;
63 }
64 
69 }
70 
75 }
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE, "Lazy Branch Probability Analysis", true, true) INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
true
Lazy Branch Probability true
Definition: LazyBranchProbabilityInfo.cpp:31
llvm::Function
Definition: Function.h:62
llvm::LazyBranchProbabilityInfoPass::print
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
Definition: LazyBranchProbabilityInfo.cpp:40
llvm::initializeLazyBranchProbabilityInfoPassPass
void initializeLazyBranchProbabilityInfoPassPass(PassRegistry &)
llvm::LoopInfoWrapperPass
The legacy pass manager's analysis pass to compute loop information.
Definition: LoopInfo.h:1268
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
TargetLibraryInfo.h
llvm::LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage
static void getLazyBPIAnalysisUsage(AnalysisUsage &AU)
Helper for client passes to set up the analysis usage on behalf of this pass.
Definition: LazyBranchProbabilityInfo.cpp:65
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:287
llvm::PassRegistry
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::LazyBranchProbabilityInfoPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LazyBranchProbabilityInfo.cpp:45
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
LoopInfo.h
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:465
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::initializeLazyBPIPassPass
void initializeLazyBPIPassPass(PassRegistry &Registry)
Helper for client passes to initialize dependent passes for LBPI.
Definition: LazyBranchProbabilityInfo.cpp:71
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::LoopInfo
Definition: LoopInfo.h:1083
DEBUG_TYPE
#define DEBUG_TYPE
Definition: LazyBranchProbabilityInfo.cpp:24
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::MCID::Branch
@ Branch
Definition: MCInstrDesc.h:156
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:221
llvm::LazyBranchProbabilityInfoPass::runOnFunction
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Definition: LazyBranchProbabilityInfo.cpp:57
llvm::LazyBranchProbabilityInfoPass::releaseMemory
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: LazyBranchProbabilityInfo.cpp:55
llvm::Registry
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
Dominators.h
llvm::AnalysisUsage::addRequiredTransitive
AnalysisUsage & addRequiredTransitive()
Definition: PassAnalysisSupport.h:81
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::LazyBranchProbabilityInfoPass
This is an alternative analysis pass to BranchProbabilityInfoWrapperPass.
Definition: LazyBranchProbabilityInfo.h:50
InitializePasses.h
LazyBranchProbabilityInfo.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38