[flang-commits] [flang] [flang] Minor speed-up to module file parsing (PR #152178)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Aug 5 10:06:16 PDT 2025
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/152178
Module files shouldn't ever produce parsing errors, and if they did in the case of a badly-generated module file, the compiler will notice and crash. So we can run the parser on module files with message deferral enabled, and that saves time that would otherwise be spent generating messages on failed parsing alternatives that are discarded anyway when backtracking. It's not a big savings (single digit percentage on overall compilation time for a big application with lots of modules), but worth doing.
>From c5afdb2ef2ce201244e5bf2f8191cb5e38d9513c Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Mon, 4 Aug 2025 11:40:39 -0700
Subject: [PATCH] [flang] Minor speed-up to module file parsing
Module files shouldn't ever produce parsing errors, and if they
did in the case of a badly-generated module file, the compiler will
notice and crash. So we can run the parser on module files with
message deferral enabled, and that saves time that would otherwise
be spent generating messages on failed parsing alternatives that
are discarded anyway when backtracking. It's not a big savings
(single digit percentage on overall compilation time for a big
application with lots of modules), but worth doing.
---
flang/lib/Parser/parsing.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/flang/lib/Parser/parsing.cpp b/flang/lib/Parser/parsing.cpp
index 93737d99567dd..ceea74766d7ea 100644
--- a/flang/lib/Parser/parsing.cpp
+++ b/flang/lib/Parser/parsing.cpp
@@ -285,6 +285,8 @@ void Parsing::Parse(llvm::raw_ostream &out) {
.set_log(&log_);
ParseState parseState{cooked()};
parseState.set_inFixedForm(options_.isFixedForm).set_userState(&userState);
+ // Don't bother managing message buffers when parsing module files.
+ parseState.set_deferMessages(options_.isModuleFile);
parseTree_ = program.Parse(parseState);
CHECK(
!parseState.anyErrorRecovery() || parseState.messages().AnyFatalError());
More information about the flang-commits
mailing list