HotColdSplitting.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- HotColdSplitting.h ---- Outline Cold Regions -------------*- 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. // This pass outlines cold regions to a separate function.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
  17. #define LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
  18. #include "llvm/IR/PassManager.h"
  19. namespace llvm {
  20. class Module;
  21. class ProfileSummaryInfo;
  22. class BlockFrequencyInfo;
  23. class TargetTransformInfo;
  24. class OptimizationRemarkEmitter;
  25. class AssumptionCache;
  26. class DominatorTree;
  27. class CodeExtractorAnalysisCache;
  28. /// A sequence of basic blocks.
  29. ///
  30. /// A 0-sized SmallVector is slightly cheaper to move than a std::vector.
  31. using BlockSequence = SmallVector<BasicBlock *, 0>;
  32. class HotColdSplitting {
  33. public:
  34. HotColdSplitting(ProfileSummaryInfo *ProfSI,
  35. function_ref<BlockFrequencyInfo *(Function &)> GBFI,
  36. function_ref<TargetTransformInfo &(Function &)> GTTI,
  37. std::function<OptimizationRemarkEmitter &(Function &)> *GORE,
  38. function_ref<AssumptionCache *(Function &)> LAC)
  39. : PSI(ProfSI), GetBFI(GBFI), GetTTI(GTTI), GetORE(GORE), LookupAC(LAC) {}
  40. bool run(Module &M);
  41. private:
  42. bool isFunctionCold(const Function &F) const;
  43. bool shouldOutlineFrom(const Function &F) const;
  44. bool outlineColdRegions(Function &F, bool HasProfileSummary);
  45. Function *extractColdRegion(const BlockSequence &Region,
  46. const CodeExtractorAnalysisCache &CEAC,
  47. DominatorTree &DT, BlockFrequencyInfo *BFI,
  48. TargetTransformInfo &TTI,
  49. OptimizationRemarkEmitter &ORE,
  50. AssumptionCache *AC, unsigned Count);
  51. ProfileSummaryInfo *PSI;
  52. function_ref<BlockFrequencyInfo *(Function &)> GetBFI;
  53. function_ref<TargetTransformInfo &(Function &)> GetTTI;
  54. std::function<OptimizationRemarkEmitter &(Function &)> *GetORE;
  55. function_ref<AssumptionCache *(Function &)> LookupAC;
  56. };
  57. /// Pass to outline cold regions.
  58. class HotColdSplittingPass : public PassInfoMixin<HotColdSplittingPass> {
  59. public:
  60. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  61. };
  62. } // end namespace llvm
  63. #endif // LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif