blob: 439758560284171e008fbe7e66f0f4b2666364dd [file] [log] [blame]
Adam Nemetc2f791d2016-07-13 05:01:48 +00001//===- LazyBlockFrequencyInfo.cpp - Lazy Block Frequency Analysis ---------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Adam Nemetc2f791d2016-07-13 05:01:48 +00006//
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
Adam Nemet4c980232017-02-14 17:21:12 +000011// the analysis pass is executed but rather when the BFI result is explicitly
Adam Nemetc2f791d2016-07-13 05:01:48 +000012// requested by the analysis client.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
Adam Nemetaa3506c2016-07-28 23:31:12 +000017#include "llvm/Analysis/LazyBranchProbabilityInfo.h"
Adam Nemetc2f791d2016-07-13 05:01:48 +000018#include "llvm/Analysis/LoopInfo.h"
Mikael Holmen2ca16892018-05-17 09:05:40 +000019#include "llvm/IR/Dominators.h"
Adam Nemetc2f791d2016-07-13 05:01:48 +000020
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);
Mikael Holmen2ca16892018-05-17 09:05:40 +000044 // 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>();
Adam Nemetc2f791d2016-07-13 05:01:48 +000048 AU.addRequired<LoopInfoWrapperPass>();
49 AU.setPreservesAll();
50}
51
52void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
53
54bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
Adam Nemetaa3506c2016-07-28 23:31:12 +000055 auto &BPIPass = getAnalysis<LazyBranchProbabilityInfoPass>();
Adam Nemetc2f791d2016-07-13 05:01:48 +000056 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Adam Nemetaa3506c2016-07-28 23:31:12 +000057 LBFI.setAnalysis(&F, &BPIPass, &LI);
Adam Nemetc2f791d2016-07-13 05:01:48 +000058 return false;
59}
60
61void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
Adam Nemetaa3506c2016-07-28 23:31:12 +000062 LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
Adam Nemetc2f791d2016-07-13 05:01:48 +000063 AU.addRequired<LazyBlockFrequencyInfoPass>();
64 AU.addRequired<LoopInfoWrapperPass>();
65}
66
67void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
Adam Nemetaa3506c2016-07-28 23:31:12 +000068 initializeLazyBPIPassPass(Registry);
Adam Nemetc2f791d2016-07-13 05:01:48 +000069 INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
70 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
71}