7219 Commits

Author SHA1 Message Date
Kazu Hirata
1f3c38f125
[Support] Remove an unnecessary cast (NFC) (#154048)
qp is already of uint64_t.
2025-08-17 23:46:20 -07:00
Kazu Hirata
0ede7ace0d
[ADT] Use llvm::copy in SmallPtrSet.cpp (NFC) (#153930)
This patch uses llvm::copy in combination with buckets() and
small_buckets().
2025-08-16 06:47:18 -07:00
Kazu Hirata
627f8018fe
[ADT] Rename NumNonEmpty to NumEntries in SmallPtrSet (NFC) (#153757)
Without this patch, we use NumNonEmpty, which keeps track of the
number of valid entries plus tombstones even though we have a separate
variable to keep track of the number of tombstones.

This patch simplifies the metadata.  Specifically, it changes the name
and semantics of the variable to NumEntries to keep track of the
number of valid entries.

The difference in semantics requires some code changes aside from
mechanical replacements:

- size() just returns NumEntries.

- erase_imp() and remove_if() need to decrement NumEntries in the
  large mode.

- insert_imp_big() increments NumEntries for successful insertions,
  regardless of whether a tombstone is being replaced with a valid
  entry.  It also computes the number of non-tombstone empty slots as:

  CurArraySize - NumEntries - NumTombstones

- Grow() no longer needs NumNonEmpty -= NumTombstones.

Overall, the resulting code should look more intuitive and more
consistent with DenseMapSet.
2025-08-15 21:22:37 -07:00
joaosaffran
37729d8ceb
[HLSL] Refactoring DXILABI.h to not depend on scope printer (#153840)
This patch refactors DXILABI to remove the dependency on scope printer. 
Closes: #153827

---------

Co-authored-by: Joao Saffran <{ID}+{username}@users.noreply.github.com>
2025-08-15 21:33:44 -04:00
Steven Wu
7e46f5db21
[Support] Add mapped_file_region::sync(), equivalent to msync (#153632) 2025-08-14 17:05:33 -07:00
joaosaffran
d56fa96524
[DirectX] Add Range Overlap validation (#152229)
As part of the Root Signature Spec, we need to validate if Root
Signatures are not defining overlapping ranges.
Closes: https://github.com/llvm/llvm-project/issues/126645

---------

Co-authored-by: joaosaffran <joao.saffran@microsoft.com>
Co-authored-by: Joao Saffran <{ID}+{username}@users.noreply.github.com>
Co-authored-by: Joao Saffran <jderezende@microsoft.com>
2025-08-14 18:40:11 -04:00
Aiden Grossman
47e62e846b Revert "[APFloat] Fix getExactInverse for DoubleAPFloat"
This reverts commit f4941319cba19d7691baa6ec783c84be4d847637.

This broke llvm/test/CodeGen/Thumb2/mve-vcvt-fixed-to-float.ll which
took out a ton of buildbots and also broke premerge.
2025-08-14 04:39:50 +00:00
Pedro Lobo
08eff57444
[ADT] Add signed and unsigned mulExtended to APInt (#153399)
Adds `mulsExtended` and `muluExtended` methods to `APInt`, as suggested
in #153293.
These are based on the `MULDQ` and `MULUDQ` x86 intrinsics.
2025-08-13 22:37:33 +01:00
Richard Smith
85cd3d9868
Work around documented Linux mmap bug. (#152595)
On Linux, mmap doesn't always zero-fill slack bytes ([man page]),
despite being required to do so by POSIX. If the final page of a file is
in the page cache and the bytes past the end of the file get overwritten
by some process, those bytes then remain non-zero until the page falls
out of the cache or another process overwrites them.

Stop trusting that mmap behaves properly and instead check
whether the buffer was indeed properly terminated. If not, fall back to
using `read` to read the file contents.

This fixes an obscure clang crash bug that can occur if another program
(such as an editor) mmap's a source file and writes past the end of the
mmap'd region shortly before clang or clangd attempts to parse the file.

 [man page]: https://man7.org/linux/man-pages/man2/mmap.2.html#BUGS
2025-08-13 12:39:25 -07:00
David Majnemer
f4941319cb [APFloat] Fix getExactInverse for DoubleAPFloat
Some background: getExactInverse()'s callers expect that
the result is not subnormal.

DoubleAPFloat implemented getExactInverse() by going through
semPPCDoubleDoubleLegacy.

This means that numbers like 0x1p1022 which would have a normal inverse
in semPPCDoubleDouble would not in semPPCDoubleDoubleLegacy.

This commit refactors the logic into a single method on APFloat which
uses getExactLog2Abs() and scalbn() to calculate the inverse without
having to compute a reciprocal and test if it is inexact.
This approach works for both IEEEFloat and DoubleAPFloat.
2025-08-13 11:39:53 -07:00
David Majnemer
acef1db3b2 [APFloat] Remove some overly optimistic assertions
An earlier draft of DoubleAPFloat::convertToSignExtendedInteger had
arranged for overflow to be handled in a different way.  However, these
assertions are now possible if Hi+Lo are out of range and Lo != 0.

A test has been added to defend against a regression.
2025-08-12 18:32:58 -07:00
David Majnemer
f6d143fd1f [APFloat] Properly implement frexp(DoubleAPFloat)
The prior implementation did not consider that the Lo component may
underflow when it undergoes scaling.  This means that we need to
carefully handle things like binade crossings or how to handle
roundTowardZero when Hi and Lo have different signs.

Particularly annoying is roundTiesToAway when Hi and Lo have different
signs.  It basically requires us to implement roundTiesTowardZero.
2025-08-12 17:03:27 -07:00
David Majnemer
e722ef4956 Reapply "[APFloat] Properly implement DoubleAPFloat::convertToSignExtendedInteger"
This reverts commit 8b44945a9231d4d7be0858a1c5d9c13d397bc512.

The compilation failure under !NDEBUG has been fixed.
2025-08-12 17:01:49 -07:00
Macsen Casaus
6fa13d79cf
[InstCombine] Add additional known bits info for self multiply (#151202)
Closes #151043 
https://alive2.llvm.org/ce/z/JyMSk8
2025-08-11 10:52:04 +02:00
Kazu Hirata
8b44945a92 Revert "[APFloat] Properly implement DoubleAPFloat::convertToSignExtendedInteger"
This reverts commit 052c38be824d9dabb1e8fb64c1c7c3908d786e83.

I'm getting:

llvm/lib/Support/APFloat.cpp:5627:29: error:
use of undeclared identifier 'Parts'
 5627 |     assert(DstPartsCount <= Parts.size() && "Integer too big");
      |                             ^
1 error generated.
2025-08-10 00:36:29 -07:00
David Majnemer
052c38be82 [APFloat] Properly implement DoubleAPFloat::convertToSignExtendedInteger
Use DoubleAPFloat::roundToIntegral to get a pair of APFloat values which
hold integral values.  Then we sum the pair, taking care to make sure
that we handle edge cases like (hi=2^128, lo=-1) and ensuring that they
fit in an unsigned i128.
2025-08-09 23:23:01 -07:00
Kazu Hirata
c123f4782f
[ADT] Use range-based for loops in SmallPtrSet (NFC) (#152882)
This patch introduces helper function buckets() to convert two loops
to range-based for loops.
2025-08-09 23:05:41 -07:00
Ilia Kuklin
2ff44d7d65
[ADT] Make getAutoSenseRadix in StringRef global (#152503)
Needed in #152308
2025-08-07 22:48:17 +05:00
Kazu Hirata
02fbb6a290
[Support] Remove an unnecessary cast (NFC) (#152442)
pattern is already of const char *.
2025-08-07 07:22:50 -07:00
David Majnemer
0a23b22d1d [APFloat] Properly implement DoubleAPFloat::roundToIntegral
The previous implementation did not correctly handle double-doubles like
0x1p100 + 0x1p1 as the low order component would need more than a
106-bit significand to represent.
2025-08-06 10:42:07 -07:00
Austin
c7bacc9f26
[llvm] using wrapper llvm::sort(nfc) (#151000)
using wrapper llvm::sort(nfc)
2025-08-04 09:27:01 +08:00
David Majnemer
9fdb5e1fef [APFloat] Properly implement next for DoubleAPFloat
Rather than converting to the legacy 106-bit format, perform next() on the
low APFloat. Of course, we need to renormalize the two APFloats if
either of the two constraints are violated:
1. abs(low) <= ulp(high)/2
2. high = rtne(high + low)

Should renormalization be needed, it will increment the high component
and set low to the smallest value which obeys these rules.
2025-08-01 12:34:33 -07:00
Martin Storsjö
1c60b7da4f
[Support] [Windows] Conditionally compile the SetThreadInformation calls (#151388)
The declarations for this API are missing in older mingw-w64 headers
(versions before v12). This API is also hidden if building with MS
WinSDK if targeting versions before Windows 10.

Check whether THREAD_POWER_THROTTLING_CURRENT_VERSION is defined before
using this API; this constant is a #define in both WinSDK and mingw-w64.
2025-07-31 21:54:09 +03:00
Daniel Paoliello
4adce336f4
[win][arm64ec] Fixes to unblock building LLVM and Clang as Arm64EC (#150068)
These changes allow LLVM and Clang to be built with Clang targeting
Arm64EC using the MSVC linker.

Built with these options:
```
-DLLVM_ENABLE_PROJECTS="clang"
-DLLVM_HOST_TRIPLE=arm64ec-pc-windows-msvc
-DCMAKE_C_COMPILER=clang-cl.exe
-DCMAKE_C_COMPILER_TARGET=arm64ec-pc-windows-msvc
-DCMAKE_CXX_COMPILER=clang-cl.exe
-DCMAKE_CXX_COMPILER_TARGET=arm64ec-pc-windows-msvc
-DCMAKE_LINKER_TYPE=MSVC
```
2025-07-31 09:30:05 -07:00
James Y Knight
9ddbb478ce
NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for llvm::vfs::FileSystem. (#151407)
This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new
object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>`
instead of `FileSystem*` or `FileSystem&`, when dealing with existing
objects.

Part of cleanup #151026.
2025-07-31 09:57:13 -04:00
Tim Blechmann
860b1e68ea
Windows: use EcoQoS for ThreadPriority::Background (#148797)
The SetThreadInformation API allows threads to be scheduled on the most
efficient cores on the most efficient frequency.
Using this API for ThreadPriority::Background should make clangd-based
IDEs a little less CPU hungry.

---------

Co-authored-by: Alexandre Ganea <aganea@havenstudios.com>
2025-07-29 11:24:06 -04:00
Kazu Hirata
5e150bb781
[Support] Remove an unnecessary cast (NFC) (#151083)
NumRead is already of ssize_t.
2025-07-29 08:19:01 -07:00
Mehdi Amini
9c82f87aec
Introduce a "log level" support for DEBUG_TYPE (#150855)
This allows to set an optional integer level for a given debug type. The
string format is `type[:level]`, and the integer is interpreted as such:

- if not provided: all debugging for this debug type is enabled.
- if >0: all debug that is < to the level is enabled.
- if 0: same as for >0 but also does not disable the other debug-types,
it acts as a negative filter.

The LDBG() macro is updated to accept an optional log level to
illustrate the feature. Here is the expected behavior:

LDBG() << "A"; // Identical to LDBG(1) << "A";
LDBG(2) << "B";

With `--debug-only=some_type`: we'll see A and B in the output.  
With `--debug-only=some_type:1`: we'll see A but not B in the output. 
With `--debug-only=some_type:2`: we'll see A and B in the output. (same
with any level above 2)
With `--debug-only=some_type:0`: we'll see neither A nor B in the
output, but we'll see any other logging for other debug types.
2025-07-28 18:10:36 +02:00
Aaron Ballman
479ae4aa8f
Revert "fix: replace report_fatal_error with Diags and exit" (#150662)
Reverts llvm/llvm-project#147959
2025-07-25 13:24:00 -04:00
woruyu
9d3dd8efe0
fix: replace report_fatal_error with Diags and exit (#147959)
report_fatal_error is not a good way to report diagnostics to the users, so this switches to using actual diagnostic reporting mechanisms instead.

Fixes #147187
2025-07-25 10:20:30 -04:00
Andrew Rogers
04892228b1
[llvm] get cl::opt instantiations working with MSVC DLL build (#147810)
## Purpose

This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `llvm:🆑:opt` explicit
template instantiations for export with `LLVM_TEMPLATE_ABI` and
`LLVM_EXPORT_TEMPLATE`. This annotation currently has no meaningful
impact on the LLVM build; however, it is a prerequisite to support an
LLVM Windows DLL (shared library) build.

## Background

This effort is tracked in #109483. Additional context is provided in
[this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307),
and documentation for `LLVM_ABI` and related annotations is found in the
LLVM repo
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst).

Annotating the `llvm:🆑:opt` template instances for DLL export was not
straight-forward like other explicit template instances that have
already been annotated. Annotating them as documented
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst#templates)
results in link errors when building a Windows DLL using MSVC.

## Overview 
There are two specific issues that appear when exporting the
`llvm:🆑:opt` templates and compiling a Windows DLL with MSVC:
1. We cannot export `opt<std::string>`. This is because MSVC exports all
ancestor classes when exporting an instantiated template class. Since
one of `opt`'s ancestor classes is its type argument (via
`opt_storage`), it is an ancestor of `std::string`. Therefore, if we
export `opt<std::string>` from the LLVM DLL, MSVC forces
`std::basic_string` to also be exported. This leads to duplicate symbol
errors and generally seems like a bad idea. Compiling with `clang-cl`
does not exhibit this behavior.
2. The `opt` template instances other than `opt<bool>` get optimized out
because they are not referenced in the TU (`opt<bool>` actually is). It
is unclear exactly why MSVC optimizes these template instances away, but
`clang-cl` does not. Adding explicit references to the instantiated
`opt` template classes' vtables via implicit virtual destructor forces
MSVC to export them.

## Validation
Windows with MSVC
Windows with Clang
2025-07-24 11:03:58 -07:00
Mark Murray
d52675e0a7
[lld][AArch64][Build Attributes] Add support for AArch64 Build Attributes (#147970)
This patch enables lld to read AArch64 Build Attributes and convert them
into GNU Properties.

Changes:
    - Parses AArch64 Build Attributes from input object files.
    - Converts known attributes into corresponding GNU Properties.
    - Merges attributes when linking multiple objects.

Spec reference:
    https://github.com/ARM-software/abi-aa/pull/230/files#r1030

Co-authored-by: Sivan Shani <sivan.shani@arm.com>

---------

Co-authored-by: Sivan Shani <sivan.shani@arm.com>
2025-07-24 10:38:36 +01:00
Guy David
802ea0eb78
[Support] System include SipHash.h (#149499)
A regular include may not search the system include path.
2025-07-19 15:00:21 +03:00
Matt Arsenault
2f38ced51b
StringMap: Remove redundant member init in constructor (#149491)
These are already zeroinitialized in the field definitions.
2025-07-19 09:15:48 +09:00
Tomohiro Kashiwada
8de61eb01c
[Support/BLAKE3] quick fix for Cygwin build (#148635)
BLAKE3 1.8.2 ( imported in d2ad63a193216d008c8161879a59c5f42e0125cc )
fails to build for the Cygwin target.

see: https://github.com/BLAKE3-team/BLAKE3/issues/494

As a temporary workaround, add `&& !defined(__CYGWIN__)` to BLAKE3
locally.

resolves https://github.com/llvm/llvm-project/issues/148365
2025-07-18 00:16:08 +03:00
Nikita Popov
1754a7d573
[Support][BLAKE3] Restore static on blake3_hash4_neon (#149046)
This was dropped in #147948 and causes symbol conflicts if libblake3 is
also linked.
2025-07-16 17:49:19 +02:00
Marina Taylor
dd3d26bc89
Revert "[Support] Error if SocketPath is too long" (#149096)
Reverts llvm/llvm-project#148903 due to bot failure
https://lab.llvm.org/buildbot/#/builders/187/builds/8162
2025-07-16 16:48:59 +01:00
Marina Taylor
73630d5e20
[Support] Error if SocketPath is too long (#148903)
If the path is longer than sockaddr_un's buffer, it will be truncated,
at which point it may become indistinguishable from similar truncated
paths. This will cause `bind` to fail with an "Address already in use"
error. There is some existing code that checks `fs::exists` to catch
these errors, but since `fs::exists` compares the full un-truncated
paths, a too-long path will prevent those checks from working.

rdar://154397133
2025-07-16 12:15:23 +01:00
Jordan Rupprecht
60579ec305
[Support][BLAKE3] Prefix more blake3 methods (#149007)
Added by #147948, blake3_xof_many and blake3_compress_subtree_wide cause
conflicts when linking llvm and blake3 statically into the same binary.
Similar to #148607.
2025-07-16 11:31:48 +02:00
Dmitry Vasilyev
efa94cf703
[Support/rpmalloc] Updated fake atomics with Interlocked functions (#148303)
Most atomic functions used Interlocked functions in case of MSVC (since MSVC does not do C11 yet).
But few load/store functions are dummy.
Use Interlocked functions for these atomics to ensure they are thread-safe.

This PR fixes #146205.

LLVM is on VS 2019 version 16.7 currently and eventually we require VS 2022 if we wanted to use stdatomics in rpmalloc, etc. In the meanwhile, we use the Interlocked intrinsics when building with MSVC.
2025-07-15 22:42:27 +04:00
Nikita Popov
4b52d221a0
[Support][BLAKE3] Prefix blake3_xof_many_avx512 (#148607)
This symbol was introduced in #147948, but not prefixed, resulting in
conflicts if libblake3 and LLVM are both linked statically into the same
binary.
2025-07-14 14:32:47 -07:00
Dmitry Vasilyev
d2ad63a193
[Support/BLAKE3] Make g_cpu_features thread safe (#147948)
`g_cpu_features` can be updated multiple times by `get_cpu_features()`,
which reports a thread sanitizer error when used with multiple lld
threads.

This PR updates BLAKE3 to v1.8.2.
2025-07-12 11:02:56 +04:00
Rahul Joshi
d8a2141ff9
[NFC][LLVM][ADT] Simplify StringRef case insensitive compare (#147994)
Change `ascii_strncasecmp` to use a range for loop and use StringRef
parameters.
2025-07-10 13:08:19 -07:00
Peter Collingbourne
7f3afab918
Extract SipHash implementation into a header.
This is so that we'll be able to use it in compiler-rt as well.
Dependencies on LLVM Support were removed from the header by restoring
code from the original SipHash implementation.

Reviewers: kuhar, dwblaikie, ahmedbougacha

Reviewed By: dwblaikie

Pull Request: https://github.com/llvm/llvm-project/pull/134197
2025-07-09 16:07:16 -07:00
Alex Langford
9337594e33
[Support] Don't re-raise signals sent from kernel (#145759)
When an llvm tool crashes (e.g. from a segmentation fault),
SignalHandler will re-raise the signal. The effect is that crash reports
now contain SignalHandler in the stack trace. The crash reports are
still useful, but the presence of SignalHandler can confuse tooling and
automation that deduplicate or analyze crash reports.

rdar://150464802
2025-07-09 14:53:15 -07:00
Matthias Braun
bdc0119e1b
ErrorHandling: Check for EINTR and partial writes (#147595)
Calls to the posix `write` function can return -1 and set errno to
`EINTR` or perform partial writes when interrupted by signals. In those
cases applications are supposed to just try again. See for example the
documentation in glibc:
https://sourceware.org/glibc/manual/latest/html_node/I_002fO-Primitives.html#index-write

This fixes the uses in `ErrorHandling.cpp` to retry as needed.
2025-07-09 11:19:21 -07:00
Kazu Hirata
75b989ec73
[Support] Remove an unnecessary cast (NFC) (#147548)
I is already of int64_t.
2025-07-08 12:47:23 -07:00
Pavel Labath
0a60c4ca22
[Support] Add signed operations to DataExtractor (#147261)
This is motivated by the [SFrame format](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900),
which contains several signed fields.

Having explicit signed operations makes the parsing code read better and
avoids potential surprises if e.g. a "signed" uint8_t value is converted
ta greater width.
2025-07-08 08:47:04 +02:00
Kazu Hirata
ea88634764
[Support] Remove an unnecessary cast (NFC) (#146810)
We don't need to cast std::string to std::string.
2025-07-03 12:02:26 -07:00
vabridgers
c71bbd50a1
[analyzer] Correct Z3 test cases, fix exposed crashes (#146597)
PR145731 corrected the analyzer test runner to consider use of z3 when
used by testcases, which exposed problems in test cases PR37855.c and
crashes in z3-crosscheck.c This change fixes those crashes and
re-enables the test cases that were "XFAIL"'d out.

Co-authored-by: einvbri <vince.a.bridgers@ericsson.com>
2025-07-03 09:08:00 -05:00