1 //===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This is the interface to build a ModuleSummaryIndex for a module.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
15 #define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/IR/ModuleSummaryIndex.h"
19 #include "llvm/Pass.h"
23 class BlockFrequencyInfo;
25 /// Class to build a module summary index for the given Module, possibly from
27 class ModuleSummaryIndexBuilder {
28 /// The index being built
29 std::unique_ptr<ModuleSummaryIndex> Index;
30 /// The module for which we are building an index
34 /// Default constructor
35 ModuleSummaryIndexBuilder() = default;
37 /// Constructor that builds an index for the given Module. An optional
38 /// callback can be supplied to obtain the frequency info for a function.
39 ModuleSummaryIndexBuilder(
41 std::function<BlockFrequencyInfo *(const Function &F)> Ftor = nullptr);
43 /// Get a reference to the index owned by builder
44 ModuleSummaryIndex &getIndex() const { return *Index; }
46 /// Take ownership of the built index
47 std::unique_ptr<ModuleSummaryIndex> takeIndex() { return std::move(Index); }
50 /// Compute summary for given function with optional frequency information
51 void computeFunctionSummary(const Function &F,
52 BlockFrequencyInfo *BFI = nullptr);
54 /// Compute summary for given variable with optional frequency information
55 void computeVariableSummary(const GlobalVariable &V);
58 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
59 class ModuleSummaryIndexWrapperPass : public ModulePass {
60 std::unique_ptr<ModuleSummaryIndexBuilder> IndexBuilder;
65 ModuleSummaryIndexWrapperPass();
67 /// Get the index built by pass
68 ModuleSummaryIndex &getIndex() { return IndexBuilder->getIndex(); }
69 const ModuleSummaryIndex &getIndex() const {
70 return IndexBuilder->getIndex();
73 bool runOnModule(Module &M) override;
74 bool doFinalization(Module &M) override;
75 void getAnalysisUsage(AnalysisUsage &AU) const override;
78 //===--------------------------------------------------------------------===//
80 // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
81 // object for the module, to be written to bitcode or LLVM assembly.
83 ModulePass *createModuleSummaryIndexWrapperPass();
85 /// Returns true if \p M is eligible for ThinLTO promotion.
87 /// Currently we check if it has any any InlineASM that uses an internal symbol.
88 bool moduleCanBeRenamedForThinLTO(const Module &M);