1//===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// This is the interface to build a ModuleSummaryIndex for a module.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
15#define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
16
17#include "llvm/ADT/Optional.h"
18#include "llvm/IR/ModuleSummaryIndex.h"
19#include "llvm/IR/PassManager.h"
20#include "llvm/Pass.h"
21#include <functional>
22
23namespace llvm {
24
25class BlockFrequencyInfo;
26class Function;
27class Module;
28class ProfileSummaryInfo;
29
30/// Direct function to compute a \c ModuleSummaryIndex from a given module.
31///
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
35/// that information.
36ModuleSummaryIndex buildModuleSummaryIndex(
37 const Module &M,
38 std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
39 ProfileSummaryInfo *PSI);
40
41/// Analysis pass to provide the ModuleSummaryIndex object.
42class ModuleSummaryIndexAnalysis
43 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
44 friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
45
46 static AnalysisKey Key;
47
48public:
49 using Result = ModuleSummaryIndex;
50
51 Result run(Module &M, ModuleAnalysisManager &AM);
52};
53
54/// Legacy wrapper pass to provide the ModuleSummaryIndex object.
55class ModuleSummaryIndexWrapperPass : public ModulePass {
56 Optional<ModuleSummaryIndex> Index;
57
58public:
59 static char ID;
60
61 ModuleSummaryIndexWrapperPass();
62
63 /// Get the index built by pass
64 ModuleSummaryIndex &getIndex() { return *Index; }
65 const ModuleSummaryIndex &getIndex() const { return *Index; }
66
67 bool runOnModule(Module &M) override;
68 bool doFinalization(Module &M) override;
69 void getAnalysisUsage(AnalysisUsage &AU) const override;
70};
71
72//===--------------------------------------------------------------------===//
73//
74// createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
75// object for the module, to be written to bitcode or LLVM assembly.
76//
77ModulePass *createModuleSummaryIndexWrapperPass();
78
79} // end namespace llvm
80
81#endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
82