[cfe-dev] [RFC] Clearing Clang AST before running backend optimizations/codegen to save memory

Arthur Eubanks via cfe-dev cfe-dev at lists.llvm.org
Fri Sep 17 14:30:30 PDT 2021

We keep around the Clang AST when we do backend optimizations on the IR.
This causes the peak memory usage to be more than necessary since (I
believe) generally we don't need the Clang AST when running optimizations.
This gives us more room to work with things like caching analyses, at least
for frontend compilations.

Measuring the effects of this when building LLVM's PassBuilder.cpp (longest
LLVM file to compile), I measured a drop of peak memory usage
(/usr/bin/time's max rss) from ~1.3-1.4G to ~1.0G.

There are still a couple issues I haven't dug too deeply into yet, mostly
to do with cleaning things up when freeing memory, so right now it's only
enabled with -disable-free which works around those issues. Most clang
tests pass with this patch; there are a couple things that crash (e.g.
-Rpass, clang interpreter) where we can investigate further or just disable
this feature.

Prototype: https://reviews.llvm.org/D109781

Any concerns with this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210917/8180ef8d/attachment.html>

More information about the cfe-dev mailing list