Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:40

0001 //===- HotColdSplitting.h ---- Outline Cold Regions -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //===----------------------------------------------------------------------===//
0007 //
0008 // This pass outlines cold regions to a separate function.
0009 //
0010 //===----------------------------------------------------------------------===//
0011 
0012 #ifndef LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
0013 #define LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
0014 
0015 #include "llvm/IR/PassManager.h"
0016 #include "llvm/Support/BranchProbability.h"
0017 
0018 namespace llvm {
0019 
0020 class Module;
0021 class ProfileSummaryInfo;
0022 class BasicBlock;
0023 class BlockFrequencyInfo;
0024 class TargetTransformInfo;
0025 class OptimizationRemarkEmitter;
0026 class AssumptionCache;
0027 class DominatorTree;
0028 class CodeExtractor;
0029 class CodeExtractorAnalysisCache;
0030 
0031 /// A sequence of basic blocks.
0032 ///
0033 /// A 0-sized SmallVector is slightly cheaper to move than a std::vector.
0034 using BlockSequence = SmallVector<BasicBlock *, 0>;
0035 
0036 class HotColdSplitting {
0037 public:
0038   HotColdSplitting(ProfileSummaryInfo *ProfSI,
0039                    function_ref<BlockFrequencyInfo *(Function &)> GBFI,
0040                    function_ref<TargetTransformInfo &(Function &)> GTTI,
0041                    std::function<OptimizationRemarkEmitter &(Function &)> *GORE,
0042                    function_ref<AssumptionCache *(Function &)> LAC)
0043       : PSI(ProfSI), GetBFI(GBFI), GetTTI(GTTI), GetORE(GORE), LookupAC(LAC) {}
0044   bool run(Module &M);
0045 
0046 private:
0047   bool isFunctionCold(const Function &F) const;
0048   bool isBasicBlockCold(BasicBlock *BB, BranchProbability ColdProbThresh,
0049                         SmallPtrSetImpl<BasicBlock *> &AnnotatedColdBlocks,
0050                         BlockFrequencyInfo *BFI) const;
0051   bool shouldOutlineFrom(const Function &F) const;
0052   bool outlineColdRegions(Function &F, bool HasProfileSummary);
0053   bool isSplittingBeneficial(CodeExtractor &CE, const BlockSequence &Region,
0054                              TargetTransformInfo &TTI);
0055   Function *extractColdRegion(BasicBlock &EntryPoint, CodeExtractor &CE,
0056                               const CodeExtractorAnalysisCache &CEAC,
0057                               BlockFrequencyInfo *BFI, TargetTransformInfo &TTI,
0058                               OptimizationRemarkEmitter &ORE);
0059   ProfileSummaryInfo *PSI;
0060   function_ref<BlockFrequencyInfo *(Function &)> GetBFI;
0061   function_ref<TargetTransformInfo &(Function &)> GetTTI;
0062   std::function<OptimizationRemarkEmitter &(Function &)> *GetORE;
0063   function_ref<AssumptionCache *(Function &)> LookupAC;
0064 };
0065 
0066 /// Pass to outline cold regions.
0067 class HotColdSplittingPass : public PassInfoMixin<HotColdSplittingPass> {
0068 public:
0069   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
0070 };
0071 
0072 } // end namespace llvm
0073 
0074 #endif // LLVM_TRANSFORMS_IPO_HOTCOLDSPLITTING_H
0075