@@ -208,6 +208,12 @@ class ASTContext final {
208
208
DiagnosticEngine &Diags);
209
209
~ASTContext ();
210
210
211
+ // / Optional table of counters to report, nullptr when not collecting.
212
+ // /
213
+ // / This must be initialized early so that Allocate() doesn't try to access
214
+ // / it before being set to null.
215
+ UnifiedStatsReporter *Stats = nullptr ;
216
+
211
217
// / \brief The language options used for translation.
212
218
LangOptions &LangOpts;
213
219
@@ -261,12 +267,6 @@ class ASTContext final {
261
267
// / Cache of remapped types (useful for diagnostics).
262
268
llvm::StringMap<Type> RemappedTypes;
263
269
264
- // / Optional table of counters to report, nullptr when not collecting.
265
- UnifiedStatsReporter *Stats = nullptr ;
266
-
267
- // / Set a new stats reporter.
268
- void setStatsReporter (UnifiedStatsReporter *stats);
269
-
270
270
private:
271
271
// / \brief The current generation number, which reflects the number of
272
272
// / times that external modules have been loaded.
@@ -287,11 +287,11 @@ class ASTContext final {
287
287
// / Cache of module names that fail the 'canImport' test in this context.
288
288
llvm::SmallPtrSet<Identifier, 8 > FailedModuleImportNames;
289
289
290
- public:
291
290
// / \brief Retrieve the allocator for the given arena.
292
291
llvm::BumpPtrAllocator &
293
292
getAllocator (AllocationArena arena = AllocationArena::Permanent) const ;
294
293
294
+ public:
295
295
// / Allocate - Allocate memory from the ASTContext bump pointer.
296
296
void *Allocate (unsigned long bytes, unsigned alignment,
297
297
AllocationArena arena = AllocationArena::Permanent) const {
@@ -300,7 +300,9 @@ class ASTContext final {
300
300
301
301
if (LangOpts.UseMalloc )
302
302
return AlignedAlloc (bytes, alignment);
303
-
303
+
304
+ if (arena == AllocationArena::Permanent && Stats)
305
+ Stats->getFrontendCounters ().NumASTBytesAllocated += bytes;
304
306
return getAllocator (arena).Allocate (bytes, alignment);
305
307
}
306
308
@@ -395,6 +397,9 @@ class ASTContext final {
395
397
// / Retrive the syntax node memory manager for this context.
396
398
llvm::IntrusiveRefCntPtr<syntax::SyntaxArena> getSyntaxArena () const ;
397
399
400
+ // / Set a new stats reporter.
401
+ void setStatsReporter (UnifiedStatsReporter *stats);
402
+
398
403
// / Retrieve the lazy resolver for this context.
399
404
LazyResolver *getLazyResolver () const ;
400
405
0 commit comments