[lld-macho] Make printing DWARF 5 source locations work (#233946)
DWARF 5 line tables store directory and file names in __debug_line_str,
so we need to pass that through.
Morally ports 3832d7c25df912 from lld/ELF.
[X86] Generate X86MemUnfoldTable at compile time. NFC (#235442)
This is a table for memory->register unfolding. Previously we computed
this table lazily at runtime which involved sorting it. However we can
just compute it in TableGen and save geomean 0.30% compile time on
stage2-O3 builds:
https://llvm-compile-time-tracker.com/compare.php?from=2b6e769dd3add8bbd8d8be60e59f8d7e5f30ec54&to=b6594131545c6de101ef37570ac6892edabad6c7&stat=instructions:u
It doesn't make much of a difference for LTO builds since the table is
only computed once in the link step, but for non-LTO builds where there
are many codegen phases this helps.
The Clang binary size increases by 113KiB for arm64 Release + asserts,
which seems negligible (0.06% overall)
Assisted-by: Opus 5.5
PowerPC: Remove LiveVariables run and unused LiveIntervals requirement
PPCTLSDynamicCall has not used LiveIntervals since 3ff319c69047, but
still required the analysis. LiveIntervals requires there to be no
unreachable blocks or otherwise it asserts. These blocks were
indirectly removed by adding the extra LiveVariables run, because
LiveVariables has a declared requirement on
UnreachableMachineBasicBlockElim.
Drop the dead analysis requirements along with the LiveVariables run.
This also avoids computing LiveIntervals at -O0 for PIC. This is
still broken if the pipeliner is explicitly enabled on optnone
functions which requires a separate fix.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[mlir][scf] Propagate if conditions to captured select uses (#235433)
## Summary
Simplify branch-local uses of `arith.select` when an enclosing `scf.if`
uses the same scalar condition. A use in the then region takes the
select's true operand, and a use in the else region takes its false
operand. The rule also covers uses nested in those regions and preserves
uses outside the if.
For example:
```python
%x = arith.select %p, %a, %b : i32
scf.if %p {
func.call @consume(%x) : (i32) -> ()
} else {
func.call @consume(%x) : (i32) -> ()
}
[26 lines not shown]
[libc++][lldb] Add initial LLDB data-formatters (#187677)
Add synthetic child providers for `std::map` and `std::vector`. These
were translated from C++ into Python (with the help of Claude).
Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>
Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>
Co-authored-by: Med Ismail Bennani <ismail at bennani.ma>
[llvm] Remove forward and friend declarations of non-existent types (NFC) (#235397)
This patch removes forward and friend declarations of classes and
structs that are not defined anywhere in the codebase.
Assisted-by: Antigravity
[clang] Replace PointerUnion::dyn_cast with llvm::dyn_cast (NFC) (#235396)
PointerUnion::dyn_cast has been soft-deprecated in favor of
llvm::dyn_cast and llvm::dyn_cast_if_present. This patch replaces
PointerUnion::dyn_cast with llvm::dyn_cast at 7 call sites across 3
files under clang/lib/AST/.
All tests in check-clang pass with these changes, and LLM-based static
analysis of the surrounding data structures and call sites confirms that
the PointerUnion operand at each site is nonnull either by construction
or because callers ensure it is nonnull before reaching llvm::dyn_cast.
Assisted-by: Antigravity
[clang-tidy] Fix crash and invalid fix-its in bugprone-crtp-constructor-accessibility (#232163)
The fix-it puts `private:` at `getBeginLoc().getLocWithOffset(-1)` and
the old access specifier at `getEndLoc().getLocWithOffset(1)`. Stepping
back one character is what breaks:
- When the constructor starts with a macro, as in the issue, -1 leaves
the macro's SLocEntry. If the entry before it is a file, assertion
builds crash in `isMacroArgExpansion`. If it's a macro argument, nothing
asserts and `--fix` writes `private:` into that argument, so `ID(1)`
becomes `ID(1private:`.
- Without macros, `private:` gets glued onto whatever comes before the
constructor: `public:CRTP() {}` becomes `publicprivate:`, an empty
`CONSTEXPR` macro becomes `CONSTEXPRprivate:` (7 of the 12 `private:`
insertions in Boost's `date_time` at `-std=c++11`), and an unindented
constructor after a `// comment` line gets it inside the comment.
Crash repro:
[29 lines not shown]
[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.
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
[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.
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
[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
[AMDGPU][TTI] Refine gfx9 packed FP32 SLP costs for pair formation and shuffles (#208572)
On targets with packed f32 operations (hasAnyPackedFP32Ops), for throughput only: an insertelement of a computed f32 into an <N x float> costs one v_mov_b32 at any width. Load-fed lanes, arguments, constants are still free.
An f32 shuffle is costed the same way.
This makes SLP reject compute-fed gathers and cross-half shuffles that only look cheap because of the packed-arithmetic discount, while keeping profitable load-fed pairing.
Preliminary work and idea by Michael Selehov.
---------
Co-authored-by: Cursor <cursoragent at cursor.com>
[CopyProf] Add libc interceptors.
A copy is reported as unnecessary if neither the object nor any memory
it owns is modified before it is destroyed. So far, writes by
uninstrumented code, most importantly library functions (e.g. `memcpy`,
`memset`, etc.), are not accounted for, which leads to false positives.
Interceptors make these writes visible.
Additionally, objects constructed inside a d'tor are now marked as copy,
so that destroying temporaries (e.g. a string built for a log message)
does not suppress reports.
Note that `strndup` and `realpath` are not intercepted yet, as their
interceptors allocate memory via the `malloc` interceptor, which is only
added in a subsequent patch.
RFC:
https://discourse.llvm.org/t/rfc-copysanitizer-csan-detecting-unneccessary-object-copies-at-runtime/91038
Previous PR: #225905
[M68k] Use PC-relative EH pointer encodings under PIC (#235347)
The function `TargetLoweringObjectFileELF::initialize` has no `case`
branch for `m68k`, meaning the default absolute encoding is used for the
personality/lsda/type-info pointers: `DW_EH_PE_absptr`. IN a PIE or
shared lib, those pointers then need `R_68K_32` dynamic relocations in
`.eh_frame` and `.gcc_except_table` which are read-only, so a link with
the flag `-z text` fails - that flag is default for PIE. Error:
```
ld: read-only segment has dynamic relocations
```
This PR adds `m68k` to the existing `x86/ppc` case, selecting
`indirect/pcrel/sdata4` for the personality and `pcrel/sdata4` for
the LSDA (under PIC, and `absptr` otherwise). With the change, the
`.eh_frame` relocations for a PIC function with a personality and lsda
are `R_68K_PC32`, not `R_68K_32` as before. The new test checks both
relocation models.
[3 lines not shown]
[GVN] Don't coerce forwarded vectors through integers
A vector is poisoned per lane, but an integer is poisoned as a whole. So
casting a forwarded vector to an integer let a poison lane outside of the
loaded bytes poison the loaded value. Forward vectors through bytes and
`bitextract` instead.
Fixes #99268.
Fixes #209935.
[mlir][linalg] Extend FoldReduceBroadcast to float maximumf/minimumf (#233417)
Extend `FoldReduceBroadcast` to fold `reduce(broadcast(x))` into `x`
for `arith.maximumf`/`arith.minimumf` when the init is the identity
(`-inf`/`+inf`). The identity check gains a `FloatAttr` branch.
Safety: `maximumf(-inf, x) == x` for all values — finite, ±inf,
-0.0, and NaN (NaN-propagating semantics). Only an exact ±inf init
passes the check; finite/NaN inits are rejected by negative tests.
`maxnumf`/`minnumf` are deliberately excluded: they ignore NaN, so
`reduce(broadcast(NaN))` with init `-inf` would yield `-inf`, not NaN
(covered by a negative test).
Assisted-by: AI.