Skip to content

Commit 6966e56

Browse files
Reduce memory usage in AST parent map generation by only keeping pointers in the cache
1 parent c017cdf commit 6966e56

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

clang/lib/AST/ParentMapContext.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "clang/AST/ParentMapContext.h"
15-
#include "clang/AST/RecursiveASTVisitor.h"
1615
#include "clang/AST/Decl.h"
1716
#include "clang/AST/Expr.h"
17+
#include "clang/AST/RecursiveASTVisitor.h"
1818
#include "clang/AST/TemplateBase.h"
19+
#include "llvm/ADT/SmallPtrSet.h"
1920

2021
using namespace clang;
2122

@@ -69,17 +70,22 @@ class ParentMapContext::ParentMap {
6970
for (; N > 0; --N)
7071
push_back(Value);
7172
}
72-
bool contains(const DynTypedNode &Value) {
73-
return Seen.contains(Value);
73+
bool contains(const DynTypedNode &Value) const {
74+
const void *Identity = Value.getMemoizationData();
75+
assert(Identity);
76+
return Dedup.contains(Identity);
7477
}
7578
void push_back(const DynTypedNode &Value) {
76-
if (!Value.getMemoizationData() || Seen.insert(Value).second)
79+
const void *Identity = Value.getMemoizationData();
80+
if (!Identity || Dedup.insert(Identity).second) {
7781
Items.push_back(Value);
82+
}
7883
}
7984
llvm::ArrayRef<DynTypedNode> view() const { return Items; }
85+
8086
private:
81-
llvm::SmallVector<DynTypedNode, 2> Items;
82-
llvm::SmallDenseSet<DynTypedNode, 2> Seen;
87+
std::vector<DynTypedNode> Items;
88+
llvm::SmallPtrSet<const void *, 2> Dedup;
8389
};
8490

8591
/// Maps from a node to its parents. This is used for nodes that have

0 commit comments

Comments
 (0)