[clang][bytecode] Only implicitly destroy locals for EvalEmitter (#248064)
For bytecode, we want to avoid the double destroy ops. We need to call
`destroyLocals()` so we can use the return value. When evaluating
directly, we need to destroy locals in the destructor too so we don't
leak memory when a one of our visit functions returns an error early.
[MLIR][XeGPU] Fix shape_cast layout inference when a split dim is followed by others (#245127)
For a shape_cast that splits source dims, inferShapeCastSourceLayout
collapsed the result dim groups from first to last. Collapsing a group
shifts the dim indices of the groups after it. For 32x64 -> 8x4x64, the
groups are [[0, 1], [2]]. After [0, 1] is collapsed, [2] is out of
bounds and collapseDims crashes.
The PR fix it by collapsing the groups from the last one, so earlier
groups keep their indices.
assisted-by-claude
.
---------
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Define synchronization scope and clamp scopes to execution scope
- Add a Synchronization Scope section defining syncscope and syncscope instance.
- Clamp syncscope and A/V scope to execution scope when specified smaller.
- Clarify default A/V scope for synchronizing vs. other A/V operations.
- Simplify the Inclusive Scopes wording to refer to any two operations.
Assisted-by: AI
[lld-macho] Pad markLive worklist shards and move stack on idle
Avoid false cache-line sharing on Worklist's 16-byte header across
threads by aligning each nextLevel/level shard to 128 bytes. In drain(),
move the worker's stack directly into its empty nextLevel shard and
return once anyWorkerIdle is observed. Also drop an outdated sentence in
drain()'s comment.
[asan] Find the block of a large chunk without scanning all large chunks (#243675)
When a large chunk leaves the quarantine, `GetBlockBegin()` scans all
large blocks under a lock, so programs that hold thousands of them slow
down. These blocks are page aligned. Look for a `LargeChunkHeader` at
the start of the chunk header's page first, and scan only if it doesn't
point back at the chunk.
x86_64 Linux CPU time: about -30% for a `malloc(132K)`/`free` loop with
10,000 blocks live, -3.5% for a synthetic numpy script with 20,000
arrays. No change on llvm-test-suite or ASan clang.
`GetBlockBegin()`'s two header CHECKs are repeated in `Deallocate()`,
for all sanitizers. A `free()` with a forged `LargeChunkHeader` now
crashes instead of returning silently.
Assisted-by: Claude. I have reviewed every line of this PR.
CloneFunction: Check invokes for memprof metadata when pruning
The pruning cloner reports whether the cloned code contains !memprof
or !callsite metadata, but only looked at non-terminator calls. The
inliner uses this to decide whether to strip the metadata from the
copied calls if the original call site has no !callsite metadata.
As a result, the metadata was not stripped from an inlined invoke
unless the callee also had a call with the metadata.
Assisted-by: Claude
[Hexagon] Add relocation application helpers and use them in RuntimeDyld (#244507)
Add target-side helpers for applying ELF relocations to Hexagon
instruction encodings. Hexagon instruction operands may occupy
non-contiguous bit fields, so the helpers use the scalar
instruction-encoding table and the Hexagon ABI relocation descriptions
to scatter relocated values into the correct bits.
Expose a C-linkage API in llvm/Target/Hexagon/HexagonRelocation.h so
that RuntimeDyld and other Hexagon toolchain components do not depend on
private declarations:
* LLVMHexagonApplyRelocation: apply a relocation to an instruction.
* LLVMHexagonGetRelocationInfo: query the ABI properties of a relocation
(effective bits, bit mask, alignment, shift, signedness and whether
range and alignment are verified) through the LLVMHexagonRelocInfo
struct.
* LLVMHexagonVerifyRange, LLVMHexagonVerifyAlignment and
LLVMHexagonIsTruncated: relocation validation checks for diagnostics.
[34 lines not shown]
AddressSanitizer: Declare runtime functions with RuntimeLibcallsInfo
Declare the asan runtime functions with RuntimeLibcallsInfo, so they
get the signatures and attributes from the libcall definitions. The
ELF globals registration functions are only declared for ELF targets,
which are the only users.
It is now an error to run the pass for a target that does not provide
the asan runtime. Tests with no triple, or a triple without an OS, now
use a Linux triple.
The experiment report functions are only used by a hidden testing
option, so keep declaring them by name and drop their RuntimeLibcalls
entries.
The kind of hacky part of this is the pass is now reasoning directly
in terms of LibcallImpl, instead of looking up the LibcallImpl from
the Libcall. This is because at the moment non-codegen passes don't
have a simple way of using LibcallLoweringInfo. There arguably should
[4 lines not shown]
[orc-rt] Install headers via a CMake file set. (#248335)
The public headers were installed via the PUBLIC_HEADER property, which
flattened the directory structure and dropped files with duplicate names
in different directories.
Switch orc-rt-headers to a HEADERS file set so that the directory
structure is preserved.
Assisted-by: claude
[mlir][XeGPU] Do not widen leading-dim inst_data for multi_reduction (#245106)
#240592 made layout propagation keep a reused slice parent's larger
inst_data on every non-reduced dim of a vector.multi_reduction source.
When that dim comes before the last two, blocking produces tiles such as
2x8x16. Lane-level distribution of multi_reduction only supports sources
whose leading dims are unit, so the blocked op then fails to legalize.
This PR keeps the parent's inst_data only on the last two dims. Leading
dims keep inst_data[i] = lane_layout[i] * lane_data[i], so they stay
unit.
assisted-by-claude
---------
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[-Wunsafe-buffer-usage] Allow safe `memset(&x, val, sizeof(T))` calls (#247816)
`-Wunsafe-buffer-usage` currently treats `memset(&x, val, sizeof(x))` as
safe (via `isUnsafeMemset`), but warns on `memset(&x, val, sizeof(T))`
even when `x` has type T. This causes the checker to flag glibc's
`CPU_ZERO(&cpuset)` macro (which expands to `__builtin_memset(&cpuset,
'\0', sizeof(cpu_set_t))`)as unsafe.
This patch updates `isUnsafeMemset` to also consider `memset(&x, val,
sizeof(T))` safe when `x` is a `DeclRefExpr` whose type matches `T`.
---
*Disclosure: AI assistance was used in the development and
implementation of this change.*
[test][X86] Precommit tests for 32-bit ELF PIC local IFUNCs (#248322)
Add codegen tests for calls, tail calls, musttail calls, and address
materialization of internal, hidden, and dso_local IFUNCs on i386 ELF.
The test covers the pic and static relocation models with SelectionDAG,
FastISel, and GlobalISel. The checks record the current output, where
PIC code references these IFUNCs with R_386_PC32 and R_386_GOTOFF.
Needed by #248318.
Assisted-by: Gemini
[CIR] Add bytecode encodings for struct and union types (#247883)
Struct and union types were the last CIR types stored as their printed
text in bytecode. The printed form of a record expands every record it
reaches that has not been printed yet, so the text grows with the depth
of nesting and dominates CIR bytecode for C++.
A named record can refer to itself, so the reader creates it incomplete
and publishes it with tryStartCyclicRead (#229910) before reading its
members. Anonymous records cannot refer to themselves and are built once
their members are read.
Bytecode output for two of the CIR codegen TUs (-fclangir -emit-cir -c
on preprocessed sources, same binaries):
```
CIRGenModule.cpp: 7.3 GB, 4m41s, 10 GB RSS -> 4.5 MB, 19s, 1.2 GB RSS
CIRGenExprCXX.cpp: 3.9 GB, 2m11s, 6 GB RSS -> 2.0 MB, 12s, 0.9 GB RSS
```
For reference, their -O3 LLVM bitcode is 1.4 MB and 0.5 MB.
[CIR] Add verifier enforcement of illegal SVE types (#247874)
This change updates the VectorType verifier to reject illegal SVE vector
sizes and updates the StructType, UnionType, and ArrayType verifiers to
reject scalable SVE vectors and svecount as elements/members.
Although LLVM IR represents tuples as a struct of SVE vectors, I intend
to add a dedicated tuple type in CIR.
Assisted-by: Cursor / various models
EC2: Use stream-optimized VMDK format
Once enabled on all of the branches, this will reduce bandwidth
consumption from uploading weekly snapshot builds from ~500 GB to
~100 GB, as well as significantly speeding up the process.
MFC after: 2 months
Sponsored by: Amazon
(cherry picked from commit 34f2f57b836d9cec02130419f5272495860d4ddf)
EC2: Use stream-optimized VMDK format
Once enabled on all of the branches, this will reduce bandwidth
consumption from uploading weekly snapshot builds from ~500 GB to
~100 GB, as well as significantly speeding up the process.
MFC after: 2 months
Sponsored by: Amazon
(cherry picked from commit 34f2f57b836d9cec02130419f5272495860d4ddf)
[lld][MachO] Avoid redundant work in Writer::scanRelocations() (#246903)
During relocation scanning, `Writer::scanRelocations()` looks up
`target->getRelocAttrs(r.type)` up to three times per symbol relocation
(in `scanRelocations()`, `validateSymbolRelocation()`, and
`prepareSymbolRelocation()`), tests `r.referent` twice for symbol
referents, and makes an out-of-line call to `validateSymbolRelocation()`
on every symbol relocation even though it only rejects two rare
thread-local-variable cases.
Move `validateSymbolRelocation()` (whose only caller is
`Writer::scanRelocations()`) into `Writer.cpp`, split the rare TLV
validation logic into a `LLVM_ATTRIBUTE_NOINLINE` helper, and mark
`DylibSymbol` `final` so `dysym->isTlv()` avoids a virtual call on the
fast path. Fetch `RelocAttrs` once per relocation, pass it to
`validateSymbolRelocation()` and `prepareSymbolRelocation()`, hoist
loop-invariant `target->relocAttrs` and `config->emitChainedFixups`, and
dispatch on `r.referent` once for non-subtractor relocations.
Assisted by Gemini + Claude.