[clang] 1fb24fe - Reland [clang] Pass -clear-ast-before-backend in Clang::ConstructJob()
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 18 09:11:53 PDT 2021
Author: Arthur Eubanks
Date: 2021-10-18T09:08:16-07:00
New Revision: 1fb24fe85a19ae71b00875ff6c96ef1831dcf7e3
URL: https://github.com/llvm/llvm-project/commit/1fb24fe85a19ae71b00875ff6c96ef1831dcf7e3
DIFF: https://github.com/llvm/llvm-project/commit/1fb24fe85a19ae71b00875ff6c96ef1831dcf7e3.diff
LOG: 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
Differential Revision: https://reviews.llvm.org/D111270
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Interpreter/Interpreter.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index d2c08412d5932..83afbc3952d84 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4660,6 +4660,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// cleanup.
if (!C.isForDiagnostics())
CmdArgs.push_back("-disable-free");
+ CmdArgs.push_back("-clear-ast-before-backend");
#ifdef NDEBUG
const bool IsAssertBuild = false;
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 02b3025297b67..d14940d2e1321 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -113,6 +113,10 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
Clang->getTarget().adjust(Clang->getDiagnostics(), Clang->getLangOpts());
+ // Don't clear the AST before backend codegen since we do codegen multiple
+ // times, reusing the same AST.
+ Clang->getCodeGenOpts().ClearASTBeforeBackend = false;
+
return std::move(Clang);
}
More information about the cfe-commits
mailing list