ModuleSummaryAnalysis.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ModuleSummaryAnalysis.h - Module summary index builder ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. /// This is the interface to build a ModuleSummaryIndex for a module.
  15. ///
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
  18. #define LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
  19. #include "llvm/IR/ModuleSummaryIndex.h"
  20. #include "llvm/IR/PassManager.h"
  21. #include "llvm/Pass.h"
  22. #include <functional>
  23. #include <optional>
  24. namespace llvm {
  25. class BlockFrequencyInfo;
  26. class Function;
  27. class Module;
  28. class ProfileSummaryInfo;
  29. class StackSafetyInfo;
  30. /// Direct function to compute a \c ModuleSummaryIndex from a given module.
  31. ///
  32. /// If operating within a pass manager which has defined ways to compute the \c
  33. /// BlockFrequencyInfo for a given function, that can be provided via
  34. /// a std::function callback. Otherwise, this routine will manually construct
  35. /// that information.
  36. ModuleSummaryIndex buildModuleSummaryIndex(
  37. const Module &M,
  38. std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
  39. ProfileSummaryInfo *PSI,
  40. std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
  41. [](const Function &F) -> const StackSafetyInfo * { return nullptr; });
  42. /// Analysis pass to provide the ModuleSummaryIndex object.
  43. class ModuleSummaryIndexAnalysis
  44. : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
  45. friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
  46. static AnalysisKey Key;
  47. public:
  48. using Result = ModuleSummaryIndex;
  49. Result run(Module &M, ModuleAnalysisManager &AM);
  50. };
  51. /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
  52. class ModuleSummaryIndexWrapperPass : public ModulePass {
  53. std::optional<ModuleSummaryIndex> Index;
  54. public:
  55. static char ID;
  56. ModuleSummaryIndexWrapperPass();
  57. /// Get the index built by pass
  58. ModuleSummaryIndex &getIndex() { return *Index; }
  59. const ModuleSummaryIndex &getIndex() const { return *Index; }
  60. bool runOnModule(Module &M) override;
  61. bool doFinalization(Module &M) override;
  62. void getAnalysisUsage(AnalysisUsage &AU) const override;
  63. };
  64. //===--------------------------------------------------------------------===//
  65. //
  66. // createModuleSummaryIndexWrapperPass - This pass builds a ModuleSummaryIndex
  67. // object for the module, to be written to bitcode or LLVM assembly.
  68. //
  69. ModulePass *createModuleSummaryIndexWrapperPass();
  70. /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
  71. class ImmutableModuleSummaryIndexWrapperPass : public ImmutablePass {
  72. const ModuleSummaryIndex *Index;
  73. public:
  74. static char ID;
  75. ImmutableModuleSummaryIndexWrapperPass(
  76. const ModuleSummaryIndex *Index = nullptr);
  77. const ModuleSummaryIndex *getIndex() const { return Index; }
  78. void getAnalysisUsage(AnalysisUsage &AU) const override;
  79. };
  80. //===--------------------------------------------------------------------===//
  81. //
  82. // ImmutableModuleSummaryIndexWrapperPass - This pass wrap provided
  83. // ModuleSummaryIndex object for the module, to be used by other passes.
  84. //
  85. ImmutablePass *
  86. createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
  87. } // end namespace llvm
  88. #endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
  89. #ifdef __GNUC__
  90. #pragma GCC diagnostic pop
  91. #endif