Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 1 | //===- LazyBlockFrequencyInfo.cpp - Lazy Block Frequency Analysis ---------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 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 |
Adam Nemet | 4c98023 | 2017-02-14 17:21:12 +0000 | [diff] [blame] | 11 | // the analysis pass is executed but rather when the BFI result is explicitly |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 12 | // requested by the analysis client. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "llvm/Analysis/LazyBlockFrequencyInfo.h" |
Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/LazyBranchProbabilityInfo.h" |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/LoopInfo.h" |
Mikael Holmen | 2ca1689 | 2018-05-17 09:05:40 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Dominators.h" |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 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) |
Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 27 | INITIALIZE_PASS_DEPENDENCY(LazyBPIPass) |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 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 { |
Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 43 | LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU); |
Mikael Holmen | 2ca1689 | 2018-05-17 09:05:40 +0000 | [diff] [blame] | 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>(); |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 48 | AU.addRequired<LoopInfoWrapperPass>(); |
| 49 | AU.setPreservesAll(); |
| 50 | } |
| 51 | |
| 52 | void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); } |
| 53 | |
| 54 | bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) { |
Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 55 | auto &BPIPass = getAnalysis<LazyBranchProbabilityInfoPass>(); |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 56 | LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 57 | LBFI.setAnalysis(&F, &BPIPass, &LI); |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 58 | return false; |
| 59 | } |
| 60 | |
| 61 | void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) { |
Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 62 | LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU); |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 63 | AU.addRequired<LazyBlockFrequencyInfoPass>(); |
| 64 | AU.addRequired<LoopInfoWrapperPass>(); |
| 65 | } |
| 66 | |
| 67 | void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) { |
Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 68 | initializeLazyBPIPassPass(Registry); |
Adam Nemet | c2f791d | 2016-07-13 05:01:48 +0000 | [diff] [blame] | 69 | INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass); |
| 70 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass); |
| 71 | } |