diff options
author | Arthur Eubanks <aeubanks@google.com> | 2021-10-13 11:51:45 -0700 |
---|---|---|
committer | Arthur Eubanks <aeubanks@google.com> | 2021-10-14 13:43:53 -0700 |
commit | d0a5f61c4f6fccec87fd5207e3fcd9502dd59854 (patch) | |
tree | 56eb2f77baa8d6efa97385de5d18c5c42a9fbfbc /clang/lib/CodeGen/CodeGenAction.cpp | |
parent | 21abe21280585401ce13d3217d051aa4bcfcc584 (diff) | |
download | llvm-d0a5f61c4f6fccec87fd5207e3fcd9502dd59854.zip llvm-d0a5f61c4f6fccec87fd5207e3fcd9502dd59854.tar.gz llvm-d0a5f61c4f6fccec87fd5207e3fcd9502dd59854.tar.bz2 |
[clang] Support -clear-ast-before-backend without -disable-free
Previously without -disable-free, -clear-ast-before-backend would crash in ~ASTContext() due to various reasons.
This works around that by doing a lot of the cleanup ahead of the destructor so that the destructor doesn't actually do any manual cleanup if we've already cleaned up beforehand.
This actually does save a measurable amount of memory with -clear-ast-before-backend, although at an almost unnoticeable runtime cost:
https://llvm-compile-time-tracker.com/compare.php?from=5d755b32f2775b9219f6d6e2feda5e1417dc993b&to=58ef1c7ad7e2ad45f9c97597905a8cf05a26258c&stat=max-rss
Previously we weren't doing any cleanup with -disable-free, so I tried measuring the impact of always doing the cleanup and didn't measure anything noticeable on llvm-compile-time-tracker.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D111767
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 4ca34db..881e30a 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -351,10 +351,16 @@ namespace clang { } } - // FIXME: Fix cleanup issues with clearing the AST when we properly free - // things. - if (CodeGenOpts.DisableFree && CodeGenOpts.ClearASTBeforeBackend) + if (CodeGenOpts.ClearASTBeforeBackend) { + // Access to the AST is no longer available after this. + // Other things that the ASTContext manages are still available, e.g. + // the SourceManager. It'd be nice if we could separate out all the + // things in ASTContext used after this point and null out the + // ASTContext, but too many various parts of the ASTContext are still + // used in various parts. + C.cleanup(); C.getAllocator().Reset(); + } EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef()); |