Index: llvm/lib/Transforms/IPO/HotColdSplitting.cpp =================================================================== --- llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -169,8 +169,11 @@ HotColdSplitting(ProfileSummaryInfo *ProfSI, function_ref GBFI, function_ref GTTI, + function_ref GetDT, + function_ref GetPDT, std::function *GORE) - : PSI(ProfSI), GetBFI(GBFI), GetTTI(GTTI), GetORE(GORE) {} + : PSI(ProfSI), GetBFI(GBFI), GetTTI(GTTI), GetDT(GetDT), GetPDT(GetPDT), + GetORE(GORE) {} bool run(Module &M); private: @@ -183,6 +186,8 @@ ProfileSummaryInfo *PSI; function_ref GetBFI; function_ref GetTTI; + function_ref GetDT; + function_ref GetPDT; std::function *GetORE; }; @@ -196,6 +201,8 @@ void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired(); AU.addRequired(); + AU.addRequired(); + AU.addRequired(); AU.addRequired(); AU.addRequired(); } @@ -463,12 +470,11 @@ ReversePostOrderTraversal RPOT(&F); // Calculate domtrees lazily. This reduces compile-time significantly. - std::unique_ptr DT; - std::unique_ptr PDT; + DominatorTree *DT = nullptr; + PostDominatorTree *PDT = nullptr; // 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. + // reduces compile-time significantly. BlockFrequencyInfo *BFI = nullptr; if (HasProfileSummary) BFI = GetBFI(F); @@ -493,9 +499,9 @@ }); if (!DT) - DT = make_unique(F); + DT = GetDT(F); if (!PDT) - PDT = make_unique(F); + PDT = GetPDT(F); auto Region = OutliningRegion::create(*BB, *DT, *PDT); if (Region.empty()) @@ -596,6 +602,13 @@ auto GBFI = [this](Function &F) { return &this->getAnalysis(F).getBFI(); }; + auto GetDT = [this](Function &F) { + return &this->getAnalysis(F).getDomTree(); + }; + auto GetPDT = [this](Function &F) { + return &this->getAnalysis(F).getPostDomTree(); + }; + std::unique_ptr ORE; std::function GetORE = [&ORE](Function &F) -> OptimizationRemarkEmitter & { @@ -603,7 +616,7 @@ return *ORE.get(); }; - return HotColdSplitting(PSI, GBFI, GTTI, &GetORE).run(M); + return HotColdSplitting(PSI, GBFI, GTTI, GetDT, GetPDT, &GetORE).run(M); } PreservedAnalyses @@ -624,6 +637,14 @@ return FAM.getResult(F); }; + auto GetDT = [&FAM](Function &F) { + return &FAM.getResult(F); + }; + + auto GetPDT = [&FAM](Function &F) { + return &FAM.getResult(F); + }; + std::unique_ptr ORE; std::function GetORE = [&ORE](Function &F) -> OptimizationRemarkEmitter & { @@ -633,7 +654,7 @@ ProfileSummaryInfo *PSI = &AM.getResult(M); - if (HotColdSplitting(PSI, GBFI, GTTI, &GetORE).run(M)) + if (HotColdSplitting(PSI, GBFI, GTTI, GetDT, GetPDT, &GetORE).run(M)) return PreservedAnalyses::none(); return PreservedAnalyses::all(); } @@ -643,6 +664,8 @@ "Hot Cold Splitting", false, false) INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_END(HotColdSplittingLegacyPass, "hotcoldsplit", "Hot Cold Splitting", false, false)