LLVM 24.0.0git
ModuleSummaryAnalysis.h
Go to the documentation of this file.
1//===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
2//
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
6//
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
17#include "llvm/IR/PassManager.h"
18#include "llvm/Pass.h"
20#include <functional>
21#include <optional>
22
23namespace llvm {
24
26class Function;
27class LLVMContext;
28class Module;
30class StackSafetyInfo;
31
32/// Return -module-summary-max-indirect-edges.
34
35/// Direct function to compute a \c ModuleSummaryIndex from a given module.
36///
37/// If operating within a pass manager which has defined ways to compute the \c
38/// BlockFrequencyInfo for a given function, that can be provided via
39/// a std::function callback. Otherwise, this routine will manually construct
40/// that information.
42 const Module &M,
43 std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
45 std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
46 [](const Function &F) -> const StackSafetyInfo * { return nullptr; });
47
48/// Analysis pass to provide the ModuleSummaryIndex object.
50 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
52
53 LLVM_ABI static AnalysisKey Key;
54
55public:
57
59};
60
61/// Legacy wrapper pass to provide the ModuleSummaryIndex object.
63 std::optional<ModuleSummaryIndex> Index;
64
65public:
66 static char ID;
67
69
70 /// Get the index built by pass
71 ModuleSummaryIndex &getIndex() { return *Index; }
72 const ModuleSummaryIndex &getIndex() const { return *Index; }
73
74 bool runOnModule(Module &M) override;
75 bool doFinalization(Module &M) override;
76 void getAnalysisUsage(AnalysisUsage &AU) const override;
77};
78
79//===--------------------------------------------------------------------===//
80//
81// createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
82// object for the module, to be written to bitcode or LLVM assembly.
83//
85
86/// Legacy wrapper pass to provide the ModuleSummaryIndex object.
88 const ModuleSummaryIndex *Index;
89
90public:
91 static char ID;
92
94 const ModuleSummaryIndex *Index = nullptr);
95 const ModuleSummaryIndex *getIndex() const { return Index; }
96 void getAnalysisUsage(AnalysisUsage &AU) const override;
97};
98
99/// NPM analysis to provide an externally-built ModuleSummaryIndex (e.g. the
100/// combined index from LTO).
102 : public AnalysisInfoMixin<ImmutableModuleSummaryIndexAnalysis> {
104 LLVM_ABI static AnalysisKey Key;
105 const ModuleSummaryIndex *Index = nullptr;
106
107public:
108 class Result {
109 const ModuleSummaryIndex *Index = nullptr;
110 Result(const ModuleSummaryIndex *Index) : Index(Index) {}
112
113 public:
114 const ModuleSummaryIndex *getIndex() const { return Index; }
116 ModuleAnalysisManager::Invalidator &) {
117 return false;
118 }
119 };
120
123 : Index(Index) {}
124
125 Result run(Module &M, ModuleAnalysisManager &AM) { return Result(Index); }
126};
127
128//===--------------------------------------------------------------------===//
129//
130// ImmutableModuleSummaryIndexWrapperPass - This pass wrap provided
131// ModuleSummaryIndex object for the module, to be used by other passes.
132//
133LLVM_ABI ImmutablePass *
134createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
135
136/// Returns true if the instruction could have memprof metadata, used to ensure
137/// consistency between summary analysis and the ThinLTO backend processing.
139
140} // end namespace llvm
141
142#endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Represent the analysis usage information of a pass.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
ImmutableModuleSummaryIndexAnalysis(const ModuleSummaryIndex *Index)
Result run(Module &M, ModuleAnalysisManager &AM)
ImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index=nullptr)
const ModuleSummaryIndex * getIndex() const
ImmutablePass(char &pid)
Definition Pass.h:285
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
ModulePass(char &pid)
Definition Pass.h:255
Analysis pass to provide the ModuleSummaryIndex object.
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &AM)
ModuleSummaryIndex & getIndex()
Get the index built by pass.
const ModuleSummaryIndex & getIndex() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Analysis providing profile information.
Interface to access stack safety analysis results for single function.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool mayHaveMemprofSummary(const CallBase *CB)
Returns true if the instruction could have memprof metadata, used to ensure consistency between summa...
LLVM_ABI ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI, std::function< const StackSafetyInfo *(const Function &F)> GetSSICallback=[](const Function &F) -> const StackSafetyInfo *{ return nullptr;})
Direct function to compute a ModuleSummaryIndex from a given module.
LLVM_ABI ModulePass * createModuleSummaryIndexWrapperPass()
LLVM_ABI unsigned getMaxSummaryIndirectEdges(const LLVMContext &C)
Return -module-summary-max-indirect-edges.
LLVM_ABI ImmutablePass * createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29