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

-fexclusive-builtin-modules enables the clang 'modules' feature exclusively for 
the clang intrinsic header files.

The end goal of this effort is to have this option on by default for x86 
targets so we could reduce the long compile time of the x86 intrinsic header 
files.


https://reviews.llvm.org/D25337

Files:
  docs/Modules.rst
  include/clang/Driver/Options.td
  lib/Driver/Tools.cpp
  test/CodeGen/3dnow-builtins.c
  test/CodeGen/adc-builtins.c
  test/CodeGen/adx-builtins.c
  test/CodeGen/attr-target-x86-mmx.c
  test/CodeGen/avx-builtins.c
  test/CodeGen/avx-cmp-builtins.c
  test/CodeGen/avx-shuffle-builtins.c
  test/CodeGen/avx2-builtins.c
  test/CodeGen/avx512bw-builtins.c
  test/CodeGen/avx512cdintrin.c
  test/CodeGen/avx512dq-builtins.c
  test/CodeGen/avx512er-builtins.c
  test/CodeGen/avx512f-builtins.c
  test/CodeGen/avx512ifma-builtins.c
  test/CodeGen/avx512ifmavl-builtins.c
  test/CodeGen/avx512pf-builtins.c
  test/CodeGen/avx512vbmi-builtins.c
  test/CodeGen/avx512vbmivl-builtin.c
  test/CodeGen/avx512vl-builtins.c
  test/CodeGen/avx512vlbw-builtins.c
  test/CodeGen/avx512vlcd-builtins.c
  test/CodeGen/avx512vldq-builtins.c
  test/CodeGen/bitscan-builtins.c
  test/CodeGen/bmi-builtins.c
  test/CodeGen/bmi2-builtins.c
  test/CodeGen/builtin-clflushopt.c
  test/CodeGen/f16c-builtins.c
  test/CodeGen/fma-builtins.c
  test/CodeGen/fma4-builtins.c
  test/CodeGen/fsgsbase-builtins.c
  test/CodeGen/lzcnt-builtins.c
  test/CodeGen/mmx-builtins.c
  test/CodeGen/pku.c
  test/CodeGen/popcnt-builtins.c
  test/CodeGen/prefetchw-builtins.c
  test/CodeGen/rd-builtins.c
  test/CodeGen/rdrand-builtins.c
  test/CodeGen/rtm-builtins.c
  test/CodeGen/sha-builtins.c
  test/CodeGen/sse-builtins.c
  test/CodeGen/sse2-builtins.c
  test/CodeGen/sse3-builtins.c
  test/CodeGen/sse41-builtins.c
  test/CodeGen/sse42-builtins.c
  test/CodeGen/sse4a-builtins.c
  test/CodeGen/ssse3-builtins.c
  test/CodeGen/target-builtin-error-2.c
  test/CodeGen/target-builtin-error.c
  test/CodeGen/target-builtin-noerror.c
  test/CodeGen/target-features-error-2.c
  test/CodeGen/tbm-builtins.c
  test/CodeGen/xop-builtins.c
  test/CodeGenCXX/mangle-ms-vector-types.cpp
  test/Driver/modules.m
  test/Driver/modules.mm
  test/Headers/x86-intrinsics-headers.c
  test/Headers/x86intrin-2.c
  test/Headers/x86intrin.c
  test/Headers/x86intrin.cpp
  test/lit.cfg

Index: test/lit.cfg
===================================================================
--- test/lit.cfg
+++ test/lit.cfg
@@ -268,6 +268,12 @@
 config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
 config.substitutions.append( ('%itanium_abi_triple', makeItaniumABITriple(config.target_triple)) )
 config.substitutions.append( ('%ms_abi_triple', makeMSABITriple(config.target_triple)) )
+config.substitutions.append( ('%use_builtin_modules',
+                              ' -fmodules -fmodule-map-file=' + 
+                              getClangBuiltinIncludeDir(config.clang) +
+                              '/module.modulemap '
+                              '-fmodules-cache-path=%t_builtin_modules '
+                              '-fmodules-validate-system-headers ' ))
 
 # The host triple might not be set, at least if we're compiling clang from
 # an already installed llvm.
