forked from OSchip/llvm-project
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:
parent
d1517e184c
commit
a8a3bd2100
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue