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/Optional.h"
18 #include "llvm/IR/ModuleSummaryIndex.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Pass.h"
25 class BlockFrequencyInfo;
28 class ProfileSummaryInfo;
30 /// Direct function to compute a \c ModuleSummaryIndex from a given module.
32 /// If operating within a pass manager which has defined ways to compute the \c
33 /// BlockFrequencyInfo for a given function, that can be provided via
34 /// a std::function callback. Otherwise, this routine will manually construct
36 ModuleSummaryIndex buildModuleSummaryIndex(
38 std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
39 ProfileSummaryInfo *PSI);
41 /// Analysis pass to provide the ModuleSummaryIndex object.
42 class ModuleSummaryIndexAnalysis
43 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
44 friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
46 static AnalysisKey Key;
49 using Result = ModuleSummaryIndex;
51 Result run(Module &M, ModuleAnalysisManager &AM);
54 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
55 class ModuleSummaryIndexWrapperPass : public ModulePass {
56 Optional<ModuleSummaryIndex> Index;
61 ModuleSummaryIndexWrapperPass();
63 /// Get the index built by pass
64 ModuleSummaryIndex &getIndex() { return *Index; }
65 const ModuleSummaryIndex &getIndex() const { return *Index; }
67 bool runOnModule(Module &M) override;
68 bool doFinalization(Module &M) override;
69 void getAnalysisUsage(AnalysisUsage &AU) const override;
72 //===--------------------------------------------------------------------===//
74 // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
75 // object for the module, to be written to bitcode or LLVM assembly.
77 ModulePass *createModuleSummaryIndexWrapperPass();
79 } // end namespace llvm
81 #endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H