SamplePGO - Clear per-function data after applying a profile.

The pass was keeping around a lot of per-function data (visited blocks,
edges, dominance, etc) that is just taking up memory for no reason. In
fact, from function to function it could potentially confuse the
propagator since some maps are indexed by line offsets which can be
common between functions.

llvm-svn: 251531
This commit is contained in:
Diego Novillo 2015-10-28 17:40:22 +00:00
parent d1517e184c
commit a8a3bd2100
1 changed files with 21 additions and 4 deletions

View File

@ -123,6 +123,7 @@ protected:
bool propagateThroughEdges(Function &F);
void computeDominanceAndLoopInfo(Function &F);
unsigned getOffset(unsigned L, unsigned H) const;
void clearFunctionData();
/// \brief Map basic blocks to their computed weights.
///
@ -175,6 +176,20 @@ protected:
};
}
/// Clear all the per-function data used to load samples and propagate weights.
void SampleProfileLoader::clearFunctionData() {
BlockWeights.clear();
EdgeWeights.clear();
VisitedBlocks.clear();
VisitedEdges.clear();
EquivalenceClass.clear();
DT = nullptr;
PDT = nullptr;
LI = nullptr;
Predecessors.clear();
Successors.clear();
}
/// \brief Returns the offset of lineno \p L to head_lineno \p H
///
/// \param L Lineno
@ -931,17 +946,19 @@ ModulePass *llvm::createSampleProfileLoaderPass(StringRef Name) {
}
bool SampleProfileLoader::runOnModule(Module &M) {
if (!ProfileIsValid)
return false;
bool retval = false;
for (auto &F : M)
if (!F.isDeclaration())
if (!F.isDeclaration()) {
clearFunctionData();
retval |= runOnFunction(F);
}
return retval;
}
bool SampleProfileLoader::runOnFunction(Function &F) {
if (!ProfileIsValid)
return false;
Samples = Reader->getSamplesFor(F);
if (!Samples->empty())
return emitAnnotations(F);