aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/InterpBuiltin.cpp
AgeCommit message (Collapse)AuthorFilesLines
18 hours [clang][x86][bytecode] Refactor BMI intrinsic wrappers to use ↵jiang19971-93/+52
interp__builtin_elementwise_int_binop (#160362) Fixes #160281
3 days[clang][bytecode][NFC] Simplify a few builtin implementations (#160910)Timm Baeder1-56/+31
4 days[clang][bytecode][NFC] Simplify align_up/down implementation (#160880)Timm Baeder1-7/+5
Fix a double assignment to a local variable and use the new popToAPSInt() overload.
6 days[AST] Fix a warningKazu Hirata1-1/+2
This patch fixes: clang/lib/AST/ByteCode/InterpBuiltin.cpp:2603:15: error: unused variable 'VT1' [-Werror,-Wunused-variable]
6 days[Headers][X86] VectorExprEvaluator::VisitCallExpr - allow SSE/AVX2/AVX512 ↵woruyu1-0/+68
pack intrinsics to be used in constexpr (#156003) Fixes #154283
7 days[clang][x86][bytecode] Replace interp__builtin_knot with static bool ↵fennecJ1-11/+2
interp__builtin_elementwise_int_unaryop callback (#160332) Fix #160287
7 days[clang][byte] Add callback mechanism to handle constexpr for unary integer ↵Simon Pilgrim1-28/+26
ops (#160280) Add interp__builtin_elementwise_int_unaryop - similar to what we already have with interp__builtin_elementwise_int_binop to handle binops Update x86 lzcnt/tzcnt intrinsics to use with a suitable callback I'll add vector handling in a future patch when we add x86 vector intrinsics that can use it
7 days[Headers][X86] Allow basic AVX512 predicate ops to be used in constexpr ↵fennecJ1-0/+64
(#159998) Fixes #158646
11 days[Clang] Rename elementwise builtins to `clzg` and `ctzg` (#157128)Joseph Huber1-4/+4
Summary: The added bit counting builtins for vectors used `cttz` and `ctlz`, which is consistent with the LLVM naming convention. However, these are clang builtins and implement exactly the `__builtin_ctzg` and `__builtin_clzg` behavior. It is confusing to people familiar with other other builtins that these are the only bit counting intrinsics named differently. This includes the additional operation for the undefined zero case, which was added as a `clzg` extension.
12 days[Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow ↵Aditya Chaudhari1-0/+60
AVX/AVX512 subvector insertion intrinsics to be used in constexpr #157709 (#158778) AVX/AVX512 vector insert intrinsics now support constexpr evaluation in both the AST evaluator and bytecode interpreter paths. FIXES: #157709
13 days[clang][bytecode][NFC] Add some popToAPSInt convenience API (#159252)Timm Baeder1-62/+39
Add a variant that takes a QualType and one that takes an expression. That way we don't have to repeat the clunky classify() calls all over the place.
2025-09-15[X86][bytecode] Allow SSE/AVX BLEND imm intrinsics to be used in constexpr ↵Brandon1-0/+44
(#157776) This marks the following builtins as constexpr, which allows their corresponding intrinsics to be used in constexprs. | Intrinsics | X86 Builtins | CPUID Flags | Header | | -------------------- | --------------------------- | ----------- | ----------- | | `_mm_blend_pd` | `__builtin_ia32_blendpd` | SSE4.1 | smmintrin.h | | `_mm256_blend_pd` | `__builtin_ia32_blendpd256` | AVX | immintrin.h | | `_mm_blend_ps` | `__builtin_ia32_blendps` | SSE4.1 | smmintrin.h | | `_mm256_blend_ps` | `__builtin_ia32_blendps256` | AVX | immintrin.h | | `_mm_blend_epi16` | `__builtin_ia32_pblendw128` | SSE4.1 | smmintrin.h | | `_mm256_blend_epi16` | `__builtin_ia32_pblendw256` | AVX2 | immintrin.h | | `_mm_blend_epi32` | `__builtin_ia32_pblendd128` | AVX2 | immintrin.h | | `_mm256_blend_epi32` | `__builtin_ia32_pblendd256` | AVX2 | immintrin.h | Fixes #157065 --------- Co-authored-by: Timm Baeder <tbaeder@redhat.com> Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-09-11[clang][bytecode] Check builtin carryops for dummy pointers (#157490)Timm Baeder1-0/+3
Fixes #157422
2025-09-11[clang][bytecode] Check strlen impl for primitive arrays (#157494)Timm Baeder1-0/+3
Fixes #157428
2025-09-09[Headers][X86] Enable constexpr handling for MMX/SSE/AVX/AVX512 avg ↵Bhasawut Singhaphan1-0/+9
intrinsics (#157464) This PR updates the avg builtins to support constant expression handling, by extending the VectorExprEvaluator::VisitCallExpr that handles elementwise integer binop builtins. Closes #155390 --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-09-09[clang][bytecode][X86] Allow AVX512 funnel shift by scalar immediate ↵Simon Pilgrim1-1/+53
intrinsics to be used in constexpr (#157681) Extends interp__builtin_elementwise_triop to handle (vector, vector, scalar) trinary op intrinsics Fixes #153152
2025-09-09[X86] Allow remaining AVX512 per-element shift intrinsics to be used in ↵Simon Pilgrim1-0/+14
constexpr (#157696) Handle missing AVX512F epi64 and AVX512BW epi16 cases with existing code paths Fixes #154287
2025-09-05[X86][bytecode] Allow SSE/AVX BLENDVPD/PD intrinsics to be used in constexpr ↵Simon Pilgrim1-0/+9
(#157126) BLENDV intrinsics use the signbit of the condition mask to select between the LHS (false) and RHS (true) operands Fixes #157066
2025-09-05[Clang][bytecode] Add interp__builtin_elementwise_triop_fp to handle general ↵Simon Pilgrim1-7/+16
3-operand floating point intrinsics (#157106) Refactor interp__builtin_elementwise_fma into something similar to interp__builtin_elementwise_triop with a callback function argument to allow reuse with other intrinsics. This will allow reuse with some upcoming x86 intrinsics
2025-09-05[X86][bytecode] Allow SSE/AVX PBLENDVB intrinsics to be used in constexpr ↵Simon Pilgrim1-0/+7
(#157100) BLENDV intrinsics use the signbit of the condition mask to select between the LHS (false) and RHS (true) operands First part of #157066 - the BLENDVPS/D requires floatbits hacking which I need to do some prep work for
2025-09-05[Clang][bytecode] interp__builtin_elementwise_binop - remove unused ↵Simon Pilgrim1-10/+10
BuiltinID argument. NFC (#157109)
2025-09-05[Clang][bytecode] Add interp__builtin_elementwise_triop to handle general ↵Simon Pilgrim1-31/+20
3-operand integer intrinsics (#156944) Refactor interp__builtin_elementwise_fsh into something similar to interp__builtin_elementwise_int_binop with a callback function argument to allow reuse with other intrinsics This will allow reuse with some upcoming x86 intrinsics We can flesh out handling for mixed vector/scalar args as the need arises
2025-09-04[Clang] Enable constexpr handling for builtin elementwise fshl/fshr (#153572)Chaitanya Koparkar1-0/+63
Fixes #153151.
2025-09-03[X86] Allow AVX512 512-bit variants of AVX2 per-element i32 shift intrinsics ↵Simon Pilgrim1-0/+3
to be used in constexpr (#156480) Followup to #154780
2025-08-30[X86] Add constexpr handling for XOP/AVX512 rotate by immediate intrinsics ↵Simon Pilgrim1-0/+24
(#156047)
2025-08-29[Headers][X86] VisitCallExpr constexpr immediate shifts (#154293) (#155542)Justin Riddell1-14/+55
Fixes #154293 Implement VectorExprEvaluator::VisitCallExpr constexpr support for left, right, arithmetic shift for MMX/SSE/AVX2/AVX512 intrinsics _mm*_slli_epi* _mm*_srli_epi* _mm*_srai_epi* _mm*_mask_slli_epi* _mm*_maskz_slli_epi* NOTE: not all intrinsics have all widths i.e. _mm_srli_pi32 doesn't have pi64 etc.
2025-08-29[clang][x86] Ensure we use the shifted value bit width to check for out of ↵Simon Pilgrim1-6/+6
bounds per-element shift amounts (#156019) This should allow us to reuse these cases for the shift-by-immediate builtins in #155542
2025-08-29[Clang][bytecode] interp__builtin_elementwise_int_binop - use APSInt ↵Simon Pilgrim1-70/+46
callback instead of repeated switch statement (#155891) Users of interp__builtin_elementwise_int_binop are going to be very well defined, we can use a simple callback mechanism (including existing llvm::APIntOps static methods) to perform the evaluation and avoid a repeated switch statement. Hopefully this will help keep interp__builtin_elementwise_int_binop clean as we add more uses
2025-08-26[Clang] Support generic bit counting builtins on fixed boolean vectors (#154203)Joseph Huber1-6/+40
Summary: Boolean vectors as implemented in clang can be bit-casted to an integer that is rounded up to the next primitive sized integer. Users can do this themselves, but since the counting bits are very likely to be used with bitmasks like this and the generic forms are expected to be generic it seems reasonable that we handle this case directly.
2025-08-26[clang][bytecode] Support remaining add_sat like X86 builtins (#155358)Timm Baeder1-4/+44
2025-08-26[clang][bytecode][NFC] Check InitializingBlocks in _within_lifetime (#155378)Timm Baeder1-6/+2
This kind of check is exactly why InterpState::InitializingBlocks exists.
2025-08-25[clang] NFC: change more places to use Type::getAsTagDecl and friends (#155313)Matheus Izvekov1-14/+7
This changes a bunch of places which use getAs<TagType>, including derived types, just to obtain the tag definition. This is preparation for #155028, offloading all the changes that PR used to introduce which don't depend on any new helpers.
2025-08-21[clang][bytecode] Guard strcmp against differing element types (#154777)Timm Baeder1-1/+6
This can happen when casts are involved. Fixes #154006
2025-08-21[clang][bytecode] Implement ia32_select* builtins (#154758)Timm Baeder1-0/+61
2025-08-21[clang][bytecode] Fix an out-of-bounds access with ia32_pmul* (#154750)Timm Baeder1-6/+11
... builtins. We used to access the I'th index of the output vector, but that doesn't work since the output vector is only half the size of the input vector.
2025-08-20[AST] Fix warningsKazu Hirata1-0/+4
This patch fixes: clang/lib/AST/ByteCode/InterpBuiltin.cpp:1827:21: error: unused variable 'ASTCtx' [-Werror,-Wunused-variable] clang/lib/AST/ByteCode/InterpBuiltin.cpp:2724:18: error: unused variable 'Arg2Type' [-Werror,-Wunused-variable] clang/lib/AST/ByteCode/InterpBuiltin.cpp:2725:18: error: unused variable 'Arg3Type' [-Werror,-Wunused-variable] clang/lib/AST/ByteCode/InterpBuiltin.cpp:2748:18: error: unused variable 'ElemT' [-Werror,-Wunused-variable]
2025-08-20[clang] Enable constexpr handling for __builtin_elementwise_fma (#152919)Chaitanya Koparkar1-0/+58
Fixes https://github.com/llvm/llvm-project/issues/152455.
2025-08-20[clang] Introduce elementwise ctlz/cttz builtins (#131995)Fraser Cormack1-0/+92
These builtins are modeled on the clzg/ctzg builtins, which accept an optional second argument. This second argument is returned if the first argument is 0. These builtins unconditionally exhibit zero-is-undef behaviour, regardless of target preference for the other ctz/clz builtins. The builtins have constexpr support. Fixes #154113
2025-08-19[clang][bytecode] Implement ia32_pmul* builtins (#154315)Timm Baeder1-0/+51
2025-08-19[clang][bytecode] Support pmul X86 builtins (#154275)Timm Baeder1-3/+24
2025-08-18[clang][bytecode] Improve __builtin_{,dynamic_}object_size implementation ↵Timm Baeder1-21/+129
(#153601)
2025-08-15[Clang][Bytecode][NFC] Move Result into APSInt constructor (#153664)Shafik Yaghmour1-1/+1
Static analysis flagged this line because we are copying Result instead of moving it.
2025-08-14[clang] constexpr `__builtin_elementwise_abs` support (#152497)Vincent1-10/+66
Added constant evaluation support for `__builtin_elementwise_abs` on integer, float and vector type. fixes #152276 --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-08-13[clang][bytecode] Diagnose incomplete types more consistently (#153368)Timm Baeder1-13/+21
To match the diagnostics of the current interpreter.
2025-08-12[clang] constexpr integer `__builtin_elementwise_{max,min}` (#152294)Iris Shi1-1/+78
- Closes #152278 - Part of #51787 This PR adds support for the bulitin elementwise max/min functions for integer types.
2025-08-11[clang][bytecode] Avoid a getValue() call in builtin_isinf (#152939)Timm Baeder1-3/+4
Get the APFloat once and work with that, instead of calling isInf() and potentially isNegative().
2025-08-10[clang][bytecode][NFC] Fix ternary operators with known IsArray values (#152894)Timm Baeder1-5/+3
After https://github.com/llvm/llvm-project/pull/146471, the values here are known.
2025-08-09[clang][bytecode] Add AccessFlags to Block (#152590)Timm Baeder1-0/+7
This way, we can check a single uint8_t for != 0 to know whether this block is accessible or not. If not, we still need to figure out why not and diagnose appropriately of course.
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-3/+4
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-07[clang][bytecode] Refactor Check* functions (#152300)Timm Baeder1-2/+2
... so we don't have to create Pointer instances when we don't need them.