]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Analysis/LazyBlockFrequencyInfo.cpp
Merge ^/vendor/libc++/dist up to its last change, and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Analysis / LazyBlockFrequencyInfo.cpp
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.
13 //
14 //===----------------------------------------------------------------------===//
15
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
21 using namespace llvm;
22
23 #define DEBUG_TYPE "lazy-block-freq"
24
25 INITIALIZE_PASS_BEGIN(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
26                       "Lazy Block Frequency Analysis", true, true)
27 INITIALIZE_PASS_DEPENDENCY(LazyBPIPass)
28 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
29 INITIALIZE_PASS_END(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
30                     "Lazy Block Frequency Analysis", true, true)
31
32 char LazyBlockFrequencyInfoPass::ID = 0;
33
34 LazyBlockFrequencyInfoPass::LazyBlockFrequencyInfoPass() : FunctionPass(ID) {
35   initializeLazyBlockFrequencyInfoPassPass(*PassRegistry::getPassRegistry());
36 }
37
38 void LazyBlockFrequencyInfoPass::print(raw_ostream &OS, const Module *) const {
39   LBFI.getCalculated().print(OS);
40 }
41
42 void LazyBlockFrequencyInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
43   LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
44   // We require DT so it's available when LI is available. The LI updating code
45   // asserts that DT is also present so if we don't make sure that we have DT
46   // here, that assert will trigger.
47   AU.addRequired<DominatorTreeWrapperPass>();
48   AU.addRequired<LoopInfoWrapperPass>();
49   AU.setPreservesAll();
50 }
51
52 void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
53
54 bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
55   auto &BPIPass = getAnalysis<LazyBranchProbabilityInfoPass>();
56   LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
57   LBFI.setAnalysis(&F, &BPIPass, &LI);
58   return false;
59 }
60
61 void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
62   LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
63   AU.addRequired<LazyBlockFrequencyInfoPass>();
64   AU.addRequired<LoopInfoWrapperPass>();
65 }
66
67 void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
68   initializeLazyBPIPassPass(Registry);
69   INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
70   INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
71 }