STL icon indicating copy to clipboard operation
STL copied to clipboard

Solutions for ClangCL `intrin0.h` header for `_STL_INTRIN_HEADER` macro

Open MaxEW707 opened this issue 1 year ago • 1 comments
trafficstars

Background Reading

See this MSVC STL PR from last year for historical context: https://github.com/microsoft/STL/pull/3285

See this Clang bug report that spawned this work: https://github.com/llvm/llvm-project/issues/53520 See this Clang PR for context on the changes we would like to make to clang to support intrin0.h: https://github.com/llvm/llvm-project/pull/75711

Problem

As you are well aware intrin0.h is a header shipped with MSVC that stores the minimal set of intrinsics for the MSVC STL to reduce header include time.

immintrin.h shipped with ClangCL only includes the simd intrinsics if they are enabled at compile time. This prevents the ability to do runtime simd detection with ClangCL. This was done to reduce the header include times from _STL_INTRIN_HEADER using intrin.h which ends up including immintrin.h.

To solve this I am adding a similar intrinsic header to ClangCL to mimic intrin0.h for MSVC STL.

Solution

At noted above we already have a PR up that provides the minimal set of intrinsics that the MSVC STL requires.

We would like to come to some agreement about how to do the feature check so we can use this new minimal intrin header when it becomes available. We can be flexible and we want our solution to work for you. Not force our solution onto you.

We can't use __has_include(<intrin0.h>) because MSVC ships its own copy of intrin0.h and thus can't distinguish it from ours.

We can't use __has_include_next(<intrin0.h>) inside yvals_core.h to determine if ClangCL is providing its own header since clang will rightfully warn that it will be found by absolute path, "#include_next in file found relative to primary source file or found by absolute path; will search from start of include path [-Winclude-next-absolute-path]".

We can do a version check for when this header will be introduced.

The proposed solution that I am thinking is the way to go is for clang to have its own custom name for the header such as intrin_msvc_stl.h and then we can easily do a __has_include check.

I don't intend for this PR to get merged before we merge the clang PR linked above. Would appreciate which avenue you guys would like us to go down to support this feature. Thanks :).

MaxEW707 avatar Dec 21 '23 22:12 MaxEW707

Thanks for the extensive writeup with links to the source material, I needed a refresher and I suspect other maintainers are less familiar with the history of clang-cl and intrin.h. I'm glad someone finally found the time and motivation to make a clang-specific intrin0.h.

CaseyCarter avatar Jan 04 '24 02:01 CaseyCarter

We talked about this at the weekly maintainer meeting - thanks for working on improving the throughput situation here! Your LLVM PR appears to be progressing nicely and it looks like there are no changes needed in microsoft/STL right now. @CaseyCarter mentioned that we should be able to close this PR now - does that sound right to you?

StephanTLavavej avatar Jan 24 '24 22:01 StephanTLavavej

@CaseyCarter mentioned that we should be able to close this PR now - does that sound right to you?

Correct feel free to close this PR since it appears our direction on Clang is satisfactory for you guys. I can open another PR if required in the future.

MaxEW707 avatar Jan 25 '24 05:01 MaxEW707

Excellent, thank you! :heart_eyes_cat:

StephanTLavavej avatar Jan 25 '24 11:01 StephanTLavavej