Index: test/Headers/x86intrin.cpp
===================================================================
--- test/Headers/x86intrin.cpp
+++ test/Headers/x86intrin.cpp
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding %s -verify
+
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding %s -verify
+
 // expected-no-diagnostics
 
 #if defined(i386) || defined(__x86_64__)
Index: test/Headers/x86intrin.c
===================================================================
--- test/Headers/x86intrin.c
+++ test/Headers/x86intrin.c
@@ -1,6 +1,11 @@
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding %s -verify
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding -fno-lax-vector-conversions %s -verify
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding -x c++ %s -verify
+
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding %s -verify
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding -fno-lax-vector-conversions %s -verify
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding -x c++ %s -verify
+
 // expected-no-diagnostics
 
 #if defined(i386) || defined(__x86_64__)
Index: test/Headers/x86intrin-2.c
===================================================================
--- test/Headers/x86intrin-2.c
+++ test/Headers/x86intrin-2.c
@@ -1,6 +1,11 @@
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding %s -verify
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding -fno-lax-vector-conversions %s -verify
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding -x c++ %s -verify
+
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding %s -verify
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding -fno-lax-vector-conversions %s -verify
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding -x c++ %s -verify
+
 // expected-no-diagnostics
 
 #if defined(i386) || defined(__x86_64__)
Index: test/Headers/x86-intrinsics-headers.c
===================================================================
--- test/Headers/x86-intrinsics-headers.c
+++ test/Headers/x86-intrinsics-headers.c
@@ -2,6 +2,10 @@
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding -fno-lax-vector-conversions %s
 // RUN: %clang_cc1 -fsyntax-only -ffreestanding -x c++ %s
 
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding %s
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding -fno-lax-vector-conversions %s
+// RUN: %clang_cc1 %use_builtin_modules -fsyntax-only -ffreestanding -x c++ %s
+
 #if defined(i386) || defined(__x86_64__)
 
 #ifdef __SSE4_2__
Index: test/Driver/modules.mm
===================================================================
--- test/Driver/modules.mm
+++ test/Driver/modules.mm
@@ -1,15 +1,19 @@
 // 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 -fmodules -fno-cxx-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
+// RUN: %clang -fno-exclusive-builtin-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
 // CHECK-NO-MODULES-NOT: -fmodules
 
 // RUN: %clang -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MODULES %s
 // RUN: %clang -fmodules -fno-cxx-modules -fcxx-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MODULES %s
+// RUN: %clang -fexclusive-builtin-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MODULES %s
 // CHECK-HAS-MODULES: -fmodules
 
 // RUN: %clang -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MAPS %s
 // RUN: %clang -fimplicit-module-maps -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MAPS %s
 // RUN: %clang -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MAPS %s
 // RUN: %clang -fmodules -fno-implicit-module-maps -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MAPS %s
+// RUN: %clang -fexclusive-builtin-modules -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MAPS %s
+// RUN: %clang -fexclusive-builtin-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MAPS %s
 // CHECK-HAS-MAPS: -fimplicit-module-maps
 // CHECK-NO-MAPS-NOT: -fimplicit-module-maps
Index: test/Driver/modules.m
===================================================================
--- test/Driver/modules.m
+++ test/Driver/modules.m
@@ -39,6 +39,12 @@
 // RUN: %clang -fmodules-disable-diagnostic-validation -### %s 2>&1 | FileCheck -check-prefix=MODULES_DISABLE_DIAGNOSTIC_VALIDATION %s
 // MODULES_DISABLE_DIAGNOSTIC_VALIDATION: -fmodules-disable-diagnostic-validation
 
+// RUN: %clang -fexclusive-builtin-modules -### %s 2>&1 | FileCheck -check-prefix=EXCLUSIVE_BUILTIN_MODULES %s
+// EXCLUSIVE_BUILTIN_MODULES-DAG: -fmodules
+// EXCLUSIVE_BUILTIN_MODULES-DAG: -fmodule-map-file={{.*}}module.modulemap
+// EXCLUSIVE_BUILTIN_MODULES-DAG: -fmodules-cache-path=
+// EXCLUSIVE_BUILTIN_MODULES-DAG: -fmodules-validate-system-headers
+
 // RUN: %clang -fmodules -### %s 2>&1 | FileCheck -check-prefix=MODULES_PREBUILT_PATH_DEFAULT %s
 // MODULES_PREBUILT_PATH_DEFAULT-NOT: -fprebuilt-module-path
 
