llunak updated this revision to Diff 229722.
llunak added a comment.
It turns out that this patch may introduce unwanted changes, specifically it
can cause err_specialization_after_instantiation if the specialization is done
in a source file but needed already by code in the PCH. But this seems to be
rare (I've encountered it only after building the Skia library with
put-everything-in-the-PCH), is easy to avoid (PCHs often need little tweaks
anyway) and the performance gain is very much worth it.
Still, this means there should be an option to enable this. Done in this
version of the patch. I don't know how to handle tests for it, pretty much all
the tests pass as said above, but it seems a bit silly to duplicate all the
PCH-related ones to also use the flag.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69585/new/
https://reviews.llvm.org/D69585
Files:
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/CC1Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/Sema.cpp
Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -981,6 +981,14 @@
LateParsedInstantiations.begin(),
LateParsedInstantiations.end());
LateParsedInstantiations.clear();
+
+ // FIXME: Instantiating implicit templates already in the PCH breaks some
+ // OpenMP-specific code paths, see https://reviews.llvm.org/D69585 .
+ if(LangOpts.PCHInstantiateTemplates && !LangOpts.OpenMP) {
+ llvm::TimeTraceScope TimeScope("PerformPendingInstantiations",
+ StringRef(""));
+ PerformPendingInstantiations();
+ }
}
DiagnoseUnterminatedPragmaPack();
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3223,6 +3223,7 @@
Opts.CompleteMemberPointers = Args.hasArg(OPT_fcomplete_member_pointers);
Opts.BuildingPCHWithObjectFile = Args.hasArg(OPT_building_pch_with_obj);
+ Opts.PCHInstantiateTemplates = Args.hasArg(OPT_pch_instantiate_templates);
}
static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
Index: clang/include/clang/Driver/CC1Options.td
===================================================================
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -672,6 +672,8 @@
HelpText<"Disable inclusion of timestamp in precompiled headers">;
def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">,
HelpText<"This compilation is part of building a PCH with corresponding
object file.">;
+def pch_instantiate_templates : Flag<["-"], "pch-instantiate-templates">,
+ HelpText<"Perform pending template instantiations already while building the
PCH.">;
def aligned_alloc_unavailable : Flag<["-"], "faligned-alloc-unavailable">,
HelpText<"Aligned allocation/deallocation functions are unavailable">;
Index: clang/include/clang/Basic/LangOptions.def
===================================================================
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -160,6 +160,7 @@
BENIGN_LANGOPT(CompilingPCH, 1, 0, "building a pch")
BENIGN_LANGOPT(BuildingPCHWithObjectFile, 1, 0, "building a pch which has a
corresponding object file")
BENIGN_LANGOPT(CacheGeneratedPCH, 1, 0, "cache generated PCH files in memory")
+BENIGN_LANGOPT(PCHInstantiateTemplates, 1, 0, "performing pending template
instantiations already while building a pch")
COMPATIBLE_LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module
uses")
BENIGN_LANGOPT(ModulesSearchAll , 1, 1, "searching even non-imported modules
to find unresolved references")
COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "requiring declaration of
module uses and all headers to be in modules")
Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -981,6 +981,14 @@
LateParsedInstantiations.begin(),
LateParsedInstantiations.end());
LateParsedInstantiations.clear();
+
+ // FIXME: Instantiating implicit templates already in the PCH breaks some
+ // OpenMP-specific code paths, see https://reviews.llvm.org/D69585 .
+ if(LangOpts.PCHInstantiateTemplates && !LangOpts.OpenMP) {
+ llvm::TimeTraceScope TimeScope("PerformPendingInstantiations",
+ StringRef(""));
+ PerformPendingInstantiations();
+ }
}
DiagnoseUnterminatedPragmaPack();
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3223,6 +3223,7 @@
Opts.CompleteMemberPointers = Args.hasArg(OPT_fcomplete_member_pointers);
Opts.BuildingPCHWithObjectFile = Args.hasArg(OPT_building_pch_with_obj);
+ Opts.PCHInstantiateTemplates = Args.hasArg(OPT_pch_instantiate_templates);
}
static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
Index: clang/include/clang/Driver/CC1Options.td
===================================================================
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -672,6 +672,8 @@
HelpText<"Disable inclusion of timestamp in precompiled headers">;
def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">,
HelpText<"This compilation is part of building a PCH with corresponding object file.">;
+def pch_instantiate_templates : Flag<["-"], "pch-instantiate-templates">,
+ HelpText<"Perform pending template instantiations already while building the PCH.">;
def aligned_alloc_unavailable : Flag<["-"], "faligned-alloc-unavailable">,
HelpText<"Aligned allocation/deallocation functions are unavailable">;
Index: clang/include/clang/Basic/LangOptions.def
===================================================================
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -160,6 +160,7 @@
BENIGN_LANGOPT(CompilingPCH, 1, 0, "building a pch")
BENIGN_LANGOPT(BuildingPCHWithObjectFile, 1, 0, "building a pch which has a corresponding object file")
BENIGN_LANGOPT(CacheGeneratedPCH, 1, 0, "cache generated PCH files in memory")
+BENIGN_LANGOPT(PCHInstantiateTemplates, 1, 0, "performing pending template instantiations already while building a pch")
COMPATIBLE_LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses")
BENIGN_LANGOPT(ModulesSearchAll , 1, 1, "searching even non-imported modules to find unresolved references")
COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "requiring declaration of module uses and all headers to be in modules")
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits