blob: eb48ec3af5263972a9e0f6763e3237411c7d59df [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This is the interface to build a ModuleSummaryIndex for a module.
10///
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
14#define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
15
16#include "llvm/ADT/Optional.h"
17#include "llvm/IR/ModuleSummaryIndex.h"
18#include "llvm/IR/PassManager.h"
19#include "llvm/Pass.h"
20#include <functional>
21
22namespace llvm {
23
24class BlockFrequencyInfo;
25class Function;
26class Module;
27class ProfileSummaryInfo;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020028class StackSafetyInfo;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010029
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,
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020039 ProfileSummaryInfo *PSI,
40 std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
41 [](const Function &F) -> const StackSafetyInfo * { return nullptr; });
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010042
43/// Analysis pass to provide the ModuleSummaryIndex object.
44class ModuleSummaryIndexAnalysis
45 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
46 friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
47
48 static AnalysisKey Key;
49
50public:
51 using Result = ModuleSummaryIndex;
52
53 Result run(Module &M, ModuleAnalysisManager &AM);
54};
55
56/// Legacy wrapper pass to provide the ModuleSummaryIndex object.
57class ModuleSummaryIndexWrapperPass : public ModulePass {
58 Optional<ModuleSummaryIndex> Index;
59
60public:
61 static char ID;
62
63 ModuleSummaryIndexWrapperPass();
64
65 /// Get the index built by pass
66 ModuleSummaryIndex &getIndex() { return *Index; }
67 const ModuleSummaryIndex &getIndex() const { return *Index; }
68
69 bool runOnModule(Module &M) override;
70 bool doFinalization(Module &M) override;
71 void getAnalysisUsage(AnalysisUsage &AU) const override;
72};
73
74//===--------------------------------------------------------------------===//
75//
76// createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
77// object for the module, to be written to bitcode or LLVM assembly.
78//
79ModulePass *createModuleSummaryIndexWrapperPass();
80
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020081/// Legacy wrapper pass to provide the ModuleSummaryIndex object.
82class ImmutableModuleSummaryIndexWrapperPass : public ImmutablePass {
83 const ModuleSummaryIndex *Index;
84
85public:
86 static char ID;
87
88 ImmutableModuleSummaryIndexWrapperPass(
89 const ModuleSummaryIndex *Index = nullptr);
90 const ModuleSummaryIndex *getIndex() const { return Index; }
91 void getAnalysisUsage(AnalysisUsage &AU) const override;
92};
93
94//===--------------------------------------------------------------------===//
95//
96// ImmutableModuleSummaryIndexWrapperPass - This pass wrap provided
97// ModuleSummaryIndex object for the module, to be used by other passes.
98//
99ImmutablePass *
100createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
101
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100102} // end namespace llvm
103
104#endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H