Index: llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp =================================================================== --- llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp +++ llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp @@ -168,8 +168,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: @@ -182,6 +185,8 @@ ProfileSummaryInfo *PSI; function_ref GetBFI; function_ref GetTTI; + function_ref GetDT; + function_ref GetPDT; std::function *GetORE; }; @@ -195,6 +200,8 @@ void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired(); AU.addRequired(); + AU.addRequired(); + AU.addRequired(); AU.addRequired(); AU.addRequired(); } @@ -462,12 +469,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); @@ -492,9 +498,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()) @@ -595,6 +601,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 & { @@ -602,7 +615,7 @@ return *ORE.get(); }; - return HotColdSplitting(PSI, GBFI, GTTI, &GetORE).run(M); + return HotColdSplitting(PSI, GBFI, GTTI, GetDT, GetPDT, &GetORE).run(M); } PreservedAnalyses @@ -623,6 +636,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 & { @@ -632,7 +653,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(); } @@ -642,6 +663,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)