[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-19 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @AaronBallman Can you merge this please? We are eagerly waiting for this to 
> end up in a release! ;-)

Thank you for the ping, this fell off my radar!

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-19 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman closed 
https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-19 Thread Benjamin Buch via cfe-commits

bebuch wrote:

@AaronBallman Can you merge this please? We are eagerly waiting for this to end 
up in a release! ;-)

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-07 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

Friendly reminder that I require someone to commit on my behalf since I do not 
have write access :).

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-04 Thread Casey Carter via cfe-commits

https://github.com/CaseyCarter approved this pull request.

Thanks for devising this clever way to improve MSVCSTL throughput!

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-04 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM, thank you!

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-03 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

Just want to say thanks for everyone taking the time to review the PR and 
providing feedback :).
Looking forward to using this in the next release of clang-cl.

> I'm a bit worried that we don't have any test coverage for this file to begin 
> with, so it's a bit hard to validate that the changes are correct, but we're 
> early enough in a release cycle that I think we'll get feedback with plenty 
> of time to address unintentional fallout.

I'll look into adding unit tests next week in a separate PR. If not it will be 
closer towards the end of March due to personal things.
If any issues pop up feel free to @ me. I don't intend to commit and dash :).

> The changes should come with a release note in clang/docs/ReleaseNotes.rst so 
> that users know about the compile time performance improvements.

Done. Feel free to reword the release notes as necessary. I believe I landed on 
something that is informative but succinct. 

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-29 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

Thank you for the timing information! The yvals_core.h hack is actually a 
really clever way to handle this. I'm a bit worried that we don't have any test 
coverage for this file to begin with, so it's a bit hard to validate that the 
changes are correct, but we're early enough in a release cycle that I think 
we'll get feedback with plenty of time to address unintentional fallout.

The changes should come with a release note in `clang/docs/ReleaseNotes.rst` so 
that users know about the compile time performance improvements. Otherwise, 
this LGTM! I can land the changes on your behalf once there's a release note.

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-24 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 edited 
https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-24 Thread Max Winkler via cfe-commits


@@ -0,0 +1,26 @@
+/* === vadefs.h ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+/* Only include this if we are aiming for MSVC compatibility. */

MaxEW707 wrote:

We do not need `/* */`.

I was just copying from the other files in this folder for the copyright header 
and clang-format didn't complain.
I'll give the style guide a read and get this fixed :).

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-24 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

I will need someone to commit on my behalf since I do not have write access.

> lgtm, and good to land provided you do a quick re-check to confirm that this 
> doesn't tank compile times now with that part included. Thanks!

The include times below are done with the following source file using a locally 
release build of clang, `-ftime-trace`, and msvc stl shipped with MSVC 1939.
```
#include 
#include 
#include 
```

clang-cl.exe without `yvals_core.h` shadowing takes ~1,344 ms in the frontend. 
`intrin.h` took ~955 ms to parse.

clang-cl.exe with `yvals_core.h` shadowing takes ~395 ms in the frontend. 
`intrin0.h` took ~1.4 ms to parse.

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-24 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I am not familiar with the MSVC ecosystem, but the change looks reasonable. 
Thanks!

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-24 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,26 @@
+/* === vadefs.h ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+/* Only include this if we are aiming for MSVC compatibility. */

MaskRay wrote:

Newer lib/Headers changes prefer `//`-style comments. Do we need `/* */`?

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-23 Thread Reid Kleckner via cfe-commits

https://github.com/rnk approved this pull request.

