Skip to content

Commit a48063e

Browse files
MaxEW707SquallATF
authored andcommitted
[clang] Add intrin0.h header to mimic intrin0.h used by MSVC STL for clang-cl (llvm#75711)
Fixes llvm#53520. #### Description #### Provide `intrin0.h` to be the minimal set of intrinsics that the MSVC STL requires. The `intrin0.h` header matches the latest header provided by MSVC 1939 which does include some extra intrinsics that the MSVC STL does not use. Inside `BuiltinHeaders.def` I kept the header description as `intrin.h`. If you want me to change those to `intrin0.h` for the moved intrinsics let me know. This should now allow `immintrin.h` to be used with function targets for runtime cpu detection of simd instruction sets without worrying about the compile-time overhead from MSVC STL including `intrin.h` on clang. I still need to figure out how to best update MSVC STL to detect for the presence of `intrin0.h` from clang and to use this header over `intrin.h`. #### Testing #### Built clang locally and ran the test suite. I still need to do a pass over the existing unit tests for the ms intrinsics to make sure there aren't any gaps. Wanted to get this PR up for discussion first. Modified latest MSVC STL from github to point to `intrin0.h` for clang. Wrote some test files that included MSVC STL headers that rely on intrinsics such as `atomic`, `bit` and `vector`. Built the unit tests against x86, arm, aarch64, and x64. #### Benchmarks #### The following include times are based on the x64 target with the modified headers in this PR. These timings were done by using `clang-cl.exe -ftime-trace` and taking the wall time for parsing `intrin.h` and `intrin0.h`. `intrin.h` takes ~897ms to parse. `intrin0.h` takes ~1ms to parse. If there is anything required or a different approach is preferred let me know. I would very much like to move this over the finish line so we can use function targets with clang-cl.
1 parent b14bdef commit a48063e

File tree

10 files changed

+408
-413
lines changed

10 files changed

+408
-413
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,26 @@ Windows Support
12731273

12741274
- Clang now passes relevant LTO options to the linker (LLD) in MinGW mode.
12751275

1276+
- Clang-cl now supports function targets with intrinsic headers. This allows
1277+
for runtime feature detection of intrinsics. Previously under clang-cl
1278+
``immintrin.h`` and similar intrinsic headers would only include the intrinsics
1279+
if building with that feature enabled at compile time, e.g. ``avxintrin.h``
1280+
would only be included if AVX was enabled at compile time. This was done to work
1281+
around include times from MSVC STL including ``intrin.h`` under clang-cl.
1282+
Clang-cl now provides ``intrin0.h`` for MSVC STL and therefore all intrinsic
1283+
features without requiring enablement at compile time.
1284+
Fixes: (`#53520 <https://github.com/llvm/llvm-project/issues/53520>`_)
1285+
1286+
- Improved compile times with MSVC STL. MSVC provides ``intrin0.h`` which is a
1287+
header that only includes intrinsics that are used by MSVC STL to avoid the
1288+
use of ``intrin.h``. MSVC STL when compiled under clang uses ``intrin.h``
1289+
instead. Clang-cl now provides ``intrin0.h`` for the same compiler throughput
1290+
purposes as MSVC. Clang-cl also provides ``yvals_core.h`` to redefine
1291+
``_STL_INTRIN_HEADER`` to expand to ``intrin0.h`` instead of ``intrin.h``.
1292+
This also means that if all intrinsic features are enabled at compile time
1293+
including STL headers will no longer slow down compile times since ``intrin.h``
1294+
is not included from MSVC STL.
1295+
12761296
LoongArch Support
12771297
^^^^^^^^^^^^^^^^^
12781298
- Added builtins support for all LSX (128-bits SIMD) and LASX (256-bits SIMD)

clang/lib/Headers/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ set(x86_files
253253
)
254254

255255
set(windows_only_files
256+
intrin0.h
256257
intrin.h
257258
vadefs.h
259+
yvals_core.h
258260
)
259261

260262
set(utility_files

clang/lib/Headers/bmiintrin.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ _mm_tzcnt_64(unsigned long long __X)
161161

162162
#undef __RELAXED_FN_ATTRS
163163

164-
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
165-
defined(__BMI__)
164+
#if !defined(__SCE__) || __has_feature(modules) || defined(__BMI__)
166165

167166
/* Define the default attributes for the functions in this file. */
168167
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("bmi")))
@@ -610,7 +609,6 @@ __blsr_u64(unsigned long long __X)
610609

611610
#undef __DEFAULT_FN_ATTRS
612611

613-
#endif /* !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) \
614-
|| defined(__BMI__) */
612+
#endif /* !defined(__SCE__) || __has_feature(modules) || defined(__BMI__) */
615613

616614
#endif /* __BMIINTRIN_H */

0 commit comments

Comments
 (0)