Home | History | Annotate | Download | only in Analysis
      1 //===- 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
     12 // the analysis pass is executed but rather when the BFI results is explicitly
     13 // requested by the analysis client.
     14 //
     15 //===----------------------------------------------------------------------===//
     16 
     17 #include "llvm/Analysis/LazyBlockFrequencyInfo.h"
     18 #include "llvm/Analysis/BranchProbabilityInfo.h"
     19 #include "llvm/Analysis/LoopInfo.h"
     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)
     27 INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
     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 {
     43   AU.addRequired<BranchProbabilityInfoWrapperPass>();
     44   AU.addRequired<LoopInfoWrapperPass>();
     45   AU.setPreservesAll();
     46 }
     47 
     48 void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
     49 
     50 bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
     51   BranchProbabilityInfo &BPI =
     52       getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();
     53   LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
     54   LBFI.setAnalysis(&F, &BPI, &LI);
     55   return false;
     56 }
     57 
     58 void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
     59   AU.addRequired<BranchProbabilityInfoWrapperPass>();
     60   AU.addRequired<LazyBlockFrequencyInfoPass>();
     61   AU.addRequired<LoopInfoWrapperPass>();
     62 }
     63 
     64 void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
     65   INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass);
     66   INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
     67   INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
     68 }
     69