I think there are risks to shadowing `yvals_core.h`, but @CaseyCarter is at 
least aware of it 
[here](https://github.com/microsoft/STL/issues/3634#issuecomment-1904956652).

Once Clang ships its own intrin0.h header, the MSVC STL can adjust their 
yvals_core.h code to use it, and then we can delete this shadow header. This 
gives us the best outcome: Fast compiles today, target attribute support in 
MSVC-mode, and minimal tech debt in the long run. Sounds good to me, thanks for 
finding a solution!

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-22 Thread Nico Weber via cfe-commits

nico wrote:

Wow, that clang/lib/Headers/yvals_core.h hacks is gross, I love it :D

lgtm, and good to land provided you do a quick re-check to confirm that this 
doesn't tank compile times now with that part included. Thanks!

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-02-13 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

Ping

Wondering if there is anything else required of me to progress this PR forward. 
Let me know :).

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[openmp] [flang] [mlir] [lldb] [clang-tools-extra] [llvm] [libcxx] [lld] [compiler-rt] [clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-01-10 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

> Users (Chromium included) use recent versions of Clang that are not vendored 
> by Microsoft. Users can also use the LLVM OSS releases. I think most users 
> probably won't notice the compile time regression, and it will silently go 
> away the next time the update MSVC, but if they do and they care (and this 
> should be in the release notes), it would be nice to have a macro to get the 
> old behavior. 

I thought of another solution this morning that can work. Looks like we already 
have precedent with redefining macros in clang's interposing MSVC headers. 
`vadefs.h` for example.

MSVC STL would like to replace 
[_STL_INTRIN_HEADER](https://github.com/microsoft/STL/blob/main/stl/inc/yvals_core.h#L2038)
 macro with just `#include ` when they support the version of clang 
shipped with `intrin0.h`.

We could provide our own `yvals_core.h` header like so:
```
#include_next 

#if defined(_MSC_VER_) && defined(_STL_INTRIN_HEADER)
#undef _STL_INTRIN_HEADER
#define _STL_INTRIN_HEADER #include 
#endif
```

This should also fix users upgrading clang while still building against an 
older MSVC STL. Once MSVC STL moves forward we can probably remove this 
interposing header sometime in the future.

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-19 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,160 @@
+/*=== adxintrin.h - ADX intrinsics -===

phoebewang wrote:

adx -> adc

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-19 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

> @MaxEW707 If you pull out the adcintrin.h change into a separate PR we can 
> fast track it as it should be done anyhow

Done :). Here is the link since I can't add reviewers 
https://github.com/llvm/llvm-project/pull/75992.


https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-19 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

@MaxEW707 If you pull out the adcintrin.h change into a separate PR we can fast 
track it as it should be done anyhow

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-18 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

MSVC STL requires the x64 adc intel intrinsics. I moved those to a separate 
file `adcintrin.h` that can be included from `immintrin.h` and `intrin0.h` for 
x64.

I also made a table [here 
](https://gist.github.com/MaxEW707/2f4bf26801bc1b6b088aa7a2fadba526) of all the 
intrinsics available with MSVC's `intrin0.h`, which intrinsics are used by MSVC 
STL, which are used by MSVC STL when compiled under clang and which intrinsics 
are provided as builtins from clang.

You will notice that the `_ReadWriteBarrier` compiler barrier isn't supported 
on arm by clang.  This [godbolt](https://godbolt.org/z/xEv3oEbK6) appears to 
corroborate that finding. I am not too worried about this since I believe 
Microsoft is dropping 32-bit ARM in a future Windows 11 update if my memory is 
correct.

The last table at the end shows the intrinsics that aren't implemented in clang 
but MSVC STL has workarounds using the clang intrinsics instead. We don't have 
to worry about supporting those.


https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-18 Thread Reid Kleckner via cfe-commits

rnk wrote:

> > What I'd like to see is a pull request sent to 
> > https://github.com/microsoft/stl with some agreement about how to structure 
> > the ifdefs so we can use intrin0.h when it is available.
> 
> Sounds good I'll do that.

Thanks!

> I was thinking I could use `__has_include_next`. If 
> `__has_include_next()` is true then we know clang is providing its 
> own `intrin0.h`.
> 
> Another option I had was to preemptively get a PR up to MSVC STL with a 
> `__clang_major__` check for clang 18 assuming this PR gets in before the 
> release window.
> 
> A custom name like `intrin_msstl.h` works for me as well.

I think we can be flexible, and the important thing is that our solution should 
work for them.

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-18 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

> Is intrin0.h a header that ships with MSVC's compiler, or with MS's STL? If 
> the latter, shouldn't everything just work already?

It ships with MSVC.

`intrin0.h` from MSVC doesn't work currently due to some declarations not 
matching declarations in clang's own `intrin.h`.
For example `_addcary_u64`. Which I now realize I am missing since that is 
inside `adxintrin.h` which I mistakenly assumed only included adx instriniscs 
and not adc intrinsics as well.

> What I'd like to see is a pull request sent to 
> https://github.com/microsoft/stl with some agreement about how to structure 
> the ifdefs so we can use intrin0.h when it is available.

Sounds good I'll do that.

> We probably can't use __has_include() because MSVC ships its own 
> copy of intrin0.h, and they can't be distinguished.

I was thinking I could use `__has_include_next`. If 
`_has_include_next()` is true then we know clang is providing its 
own `intrin0.h`.

Another option I had was to preemptively get a PR up to MSVC STL with a 
`__clang_major__` check for clang 18 assuming this PR gets in before the 
release window.

A custom name like `intrin_msstl.h` works for me as well.

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-18 Thread Reid Kleckner via cfe-commits

rnk wrote:

> If we land this as-is, it'll tank build time on Windows.

While this is true, I don't think it's the right tradeoff for us to leave Intel 
intrinsics inaccessible for users who don't want to enable new 
microarchitectural features globally with command line flags. You may recall 
there are ODR issues, where enabling AVX globally results in AVX instructions 
being generated in inline functions, which then prevail at link time, and crash 
at runtime on chips where AVX is not available. We are currently prioritizing 
compile time above those needs, and that doesn't seem like the right tradeoff.

What I'd like to see is a pull request sent to https://github.com/microsoft/stl 
with some agreement about how to structure the ifdefs so we can use intrin0.h 
when it is available. We probably can't use `__has_include()` 
because MSVC ships its own copy of intrin0.h, and they can't be distinguished. 
Perhaps we should come up with our own name for `intrin0.h`, so we can 
feature-detect it. I suggest `intrin_msstl.h` or `intrin_minimal.h` or 
something.

Then, when we land this PR, the net effect is that compile time with MSVC slows 
down until the next release of the Microsoft STL, but users have access to 
Intel intrinsics as soon as possible. Does that seem reasonable?

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-18 Thread Nico Weber via cfe-commits

nico wrote:

In other words, please undo the changes to `clang/lib/Headers/immintrin.h` for 
now.

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-18 Thread Nico Weber via cfe-commits

nico wrote:

Looks like it belongs to MSVC: 
https://github.com/microsoft/STL/blob/a806c6960f1687590ffd4244794c753aa819/stl/inc/yvals_core.h#L2040

So I think the right order here is:

1. Add intrin0.h header
2. Wait for a release
3. Change MSSTL to include that in clang builds as well
4. Wait for a release of that
5. Make intrin.h the chonky header

If we land this as-is, it'll tank build time on Windows.

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-18 Thread Nico Weber via cfe-commits

nico wrote:

Is `intrin0.h` a header that ships with MSVC's compiler, or with MS's STL? If 
the latter, shouldn't everything just work already?

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-16 Thread via cfe-commits

https://github.com/MaxEW707 edited 
https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-16 Thread via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/75711

>From 8cd6db09c511ad8fde0e54e96cf3019da5b40d6e Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 13:54:16 -0500
Subject: [PATCH 1/3] Add `intrin0.h` header to mimic `intrin0.h` used by msvc
 stl

---
 clang/lib/Headers/CMakeLists.txt |   1 +
 clang/lib/Headers/immintrin.h| 166 +++---
 clang/lib/Headers/intrin.h   | 216 +---
 clang/lib/Headers/intrin0.h  | 233 +++
 4 files changed, 319 insertions(+), 297 deletions(-)
 create mode 100644 clang/lib/Headers/intrin0.h

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index f8fdd402777e48..e5ce039d5789ad 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -252,6 +252,7 @@ set(x86_files
   )
 
 set(windows_only_files
+  intrin0.h
   intrin.h
   vadefs.h
 )
diff --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index 9bfe2fcdabdb3a..f57cd385455c22 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -16,62 +16,62 @@
 
 #include 
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__MMX__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE2__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE3__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSSE3__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 (defined(__SSE4_2__) || defined(__SSE4_1__))
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 (defined(__AES__) || defined(__PCLMUL__))
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CLFLUSHOPT__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CLWB__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX2__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__F16C__)
 #include 
 #endif
@@ -79,217 +79,217 @@
 /* No feature check desired due to internal checks */
 #include 
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__BMI2__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__LZCNT__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__POPCNT__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__FMA__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX512F__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX512VL__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX512BW__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  

[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff b3e353d263f9d6ef061f4e6d89619c72a3553002 
8cd6db09c511ad8fde0e54e96cf3019da5b40d6e -- clang/lib/Headers/intrin0.h 
clang/lib/Headers/immintrin.h clang/lib/Headers/intrin.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index f57cd38545..02877c5709 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -16,281 +16,239 @@
 
 #include 
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__MMX__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__MMX__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__SSE__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__SSE__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__SSE2__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__SSE2__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__SSE3__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__SSE3__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__SSSE3__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__SSSE3__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
+#if !defined(__SCE__) || __has_feature(modules) || 
\
 (defined(__SSE4_2__) || defined(__SSE4_1__))
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
+#if !defined(__SCE__) || __has_feature(modules) || 
\
 (defined(__AES__) || defined(__PCLMUL__))
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__CLFLUSHOPT__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__CLFLUSHOPT__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__CLWB__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__CLWB__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX2__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX2__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__F16C__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__F16C__)
 #include 
 #endif
 
 /* No feature check desired due to internal checks */
 #include 
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__BMI2__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__BMI2__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__LZCNT__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__LZCNT__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__POPCNT__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__POPCNT__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__FMA__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__FMA__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX512F__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX512F__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX512VL__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX512VL__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX512BW__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX512BW__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX512BITALG__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX512BITALG__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX512CD__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX512CD__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-defined(__AVX512VPOPCNTDQ__)
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AVX512VPOPCNTDQ__)
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
+#if !defined(__SCE__) || __has_feature(modules) || 
\
 (defined(__AVX512VL__) && defined(__AVX512VPOPCNTDQ__))
 #include 
 #endif
 
-#if !defined(__SCE__) || __has_feature(modules) ||  \
-

[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (MaxEW707)


Changes

Fixes https://github.com/llvm/llvm-project/issues/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 on `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.

---

Patch is 46.59 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/75711.diff


4 Files Affected:

- (modified) clang/lib/Headers/CMakeLists.txt (+1) 
- (modified) clang/lib/Headers/immintrin.h (+83-83) 
- (modified) clang/lib/Headers/intrin.h (+2-214) 
- (added) clang/lib/Headers/intrin0.h (+233) 


``diff
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index f8fdd402777e48..e5ce039d5789ad 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -252,6 +252,7 @@ set(x86_files
   )
 
 set(windows_only_files
+  intrin0.h
   intrin.h
   vadefs.h
 )
diff --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index 9bfe2fcdabdb3a..f57cd385455c22 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -16,62 +16,62 @@
 
 #include 
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__MMX__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE2__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE3__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSSE3__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 (defined(__SSE4_2__) || defined(__SSE4_1__))
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 (defined(__AES__) || defined(__PCLMUL__))
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CLFLUSHOPT__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CLWB__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX2__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) 

[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-16 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2023-12-16 Thread via cfe-commits

https://github.com/MaxEW707 created 
https://github.com/llvm/llvm-project/pull/75711

Fixes https://github.com/llvm/llvm-project/issues/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 on `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.

>From 8cd6db09c511ad8fde0e54e96cf3019da5b40d6e Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 13:54:16 -0500
Subject: [PATCH] Add `intrin0.h` header to mimic `intrin0.h` used by msvc stl

---
 clang/lib/Headers/CMakeLists.txt |   1 +
 clang/lib/Headers/immintrin.h| 166 +++---
 clang/lib/Headers/intrin.h   | 216 +---
 clang/lib/Headers/intrin0.h  | 233 +++
 4 files changed, 319 insertions(+), 297 deletions(-)
 create mode 100644 clang/lib/Headers/intrin0.h

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index f8fdd402777e48..e5ce039d5789ad 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -252,6 +252,7 @@ set(x86_files
   )
 
 set(windows_only_files
+  intrin0.h
   intrin.h
   vadefs.h
 )
diff --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index 9bfe2fcdabdb3a..f57cd385455c22 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -16,62 +16,62 @@
 
 #include 
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__MMX__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE2__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE3__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSSE3__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 (defined(__SSE4_2__) || defined(__SSE4_1__))
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 (defined(__AES__) || defined(__PCLMUL__))
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CLFLUSHOPT__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CLWB__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+#if !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__AVX__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) ||