Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
Line
Count
Source
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
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
21
using namespace llvm;
22
23
#define DEBUG_TYPE "lazy-branch-prob"
24
25
73.7k
INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
26
73.7k
                      "Lazy Branch Probability Analysis", true, true)
27
73.7k
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
28
73.7k
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
29
73.7k
INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
30
                    "Lazy Branch Probability Analysis", true, true)
31
32
char LazyBranchProbabilityInfoPass::ID = 0;
33
34
LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass()
35
220k
    : FunctionPass(ID) {
36
220k
  initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry());
37
220k
}
38
39
void LazyBranchProbabilityInfoPass::print(raw_ostream &OS,
40
32
                                          const Module *) const {
41
32
  LBPI->getCalculated().print(OS);
42
32
}
43
44
220k
void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
45
220k
  // We require DT so it's available when LI is available. The LI updating code
46
220k
  // asserts that DT is also present so if we don't make sure that we have DT
47
220k
  // here, that assert will trigger.
48
220k
  AU.addRequired<DominatorTreeWrapperPass>();
49
220k
  AU.addRequired<LoopInfoWrapperPass>();
50
220k
  AU.addRequired<TargetLibraryInfoWrapperPass>();
51
220k
  AU.setPreservesAll();
52
220k
}
53
54
6.22M
void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); }
55
56
6.22M
bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) {
57
6.22M
  LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
58
6.22M
  TargetLibraryInfo &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
59
6.22M
  LBPI = llvm::make_unique<LazyBranchProbabilityInfo>(&F, &LI, &TLI);
60
6.22M
  return false;
61
6.22M
}
62
63
563k
void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
64
563k
  AU.addRequired<LazyBranchProbabilityInfoPass>();
65
563k
  AU.addRequired<LoopInfoWrapperPass>();
66
563k
  AU.addRequired<TargetLibraryInfoWrapperPass>();
67
563k
}
68
69
147k
void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {
70
147k
  INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass);
71
147k
  INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
72
147k
  INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass);
73
147k
}