Skip to content

Commit 47eb99a

Browse files
committed
[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. Differential Revision: https://reviews.llvm.org/D111270
1 parent ccbfcfd commit 47eb99a

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,6 +4660,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
46604660
// cleanup.
46614661
if (!C.isForDiagnostics())
46624662
CmdArgs.push_back("-disable-free");
4663+
CmdArgs.push_back("-clear-ast-before-backend");
46634664

46644665
#ifdef NDEBUG
46654666
const bool IsAssertBuild = false;

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
113113

114114
Clang->getTarget().adjust(Clang->getDiagnostics(), Clang->getLangOpts());
115115

116+
// Don't clear the AST before backend codegen since we do codegen multiple
117+
// times, reusing the same AST.
118+
Clang->getCodeGenOpts().ClearASTBeforeBackend = false;
119+
116120
return std::move(Clang);
117121
}
118122

0 commit comments

Comments
 (0)