]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
Upgrade to OpenPAM Radula.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Analysis / ModuleSummaryAnalysis.h
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/STLExtras.h"
18 #include "llvm/IR/ModuleSummaryIndex.h"
19 #include "llvm/Pass.h"
20
21 namespace llvm {
22
23 class BlockFrequencyInfo;
24
25 /// Class to build a module summary index for the given Module, possibly from
26 /// a Pass.
27 class ModuleSummaryIndexBuilder {
28   /// The index being built
29   std::unique_ptr<ModuleSummaryIndex> Index;
30   /// The module for which we are building an index
31   const Module *M;
32
33 public:
34   /// Default constructor
35   ModuleSummaryIndexBuilder() = default;
36
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(
40       const Module *M,
41       std::function<BlockFrequencyInfo *(const Function &F)> Ftor = nullptr);
42
43   /// Get a reference to the index owned by builder
44   ModuleSummaryIndex &getIndex() const { return *Index; }
45
46   /// Take ownership of the built index
47   std::unique_ptr<ModuleSummaryIndex> takeIndex() { return std::move(Index); }
48
49 private:
50   /// Compute summary for given function with optional frequency information
51   void computeFunctionSummary(const Function &F,
52                               BlockFrequencyInfo *BFI = nullptr);
53
54   /// Compute summary for given variable with optional frequency information
55   void computeVariableSummary(const GlobalVariable &V);
56 };
57
58 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
59 class ModuleSummaryIndexWrapperPass : public ModulePass {
60   std::unique_ptr<ModuleSummaryIndexBuilder> IndexBuilder;
61
62 public:
63   static char ID;
64
65   ModuleSummaryIndexWrapperPass();
66
67   /// Get the index built by pass
68   ModuleSummaryIndex &getIndex() { return IndexBuilder->getIndex(); }
69   const ModuleSummaryIndex &getIndex() const {
70     return IndexBuilder->getIndex();
71   }
72
73   bool runOnModule(Module &M) override;
74   bool doFinalization(Module &M) override;
75   void getAnalysisUsage(AnalysisUsage &AU) const override;
76 };
77
78 //===--------------------------------------------------------------------===//
79 //
80 // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
81 // object for the module, to be written to bitcode or LLVM assembly.
82 //
83 ModulePass *createModuleSummaryIndexWrapperPass();
84
85 /// Returns true if \p M is eligible for ThinLTO promotion.
86 ///
87 /// Currently we check if it has any any InlineASM that uses an internal symbol.
88 bool moduleCanBeRenamedForThinLTO(const Module &M);
89 }
90
91 #endif