402 Commits

Author SHA1 Message Date
Kazu Hirata
886655869c [clang] Fix typos in documentation 2023-12-21 08:18:49 -08:00
Nikolas Klauser
b204321302
[Clang][docs] Update extension documentation (#75150)
This is back-ported to C++03 now, since clang accepts C++11 attributes
in C++03. https://godbolt.org/z/f7xG18bdE
2023-12-12 12:22:03 +01:00
Joseph Huber
4e80bc7d71
[Clang] Introduce scoped variants of GNU atomic functions (#72280)
Summary:
The standard GNU atomic operations are a very common way to target
hardware atomics on the device. With more heterogenous devices being
introduced, the concept of memory scopes has been in the LLVM language
for awhile via the `syncscope` modifier. For targets, such as the GPU,
this can change code generation depending on whether or not we only need
to be consistent with the memory ordering with the entire system, the
single GPU device, or lower.

Previously these scopes were only exported via the `opencl` and `hip`
variants of these functions. However, this made it difficult to use
outside of those languages and the semantics were different from the
standard GNU versions. This patch introduces a `__scoped_atomic` variant
for the common functions. There was some discussion over whether or not
these should be overloads of the existing ones, or simply new variants.
I leant towards new variants to be less disruptive.

The scope here can be one of the following

```
__MEMORY_SCOPE_SYSTEM // All devices and systems
__MEMORY_SCOPE_DEVICE // Just this device
__MEMORY_SCOPE_WRKGRP // A 'work-group' AKA CUDA block
__MEMORY_SCOPE_WVFRNT // A 'wavefront' AKA CUDA warp
__MEMORY_SCOPE_SINGLE // A single thread.
```
Naming consistency was attempted, but it is difficult to capture to full
spectrum with no many names. Suggestions appreciated.
2023-12-07 13:40:25 -06:00
Utkarsh Saxena
e825cc4eba
[clang] Add separate C++23 extension flag for attrs on lambda (#74553) 2023-12-07 14:52:10 +01:00
Younan Zhang
b3392c447a
[clang] Reject incomplete type arguments for __builtin_dump_struct (#72749)
We used to assume that the CXXRecordDecl passed to the 1st argument
always had a definition. This is not true since a pointer to an
incomplete type was not excluded.

Fixes https://github.com/llvm/llvm-project/issues/63506
2023-12-05 09:59:42 +08:00
Matt Arsenault
0237f1b998
clang: Add pragma clang fp reciprocal (#68267)
Just follow along with the reassociate pragma. This allows locally
setting the arcp fast math flag. Previously you could only access this
through the global -freciprocal-math.

Fixes #64798
2023-11-28 23:38:50 +09:00
philnik777
4cc791bc98
[Clang] Add __datasizeof (#67805)
The data size is required for implementing the `memmove` optimization
for `std::copy`, `std::move` etc. correctly as well as replacing
`__compressed_pair` with `[[no_unique_address]]` in libc++. Since the
compiler already knows the data size, we can avoid some complexity by
exposing that information.
2023-11-13 11:00:07 +01:00
Lawrence Benson
de65b6bec6
[Clang] Add __builtin_vectorelements to get number of elements in vector (#69010)
Adds a new `__builtin_vectorelements()` function which returns the
number of elements for a given vector either at compile-time for
fixed-sized vectors, e.g., created via `__attribute__((vector_size(N)))`
or at runtime via a call to `@llvm.vscale.i32()` for scalable vectors,
e.g., SVE or RISCV V.

The new builtin follows a similar path as `sizeof()`, as it essentially
does the same thing but for the number of elements in vector instead of
the number of bytes. This allows us to re-use a lot of the existing
logic to handle types etc.

A small side addition is `Type::isSizelessVectorType()`, which we need
to distinguish between sizeless vectors (SVE, RISCV V) and sizeless
types (WASM).

This is the [corresponding
discussion](https://discourse.llvm.org/t/new-builtin-function-to-get-number-of-lanes-in-simd-vectors/73911).
2023-10-19 10:45:08 +02:00
Christopher Di Bella
8f3b0b4171 [clang] adds __reference_constructs_from_temporary
This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Differential Revision: https://reviews.llvm.org/D135341
2023-09-13 23:51:43 +00:00
Christopher Di Bella
dfd1d8d505 Revert "adds __reference_constructs_from_temporary"
I'm reverting this on principle, since it didn't get the Phabricator
approval I thought it had (only an informal LGTM). Will re-apply once
it has been properly approved.

This reverts commit e1bfeb6bcc627a94c5ab3a5417d290c7dc516d54.
2023-09-11 23:44:50 +00:00
Christopher Di Bella
e1bfeb6bcc adds __reference_constructs_from_temporary
This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Differential Revision: https://reviews.llvm.org/D135341
2023-09-11 23:14:08 +00:00
Zahira Ammarguellat
2c93e3c1c8 Take math-errno into account with '#pragma float_control(precise,on)' and
'attribute__((optnone)).

Differential Revision: https://reviews.llvm.org/D151834
2023-09-08 09:48:53 -04:00
Serge Pavlov
9fd57e4d48 [clang] Support vectors in __builtin_isfpclass
Builtin function `__builtin_isfpclass` now can be called for a vector
of floating-point values. In this case it is applied to the vector
elementwise and produces vector of integer values.

Differential Revision: https://reviews.llvm.org/D153339
2023-09-02 11:52:43 +07:00
Kazu Hirata
3a14993fa4 Fix typos in documentation 2023-08-27 00:18:14 -07:00
Kazu Hirata
11e2975810 Fx typos in documentation 2023-08-18 23:36:04 -07:00
Alejandro Aguirre
00158ae236 [clang] Enable constexpr on LZCNT/POPCNT MS extension intrinsics
As discussed on #46593 - this enables us to use __lzcnt / __popcnt intrinsics inside constexpr code.

Differential Revision: https://reviews.llvm.org/D157420
2023-08-14 11:33:33 +01:00
Jianjian GUAN
9d0cf88e70 [clang][doc] Mark _Float16 is support natively when Zfh or Zhinx is available
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D157693
2023-08-14 11:27:15 +08:00
Matt Arsenault
9e3d9c9eae clang: Add __builtin_elementwise_sqrt
This will be used in the opencl builtin headers to provide direct
intrinsic access with proper !fpmath metadata.

https://reviews.llvm.org/D156737
2023-08-11 19:32:39 -04:00
Aaron Ballman
315d1d094f [C23] Update user-facing docs for C23
This changes some public references of C2x to be C23, corrects standard
citations to use the final paragraph numbers, and adds some information
about differences between C17 and C23 modes.
2023-08-10 14:19:41 -04:00
Jun Sha (Joshua)
a5791bfef4 [RISCV][BF16] Enable __bf16 for riscv targets
The RISC-V psABI recently added __bf16 in https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/367.
Now we can enable this new type in clang.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D150929
2023-08-01 13:59:27 +08:00
Joshua Batista
57f879cdd4 clang: Add elementwise bitreverse builtin
Add codegen for llvm bitreverse elementwise builtin
The bitreverse elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types, or too many inputs.
The new builtin is restricted to integer types only.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D156357
2023-07-31 10:59:13 -07:00
Joshua Batista
3a98e73169 clang: Add elementwise pow builtin
Add codegen for llvm pow elementwise builtin
The pow elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types, or too many inputs.
The new builtin is restricted to floating point types only.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D153310
2023-07-24 14:03:58 -07:00
Nikolas Klauser
874217f99b [clang] Enable C++11-style attributes in all language modes
This also ignores and deprecates the `-fdouble-square-bracket-attributes` command line flag, which seems to not be used anywhere. At least a code search exclusively found mentions of it in documentation: https://sourcegraph.com/search?q=context:global+-fdouble-square-bracket-attributes+-file:clang/*+-file:test/Sema/*+-file:test/Parser/*+-file:test/AST/*+-file:test/Preprocessor/*+-file:test/Misc/*+archived:yes&patternType=standard&sm=0&groupBy=repo

RFC: https://discourse.llvm.org/t/rfc-enable-c-11-c2x-attributes-in-all-standard-modes-as-an-extension-and-remove-fdouble-square-bracket-attributes

This enables `[[]]` attributes in all C and C++ language modes without warning by default. `-Wc++-extensions` does warn. GCC has enabled this extension in all C modes since GCC 10.

Reviewed By: aaron.ballman, MaskRay

Spies: #clang-vendors, beanz, JDevlieghere, Michael137, MaskRay, sstefan1, jplehr, cfe-commits, lldb-commits, dmgreen, jdoerfert, wenlei, wlei

Differential Revision: https://reviews.llvm.org/D151683
2023-07-22 09:34:15 -07:00
Nikolas Klauser
f6d557ee34 [clang][NFC] Remove trailing whitespaces and enforce it in lib, include and docs
A lot of editors remove trailing whitespaces. This patch removes any trailing whitespaces and makes sure that no new ones are added.

Reviewed By: erichkeane, paulkirth, #libc, philnik

Spies: wangpc, aheejin, MaskRay, pcwang-thead, cfe-commits, libcxx-commits, dschuff, nemanjai, arichardson, kbarton, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, s.egerton, sameer.abuasal, apazos, luismarques, martong, frasercrmck, steakhal, luke

Differential Revision: https://reviews.llvm.org/D151963
2023-06-26 09:34:36 -07:00
Matt Arsenault
9d84f8dc94 clang: Add __builtin_elementwise_rint and nearbyint
These are basically the same thing and only differ for strictfp,
so add both for future proofing. Note all the elementwise functions are
currently broken for strictfp, and use non-constrained ops. Add a test
that demonstrates this, but doesn't attempt to fix it.
2023-06-23 19:52:06 -04:00
Zahira Ammarguellat
63b0b82fd6 When float_t and double_t types are used inside a scope with
a '#pragma clang fp eval_method, it can lead to ABI breakage.
See https://godbolt.org/z/56zG4Wo91
This patch prevents this.

Differential Revision: https://reviews.llvm.org/D153590
2023-06-23 15:12:51 -04:00
Matt Arsenault
2a488b4443 clang: Add __builtin_elementwise_round 2023-06-19 11:32:56 -04:00
Serge Pavlov
112fa9aa70 [Doc] Fix table layout 2023-06-18 23:46:08 +07:00
Serge Pavlov
7dd387d297 [clang] Add __builtin_isfpclass
A new builtin function __builtin_isfpclass is added. It is called as:

    __builtin_isfpclass(<floating point value>, <test>)

and returns an integer value, which is non-zero if the floating point
argument falls into one of the classes specified by the second argument,
and zero otherwise. The set of classes is an integer value, where each
value class is represented by a bit. There are ten data classes, as
defined by the IEEE-754 standard, they are represented by bits:

    0x0001 (__FPCLASS_SNAN)         - Signaling NaN
    0x0002 (__FPCLASS_QNAN)         - Quiet NaN
    0x0004 (__FPCLASS_NEGINF)       - Negative infinity
    0x0008 (__FPCLASS_NEGNORMAL)    - Negative normal
    0x0010 (__FPCLASS_NEGSUBNORMAL) - Negative subnormal
    0x0020 (__FPCLASS_NEGZERO)      - Negative zero
    0x0040 (__FPCLASS_POSZERO)      - Positive zero
    0x0080 (__FPCLASS_POSSUBNORMAL) - Positive subnormal
    0x0100 (__FPCLASS_POSNORMAL)    - Positive normal
    0x0200 (__FPCLASS_POSINF)       - Positive infinity

They have corresponding builtin macros to facilitate using the builtin
function:

    if (__builtin_isfpclass(x, __FPCLASS_NEGZERO | __FPCLASS_POSZERO) {
      // x is any zero.
    }

The data class encoding is identical to that used in llvm.is.fpclass
function.

Differential Revision: https://reviews.llvm.org/D152351
2023-06-18 22:53:32 +07:00
Paulo Matos
55aeb23fe0 [clang][WebAssembly] Implement support for table types and builtins
This commit implements support for WebAssembly table types and
respective builtins. Table tables are WebAssembly objects to store
reference types. They have a large amount of semantic restrictions
including, but not limited to, only being allowed to be declared
at the top-level as static arrays of zero-length. Not being arguments
or result of functions, not being stored ot memory, etc.

This commit introduces the __attribute__((wasm_table)) to attach to
arrays of WebAssembly reference types. And the following builtins to
manage tables:

* ref   __builtin_wasm_table_get(table, idx)
* void  __builtin_wasm_table_set(table, idx, ref)
* uint  __builtin_wasm_table_size(table)
* uint  __builtin_wasm_table_grow(table, ref, uint)
* void  __builtin_wasm_table_fill(table, idx, ref, uint)
* void  __builtin_wasm_table_copy(table, table, uint, uint, uint)

This commit also enables reference-types feature at bleeding-edge.

This is joint work with Alex Bradbury (@asb).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D139010
2023-06-10 15:53:13 +02:00
Aaron Ballman
12728e1449 [C] Support _Generic expressions with a type operand
_Generic accepts an expression operand whose type is matched against a
list of associations. The expression operand is unevaluated, but the
type matched is the type after lvalue conversion. This conversion loses
type information, which makes it more difficult to match against
qualified or incomplete types.

This extension allows _Generic to accept a type operand instead of an
expression operand. The type operand form does not undergo any
conversions and is matched directly against the association list.

This extension is also supported in C++ as we already supported
_Generic selection expressions there.

The RFC for this extension can be found at:
https://discourse.llvm.org/t/rfc-generic-selection-expression-with-a-type-operand/70388

Differential Revision: https://reviews.llvm.org/D149904
2023-06-05 11:09:58 -04:00
Kazu Hirata
a82f2b2db3 Fix typos in documentation 2023-05-28 13:13:12 -07:00
M. Zeeshan Siddiqui
dd2e681612 [Docs] Fix Sphinx documentation formatting issues in LanguageExtensions.rst
Fix indentation and spacing.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D151610
2023-05-27 16:45:21 +08:00
M. Zeeshan Siddiqui
e621757365 [Clang][BFloat16] Upgrade __bf16 to arithmetic type, change mangling, and extend excess precision support
Pursuant to discussions at
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033/22,
this commit enhances the handling of the __bf16 type in Clang.
- Firstly, it upgrades __bf16 from a storage-only type to an arithmetic
  type.
- Secondly, it changes the mangling of __bf16 to DF16b on all
  architectures except ARM. This change has been made in
  accordance with the finalization of the mangling for the
  std::bfloat16_t type, as discussed at
  https://github.com/itanium-cxx-abi/cxx-abi/pull/147.
- Finally, this commit extends the existing excess precision support to
  the __bf16 type. This applies to hardware architectures that do not
  natively support bfloat16 arithmetic.
Appropriate tests have been added to verify the effects of these
changes and ensure no regressions in other areas of the compiler.

Reviewed By: rjmccall, pengfei, zahiraam

Differential Revision: https://reviews.llvm.org/D150913
2023-05-27 13:33:50 +08:00
Aaron Ballman
09841d792f Add WG14 N2607 to the list of backported features
Arrays and their element types are identically qualified as of C2x,
and we support that behavior as far back as C89.

As a drive-by, this adds the paper number for designated initializers
so that all the WG14 features can be uniquely identified despite the
lack of a feature testing macro.
2023-05-22 08:16:32 -04:00
Jakub Mazurkiewicz
78d8312ace [Clang][clang-cl] Implement __builtin_FUNCSIG
This patch implements __builtin_FUNCSIG intrinsic which returns the same string as __FUNCSIG__.

Fixes https://github.com/llvm/llvm-project/issues/58951
Differential Revision: https://reviews.llvm.org/D150183
2023-05-19 12:02:44 -04:00
Kazu Hirata
2db0812882 [clang] Fix typos in documentation 2023-05-12 23:19:17 -07:00
jinge90
2ed77846a9 This patch adds doc for __builtin_flt_rounds and __builtin_set_flt_rounds
and also adds description for default fp environment.

Reviewed By:rjmccall, sepavloff
Differential Revision: https://reviews.llvm.org/D146188
2023-05-12 11:12:36 +08:00
Nikolas Klauser
b09fad7f8e [clang] Document extensions from later standards
Reviewed By: aaron.ballman

Spies: H-G-Hristov, cfe-commits

Differential Revision: https://reviews.llvm.org/D150321
2023-05-11 11:54:46 -07:00
Nikolas Klauser
e98776a180 [clang] Add __is_trivially_equality_comparable
This patch adds a new trait to allow standard libraries to forward `std::equal` calls to `memcmp` in more cases.

Reviewed By: aaron.ballman

Spies: Mordante, shafik, xbolva00, libcxx-commits, cfe-commits, ldionne

Differential Revision: https://reviews.llvm.org/D147175
2023-04-17 15:36:21 +02:00
Vlad Serebrennikov
467ed27987 [clang] Extend pragma dump to support expressions
Extend `#pragma clang __debug dump` to support not only single identifier, but an expression as well. This makes it possible to test ADL and overload resolution directly, without being creative to make them observable via diagnostics (e.g. when [[ http://eel.is/c++draft/over.match.best | over.match.best ]] is involved). This implementation has a known limitation of not supporting dependent expressions properly, but it's quite useful even without such support.

Differential Revision: https://reviews.llvm.org/D144115
2023-03-24 17:35:35 +03:00
Aaron Ballman
ef310c6d49 Fix Clang sphinx build
This addresses the issues found in:
https://lab.llvm.org/buildbot/#/builders/92/builds/41772
2023-03-24 07:27:07 -04:00
Bruno Cardoso Lopes
07ef7b1ff2 [Builtins] Add __builtin_assume_separate_storage
Plumbing from the language level to the assume intrinsics with
separate_storage operand bundles.

Patch by David Goldblatt (davidtgoldblatt)

Differential Revision: https://reviews.llvm.org/D136515
2023-03-23 16:35:30 -07:00
Ilya Karapsin
2147e940e8 Add __builtin_FILE_NAME()
Add '__builtin_FILE_NAME()', which expands to the filename because the
full path is not always needed. It corresponds to the '__FILE_NAME__'
predefined macro and is consistent with the other '__builin' functions
added for predefined macros.

Differential Revision: https://reviews.llvm.org/D144878
2023-03-17 09:52:41 -04:00
Joshua Batista
4c82050c56 Add codegen for llvm exp/exp2 elementwise builtins
Add codegen for llvm exp/exp2 elementwise builtin
The exp/exp2 elementwise builtins are necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types.
The new builtins are restricted to floating point types only.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D145270
2023-03-09 12:14:59 -08:00
Matt Arsenault
8709bcacfb clang: Add __builtin_elementwise_fma
I didn't understand why the other builtins have promotion logic,
or how it would apply for a ternary operation. Implicit conversions
are evil to begin with,  and even more so when the purpose is to get
an exact IR intrinsic. This checks all the arguments have the same type.
2023-02-24 21:55:08 -04:00
Fangrui Song
44b391fc47 LanguageExtensions.rst: fix a typo in the #pragma clang deprecated example 2023-02-24 12:41:49 -08:00
Nick Desaulniers
54186d33c3 [clang] add __has_extension(gnu_asm_goto_with_outputs_full)
Also move the line about __has_extension(gnu_asm_goto_with_outputs) so
that it is more generally about asm goto, not the paragraph on symbolic
references.

Reviewed By: efriedma, void

Differential Revision: https://reviews.llvm.org/D143205
2023-02-16 17:58:35 -08:00
Nick Desaulniers
329ef60f3e [Clang] support for outputs along indirect edges of asm goto
Initial support for asm goto w/ outputs (D69876) only supported outputs
along the "default" (aka "fallthrough") edge.

We can support outputs along all edges by repeating the same pattern of
stores along the indirect edges that we allready do for the default
edge.  One complication is that these indirect edges may be critical
edges which would need to be split. Another issue is that mid-codgen of
LLVM IR, the control flow graph might not reflect the control flow of
the final function.

To avoid this "chicken and the egg" problem assume that any given
indirect edge may become a critical edge, and pro-actively split it.
This is unnecessary if the edge does not become critical, but LLVM will
optimize such cases via tail duplication.

Fixes: https://github.com/llvm/llvm-project/issues/53562

Reviewed By: void

Differential Revision: https://reviews.llvm.org/D136497
2023-02-16 17:58:34 -08:00
KAWASHIMA Takahiro
e8d44841c5 [docs] Update the ACLE URL 2023-02-14 19:14:04 +09:00