LLVM 22.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 Module;
29class StackSafetyInfo;
30
31/// Direct function to compute a \c ModuleSummaryIndex from a given module.
32///
33/// If operating within a pass manager which has defined ways to compute the \c
34/// BlockFrequencyInfo for a given function, that can be provided via
35/// a std::function callback. Otherwise, this routine will manually construct
36/// that information.
38 const Module &M,
39 std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
41 std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
42 [](const Function &F) -> const StackSafetyInfo * { return nullptr; });
43
44/// Analysis pass to provide the ModuleSummaryIndex object.
46 : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
48
49 LLVM_ABI static AnalysisKey Key;
50
51public:
53
55};
56
57/// Legacy wrapper pass to provide the ModuleSummaryIndex object.
59 std::optional<ModuleSummaryIndex> Index;
60
61public:
62 static char ID;
63
65
66 /// Get the index built by pass
67 ModuleSummaryIndex &getIndex() { return *Index; }
68 const ModuleSummaryIndex &getIndex() const { return *Index; }
69
70 bool runOnModule(Module &M) override;
71 bool doFinalization(Module &M) override;
72 void getAnalysisUsage(AnalysisUsage &AU) const override;
73};
74
75//===--------------------------------------------------------------------===//
76//
77// createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
78// object for the module, to be written to bitcode or LLVM assembly.
79//
81
82/// Legacy wrapper pass to provide the ModuleSummaryIndex object.
84 const ModuleSummaryIndex *Index;
85
86public:
87 static char ID;
88
90 const ModuleSummaryIndex *Index = nullptr);
91 const ModuleSummaryIndex *getIndex() const { return Index; }
92 void getAnalysisUsage(AnalysisUsage &AU) const override;
93};
94
95//===--------------------------------------------------------------------===//
96//
97// ImmutableModuleSummaryIndexWrapperPass - This pass wrap provided
98// ModuleSummaryIndex object for the module, to be used by other passes.
99//
100LLVM_ABI ImmutablePass *
101createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
102
103/// Returns true if the instruction could have memprof metadata, used to ensure
104/// consistency between summary analysis and the ThinLTO backend processing.
106
107} // end namespace llvm
108
109#endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
#define LLVM_ABI
Definition Compiler.h:213
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:55
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...
ImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index=nullptr)
const ModuleSummaryIndex * getIndex() const
ImmutablePass(char &pid)
Definition Pass.h:287
ModulePass(char &pid)
Definition Pass.h:257
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:67
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 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.
Definition PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29