[PATCH] D27897: [Modules] Enable the Modules language feature by default for the Clang builtins.

Elad Cohen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 17 22:56:04 PST 2016


eladcohen created this revision.
eladcohen added reviewers: rsmith, rnk, zvi, chandlerc, thakis.
eladcohen added a subscriber: cfe-commits.

The motivation is to reduce the compile time of the Clang intrinsics header files. Furthermore, this should allow us to remove the feature guards from these headers D27896 <https://reviews.llvm.org/D27896> and solve some MSVC compatibility issues regarding intrinsics.

See also the threads "The intrinsics headers (especially avx512) are too big. What to do about it?" and "clang-cl's <intrin.h>, _tzcnt_u32, and compatibility with MSVC's <intrin.h>" in cfe-dev.


https://reviews.llvm.org/D27897

Files:
  lib/Driver/Tools.cpp
  test/Driver/modules.mm


Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5615,11 +5615,26 @@
     CmdArgs.push_back("-fcoroutines-ts");
   }
 
+  // If modules is not asked for explicitly enable it exclusively
+  // for the Clang builtins in applicable cases.
+  bool HaveBuiltinModules = !Args.hasArg(options::OPT_fno_implicit_modules) &&
+                            !Args.hasArg(options::OPT_fmodules) &&
+                            !Args.hasArg(options::OPT_include) &&
+                            !isa<PreprocessJobAction>(JA) &&
+                            ((JA.getType() == types::TY_LLVM_BC) ||
+                             (JA.getType() == types::TY_LLVM_IR) ||
+                             (JA.getType() == types::TY_LTO_BC) ||
+                             (JA.getType() == types::TY_LTO_IR) ||
+                             (JA.getType() == types::TY_PP_Asm) ||
+                             (JA.getType() == types::TY_Object) ||
+                             (JA.getType() == types::TY_AST));
+
   // -fmodules enables the use of precompiled modules (off by default).
   // Users can pass -fno-cxx-modules to turn off modules support for
   // C++/Objective-C++ programs.
   bool HaveClangModules = false;
-  if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) {
+  if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules,
+                   HaveBuiltinModules)) {
     bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
                                      options::OPT_fno_cxx_modules, true);
     if (AllowedInCXX || !types::isCXX(InputType)) {
@@ -5635,9 +5650,11 @@
   }
 
   // -fmodule-maps enables implicit reading of module map files. By default,
-  // this is enabled if we are using Clang's flavor of precompiled modules.
+  // this is enabled if Clang's flavor of precompiled modules is explicitly
+  // enabled.
   if (Args.hasFlag(options::OPT_fimplicit_module_maps,
-                   options::OPT_fno_implicit_module_maps, HaveClangModules)) {
+                   options::OPT_fno_implicit_module_maps,
+                   HaveClangModules && !HaveBuiltinModules)) {
     CmdArgs.push_back("-fimplicit-module-maps");
   }
 
@@ -5701,7 +5718,8 @@
 
   // -fbuiltin-module-map can be used to load the clang
   // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
+  if (Args.hasArg(options::OPT_fbuiltin_module_map) ||
+	  (HaveClangModules && HaveBuiltinModules)) {
     SmallString<128> BuiltinModuleMap(getToolChain().getDriver().ResourceDir);
     llvm::sys::path::append(BuiltinModuleMap, "include");
     llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
Index: test/Driver/modules.mm
===================================================================
--- test/Driver/modules.mm
+++ test/Driver/modules.mm
@@ -1,5 +1,8 @@
-// RUN: %clang -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
-// RUN: %clang -fcxx-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
+// RUN: %clang -### %s 2>&1 | FileCheck -check-prefix=CHECK-DEFAULT-MODULES %s
+// CHECK-DEFAULT-MODULES: -fmodules
+
+// RUN: %clang -fno-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
+// RUN: %clang -fno-cxx-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
 // RUN: %clang -fmodules -fno-cxx-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
 // CHECK-NO-MODULES-NOT: -fmodules
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27897.81874.patch
Type: text/x-patch
Size: 3535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161218/4a367447/attachment.bin>


More information about the cfe-commits mailing list