Index: test/CodeGenCXX/mangle-ms-vector-types.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms-vector-types.cpp
+++ test/CodeGenCXX/mangle-ms-vector-types.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fms-extensions -ffreestanding -target-feature +avx -emit-llvm %s -o - -triple=i686-pc-win32 | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -fms-extensions -ffreestanding -target-feature +avx -emit-llvm %s -o - -triple=i686-pc-win32 | FileCheck %s
+
 #include <xmmintrin.h>
 #include <emmintrin.h>
 #include <immintrin.h>
Index: test/CodeGen/xop-builtins.c
===================================================================
--- test/CodeGen/xop-builtins.c
+++ test/CodeGen/xop-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +xop -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +xop -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +xop -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +xop -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/tbm-builtins.c
===================================================================
--- test/CodeGen/tbm-builtins.c
+++ test/CodeGen/tbm-builtins.c
@@ -1,9 +1,13 @@
 // RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-unknown-unknown -target-feature +tbm -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -O3 -triple=x86_64-unknown-unknown -target-feature +tbm -emit-llvm -o - | FileCheck %s
+
 // FIXME: The code generation checks for add/sub and/or are depending on the optimizer.
 // The REQUIRES keyword will be removed when the FIXME is complete.
 // REQUIRES: x86-registered-target
 
 
+
 #include <x86intrin.h>
 
 // NOTE: This should match the tests in llvm/test/CodeGen/X86/tbm-intrinsics-fast-isel.ll
Index: test/CodeGen/target-features-error-2.c
===================================================================
--- test/CodeGen/target-features-error-2.c
+++ test/CodeGen/target-features-error-2.c
@@ -1,10 +1,15 @@
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_SSE42
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_1
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_2
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_3
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_4
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_SSE42
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_1
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_2
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_3
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_4
+
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_SSE42
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_1
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_2
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_3
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_4
 
-#define __MM_MALLOC_H
 #include <x86intrin.h>
 
 #if NEED_SSE42
Index: test/CodeGen/target-builtin-noerror.c
===================================================================
--- test/CodeGen/target-builtin-noerror.c
+++ test/CodeGen/target-builtin-noerror.c
@@ -1,6 +1,7 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -o -
-#define __MM_MALLOC_H
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -o -
+
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -o -
 
 #include <x86intrin.h>
 
Index: test/CodeGen/target-builtin-error.c
===================================================================
--- test/CodeGen/target-builtin-error.c
+++ test/CodeGen/target-builtin-error.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o -
-#define __MM_MALLOC_H
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o -
+
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o -
 
 #include <x86intrin.h>
 
Index: test/CodeGen/target-builtin-error-2.c
===================================================================
--- test/CodeGen/target-builtin-error-2.c
+++ test/CodeGen/target-builtin-error-2.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o -
-#define __MM_MALLOC_H
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o -
+
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-linux-gnu -S -verify -o -
 
 #include <x86intrin.h>
 
