From 337c8c682f2e5c55f6ed66fa770602c95e7b223b Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Wed, 12 Feb 2014 10:33:14 +0000 Subject: [PATCH] Add an option to allow Clang verify source files for a module only once during the build When Clang loads the module, it verifies the user source files that the module was built from. If any file was changed, the module is rebuilt. There are two problems with this: 1. correctness: we don't verify system files (there are too many of them, and stat'ing all of them would take a lot of time); 2. performance: the same module file is verified again and again during a single build. This change allows the build system to optimize source file verification. The idea is based on the fact that while the project is being built, the source files don't change. This allows us to verify the module only once during a single build session. The build system passes a flag, -fbuild-session-timestamp=, to inform Clang of the time when the build started. The build system also requests to enable this feature by passing -fmodules-validate-once-per-build-session. If these flags are not passed, the behavior is not changed. When Clang verifies the module the first time, it writes out a timestamp file. Then, when Clang loads the module the second time, it finds a timestamp file, so it can compare the verification timestamp of the module with the time when the build started. If the verification timestamp is too old, the module is verified again, and the timestamp file is updated. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201224 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang-c/Index.h | 2 +- include/clang/Basic/DiagnosticDriverKinds.td | 4 ++ include/clang/Driver/Options.td | 7 +++ include/clang/Frontend/Utils.h | 11 +++++ include/clang/Lex/HeaderSearchOptions.h | 15 +++++- include/clang/Serialization/Module.h | 10 ++++ lib/Driver/Tools.cpp | 10 ++++ lib/Frontend/CompilerInstance.cpp | 25 +++++----- lib/Frontend/CompilerInvocation.cpp | 26 +++++++++-- lib/Serialization/ASTReader.cpp | 49 ++++++++++++++++++-- lib/Serialization/ModuleManager.cpp | 10 ++++ test/Driver/modules.m | 10 ++++ tools/c-index-test/c-index-test.c | 10 ++++ tools/libclang/CMakeLists.txt | 1 + tools/libclang/libclang.exports | 1 + 15 files changed, 166 insertions(+), 25 deletions(-) diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index d98c1e66fd..0f15216900 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -30,7 +30,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 21 +#define CINDEX_VERSION_MINOR 22 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 10000) \ diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index dbc5ce994c..cc7d8969f3 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -166,4 +166,8 @@ def err_analyzer_config_no_value : Error< "analyzer-config option '%0' has a key but no value">; def err_analyzer_config_multiple_values : Error< "analyzer-config option '%0' should contain only one '='">; + +def err_drv_modules_validate_once_requires_timestamp : Error< + "option '-fmodules-validate-once-per-build-session' requires " + "'-fbuild-session-timestamp='">; } diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 52cd9efdd4..ed0fc0315e 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -581,6 +581,13 @@ def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, Group">, HelpText<"Specify the interval (in seconds) after which a module file will be considered unused">; +def fbuild_session_timestamp : Joined<["-"], "fbuild-session-timestamp=">, + Group, Flags<[CC1Option]>, MetaVarName<"