aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Serialization/ModuleManager.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-01-28 16:46:33 +0000
committerDouglas Gregor <dgregor@apple.com>2013-01-28 16:46:33 +0000
commitd3cf5fba332fc77f7e72ef58077822606718671d (patch)
tree87fd322e2cd4ff3a4961839b00b8d29dd9169132 /include/clang/Serialization/ModuleManager.h
parentd75ff6496bfb599a9edde41681873919d4d44152 (diff)
Eliminate memory allocation from most invocations of
ModuleManager::visit() by keeping a free list of the two data structures used to store state (a preallocated stack and a visitation number vector). Improves -fsyntax-only performance for my modules test case by 2.8%. Modules has pulled ahead by almost 10% with the global module index. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173692 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Serialization/ModuleManager.h')
-rw-r--r--include/clang/Serialization/ModuleManager.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/include/clang/Serialization/ModuleManager.h b/include/clang/Serialization/ModuleManager.h
index 05d702664e..60e3b40a7a 100644
--- a/include/clang/Serialization/ModuleManager.h
+++ b/include/clang/Serialization/ModuleManager.h
@@ -43,7 +43,7 @@ class ModuleManager {
/// \brief The visitation order.
SmallVector<ModuleFile *, 4> VisitOrder;
-
+
/// \brief The list of module files that both we and the global module index
/// know about.
///
@@ -63,6 +63,40 @@ class ModuleManager {
/// \brief Update the set of modules files we know about known to the global index.
void updateModulesInCommonWithGlobalIndex();
+ /// \brief State used by the "visit" operation to avoid malloc traffic in
+ /// calls to visit().
+ struct VisitState {
+ explicit VisitState(unsigned N)
+ : VisitNumber(N, 0), NextVisitNumber(1), NextState(0)
+ {
+ Stack.reserve(N);
+ }
+
+ ~VisitState() {
+ delete NextState;
+ }
+
+ /// \brief The stack used when marking the imports of a particular module
+ /// as not-to-be-visited.
+ SmallVector<ModuleFile *, 4> Stack;
+
+ /// \brief The visit number of each module file, which indicates when
+ /// this module file was last visited.
+ SmallVector<unsigned, 4> VisitNumber;
+
+ /// \brief The next visit number to use to mark visited module files.
+ unsigned NextVisitNumber;
+
+ /// \brief The next visit state.
+ VisitState *NextState;
+ };
+
+ /// \brief The first visit() state in the chain.
+ VisitState *FirstVisitState;
+
+ VisitState *allocateVisitState();
+ void returnVisitState(VisitState *State);
+
public:
typedef SmallVector<ModuleFile*, 2>::iterator ModuleIterator;
typedef SmallVector<ModuleFile*, 2>::const_iterator ModuleConstIterator;