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

2017-01-03 Thread Elad Cohen via Phabricator via cfe-commits
eladcohen added a comment.

ping


https://reviews.llvm.org/D27897



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-12-17 Thread Elad Cohen via Phabricator via cfe-commits
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  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 , _tzcnt_u32, and compatibility 
with MSVC's " 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(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
 


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(JA) &&
+((JA.getType() == types::TY_LLVM_BC) ||
+ (JA.getType() == types::TY_LLVM_IR) ||
+ (JA.getType() ==