1 //===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This is the interface to build a ModuleSummaryIndex for a module.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
15 #define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/IR/ModuleSummaryIndex.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Pass.h"
23 class BlockFrequencyInfo;
24 class ProfileSummaryInfo;
26 /// Direct function to compute a \c ModuleSummaryIndex from a given module.
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
32 ModuleSummaryIndex buildModuleSummaryIndex(
34 std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
35 ProfileSummaryInfo *PSI);
37 /// Analysis pass to provide the ModuleSummaryIndex object.
38 class ModuleSummaryIndexAnalysis
39 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
40 friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
41 static AnalysisKey Key;
44 typedef ModuleSummaryIndex Result;
46 Result run(Module &M, ModuleAnalysisManager &AM);
49 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
50 class ModuleSummaryIndexWrapperPass : public ModulePass {
51 Optional<ModuleSummaryIndex> Index;
56 ModuleSummaryIndexWrapperPass();
58 /// Get the index built by pass
59 ModuleSummaryIndex &getIndex() { return *Index; }
60 const ModuleSummaryIndex &getIndex() const { return *Index; }
62 bool runOnModule(Module &M) override;
63 bool doFinalization(Module &M) override;
64 void getAnalysisUsage(AnalysisUsage &AU) const override;
67 //===--------------------------------------------------------------------===//
69 // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
70 // object for the module, to be written to bitcode or LLVM assembly.
72 ModulePass *createModuleSummaryIndexWrapperPass();