forked from OSchip/llvm-project
CursorVisitor: cache worklists created for data-recursion to reduce malloc() traffic.
llvm-svn: 119290
This commit is contained in:
parent
8d69a2160e
commit
a4c27ec73b
|
@ -177,6 +177,10 @@ class CursorVisitor : public DeclVisitor<CursorVisitor, bool>,
|
|||
DeclContext::decl_iterator *DI_current;
|
||||
DeclContext::decl_iterator DE_current;
|
||||
|
||||
// Cache of pre-allocated worklists for data-recursion walk of Stmts.
|
||||
llvm::SmallVector<VisitorWorkList*, 5> WorkListFreeList;
|
||||
llvm::SmallVector<VisitorWorkList*, 5> WorkListCache;
|
||||
|
||||
using DeclVisitor<CursorVisitor, bool>::Visit;
|
||||
using TypeLocVisitor<CursorVisitor, bool>::Visit;
|
||||
using StmtVisitor<CursorVisitor, bool>::Visit;
|
||||
|
@ -223,6 +227,14 @@ public:
|
|||
StmtParent = 0;
|
||||
}
|
||||
|
||||
~CursorVisitor() {
|
||||
// Free the pre-allocated worklists for data-recursion.
|
||||
for (llvm::SmallVectorImpl<VisitorWorkList*>::iterator
|
||||
I = WorkListCache.begin(), E = WorkListCache.end(); I != E; ++I) {
|
||||
delete *I;
|
||||
}
|
||||
}
|
||||
|
||||
ASTUnit *getASTUnit() const { return TU; }
|
||||
|
||||
bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
|
||||
|
@ -2019,9 +2031,20 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
|
|||
}
|
||||
|
||||
bool CursorVisitor::VisitDataRecursive(Stmt *S) {
|
||||
VisitorWorkList WL;
|
||||
EnqueueWorkList(WL, S);
|
||||
return RunVisitorWorkList(WL);
|
||||
VisitorWorkList *WL = 0;
|
||||
if (!WorkListFreeList.empty()) {
|
||||
WL = WorkListFreeList.back();
|
||||
WL->clear();
|
||||
WorkListFreeList.pop_back();
|
||||
}
|
||||
else {
|
||||
WL = new VisitorWorkList();
|
||||
WorkListCache.push_back(WL);
|
||||
}
|
||||
EnqueueWorkList(*WL, S);
|
||||
bool result = RunVisitorWorkList(*WL);
|
||||
WorkListFreeList.push_back(WL);
|
||||
return result;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
Loading…
Reference in New Issue