ModuleSummaryAnalysis.h revision 355940
1230557Sjimharris//===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===// 2230557Sjimharris// 3230557Sjimharris// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4230557Sjimharris// See https://llvm.org/LICENSE.txt for license information. 5230557Sjimharris// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6230557Sjimharris// 7230557Sjimharris//===----------------------------------------------------------------------===// 8230557Sjimharris/// \file 9230557Sjimharris/// This is the interface to build a ModuleSummaryIndex for a module. 10230557Sjimharris/// 11230557Sjimharris//===----------------------------------------------------------------------===// 12230557Sjimharris 13230557Sjimharris#ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H 14230557Sjimharris#define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H 15230557Sjimharris 16230557Sjimharris#include "llvm/ADT/Optional.h" 17230557Sjimharris#include "llvm/IR/ModuleSummaryIndex.h" 18230557Sjimharris#include "llvm/IR/PassManager.h" 19230557Sjimharris#include "llvm/Pass.h" 20230557Sjimharris#include <functional> 21230557Sjimharris 22230557Sjimharrisnamespace llvm { 23230557Sjimharris 24230557Sjimharrisclass BlockFrequencyInfo; 25230557Sjimharrisclass Function; 26230557Sjimharrisclass Module; 27230557Sjimharrisclass ProfileSummaryInfo; 28230557Sjimharris 29230557Sjimharris/// Direct function to compute a \c ModuleSummaryIndex from a given module. 30230557Sjimharris/// 31230557Sjimharris/// If operating within a pass manager which has defined ways to compute the \c 32230557Sjimharris/// BlockFrequencyInfo for a given function, that can be provided via 33230557Sjimharris/// a std::function callback. Otherwise, this routine will manually construct 34230557Sjimharris/// that information. 35230557SjimharrisModuleSummaryIndex buildModuleSummaryIndex( 36230557Sjimharris const Module &M, 37230557Sjimharris std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback, 38230557Sjimharris ProfileSummaryInfo *PSI); 39230557Sjimharris 40230557Sjimharris/// Analysis pass to provide the ModuleSummaryIndex object. 41230557Sjimharrisclass ModuleSummaryIndexAnalysis 42230557Sjimharris : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> { 43230557Sjimharris friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>; 44230557Sjimharris 45230557Sjimharris static AnalysisKey Key; 46230557Sjimharris 47230557Sjimharrispublic: 48230557Sjimharris using Result = ModuleSummaryIndex; 49230557Sjimharris 50230557Sjimharris Result run(Module &M, ModuleAnalysisManager &AM); 51230557Sjimharris}; 52230557Sjimharris 53230557Sjimharris/// Legacy wrapper pass to provide the ModuleSummaryIndex object. 54230557Sjimharrisclass ModuleSummaryIndexWrapperPass : public ModulePass { 55230557Sjimharris Optional<ModuleSummaryIndex> Index; 56230557Sjimharris 57230557Sjimharrispublic: 58230557Sjimharris static char ID; 59230557Sjimharris 60230557Sjimharris ModuleSummaryIndexWrapperPass(); 61230557Sjimharris 62230557Sjimharris /// Get the index built by pass 63230557Sjimharris ModuleSummaryIndex &getIndex() { return *Index; } 64230557Sjimharris const ModuleSummaryIndex &getIndex() const { return *Index; } 65230557Sjimharris 66230557Sjimharris bool runOnModule(Module &M) override; 67230557Sjimharris bool doFinalization(Module &M) override; 68230557Sjimharris void getAnalysisUsage(AnalysisUsage &AU) const override; 69230557Sjimharris}; 70230557Sjimharris 71230557Sjimharris//===--------------------------------------------------------------------===// 72230557Sjimharris// 73230557Sjimharris// createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex 74230557Sjimharris// object for the module, to be written to bitcode or LLVM assembly. 75230557Sjimharris// 76230557SjimharrisModulePass *createModuleSummaryIndexWrapperPass(); 77230557Sjimharris 78230557Sjimharris} // end namespace llvm 79230557Sjimharris 80230557Sjimharris#endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H 81230557Sjimharris