Index: test/CodeGen/ssse3-builtins.c
===================================================================
--- test/CodeGen/ssse3-builtins.c
+++ test/CodeGen/ssse3-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/sse4a-builtins.c
===================================================================
--- test/CodeGen/sse4a-builtins.c
+++ test/CodeGen/sse4a-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4a -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4a -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/sse42-builtins.c
===================================================================
--- test/CodeGen/sse42-builtins.c
+++ test/CodeGen/sse42-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.2 -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.2 -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/sse41-builtins.c
===================================================================
--- test/CodeGen/sse41-builtins.c
+++ test/CodeGen/sse41-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/sse3-builtins.c
===================================================================
--- test/CodeGen/sse3-builtins.c
+++ test/CodeGen/sse3-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse3 -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse3 -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/sse2-builtins.c
===================================================================
--- test/CodeGen/sse2-builtins.c
+++ test/CodeGen/sse2-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/sse-builtins.c
===================================================================
--- test/CodeGen/sse-builtins.c
+++ test/CodeGen/sse-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/sha-builtins.c
===================================================================
--- test/CodeGen/sha-builtins.c
+++ test/CodeGen/sha-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +sha -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +sha -emit-llvm -o - | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/rtm-builtins.c
===================================================================
--- test/CodeGen/rtm-builtins.c
+++ test/CodeGen/rtm-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +rtm -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +rtm -emit-llvm -o - | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/rdrand-builtins.c
===================================================================
--- test/CodeGen/rdrand-builtins.c
+++ test/CodeGen/rdrand-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -target-feature +rdrnd -target-feature +rdseed -emit-llvm -o - %s | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding -triple x86_64-unknown-unknown -target-feature +rdrnd -target-feature +rdseed -emit-llvm -o - %s | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/rd-builtins.c
===================================================================
--- test/CodeGen/rd-builtins.c
+++ test/CodeGen/rd-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/prefetchw-builtins.c
===================================================================
--- test/CodeGen/prefetchw-builtins.c
+++ test/CodeGen/prefetchw-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -target-feature +prfchw -emit-llvm -o - %s | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding -triple x86_64-unknown-unknown -target-feature +prfchw -emit-llvm -o - %s | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/popcnt-builtins.c
===================================================================
--- test/CodeGen/popcnt-builtins.c
+++ test/CodeGen/popcnt-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/pku.c
===================================================================
--- test/CodeGen/pku.c
+++ test/CodeGen/pku.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pku -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pku -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/mmx-builtins.c
===================================================================
--- test/CodeGen/mmx-builtins.c
+++ test/CodeGen/mmx-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/lzcnt-builtins.c
===================================================================
--- test/CodeGen/lzcnt-builtins.c
+++ test/CodeGen/lzcnt-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +lzcnt -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +lzcnt -emit-llvm -o - | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/fsgsbase-builtins.c
===================================================================
--- test/CodeGen/fsgsbase-builtins.c
+++ test/CodeGen/fsgsbase-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +fsgsbase -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +fsgsbase -emit-llvm -o - | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/fma4-builtins.c
===================================================================
--- test/CodeGen/fma4-builtins.c
+++ test/CodeGen/fma4-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +fma4 -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +fma4 -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/fma-builtins.c
===================================================================
--- test/CodeGen/fma-builtins.c
+++ test/CodeGen/fma-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +fma -emit-llvm -o - | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +fma -emit-llvm -o - | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/f16c-builtins.c
===================================================================
--- test/CodeGen/f16c-builtins.c
+++ test/CodeGen/f16c-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/builtin-clflushopt.c
===================================================================
--- test/CodeGen/builtin-clflushopt.c
+++ test/CodeGen/builtin-clflushopt.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-feature +clflushopt  -emit-llvm -o - -Wall -Werror | FileCheck %s
-#define __MM_MALLOC_H
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +clflushopt  -emit-llvm -o - -Wall -Werror | FileCheck %s
+
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +clflushopt  -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 void test_mm_clflushopt(char * __m) {
Index: test/CodeGen/bmi2-builtins.c
===================================================================
--- test/CodeGen/bmi2-builtins.c
+++ test/CodeGen/bmi2-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B32
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B32
 
 #include <x86intrin.h>
 
Index: test/CodeGen/bmi-builtins.c
===================================================================
--- test/CodeGen/bmi-builtins.c
+++ test/CodeGen/bmi-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/bitscan-builtins.c
===================================================================
--- test/CodeGen/bitscan-builtins.c
+++ test/CodeGen/bitscan-builtins.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
 #include <immintrin.h>
 
 int test_bit_scan_forward(int a) {
Index: test/CodeGen/avx512vldq-builtins.c
===================================================================
--- test/CodeGen/avx512vldq-builtins.c
+++ test/CodeGen/avx512vldq-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512dq -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512dq -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512vlcd-builtins.c
===================================================================
--- test/CodeGen/avx512vlcd-builtins.c
+++ test/CodeGen/avx512vlcd-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vl -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512vlbw-builtins.c
===================================================================
--- test/CodeGen/avx512vlbw-builtins.c
+++ test/CodeGen/avx512vlbw-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512vl-builtins.c
===================================================================
--- test/CodeGen/avx512vl-builtins.c
+++ test/CodeGen/avx512vl-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512vbmivl-builtin.c
===================================================================
--- test/CodeGen/avx512vbmivl-builtin.c
+++ test/CodeGen/avx512vbmivl-builtin.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vbmi -target-feature +avx512vl -target-feature +avx512bw -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vbmi -target-feature +avx512vl -target-feature +avx512bw -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512vbmi-builtins.c
===================================================================
--- test/CodeGen/avx512vbmi-builtins.c
+++ test/CodeGen/avx512vbmi-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vbmi -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512vbmi -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512pf-builtins.c
===================================================================
--- test/CodeGen/avx512pf-builtins.c
+++ test/CodeGen/avx512pf-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512ifmavl-builtins.c
===================================================================
--- test/CodeGen/avx512ifmavl-builtins.c
+++ test/CodeGen/avx512ifmavl-builtins.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-feature +avx512ifma -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512ifma -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
 
-#define __MM_MALLOC_H
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512ifma -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512ifma-builtins.c
===================================================================
--- test/CodeGen/avx512ifma-builtins.c
+++ test/CodeGen/avx512ifma-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512ifma -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512ifma -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512f-builtins.c
===================================================================
--- test/CodeGen/avx512f-builtins.c
+++ test/CodeGen/avx512f-builtins.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck %s
+
 #include <immintrin.h>
 
 __m512d test_mm512_sqrt_pd(__m512d a)
Index: test/CodeGen/avx512er-builtins.c
===================================================================
--- test/CodeGen/avx512er-builtins.c
+++ test/CodeGen/avx512er-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512dq-builtins.c
===================================================================
--- test/CodeGen/avx512dq-builtins.c
+++ test/CodeGen/avx512dq-builtins.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512dq -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512dq -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512cdintrin.c
===================================================================
--- test/CodeGen/avx512cdintrin.c
+++ test/CodeGen/avx512cdintrin.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512cd -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx512bw-builtins.c
===================================================================
--- test/CodeGen/avx512bw-builtins.c
+++ test/CodeGen/avx512bw-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx2-builtins.c
===================================================================
--- test/CodeGen/avx2-builtins.c
+++ test/CodeGen/avx2-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/avx-shuffle-builtins.c
===================================================================
--- test/CodeGen/avx-shuffle-builtins.c
+++ test/CodeGen/avx-shuffle-builtins.c
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s
 // FIXME: This is testing optimized generation of shuffle instructions and should be fixed.
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx-cmp-builtins.c
===================================================================
--- test/CodeGen/avx-cmp-builtins.c
+++ test/CodeGen/avx-cmp-builtins.c
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s
 // FIXME: The shufflevector instructions in test_cmpgt_sd are relying on O3 here.
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s
 
 #include <immintrin.h>
 
Index: test/CodeGen/avx-builtins.c
===================================================================
--- test/CodeGen/avx-builtins.c
+++ test/CodeGen/avx-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/attr-target-x86-mmx.c
===================================================================
--- test/CodeGen/attr-target-x86-mmx.c
+++ test/CodeGen/attr-target-x86-mmx.c
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -triple i386-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding -triple i386-linux-gnu -emit-llvm %s -o - | FileCheck %s
 // Picking a cpu that doesn't have mmx or sse by default so we can enable it later.
 
-#define __MM_MALLOC_H
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding -triple i386-linux-gnu -emit-llvm %s -o - | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/adx-builtins.c
===================================================================
--- test/CodeGen/adx-builtins.c
+++ test/CodeGen/adx-builtins.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffreestanding -target-feature +adx -emit-llvm -o - %s | FileCheck %s
 
+// RUN: %clang_cc1 %use_builtin_modules -triple x86_64-unknown-unknown -ffreestanding -target-feature +adx -emit-llvm -o - %s | FileCheck %s
+
 #include <x86intrin.h>
 
 unsigned char test_addcarryx_u32(unsigned char __cf, unsigned int __x,
Index: test/CodeGen/adc-builtins.c
===================================================================
--- test/CodeGen/adc-builtins.c
+++ test/CodeGen/adc-builtins.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
-#define __MM_MALLOC_H
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
 #include <x86intrin.h>
 
Index: test/CodeGen/3dnow-builtins.c
===================================================================
--- test/CodeGen/3dnow-builtins.c
+++ test/CodeGen/3dnow-builtins.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +3dnowa -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=GCC -check-prefix=CHECK
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-scei-ps4 -target-feature +3dnowa -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=PS4 -check-prefix=CHECK
 
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +3dnowa -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=GCC -check-prefix=CHECK
+// RUN: %clang_cc1 %use_builtin_modules -ffreestanding %s -triple=x86_64-scei-ps4 -target-feature +3dnowa -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=PS4 -check-prefix=CHECK
 
 #include <x86intrin.h>
 
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5441,10 +5441,31 @@
     HaveAnyModules = true;
   }
 
+  // -fexclusive-builtin-modules enables the use of precompiled modules
+  // exclusively for the Clang builtins (off by default).
+  // This is disabled if the user is using -fmodules or -fmodules-ts
+  bool HaveExclusiveBuiltinModules = false;
+  if (!HaveAnyModules &&
+      Args.hasFlag(options::OPT_fexclusive_builtin_modules,
+                   options::OPT_fno_exclusive_builtin_modules, false)) {
+    HaveExclusiveBuiltinModules = true;
+  }
+
+  if (HaveExclusiveBuiltinModules) {
+    SmallString<128> BuiltinModuleMap(getToolChain().getDriver().ResourceDir);
+    llvm::sys::path::append(BuiltinModuleMap, "include");
+    llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
+    if (llvm::sys::fs::exists(BuiltinModuleMap)) {
+      HaveAnyModules = HaveClangModules = true;
+      CmdArgs.push_back("-fmodules");
+      CmdArgs.push_back(Args.MakeArgString("-fmodule-map-file=" +
+                                           BuiltinModuleMap));
+      CmdArgs.push_back("-fmodules-validate-system-headers");
+    }
+  } else if (Args.hasFlag(options::OPT_fimplicit_module_maps,
+                   options::OPT_fno_implicit_module_maps, HaveClangModules)) {
   // -fmodule-maps enables implicit reading of module map files. By default,
   // this is enabled if we are using Clang's flavor of precompiled modules.
-  if (Args.hasFlag(options::OPT_fimplicit_module_maps,
-                   options::OPT_fno_implicit_module_maps, HaveClangModules)) {
     CmdArgs.push_back("-fimplicit-module-maps");
   }
 
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -792,6 +792,9 @@
   HelpText<"Inline functions wich are (explicitly or implicitly) marked inline">;
 def finline : Flag<["-"], "finline">, Group<clang_ignored_f_Group>;
 def finput_charset_EQ : Joined<["-"], "finput-charset=">, Group<f_Group>;
+def fexclusive_builtin_modules : Flag <["-"], "fexclusive-builtin-modules">, Group<f_Group>,
+  Flags<[DriverOption]>,
+  HelpText<"Enable the 'modules' language feature exclusively for the builtin header files">;
 def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group<f_Group>;
 def finstrument_functions : Flag<["-"], "finstrument-functions">, Group<f_Group>, Flags<[CC1Option]>,
   HelpText<"Generate calls to instrument function entry and exit">;
@@ -965,6 +968,8 @@
   HelpText<"Disable C++ copy constructor elision">, Flags<[CC1Option]>;
 def fno_eliminate_unused_debug_symbols : Flag<["-"], "fno-eliminate-unused-debug-symbols">, Group<f_Group>;
 def fno_exceptions : Flag<["-"], "fno-exceptions">, Group<f_Group>;
+def fno_exclusive_builtin_modules : Flag <["-"], "fno-exclusive-builtin-modules">, Group<f_Group>,
+  Flags<[DriverOption]>;
 def fno_gnu_keywords : Flag<["-"], "fno-gnu-keywords">, Group<f_Group>, Flags<[CC1Option]>;
 def fno_inline_functions : Flag<["-"], "fno-inline-functions">, Group<f_clang_Group>, Flags<[CC1Option]>;
 def fno_inline : Flag<["-"], "fno-inline">, Group<f_clang_Group>, Flags<[CC1Option]>;
Index: docs/Modules.rst
===================================================================
--- docs/Modules.rst
+++ docs/Modules.rst
@@ -174,6 +174,9 @@
 ``-fmodules``
   Enable the modules feature.
 
+``-fexclusive-builtin-modules``
+  Enable the modules feature exclusively for the Clang builtins.
+
 ``-fimplicit-module-maps``
   Enable implicit search for module map files named ``module.modulemap`` and similar. This option is implied by ``-fmodules``. If this is disabled with ``-fno-implicit-module-maps``, module map files will only be loaded if they are explicitly specified via ``-fmodule-map-file`` or transitively used by another module map file.
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to