1 //===- HotColdSplitting.h ---- Outline Cold Regions -------------*- 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 // This pass outlines cold regions to a separate function. 9 // 10 //===----------------------------------------------------------------------===// 11 12 #ifndef LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H 13 #define LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H 14 15 #include "llvm/IR/PassManager.h" 16 #include "llvm/Support/BranchProbability.h" 17 18 namespace llvm { 19 20 class Module; 21 class ProfileSummaryInfo; 22 class BlockFrequencyInfo; 23 class TargetTransformInfo; 24 class OptimizationRemarkEmitter; 25 class AssumptionCache; 26 class DominatorTree; 27 class CodeExtractor; 28 class CodeExtractorAnalysisCache; 29 30 /// A sequence of basic blocks. 31 /// 32 /// A 0-sized SmallVector is slightly cheaper to move than a std::vector. 33 using BlockSequence = SmallVector<BasicBlock *, 0>; 34 35 class HotColdSplitting { 36 public: HotColdSplitting(ProfileSummaryInfo * ProfSI,function_ref<BlockFrequencyInfo * (Function &)> GBFI,function_ref<TargetTransformInfo & (Function &)> GTTI,std::function<OptimizationRemarkEmitter & (Function &)> * GORE,function_ref<AssumptionCache * (Function &)> LAC)37 HotColdSplitting(ProfileSummaryInfo *ProfSI, 38 function_ref<BlockFrequencyInfo *(Function &)> GBFI, 39 function_ref<TargetTransformInfo &(Function &)> GTTI, 40 std::function<OptimizationRemarkEmitter &(Function &)> *GORE, 41 function_ref<AssumptionCache *(Function &)> LAC) 42 : PSI(ProfSI), GetBFI(GBFI), GetTTI(GTTI), GetORE(GORE), LookupAC(LAC) {} 43 bool run(Module &M); 44 45 private: 46 bool isFunctionCold(const Function &F) const; 47 bool isBasicBlockCold(BasicBlock *BB, BranchProbability ColdProbThresh, 48 SmallPtrSetImpl<BasicBlock *> &AnnotatedColdBlocks, 49 BlockFrequencyInfo *BFI) const; 50 bool shouldOutlineFrom(const Function &F) const; 51 bool outlineColdRegions(Function &F, bool HasProfileSummary); 52 bool isSplittingBeneficial(CodeExtractor &CE, const BlockSequence &Region, 53 TargetTransformInfo &TTI); 54 Function *extractColdRegion(BasicBlock &EntryPoint, CodeExtractor &CE, 55 const CodeExtractorAnalysisCache &CEAC, 56 BlockFrequencyInfo *BFI, TargetTransformInfo &TTI, 57 OptimizationRemarkEmitter &ORE); 58 ProfileSummaryInfo *PSI; 59 function_ref<BlockFrequencyInfo *(Function &)> GetBFI; 60 function_ref<TargetTransformInfo &(Function &)> GetTTI; 61 std::function<OptimizationRemarkEmitter &(Function &)> *GetORE; 62 function_ref<AssumptionCache *(Function &)> LookupAC; 63 }; 64 65 /// Pass to outline cold regions. 66 class HotColdSplittingPass : public PassInfoMixin<HotColdSplittingPass> { 67 public: 68 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 69 }; 70 71 } // end namespace llvm 72 73 #endif // LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H 74 75