Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:15

0001 //===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 /// This is the interface to build a ModuleSummaryIndex for a module.
0010 ///
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
0014 #define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
0015 
0016 #include "llvm/IR/ModuleSummaryIndex.h"
0017 #include "llvm/IR/PassManager.h"
0018 #include "llvm/Pass.h"
0019 #include <functional>
0020 #include <optional>
0021 
0022 namespace llvm {
0023 
0024 class BlockFrequencyInfo;
0025 class Function;
0026 class Module;
0027 class ProfileSummaryInfo;
0028 class StackSafetyInfo;
0029 
0030 /// Direct function to compute a \c ModuleSummaryIndex from a given module.
0031 ///
0032 /// If operating within a pass manager which has defined ways to compute the \c
0033 /// BlockFrequencyInfo for a given function, that can be provided via
0034 /// a std::function callback. Otherwise, this routine will manually construct
0035 /// that information.
0036 ModuleSummaryIndex buildModuleSummaryIndex(
0037     const Module &M,
0038     std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
0039     ProfileSummaryInfo *PSI,
0040     std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
0041         [](const Function &F) -> const StackSafetyInfo * { return nullptr; });
0042 
0043 /// Analysis pass to provide the ModuleSummaryIndex object.
0044 class ModuleSummaryIndexAnalysis
0045     : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
0046   friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
0047 
0048   static AnalysisKey Key;
0049 
0050 public:
0051   using Result = ModuleSummaryIndex;
0052 
0053   Result run(Module &M, ModuleAnalysisManager &AM);
0054 };
0055 
0056 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
0057 class ModuleSummaryIndexWrapperPass : public ModulePass {
0058   std::optional<ModuleSummaryIndex> Index;
0059 
0060 public:
0061   static char ID;
0062 
0063   ModuleSummaryIndexWrapperPass();
0064 
0065   /// Get the index built by pass
0066   ModuleSummaryIndex &getIndex() { return *Index; }
0067   const ModuleSummaryIndex &getIndex() const { return *Index; }
0068 
0069   bool runOnModule(Module &M) override;
0070   bool doFinalization(Module &M) override;
0071   void getAnalysisUsage(AnalysisUsage &AU) const override;
0072 };
0073 
0074 //===--------------------------------------------------------------------===//
0075 //
0076 // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
0077 // object for the module, to be written to bitcode or LLVM assembly.
0078 //
0079 ModulePass *createModuleSummaryIndexWrapperPass();
0080 
0081 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
0082 class ImmutableModuleSummaryIndexWrapperPass : public ImmutablePass {
0083   const ModuleSummaryIndex *Index;
0084 
0085 public:
0086   static char ID;
0087 
0088   ImmutableModuleSummaryIndexWrapperPass(
0089       const ModuleSummaryIndex *Index = nullptr);
0090   const ModuleSummaryIndex *getIndex() const { return Index; }
0091   void getAnalysisUsage(AnalysisUsage &AU) const override;
0092 };
0093 
0094 //===--------------------------------------------------------------------===//
0095 //
0096 // ImmutableModuleSummaryIndexWrapperPass - This pass wrap provided
0097 // ModuleSummaryIndex object for the module, to be used by other passes.
0098 //
0099 ImmutablePass *
0100 createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
0101 
0102 /// Returns true if the instruction could have memprof metadata, used to ensure
0103 /// consistency between summary analysis and the ThinLTO backend processing.
0104 bool mayHaveMemprofSummary(const CallBase *CB);
0105 
0106 } // end namespace llvm
0107 
0108 #endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H