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

source code of llvm/include/llvm/Transforms/IPO/HotColdSplitting.h