]> granicus.if.org Git - clang/commitdiff
Modular Codegen: Separate flags for function and debug info support
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 12 Apr 2017 20:58:33 +0000 (20:58 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 12 Apr 2017 20:58:33 +0000 (20:58 +0000)
This allows using and testing these two features separately. (noteably,
debug info is, so far as I know, always a win (basically). But function
modular codegen is currently a loss for highly optimized code - where
most of the linkonce_odr definitions are optimized away, so providing
weak_odr definitions is only overhead)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300104 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.def
include/clang/Driver/CC1Options.td
lib/Frontend/CompilerInvocation.cpp
lib/Lex/ModuleMap.cpp
lib/Serialization/ASTWriter.cpp
lib/Serialization/ASTWriterDecl.cpp
test/Modules/Inputs/codegen-flags/foo.h [new file with mode: 0644]
test/Modules/Inputs/codegen-flags/foo.modulemap [new file with mode: 0644]
test/Modules/Inputs/codegen-flags/use.cpp [new file with mode: 0644]
test/Modules/codegen-flags.test [new file with mode: 0644]
test/Modules/codegen.test

index 1a142b8b746549b7bae6558574d9518ebb62abc9..c8e1972997547ece06eb4a6eb608ab8b0102fa6b 100644 (file)
@@ -201,7 +201,8 @@ LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(NewAlignOverride  , 32, 0, "maximum alignment guaranteed by '::operator new(size_t)'")
 LANGOPT(ConceptsTS , 1, 0, "enable C++ Extensions for Concepts")
-BENIGN_LANGOPT(ModularCodegen , 1, 0, "Modular codegen")
+BENIGN_LANGOPT(ModulesCodegen , 1, 0, "Modules code generation")
+BENIGN_LANGOPT(ModulesDebugInfo , 1, 0, "Modules debug info")
 BENIGN_LANGOPT(ElideConstructors , 1, 1, "C++ copy constructor elision")
 BENIGN_LANGOPT(DumpRecordLayouts , 1, 0, "dumping the layout of IRgen'd records")
 BENIGN_LANGOPT(DumpRecordLayoutsSimple , 1, 0, "dumping the layout of IRgen'd records in a simple form")
index d35844c1f1f122d89e45e1504116960caf823197..ba09bccfe1c537fda7d9779601a247bea275bcf0 100644 (file)
@@ -436,10 +436,14 @@ def fmodules_local_submodule_visibility :
   Flag<["-"], "fmodules-local-submodule-visibility">,
   HelpText<"Enforce name visibility rules across submodules of the same "
            "top-level module.">;
-def fmodule_codegen :
+def fmodules_codegen :
   Flag<["-"], "fmodules-codegen">,
   HelpText<"Generate code for uses of this module that assumes an explicit "
            "object file will be built for the module">;
+def fmodules_debuginfo :
+  Flag<["-"], "fmodules-debuginfo">,
+  HelpText<"Generate debug info for types in an object file built from this "
+           "module and do not generate them elsewhere">;
 def fmodule_format_EQ : Joined<["-"], "fmodule-format=">,
   HelpText<"Select the container format for clang modules and PCH. "
            "Supported options are 'raw' and 'obj'.">;
index b9c24ab6c00332481e59d359ecd172cd23462f36..1ebaf8f4d8bec3e439081b79bb3104d7422345f0 100644 (file)
@@ -2017,7 +2017,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
       Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse;
   Opts.ModulesLocalVisibility =
       Args.hasArg(OPT_fmodules_local_submodule_visibility) || Opts.ModulesTS;
-  Opts.ModularCodegen = Args.hasArg(OPT_fmodule_codegen);
+  Opts.ModulesCodegen = Args.hasArg(OPT_fmodules_codegen);
+  Opts.ModulesDebugInfo = Args.hasArg(OPT_fmodules_debuginfo);
   Opts.ModulesSearchAll = Opts.Modules &&
     !Args.hasArg(OPT_fno_modules_search_all) &&
     Args.hasArg(OPT_fmodules_search_all);
index 61ad5948cd50d5c1701b3fc576649878ca369fcd..4f3db8dd6436037cda9f8b2fa575d5e941c6a258 100644 (file)
@@ -91,7 +91,6 @@ ModuleMap::ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags,
       HeaderInfo(HeaderInfo), BuiltinIncludeDir(nullptr),
       SourceModule(nullptr), NumCreatedModules(0) {
   MMapLangOpts.LineComment = true;
-  MMapLangOpts.ModularCodegen = LangOpts.ModularCodegen;
 }
 
 ModuleMap::~ModuleMap() {
index 7dd2ca302ca6bf3c28cd6a1ad3cc5157b168c3a5..d52c4fd770634dec58ecc4b8db2ef0aa8e50e13c 100644 (file)
@@ -4782,7 +4782,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
   if (!EagerlyDeserializedDecls.empty())
     Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls);
 
-  if (Context.getLangOpts().ModularCodegen)
+  if (!ModularCodegenDecls.empty())
     Stream.EmitRecord(MODULAR_CODEGEN_DECLS, ModularCodegenDecls);
 
   // Write the record containing tentative definitions.
@@ -5788,11 +5788,10 @@ void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
 
   // getODRHash will compute the ODRHash if it has not been previously computed.
   Record->push_back(D->getODRHash());
-
-  bool ModularCodegen = Writer->Context->getLangOpts().ModularCodegen &&
-                        Writer->WritingModule && !D->isDependentType();
-  Record->push_back(ModularCodegen);
-  if (ModularCodegen)
+  bool ModulesDebugInfo = Writer->Context->getLangOpts().ModulesDebugInfo &&
+                          Writer->WritingModule && !D->isDependentType();
+  Record->push_back(ModulesDebugInfo);
+  if (ModulesDebugInfo)
     Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D));
 
   // IsLambda bit is already saved.
