Clean SPTMap in frame anaylsis in parallel

Summary:
This diff parallelize the STPClean() function reducing its runtime from 5 seconds to 0.4 on HHVM,
Making the runtime for the frame optimizer goes down to 33 seconds on HHVM.

(cherry picked from FBD15914371)
This commit is contained in:
laith sakka 2019-06-19 18:01:00 -07:00 committed by Maksim Panchenko
parent 86b529bd54
commit 00c252f6d8
3 changed files with 57 additions and 3 deletions

View File

@ -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

View File

@ -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<uint64_t, BinaryFunction>::iterator BlockBegin,
std::map<uint64_t, BinaryFunction>::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

View File

@ -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();