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;
28 class StackSafetyInfo;
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,
40 std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
41 [](const Function &F) -> const StackSafetyInfo * { return nullptr; });
43 /// Analysis pass to provide the ModuleSummaryIndex object.
44 class ModuleSummaryIndexAnalysis
45 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
46 friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
48 static AnalysisKey Key;
51 using Result = ModuleSummaryIndex;
53 Result run(Module &M, ModuleAnalysisManager &AM);
56 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
57 class ModuleSummaryIndexWrapperPass : public ModulePass {
58 Optional<ModuleSummaryIndex> Index;
63 ModuleSummaryIndexWrapperPass();
65 /// Get the index built by pass
66 ModuleSummaryIndex &getIndex() { return *Index; }
67 const ModuleSummaryIndex &getIndex() const { return *Index; }
69 bool runOnModule(Module &M) override;
70 bool doFinalization(Module &M) override;
71 void getAnalysisUsage(AnalysisUsage &AU) const override;
74 //===--------------------------------------------------------------------===//
76 // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
77 // object for the module, to be written to bitcode or LLVM assembly.
79 ModulePass *createModuleSummaryIndexWrapperPass();
81 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
82 class ImmutableModuleSummaryIndexWrapperPass : public ImmutablePass {
83 const ModuleSummaryIndex *Index;
88 ImmutableModuleSummaryIndexWrapperPass(
89 const ModuleSummaryIndex *Index = nullptr);
90 const ModuleSummaryIndex *getIndex() const { return Index; }
91 void getAnalysisUsage(AnalysisUsage &AU) const override;
94 //===--------------------------------------------------------------------===//
96 // ImmutableModuleSummaryIndexWrapperPass - This pass wrap provided
97 // ModuleSummaryIndex object for the module, to be used by other passes.
100 createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
102 } // end namespace llvm
104 #endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H