[cfe-commits] r155425 - in /cfe/trunk: lib/Headers/CMakeLists.txt lib/Headers/intrin.h test/Headers/ms-intrin.c

Chandler Carruth chandlerc at gmail.com
Mon Apr 23 22:23:54 PDT 2012


Author: chandlerc
Date: Tue Apr 24 00:23:54 2012
New Revision: 155425

URL: http://llvm.org/viewvc/llvm-project?rev=155425&view=rev
Log:
Introduce an initial sketch of a MSVC compatible 'intrin.h' builtin
header, along with a stub test to make sure it compiles in the
appropriate modes.

Thanks to Aaron Ballman for working with me to figure out the initial
strategy here, and to Nico for reviewing and pestering me to actually
commit it.

Added:
    cfe/trunk/lib/Headers/intrin.h
    cfe/trunk/test/Headers/ms-intrin.c
Modified:
    cfe/trunk/lib/Headers/CMakeLists.txt

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=155425&r1=155424&r2=155425&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Tue Apr 24 00:23:54 2012
@@ -8,6 +8,7 @@
   float.h
   fma4intrin.h
   immintrin.h
+  intrin.h
   iso646.h
   limits.h
   lzcntintrin.h

Added: cfe/trunk/lib/Headers/intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/intrin.h?rev=155425&view=auto
==============================================================================
--- cfe/trunk/lib/Headers/intrin.h (added)
+++ cfe/trunk/lib/Headers/intrin.h Tue Apr 24 00:23:54 2012
@@ -0,0 +1,66 @@
+/*===---- intrin.h - Microsoft VS compatible X86 intrinsics -----------------===
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+/* Unless we're compiling targeting MSVC platform, this header shouldn't even
+ * *exist*. If there is a system header with the same name, defer to that,
+ * etherwise produce an error for the user.
+ */
+#ifndef _MSC_VER
+# if defined(__has_include_next) && __has_include_next(<intrin.h>)
+#  include_next <intrin.h>
+# else
+#  error The <intrin.h> builtin header is for use when targeting Windows and \
+         provides MSVC compatible intrinsic declarations. It shouldn't be used \
+         on non-Windows targets. Instead, see <x86intrin.h> which is supported \
+         by Clang, GCC, and ICC on all platforms.
+# endif
+#else /* _MSC_VER */
+
+#ifndef __INTRIN_H
+#define __INTRIN_H
+
+/* These headers need to be provided by intrin.h in case users depend on any of
+ * their contents. However, some of them are unavailable in freestanding
+ * builds, so guard them appropriately.
+ */
+#if __STDC_HOSTED__
+# include <crtdefs.h>
+# include <setjmp.h>
+#endif
+#include <stddef.h>
+
+/* Microsoft includes all of the intrinsics, and then restricts their
+ * availability based on the particular target CPU; with Clang te rely on the
+ * guarded includes used in our generic x86intrin header to pull in the
+ * intrinsic declarations / definitions which should be available for the
+ * target CPU variant.
+ */
+#include <x86intrin.h>
+
+/* FIXME: We need to provide declarations for Microsoft-specific intrinsics in
+ * addition to the chip-vendor intrinsics provided by x86intrin.h.
+ */
+
+#endif /* __INTRIN_H */
+
+#endif /* _MSC_VER */

Added: cfe/trunk/test/Headers/ms-intrin.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-intrin.c?rev=155425&view=auto
==============================================================================
--- cfe/trunk/test/Headers/ms-intrin.c (added)
+++ cfe/trunk/test/Headers/ms-intrin.c Tue Apr 24 00:23:54 2012
@@ -0,0 +1,11 @@
+// RUN: %clang -fsyntax-only -ffreestanding -target i686-pc-win32 %s
+// RUN: %clangxx -fsyntax-only -ffreestanding -target i686-pc-win32 -x c++ %s
+
+#include <intrin.h>
+
+// Ensure we're compiling in MS-compat mode.
+__declspec(naked) void f();
+
+// Ensure that we got various fundamental headers.
+// FIXME: We could probably do more extensive testing here.
+size_t test = 0;





More information about the cfe-commits mailing list