diff options
author | Florian Hahn <flo@fhahn.com> | 2019-01-24 09:44:52 +0000 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2019-01-24 09:44:52 +0000 |
commit | a6982414edf315c39ae93f3c3322476217119e99 (patch) | |
tree | 0fd3db881ba0461f60d632450fd2d4cc6c02cb13 /llvm/lib/Transforms/IPO/HotColdSplitting.cpp | |
parent | f70a4c77127853288f42c5a903312c0691c94871 (diff) | |
download | bcm5719-llvm-a6982414edf315c39ae93f3c3322476217119e99.tar.gz bcm5719-llvm-a6982414edf315c39ae93f3c3322476217119e99.zip |
[HotColdSplitting] Get DT and PDT from the pass manager.
Instead of manually computing DT and PDT, we can get the from the pass
manager, which ideally has them already cached. With the new pass
manager, we could even preserve DT/PDT on a per function basis in a
module pass.
I think this also addresses the TODO about re-using the computed DTs for
BFI. IIUC, GetBFI will fetch the DT from the pass manager and when we
will fetch the cached version later.
Reviewers: vsk, hiraditya, tejohnson, thegameg, sebpop
Reviewed By: vsk
Differential Revision: https://reviews.llvm.org/D57092
llvm-svn: 352036
Diffstat (limited to 'llvm/lib/Transforms/IPO/HotColdSplitting.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/HotColdSplitting.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp index 710a9e72569..0ff902d735c 100644 --- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -168,8 +168,11 @@ public: HotColdSplitting(ProfileSummaryInfo *ProfSI, function_ref<BlockFrequencyInfo *(Function &)> GBFI, function_ref<TargetTransformInfo &(Function &)> GTTI, + function_ref<DominatorTree *(Function &)> GetDT, + function_ref<PostDominatorTree *(Function &)> GetPDT, std::function<OptimizationRemarkEmitter &(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 @@ private: ProfileSummaryInfo *PSI; function_ref<BlockFrequencyInfo *(Function &)> GetBFI; function_ref<TargetTransformInfo &(Function &)> GetTTI; + function_ref<DominatorTree *(Function &)> GetDT; + function_ref<PostDominatorTree *(Function &)> GetPDT; std::function<OptimizationRemarkEmitter &(Function &)> *GetORE; }; @@ -195,6 +200,8 @@ public: void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<AssumptionCacheTracker>(); AU.addRequired<BlockFrequencyInfoWrapperPass>(); + AU.addRequired<DominatorTreeWrapperPass>(); + AU.addRequired<PostDominatorTreeWrapperPass>(); AU.addRequired<ProfileSummaryInfoWrapperPass>(); AU.addRequired<TargetTransformInfoWrapperPass>(); } @@ -462,12 +469,11 @@ bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) { ReversePostOrderTraversal<Function *> RPOT(&F); // Calculate domtrees lazily. This reduces compile-time significantly. - std::unique_ptr<DominatorTree> DT; - std::unique_ptr<PostDominatorTree> 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 @@ bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) { }); if (!DT) - DT = make_unique<DominatorTree>(F); + DT = GetDT(F); if (!PDT) - PDT = make_unique<PostDominatorTree>(F); + PDT = GetPDT(F); auto Region = OutliningRegion::create(*BB, *DT, *PDT); if (Region.empty()) @@ -595,6 +601,13 @@ bool HotColdSplittingLegacyPass::runOnModule(Module &M) { auto GBFI = [this](Function &F) { return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI(); }; + auto GetDT = [this](Function &F) { + return &this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree(); + }; + auto GetPDT = [this](Function &F) { + return &this->getAnalysis<PostDominatorTreeWrapperPass>(F).getPostDomTree(); + }; + std::unique_ptr<OptimizationRemarkEmitter> ORE; std::function<OptimizationRemarkEmitter &(Function &)> GetORE = [&ORE](Function &F) -> OptimizationRemarkEmitter & { @@ -602,7 +615,7 @@ bool HotColdSplittingLegacyPass::runOnModule(Module &M) { 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 @@ HotColdSplittingPass::run(Module &M, ModuleAnalysisManager &AM) { return FAM.getResult<TargetIRAnalysis>(F); }; + auto GetDT = [&FAM](Function &F) { + return &FAM.getResult<DominatorTreeAnalysis>(F); + }; + + auto GetPDT = [&FAM](Function &F) { + return &FAM.getResult<PostDominatorTreeAnalysis>(F); + }; + std::unique_ptr<OptimizationRemarkEmitter> ORE; std::function<OptimizationRemarkEmitter &(Function &)> GetORE = [&ORE](Function &F) -> OptimizationRemarkEmitter & { @@ -632,7 +653,7 @@ HotColdSplittingPass::run(Module &M, ModuleAnalysisManager &AM) { ProfileSummaryInfo *PSI = &AM.getResult<ProfileSummaryAnalysis>(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 @@ INITIALIZE_PASS_BEGIN(HotColdSplittingLegacyPass, "hotcoldsplit", "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) |