diff --git a/bolt/src/Passes/DataflowAnalysis.h b/bolt/src/Passes/DataflowAnalysis.h index da9349706167..e681a7ddec97 100644 --- a/bolt/src/Passes/DataflowAnalysis.h +++ b/bolt/src/Passes/DataflowAnalysis.h @@ -257,6 +257,11 @@ protected: } public: + /// Return the allocator id + unsigned getAllocatorId() { + return AllocatorId; + } + /// If the direction of the dataflow is forward, operates on the last /// instruction of all predecessors when performing an iteration of the /// dataflow equation for the start of this BB. If backwards, operates on diff --git a/bolt/src/Passes/FrameAnalysis.cpp b/bolt/src/Passes/FrameAnalysis.cpp index 2994e90bd6e5..a2d917ec89b8 100644 --- a/bolt/src/Passes/FrameAnalysis.cpp +++ b/bolt/src/Passes/FrameAnalysis.cpp @@ -580,6 +580,57 @@ void FrameAnalysis::printStats() { << " could not have its frame indices restored.\n"; } +void FrameAnalysis::clearSPTMap() { + if (opts::NoThreads) { + SPTMap.clear(); + return; + } + + auto clearBlock = [&](std::map::iterator BlockBegin, + std::map::iterator BlockEnd) { + for (auto It = BlockBegin; It != BlockEnd; ++It) { + auto &BF = It->second; + + if (!BF.isSimple() || !BF.hasCFG()) + continue; + + auto &SPTPtr = SPTMap.find(&BF)->second; + SPTPtr.reset(); + } + }; + + ThreadPool ThPool(opts::ThreadCount); + unsigned CurId = 0; + auto BlockBegin = BC.getBinaryFunctions().begin(); + + // Functions that use the same allocator id are on the same task + for (auto It = BC.getBinaryFunctions().begin(); + It != BC.getBinaryFunctions().end(); ++It) { + auto &BF = It->second; + + if (BF.isSimple() && BF.hasCFG()) { + auto &SPT = getSPT(BF); + + // First valid allocator id is seen + if (CurId == 0) { + BlockBegin = It; + CurId = SPT.getAllocatorId(); + continue; + } + + if (CurId != SPT.getAllocatorId()) { + CurId = SPT.getAllocatorId(); + ThPool.async(clearBlock, BlockBegin, It); + BlockBegin = It; + } + } + } + + ThPool.async(clearBlock, BlockBegin, BC.getBinaryFunctions().end()); + ThPool.wait(); + SPTMap.clear(); +} + void FrameAnalysis::preComputeSPT() { // Create a lock that postpone execution of tasks until all allocators are // initialized diff --git a/bolt/src/Passes/FrameAnalysis.h b/bolt/src/Passes/FrameAnalysis.h index 5ef34159a4b8..bb81b65dae8f 100644 --- a/bolt/src/Passes/FrameAnalysis.h +++ b/bolt/src/Passes/FrameAnalysis.h @@ -224,9 +224,7 @@ public: } /// Clean and de-allocate all SPT objects - void clearSPTMap() { - SPTMap.clear(); - } + void clearSPTMap(); /// Perform SPT analysis for all functions in parallel void preComputeSPT();