ModuleSummaryAnalysis.h revision 314564
1//===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===// 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 the interface to build a ModuleSummaryIndex for a module. 11/// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H 15#define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H 16 17#include "llvm/ADT/STLExtras.h" 18#include "llvm/IR/ModuleSummaryIndex.h" 19#include "llvm/IR/PassManager.h" 20#include "llvm/Pass.h" 21 22namespace llvm { 23class BlockFrequencyInfo; 24class ProfileSummaryInfo; 25 26/// Direct function to compute a \c ModuleSummaryIndex from a given module. 27/// 28/// If operating within a pass manager which has defined ways to compute the \c 29/// BlockFrequencyInfo for a given function, that can be provided via 30/// a std::function callback. Otherwise, this routine will manually construct 31/// that information. 32ModuleSummaryIndex buildModuleSummaryIndex( 33 const Module &M, 34 std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback, 35 ProfileSummaryInfo *PSI); 36 37/// Analysis pass to provide the ModuleSummaryIndex object. 38class ModuleSummaryIndexAnalysis 39 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> { 40 friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>; 41 static AnalysisKey Key; 42 43public: 44 typedef ModuleSummaryIndex Result; 45 46 Result run(Module &M, ModuleAnalysisManager &AM); 47}; 48 49/// Legacy wrapper pass to provide the ModuleSummaryIndex object. 50class ModuleSummaryIndexWrapperPass : public ModulePass { 51 Optional<ModuleSummaryIndex> Index; 52 53public: 54 static char ID; 55 56 ModuleSummaryIndexWrapperPass(); 57 58 /// Get the index built by pass 59 ModuleSummaryIndex &getIndex() { return *Index; } 60 const ModuleSummaryIndex &getIndex() const { return *Index; } 61 62 bool runOnModule(Module &M) override; 63 bool doFinalization(Module &M) override; 64 void getAnalysisUsage(AnalysisUsage &AU) const override; 65}; 66 67//===--------------------------------------------------------------------===// 68// 69// createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex 70// object for the module, to be written to bitcode or LLVM assembly. 71// 72ModulePass *createModuleSummaryIndexWrapperPass(); 73} 74 75#endif 76