[libc][stdfix] Implement expuhk and expuk functions (#240631)
Implement `expuhk` and `expuk` functions with unit tests.
```c
unsigned short accum expuhk(unsigned short accum);
unsigned accum expuk(unsigned accum);
```
[MLIR][Vector] Fix ShapeCastBroadcastFolder when shape_cast changes non-unit dim strides (#227574)
### Summary
`ShapeCastBroadcastFolder` previously checked whether
`vector.shape_cast(vector.broadcast)` could be folded into a single
`vector.broadcast` by comparing the scalar product of stretched unit
dimensions (`getBroadcastStretchingFactor`).
However, a single scalar product is insufficient when `srcShape` has
multiple unit dimensions across different sides of a non-unit dimension,
and the `shape_cast` shifts the broadcast factor from an inner unit
dimension to an outer unit dimension.
For example:
```mlir
%0 = vector.broadcast %arg0 : vector<1x4x1xf32> to vector<1x4x4xf32>
%1 = vector.shape_cast %0 : vector<1x4x4xf32> to vector<4x4x1xf32>
```
[26 lines not shown]
[clang-tidy] Fix false negative for binary logical expressions for tw… (#230846)
Fixes #230601
This PR addresses the false-negative scenario where
`bugprone-redundant-branch-condition` fails to trigger on simple
two-variable logical conjunction expressions (e.g., `if (x && y) { if
(y) ... }`).
Note: This is a partial fix. As noted in the code's `// FIXME` comments,
handling longer conjunctive and disjunctive chain clauses (3 or more
variables) requires further extension is not yet touched.
---------
Co-authored-by: EugeneZelenko <eugene.zelenko at gmail.com>
Co-authored-by: Zeyi Xu <zeyi2 at nekoarch.cc>
[llvm-dwarfdump] Fix --error-display=summary and --error-display=quiet (#234308)
Before the patch `--error-display=summary` printed every error in detail
and no summary, and `--error-display=quiet` printed the aggregated
summary.
This patch adds `DIDumpOptions::ShowErrorDetails` to control per-error
output, and make `DIDumpOptions::ShowAggregateErrors` switch only the
"Aggregated error counts" summary. `DIDumpOptions::ShowErrorDetails`
defaults to true, so other DWARFVerifier users keep printing details.
Verbose no longer affects which verifier output is printed.
`llvm-dwarfdump --verify` sets `Verbose = true` unconditionally again,
and it only selects the format of the DIEs dumped in error details.
The duplicate .debug_line file name warning, which was gated on Verbose
to keep it out of the summary and quiet modes, is now gated on
ShowErrorDetails. As a consequence, dsymutil, DWARFLinker and
llvm-dwarfutil, which verify with default options, report this warning
[2 lines not shown]
[Offload][AMDGPU] Return the real user count from getUserCount
This patch fixes the return type of AMDGPUQueueTy::getUserCount, which
currently returns bool: that collapses the count to 0 or 1, which upsets
the occupancy measurement in assignNextQueue.
A new test checks that work is queued appropriately across hardware
queues.
Assisted-By: Claude
[Offload][AMDGPU] Return the HSA queue as a queue's native handle
Implement getNativeQueueHandle (introduced by #234186) for AMDGPU, so
that olGetQueueInfo can report OL_QUEUE_INFO_NATIVE_HANDLE for an AMDGPU
queue instead of UNSUPPORTED. The handle is the hsa_queue_t the queue's
stream is bound to; a stream is bound on first use, so querying binds
one if necessary. Several streams may share an HSA queue, in which case
their queues report the same handle.
Assisted-By: Claude
[LV] Allow targets to filter which types maximize bandwidth (#234642)
The motivation for this is to avoid maximizing bandwidth for `i1`s on
AArch64.
On AArch64, `i1` is a legal SVE predicate element type, but data vectors
require wider types.
Treating `i1` like any other element type in
`getSmallestAndWidestTypes()` can cause the maximize-vector-bandwidth
heuristic to select excessively large VFs based on the width of `i1`
vectors.
This is undesirable because predicate vectors are normally produced or
consumed alongside data vectors, and their legal width for such
operations matches that of the data vectors. Selecting wider predicate
vectors introduces unnecessary predicate unpacking and increases vector
register pressure.
[5 lines not shown]
[SPIRV] Select the correct `OpSelect` pseudo when dealing with untyped pointers (#240652)
We were not selecting the right flavour of `OpSelect` due to not
checking for `OpTypeUntypedPointerKHR` operands. This also exposed the
fact we were not always setting the correct register class. The patch
fixes both of these correlated issues.
[AMDGPU][AsmParser] Split the MTBUF formats into modifiers and regular operands
This eliminates the hacks parsing formats together with soffsets
that may follow them and printing them in printRegularOperand()
instead of using the custom printer as usual.
The legacy forms are supported as aliases using the
regular-operand formats.
Assisted-By: Claude
[OpenMP] Honour memory-order clauses on the flush directive
At present the acquire, release and acq_rel clauses on 'flush' are
accepted but have no effect. Flushes are emitted as __kmpc_flush runtime
calls, which implement a seq_cst fence.
AMD have had a downstream patch for a while (by Carlo Bertolli) which
adds per-ordering __kmpc_flush_* entry points to the device runtime.
This patch takes a slightly different approach: for the host, a seq_cst
flush still calls __kmpc_flush, and a flush with any other ordering
calls the __kmpc_flush_explicit entry point from #133325, so it needs
a runtime that has that. For the GPU, it emits a fence directly.
This has mild benefits: OpenMPOpt already handles fences when it converts
kernels to SPMD mode, but has no knowledge of the new __kmpc_flush calls
(either _explicit or Carlo's per-ordering flush calls). Scope names
differ per-GPU: they are determined using the mechanism introduced by
The lowering is done in OpenMPIRBuilder. The createFlush function now
[15 lines not shown]
[Clang][OpenMP] Add the OpenMP 6.0 memscope clause
This patch adds support for the 'memscope' clause from OpenMP 6.0 on
the 'flush' and 'atomic' directives. The clause selects the threads a
flush or atomic synchronizes with: those on the device (the default),
those in the contention group, or those on all devices. On 'flush',
a list may be specified alongside a memscope, but not together with a
memory-order clause (OpenMP 6.0, "17.8.6 flush Construct").
For the host, the scope is passed to the __kmpc_flush_explicit libomp
entry point as a __MEMORY_SCOPE_* value. For a GPU, the scope maps to a
target-specific syncscope for the fence.
Assisted-By: Claude
[CopyProf] Intercept new/delete and track per-object cost.
This intercepts the C++ `new` and `delete` operators, so that all
heap memory owned by a copy is tracked.
Using per-object state tracking, reports now tell the user how much
accumulated memory a copy is worth and whether it allocated.
This is useful for filtering of reports.
RFC: https://discourse.llvm.org/t/rfc-copysanitizer-csan-detecting-unneccessary-object-copies-at-runtime/91038
[CopyProf] Intercept C heap functions.
A copy that owns heap memory is only unnecessary if that memory is not
modified either. This intercepts the libc heap functions and routes them
to the CopyProf allocator, which marks memory allocated while copying as
copy, and checks the shadow memory of memory freed during destruction.
Memory allocated inside a d'tor is marked as copy as well, so that
freeing temporaries does not suppress reports.
Now that `malloc` is intercepted, `strndup` and `realpath` are
intercepted as well.
RFC: https://discourse.llvm.org/t/rfc-copysanitizer-csan-detecting-unneccessary-object-copies-at-runtime/91038
[CopyProf] Add standalone allocator. (#235453)
Detecting modifications of heap memory owned by a copy requires hooking
all (de)allocations and knowing allocation sizes. This adds a CopyProf
specific allocator based on the sanitizer_common allocator.
It provides surrogates for the libc heap functions, which are hooked up
to interceptors in a subsequent patch.
RFC:
https://discourse.llvm.org/t/rfc-copysanitizer-csan-detecting-unneccessary-object-copies-at-runtime/91038
Previous PR: #232851
Stack: #237763 → #232851 → #235453 (this PR) → #235454 → #235455
---------
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[mlir][ODS] Include headers required by generated bytecode readers and writers
The generated bytecode readers and writers use `DialectBytecodeReader`,
`DialectBytecodeWriter` and `TypeSwitch` but did not include the headers
declaring them. They therefore relied on the surrounding source file to
include these headers first.
The generated readers and writers now include
`BytecodeImplementation.h` and `TypeSwitch.h`.
As these includes must not be expanded within a namespace, all users
now include the generated file at global scope rather than within their
anonymous namespace.
Similar to #236155 and #238735 but for the bytecode generator.
Co-authored-by: Claude <noreply at anthropic.com>
[mlir][ODS] Fully qualify names in generated bytecode readers and writers
The code generated by `-gen-bytecode` referred to MLIR and LLVM
constructs such as `MLIRContext`, `DialectBytecodeReader`,
`LogicalResult`, `TypeSwitch` and `getChecked` without qualification,
as did the snippets in `BytecodeBase.td`. It therefore only compiled in
a source file with `using namespace mlir;`.
This PR fully qualifies all names emitted by the generator and by
`BytecodeBase.td`. Performed a minor refactor while doing so that also fixes an error message and makes the code less ad-hoc
Co-authored-by: Claude <noreply at anthropic.com>