Reland [clang] Pass -clear-ast-before-backend in Clang::ConstructJob()
authorArthur Eubanks <aeubanks@google.com>
Wed, 6 Oct 2021 20:57:29 +0000 (13:57 -0700)
committerArthur Eubanks <aeubanks@google.com>
Thu, 21 Oct 2021 16:25:53 +0000 (09:25 -0700)
commit19b07ec00062daffcb2fb132f4ac0f2484ff44fa
tree30f3ed79b51c15494ecb0fdb436ecda0097be18e
parent92673fad66f449f63acc76dfbb5e0bf05978663b
Reland [clang] Pass -clear-ast-before-backend in Clang::ConstructJob()

This clears the memory used for the Clang AST before we run LLVM passes.

https://llvm-compile-time-tracker.com/compare.php?from=d0a5f61c4f6fccec87fd5207e3fcd9502dd59854&to=b7437fee79e04464dd968e1a29185495f3590481&stat=max-rss
shows significant memory savings with no slowdown (in fact -O0 slightly speeds up).

For more background, see
https://lists.llvm.org/pipermail/cfe-dev/2021-September/068930.html.

Turn this off for the interpreter since it does codegen multiple times.

Relanding with fix for -print-stats: D111973

Relanding with fix for plugins: D112190

If you'd like to use this even with plugins, consider using the features
introduced in D112096.

This can be turned off with -Xclang -no-clear-ast-before-backend.

Differential Revision: https://reviews.llvm.org/D111270
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Interpreter/Interpreter.cpp