Adam Nemet | bbb141c | 2017-02-14 17:21:09 +0000 | [diff] [blame^] | 1 | ///===- LazyMachineBlockFrequencyInfo.cpp - Lazy Machine Block Frequency --===// |
| 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 | /// \file |
| 10 | /// This is an alternative analysis pass to MachineBlockFrequencyInfo. The |
| 11 | /// difference is that with this pass the block frequencies are not computed |
| 12 | /// when the analysis pass is executed but rather when the BFI result is |
| 13 | /// explicitly requested by the analysis client. |
| 14 | /// |
| 15 | ///===---------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h" |
| 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | #define DEBUG_TYPE "lazy-machine-block-freq" |
| 22 | |
| 23 | INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE, |
| 24 | "Lazy Machine Block Frequency Analysis", true, true) |
| 25 | INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo) |
| 26 | INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo) |
| 27 | INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE, |
| 28 | "Lazy Machine Block Frequency Analysis", true, true) |
| 29 | |
| 30 | char LazyMachineBlockFrequencyInfoPass::ID = 0; |
| 31 | |
| 32 | LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass() |
| 33 | : MachineFunctionPass(ID) { |
| 34 | initializeLazyMachineBlockFrequencyInfoPassPass( |
| 35 | *PassRegistry::getPassRegistry()); |
| 36 | } |
| 37 | |
| 38 | void LazyMachineBlockFrequencyInfoPass::print(raw_ostream &OS, |
| 39 | const Module *M) const { |
| 40 | LMBFI.getCalculated().print(OS, M); |
| 41 | } |
| 42 | |
| 43 | void LazyMachineBlockFrequencyInfoPass::getAnalysisUsage( |
| 44 | AnalysisUsage &AU) const { |
| 45 | AU.addRequired<MachineBranchProbabilityInfo>(); |
| 46 | AU.addRequired<MachineLoopInfo>(); |
| 47 | AU.setPreservesAll(); |
| 48 | MachineFunctionPass::getAnalysisUsage(AU); |
| 49 | } |
| 50 | |
| 51 | void LazyMachineBlockFrequencyInfoPass::releaseMemory() { |
| 52 | LMBFI.releaseMemory(); |
| 53 | } |
| 54 | |
| 55 | bool LazyMachineBlockFrequencyInfoPass::runOnMachineFunction( |
| 56 | MachineFunction &MF) { |
| 57 | auto &BPIPass = getAnalysis<MachineBranchProbabilityInfo>(); |
| 58 | auto &LI = getAnalysis<MachineLoopInfo>(); |
| 59 | LMBFI.setAnalysis(&MF, &BPIPass, &LI); |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | void LazyMachineBlockFrequencyInfoPass::getLazyMachineBFIAnalysisUsage( |
| 64 | AnalysisUsage &AU) { |
| 65 | AU.addRequired<LazyMachineBlockFrequencyInfoPass>(); |
| 66 | AU.addRequired<MachineBranchProbabilityInfo>(); |
| 67 | AU.addRequired<MachineLoopInfo>(); |
| 68 | } |
| 69 | |
| 70 | void llvm::initializeLazyMachineBFIPassPass(PassRegistry &Registry) { |
| 71 | INITIALIZE_PASS_DEPENDENCY(LazyMachineBlockFrequencyInfoPass); |
| 72 | INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo); |
| 73 | INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo); |
| 74 | } |