[cfe-commits] r173081 - in /cfe/trunk: include/clang/Serialization/Module.h lib/Serialization/ModuleManager.cpp
Douglas Gregor
dgregor at apple.com
Mon Jan 21 12:07:12 PST 2013
Author: dgregor
Date: Mon Jan 21 14:07:12 2013
New Revision: 173081
URL: http://llvm.org/viewvc/llvm-project?rev=173081&view=rev
Log:
Give ModuleFiles an index, so that we can use indexed vectors rather
than DenseMaps and SmallPtrSets for module-visitation data. ~2.6%
speedup for modules.
Modified:
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Serialization/ModuleManager.cpp
Modified: cfe/trunk/include/clang/Serialization/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/Module.h?rev=173081&r1=173080&r2=173081&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/Module.h (original)
+++ cfe/trunk/include/clang/Serialization/Module.h Mon Jan 21 14:07:12 2013
@@ -69,6 +69,9 @@
// === General information ===
+ /// \brief The index of this module in the list of modules.
+ unsigned Index;
+
/// \brief The type of this module.
ModuleKind Kind;
Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=173081&r1=173080&r2=173081&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Mon Jan 21 14:07:12 2013
@@ -49,6 +49,7 @@
if (!ModuleEntry) {
// Allocate a new module.
ModuleFile *New = new ModuleFile(Type, Generation);
+ New->Index = Chain.size();
New->FileName = FileName.str();
New->File = Entry;
New->ImportLoc = ImportLoc;
@@ -155,22 +156,26 @@
// to seed the queue.
SmallVector<ModuleFile *, 4> Queue;
Queue.reserve(N);
- llvm::DenseMap<ModuleFile *, unsigned> UnusedIncomingEdges;
+ llvm::SmallVector<unsigned, 4> UnusedIncomingEdges;
+ UnusedIncomingEdges.reserve(size());
for (ModuleIterator M = begin(), MEnd = end(); M != MEnd; ++M) {
if (unsigned Size = (*M)->ImportedBy.size())
- UnusedIncomingEdges[*M] = Size;
- else
+ UnusedIncomingEdges.push_back(Size);
+ else {
+ UnusedIncomingEdges.push_back(0);
Queue.push_back(*M);
+ }
}
-
- llvm::SmallPtrSet<ModuleFile *, 4> Skipped;
+
+ llvm::SmallVector<bool, 4> Skipped(size(), false);
unsigned QueueStart = 0;
while (QueueStart < Queue.size()) {
ModuleFile *CurrentModule = Queue[QueueStart++];
// Check whether this module should be skipped.
- if (Skipped.count(CurrentModule))
+ if (Skipped[CurrentModule->Index])
continue;
+ Skipped[CurrentModule->Index] = true;
if (Visitor(*CurrentModule, UserData)) {
// The visitor has requested that cut off visitation of any
@@ -179,7 +184,7 @@
// incoming edges (which is impossible otherwise).
SmallVector<ModuleFile *, 4> Stack;
Stack.push_back(CurrentModule);
- Skipped.insert(CurrentModule);
+ Skipped[CurrentModule->Index] = true;
while (!Stack.empty()) {
ModuleFile *NextModule = Stack.back();
Stack.pop_back();
@@ -187,11 +192,13 @@
// For any module that this module depends on, push it on the
// stack (if it hasn't already been marked as visited).
for (llvm::SetVector<ModuleFile *>::iterator
- M = NextModule->Imports.begin(),
- MEnd = NextModule->Imports.end();
+ M = NextModule->Imports.begin(),
+ MEnd = NextModule->Imports.end();
M != MEnd; ++M) {
- if (Skipped.insert(*M))
+ if (!Skipped[(*M)->Index]) {
Stack.push_back(*M);
+ Skipped[(*M)->Index] = true;
+ }
}
}
continue;
@@ -199,15 +206,16 @@
// For any module that this module depends on, push it on the
// stack (if it hasn't already been marked as visited).
- for (llvm::SetVector<ModuleFile *>::iterator M = CurrentModule->Imports.begin(),
- MEnd = CurrentModule->Imports.end();
+ for (llvm::SetVector<ModuleFile *>::iterator
+ M = CurrentModule->Imports.begin(),
+ MEnd = CurrentModule->Imports.end();
M != MEnd; ++M) {
// Remove our current module as an impediment to visiting the
// module we depend on. If we were the last unvisited module
// that depends on this particular module, push it into the
// queue to be visited.
- unsigned &NumUnusedEdges = UnusedIncomingEdges[*M];
+ unsigned &NumUnusedEdges = UnusedIncomingEdges[(*M)->Index];
if (NumUnusedEdges && (--NumUnusedEdges == 0))
Queue.push_back(*M);
}
@@ -219,18 +227,19 @@
bool (*Visitor)(ModuleFile &M, bool Preorder,
void *UserData),
void *UserData,
- llvm::SmallPtrSet<ModuleFile *, 4> &Visited) {
+ SmallVectorImpl<bool> &Visited) {
// Preorder visitation
if (Visitor(M, /*Preorder=*/true, UserData))
return true;
// Visit children
for (llvm::SetVector<ModuleFile *>::iterator IM = M.Imports.begin(),
- IMEnd = M.Imports.end();
+ IMEnd = M.Imports.end();
IM != IMEnd; ++IM) {
- if (!Visited.insert(*IM))
+ if (Visited[(*IM)->Index])
continue;
-
+ Visited[(*IM)->Index] = true;
+
if (visitDepthFirst(**IM, Visitor, UserData, Visited))
return true;
}
@@ -242,11 +251,12 @@
void ModuleManager::visitDepthFirst(bool (*Visitor)(ModuleFile &M, bool Preorder,
void *UserData),
void *UserData) {
- llvm::SmallPtrSet<ModuleFile *, 4> Visited;
+ SmallVector<bool, 16> Visited(size(), false);
for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
- if (!Visited.insert(Chain[I]))
+ if (Visited[Chain[I]->Index])
continue;
-
+ Visited[Chain[I]->Index] = true;
+
if (::visitDepthFirst(*Chain[I], Visitor, UserData, Visited))
return;
}
More information about the cfe-commits
mailing list