private:
bool isFunctionCold(const Function &F) const;
bool shouldOutlineFrom(const Function &F) const;
- bool outlineColdRegions(Function &F);
+ bool outlineColdRegions(Function &F, bool HasProfileSummary);
Function *extractColdRegion(const BlockSequence &Region, DominatorTree &DT,
BlockFrequencyInfo *BFI, TargetTransformInfo &TTI,
OptimizationRemarkEmitter &ORE, unsigned Count);
};
} // namespace
-bool HotColdSplitting::outlineColdRegions(Function &F) {
+bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) {
bool Changed = false;
// The set of cold blocks.
std::unique_ptr<DominatorTree> DT;
std::unique_ptr<PostDominatorTree> PDT;
- BlockFrequencyInfo *BFI = GetBFI(F);
+ // Calculate BFI lazily (it's only used to query ProfileSummaryInfo). This
+ // reduces compile-time significantly. TODO: When we *do* use BFI, we should
+ // be able to salvage its domtrees instead of recomputing them.
+ BlockFrequencyInfo *BFI = nullptr;
+ if (HasProfileSummary)
+ BFI = GetBFI(F);
+
TargetTransformInfo &TTI = GetTTI(F);
OptimizationRemarkEmitter &ORE = (*GetORE)(F);
if (ColdBlocks.count(BB))
continue;
- bool Cold = PSI->isColdBlock(BB, BFI) ||
+ bool Cold = (BFI && PSI->isColdBlock(BB, BFI)) ||
(EnableStaticAnalyis && unlikelyExecuted(*BB));
if (!Cold)
continue;
bool HotColdSplitting::run(Module &M) {
bool Changed = false;
+ bool HasProfileSummary = M.getProfileSummary();
for (auto It = M.begin(), End = M.end(); It != End; ++It) {
Function &F = *It;
}
LLVM_DEBUG(llvm::dbgs() << "Outlining in " << F.getName() << "\n");
- Changed |= outlineColdRegions(F);
+ Changed |= outlineColdRegions(F, HasProfileSummary);
}
return Changed;
}