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