1 //===- HotColdSplitting.h ---- Outline Cold Regions -------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
8 // This pass outlines cold regions to a separate function.
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
13 #define LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
15 #include "llvm/IR/PassManager.h"
20 class ProfileSummaryInfo;
21 class BlockFrequencyInfo;
22 class TargetTransformInfo;
23 class OptimizationRemarkEmitter;
24 class AssumptionCache;
26 class CodeExtractorAnalysisCache;
28 /// A sequence of basic blocks.
30 /// A 0-sized SmallVector is slightly cheaper to move than a std::vector.
31 using BlockSequence = SmallVector<BasicBlock *, 0>;
33 class HotColdSplitting {
35 HotColdSplitting(ProfileSummaryInfo *ProfSI,
36 function_ref<BlockFrequencyInfo *(Function &)> GBFI,
37 function_ref<TargetTransformInfo &(Function &)> GTTI,
38 std::function<OptimizationRemarkEmitter &(Function &)> *GORE,
39 function_ref<AssumptionCache *(Function &)> LAC)
40 : PSI(ProfSI), GetBFI(GBFI), GetTTI(GTTI), GetORE(GORE), LookupAC(LAC) {}
44 bool isFunctionCold(const Function &F) const;
45 bool shouldOutlineFrom(const Function &F) const;
46 bool outlineColdRegions(Function &F, bool HasProfileSummary);
47 Function *extractColdRegion(const BlockSequence &Region,
48 const CodeExtractorAnalysisCache &CEAC,
49 DominatorTree &DT, BlockFrequencyInfo *BFI,
50 TargetTransformInfo &TTI,
51 OptimizationRemarkEmitter &ORE,
52 AssumptionCache *AC, unsigned Count);
53 ProfileSummaryInfo *PSI;
54 function_ref<BlockFrequencyInfo *(Function &)> GetBFI;
55 function_ref<TargetTransformInfo &(Function &)> GetTTI;
56 std::function<OptimizationRemarkEmitter &(Function &)> *GetORE;
57 function_ref<AssumptionCache *(Function &)> LookupAC;
60 /// Pass to outline cold regions.
61 class HotColdSplittingPass : public PassInfoMixin<HotColdSplittingPass> {
63 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
66 } // end namespace llvm
68 #endif // LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H