index 8196c8d02cd28857c7641f55a27f7cc2a7a0422b..812cd9e916d918490de5ff23294c3afd2920f3b7 100644 (file)
@@ -2228,10 +2228,10 @@ void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
   Writer->ClearSwitchCaseIDs();
 
   assert(FD->doesThisDeclarationHaveABody());
-  bool ModularCodegen = Writer->Context->getLangOpts().ModularCodegen &&
+  bool ModulesCodegen = Writer->Context->getLangOpts().ModulesCodegen &&
                         Writer->WritingModule && !FD->isDependentContext();
-  Record->push_back(ModularCodegen);
-  if (ModularCodegen)
+  Record->push_back(ModulesCodegen);
+  if (ModulesCodegen)
     Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
   if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
     Record->push_back(CD->getNumCtorInitializers());
diff --git a/test/Modules/Inputs/codegen-flags/foo.h b/test/Modules/Inputs/codegen-flags/foo.h
new file mode 100644 (file)
index 0000000..7b9c1cd
--- /dev/null
@@ -0,0 +1,4 @@
+struct foo {
+};
+inline void f1() {
+}
diff --git a/test/Modules/Inputs/codegen-flags/foo.modulemap b/test/Modules/Inputs/codegen-flags/foo.modulemap
new file mode 100644 (file)
index 0000000..2e095d2
--- /dev/null
@@ -0,0 +1 @@
+module foo { header "foo.h" }
diff --git a/test/Modules/Inputs/codegen-flags/use.cpp b/test/Modules/Inputs/codegen-flags/use.cpp
new file mode 100644 (file)
index 0000000..378ff31
--- /dev/null
@@ -0,0 +1,5 @@
+#include "foo.h"
+void use() {
+  f1();
+  foo f;
+}
diff --git a/test/Modules/codegen-flags.test b/test/Modules/codegen-flags.test
new file mode 100644 (file)
index 0000000..4cc62e8
--- /dev/null
@@ -0,0 +1,25 @@
+RUN: rm -rf %t
+REQUIRES: x86-registered-target
+
+RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen-flags/foo.modulemap -o %t/foo-cg.pcm
+RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-debuginfo -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen-flags/foo.modulemap -o %t/foo-di.pcm
+
+RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - %t/foo-cg.pcm | FileCheck --check-prefix=CG %s
+RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - %t/foo-di.pcm | FileCheck --check-prefix=DI %s
+
+RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - -fmodules -fmodule-file=%t/foo-cg.pcm %S/Inputs/codegen-flags/use.cpp | FileCheck --check-prefix=CG-USE %s
+RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - -fmodules -fmodule-file=%t/foo-di.pcm %S/Inputs/codegen-flags/use.cpp | FileCheck --check-prefix=DI-USE %s
+
+CG: define weak_odr void @_Z2f1v
+CG: DICompileUnit
+CG-NOT: DICompositeType
+
+CG-USE: declare void @_Z2f1v
+CG-USE: DICompileUnit
+CG-USE: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
+
+DI-NOT: define
+DI: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
+
+DI-USE: define linkonce_odr void @_Z2f1v
+DI-USE: = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", {{.*}}, flags: DIFlagFwdDecl
index ce252e89ebdcd55b973f7539a723e6ab2febad94..e8faa12fd942ca9680abcca2912a971d29d38f43 100644 (file)
@@ -1,7 +1,7 @@
 RUN: rm -rf %t
 REQUIRES: x86-registered-target
 
-RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
+RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -fmodules-debuginfo -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
 
 RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - %t/foo.pcm | FileCheck --check-prefix=FOO --check-prefix=BOTH %s
 RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - -fmodules -fmodule-file=%t/foo.pcm %S/Inputs/codegen/use.cpp | FileCheck --check-prefix=BOTH --check-prefix=USE %s