ModuleSummaryAnalysis.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
  13. #define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
  14. #include "llvm/ADT/Optional.h"
  15. #include "llvm/IR/ModuleSummaryIndex.h"
  16. #include "llvm/IR/PassManager.h"
  17. #include "llvm/Pass.h"
  18. #include <functional>
  19. namespace llvm {
  20. class BlockFrequencyInfo;
  21. class Function;
  22. class Module;
  23. class ProfileSummaryInfo;
  24. class StackSafetyInfo;
  25. /// Direct function to compute a \c ModuleSummaryIndex from a given module.
  26. ///
  27. /// If operating within a pass manager which has defined ways to compute the \c
  28. /// BlockFrequencyInfo for a given function, that can be provided via
  29. /// a std::function callback. Otherwise, this routine will manually construct
  30. /// that information.
  31. ModuleSummaryIndex buildModuleSummaryIndex(
  32. const Module &M,
  33. std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
  34. ProfileSummaryInfo *PSI,
  35. std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
  36. [](const Function &F) -> const StackSafetyInfo * { return nullptr; });
  37. /// Analysis pass to provide the ModuleSummaryIndex object.
  38. class ModuleSummaryIndexAnalysis
  39. : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
  40. friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
  41. static AnalysisKey Key;
  42. public:
  43. using Result = ModuleSummaryIndex;
  44. Result run(Module &M, ModuleAnalysisManager &AM);
  45. };
  46. /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
  47. class ModuleSummaryIndexWrapperPass : public ModulePass {
  48. Optional<ModuleSummaryIndex> Index;
  49. public:
  50. static char ID;
  51. ModuleSummaryIndexWrapperPass();
  52. /// Get the index built by pass
  53. ModuleSummaryIndex &getIndex() { return *Index; }
  54. const ModuleSummaryIndex &getIndex() const { return *Index; }
  55. bool runOnModule(Module &M) override;
  56. bool doFinalization(Module &M) override;
  57. void getAnalysisUsage(AnalysisUsage &AU) const override;
  58. };
  59. //===--------------------------------------------------------------------===//
  60. //
  61. // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
  62. // object for the module, to be written to bitcode or LLVM assembly.
  63. //
  64. ModulePass *createModuleSummaryIndexWrapperPass();
  65. /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
  66. class ImmutableModuleSummaryIndexWrapperPass : public ImmutablePass {
  67. const ModuleSummaryIndex *Index;
  68. public:
  69. static char ID;
  70. ImmutableModuleSummaryIndexWrapperPass(
  71. const ModuleSummaryIndex *Index = nullptr);
  72. const ModuleSummaryIndex *getIndex() const { return Index; }
  73. void getAnalysisUsage(AnalysisUsage &AU) const override;
  74. };
  75. //===--------------------------------------------------------------------===//
  76. //
  77. // ImmutableModuleSummaryIndexWrapperPass - This pass wrap provided
  78. // ModuleSummaryIndex object for the module, to be used by other passes.
  79. //
  80. ImmutablePass *
  81. createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
  82. } // end namespace llvm
  83. #endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H