blob: a8178ecc0a24914f16051d2b9244bb5eb1b0826d [file] [log] [blame]
Adam Nemetc2f791d2016-07-13 05:01:48 +00001//===- LazyBlockFrequencyInfo.cpp - Lazy Block Frequency Analysis ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is an alternative analysis pass to BlockFrequencyInfoWrapperPass. The
11// difference is that with this pass the block frequencies are not computed when
Adam Nemet4c980232017-02-14 17:21:12 +000012// the analysis pass is executed but rather when the BFI result is explicitly
Adam Nemetc2f791d2016-07-13 05:01:48 +000013// requested by the analysis client.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
Adam Nemetaa3506c2016-07-28 23:31:12 +000018#include "llvm/Analysis/LazyBranchProbabilityInfo.h"
Adam Nemetc2f791d2016-07-13 05:01:48 +000019#include "llvm/Analysis/LoopInfo.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "lazy-block-freq"
24
25INITIALIZE_PASS_BEGIN(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
26 "Lazy Block Frequency Analysis", true, true)
Adam Nemetaa3506c2016-07-28 23:31:12 +000027INITIALIZE_PASS_DEPENDENCY(LazyBPIPass)
Adam Nemetc2f791d2016-07-13 05:01:48 +000028INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
29INITIALIZE_PASS_END(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
30 "Lazy Block Frequency Analysis", true, true)
31
32char LazyBlockFrequencyInfoPass::ID = 0;
33
34LazyBlockFrequencyInfoPass::LazyBlockFrequencyInfoPass() : FunctionPass(ID) {
35 initializeLazyBlockFrequencyInfoPassPass(*PassRegistry::getPassRegistry());
36}
37
38void LazyBlockFrequencyInfoPass::print(raw_ostream &OS, const Module *) const {
39 LBFI.getCalculated().print(OS);
40}
41
42void LazyBlockFrequencyInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
Adam Nemetaa3506c2016-07-28 23:31:12 +000043 LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
Adam Nemetc2f791d2016-07-13 05:01:48 +000044 AU.addRequired<LoopInfoWrapperPass>();
45 AU.setPreservesAll();
46}
47
48void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
49
50bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
Adam Nemetaa3506c2016-07-28 23:31:12 +000051 auto &BPIPass = getAnalysis<LazyBranchProbabilityInfoPass>();
Adam Nemetc2f791d2016-07-13 05:01:48 +000052 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Adam Nemetaa3506c2016-07-28 23:31:12 +000053 LBFI.setAnalysis(&F, &BPIPass, &LI);
Adam Nemetc2f791d2016-07-13 05:01:48 +000054 return false;
55}
56
57void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
Adam Nemetaa3506c2016-07-28 23:31:12 +000058 LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
Adam Nemetc2f791d2016-07-13 05:01:48 +000059 AU.addRequired<LazyBlockFrequencyInfoPass>();
60 AU.addRequired<LoopInfoWrapperPass>();
61}
62
63void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
Adam Nemetaa3506c2016-07-28 23:31:12 +000064 initializeLazyBPIPassPass(Registry);
Adam Nemetc2f791d2016-07-13 05:01:48 +000065 INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
66 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
67}