1 //===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 /// This is the interface to build a ModuleSummaryIndex for a module.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
14 #define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/IR/ModuleSummaryIndex.h"
18 #include "llvm/IR/PassManager.h"
19 #include "llvm/Pass.h"
24 class BlockFrequencyInfo
;
27 class ProfileSummaryInfo
;
29 /// Direct function to compute a \c ModuleSummaryIndex from a given module.
31 /// If operating within a pass manager which has defined ways to compute the \c
32 /// BlockFrequencyInfo for a given function, that can be provided via
33 /// a std::function callback. Otherwise, this routine will manually construct
35 ModuleSummaryIndex
buildModuleSummaryIndex(
37 std::function
<BlockFrequencyInfo
*(const Function
&F
)> GetBFICallback
,
38 ProfileSummaryInfo
*PSI
);
40 /// Analysis pass to provide the ModuleSummaryIndex object.
41 class ModuleSummaryIndexAnalysis
42 : public AnalysisInfoMixin
<ModuleSummaryIndexAnalysis
> {
43 friend AnalysisInfoMixin
<ModuleSummaryIndexAnalysis
>;
45 static AnalysisKey Key
;
48 using Result
= ModuleSummaryIndex
;
50 Result
run(Module
&M
, ModuleAnalysisManager
&AM
);
53 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
54 class ModuleSummaryIndexWrapperPass
: public ModulePass
{
55 Optional
<ModuleSummaryIndex
> Index
;
60 ModuleSummaryIndexWrapperPass();
62 /// Get the index built by pass
63 ModuleSummaryIndex
&getIndex() { return *Index
; }
64 const ModuleSummaryIndex
&getIndex() const { return *Index
; }
66 bool runOnModule(Module
&M
) override
;
67 bool doFinalization(Module
&M
) override
;
68 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
71 //===--------------------------------------------------------------------===//
73 // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
74 // object for the module, to be written to bitcode or LLVM assembly.
76 ModulePass
*createModuleSummaryIndexWrapperPass();
78 } // end namespace llvm
80 #endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H