[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
[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.
[lldb][NFC] Have a clearer contract for SymbolFiles to mark change (#241655)
SymbolFile::AddSymbols can add symbols to an ObjectFile's Symtab. It can
also modify the symbols in the Symtab -- e.g. SymbolFileWasm can add
mangled names to an existing symbol. For a recent PR, I added a call to
Symtab::SetSymbolFileAddedSymbols() when a name was added to an existing
symbol in the Symtab. But this still left open the possibility of future
SymbolFile plugins, or downstream ones, doing the same thing (changing a
symbol in a Symtab), and we would not detect that the Symtab has been
updated since its ObjectFile state.
This changes SymbolFile::AddSymbols to return a bool indicating if
Symbols were added or updated. And in SymbolFileCommon::GetSymtab,
instead of checking that the number of symbols had changed and calling
Symtab::SetSymbolFileAddedSymbols(), use this new returned value.
As I look towards a bloom filter representation of the ObjectFile's
symtab, I become more focused on making sure I can tell when a
SymbolFile has modified the Symtab in any way, so the bloom filter can
[3 lines not shown]
[MLIR][XeGPU] Spread replicated sg_layout outermost-first in expandDim (#244999)
When expandDim splits a dim whose sg_data spans the whole dim, every
subgroup holds all of it, so the replicated subgroups can sit on any of
the new dims. expandDim currently places them on the innermost new dim.
For example, expanding sg_layout = [2, 2], sg_data = [16, 1024] on dim 1
to [32, 32] gives sg_layout = [2, 1, 2], sg_data = [16, 32, 32]. This
layout by itself is fine, since the two subgroups on the inner dim are
replicas. But in the mxfp use case the inner dim is the one reduced to
compute the scale, so it is sliced away, and its two subgroups go with
it. The multi_reduction rule then no longer sees those subgroups and
splits the reduced dim across them.
This PR places replicated subgroups on the outermost new dims instead.
For the same example, expandDim now gives sg_layout = [2, 2, 1], sg_data
= [16, 32, 32]. The sliced dim then has only one subgroup, so the
reduction rule sees all subgroups in use and keeps the reduction within
each subgroup:
main: slice<sg_layout = [2, 1, 2], sg_data = [16, 32, 32], dims = [2]>
[12 lines not shown]
[lldb] Add a DataFileCache for ObjectFile header bytes (#231344)
When creating a memory-read module, lldb needs to read the binary's
header & load commands (Mach-O terminology) out of memory, and then read
the symbol table out of memory. In
https://github.com/llvm/llvm-project/pull/229305 I added a new setting
default-on which saves the symbol table for a memory-read binary in the
DataFileCache. But we're still reading the header and load command bytes
out of memory on every debug session, and if there are a large number of
binary images being read from memory, this packet communication will be
a real performance problem.
This patch enables a new DataFileCache file with the same
`symbols.enable-lldb-index-cache-memory-modules` default-on setting,
"headerbytes". After creating a memory-read binary, it saves the bytes
of the header to the DataFileCache. And before reading a new memory-read
binary, it looks in the DataFileCache to see if the header bytes are
already available. If so, it puts those bytes in the Process
memory-cache, and allows the ObjectFile plugin sublcass to read them.
[37 lines not shown]
[MLIR][XeGPU] Check that a split shape_cast layout collapses at subgroup level (#245861)
For a shape_cast that splits a source dim, the source layout is derived
by collapsing the result layout. That is only exact when each sg tile is
contiguous in the collapsed dim. setupShapeCastResultLayout already
checks this for inst_data and lane layouts, but not at subgroup level.
In simple_mxfp_gemm_quantizeA_F4/F8, the result layout sg_layout = [2,
1, 2], sg_data = [16, 32, 16] of a 32x1024 -> 32x32x32 shape_cast was
collapsed to sg_data = [16, 512]. Its sg tile is not contiguous, so the
scales came out wrong.
This PR adds the subgroup check. When a group does not collapse, its
subgroups move to the group's outer dims (here [2, 2, 1] / [16, 16,
32]), and a convert_layout gives the consumer its layout.
assisted-by-claude
---------
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[lld][MachO] Avoid redundant work in Writer::scanRelocations()
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 runs the full `validateSymbolRelocation()` body on every
symbol relocation even though it only rejects two rare
thread-local-variable cases.
Split the rare TLV validation logic in `validateSymbolRelocation()` 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.
[lld][MachO][NFC] Move validateSymbolRelocation() into Writer.cpp (#248324)
`Writer::scanRelocations()` is the only caller of
`validateSymbolRelocation()`. Move it as-is into `Writer.cpp` as a
`static` helper in preparation for #246903 (which optimizes
`Writer::scanRelocations()` and includes the full benchmark results).
[SampleProfile] Keep inline-root discovery in the sample loader
Move the IR inline-frame scan and selective root discovery out of the
public SampleProfileReader API. The loader retains the same depth-ordered
algorithm and delegates named profile reads to the existing reader API.
Preserve nested-profile preference, missing-outer-frame discovery,
request deduplication, remapping, and error propagation.
Reject a missing or zero-head root before looking up the call target.
Use the matched profile's function identity directly, without changing
the target-count, definition, checksum, or phase checks.
Assisted-by: Metamate
[MC,RISCV] Use a symbol for the skip target of linker-relaxable long branches (#247437)
When the assembler relaxes an out-of-range conditional branch to an
inverted branch over a JAL, the branch should carry a relocation but
doesn't:
```
0: c.beqz a0, 0x6 # no relocation
2: jal zero, ext # R_RISCV_JAL ext, R_RISCV_RELAX
6:
```
Add a MCAsmBackend::relaxInstruction overload, overridden by RISC-V to
define a temporary symbol at the start of the next fragment and append
it to the long branch pseudo. The inverted branch targets that symbol
and gets an R_RISCV_BRANCH or R_RISCV_RVC_BRANCH relocation.
Fixes #236343
LLM-aided
[llvm-exegesis] Use memfd_create over shm_open (#246568)
The shm_open strategy relied on having a unique filename in /dev/shm per
exegesis invocation (which might be called on multiple threads in the
same process by API users). This is fundamentally fragile (see past
commits to add support for threads). The most recent example is that
bazel will try and run tests in some cases in their own PID namespaces
which breaks the current assumption that PIDs are globally unique.
Instead, use memfd_create so that we do not need to come up with a
globally unique name at all. This also removes a bunch of string
handling to construct filenames which is nice. The only potential issue
is that memfd_create was only introduced in Linux 3.4/a glibc of a
similar era. I remember people complaining that some parts of
llvm-exegesis broke builds on RHEL6 which uses Linux kernel 2 and does
not support memfd_create. But RHEL6 is extra dead at this point, so
hopefully that's not an issue anymore.
Assisted-By: LLM
[lld][MachO][NFC] Introduce SectionView for section-level predicates (#248238)
Add a lightweight `SectionView` wrapper implicitly constructible from
either a `Section` or an `InputSection`, and convert all section-level
predicate functions (`isCodeSection`, `isCfStringSection`,
`isClassRefsSection`, `isSelRefsSection`, `isEhFrameSection`,
`isGccExceptTabSection`, `usesAuthGot`, and ICF's
`isFoldableIgnoringRelocatedBytes`) to accept `SectionView`.
This avoids duplicating `(const Section &)` / `(const InputSection *)`
overloads as we refactor loops over `InputSection`s (which are generally
grouped by their originating `Section`) to hoist or cache section-level
predicate results across consecutive subsections of the same `Section`.
Assisted by Gemini.
RuntimeLibcalls: Make asan runtime available with out of tree support (#248131)
The previous set of systems was based on what targets are built in the
compiler-rt sources. However a few targets have out of tree runtimes,
so list those too (MSVC on AArch64, AMDGPU, Emscripten and the
PlayStation SDK). Also, drop the stack poisoning functions from
AMDGPU since the pass skips inserting those for it.
Assisted-by: Claude
[SampleProfile] Split stale inline-frame matching into a follow-up
Keep the basic inline-profile recovery in #245375 and move the stale-location
extension into a separate stacked change. Preserve selective root discovery,
nested-profile preference, missing-outer-frame handling, and the definition,
call-count, zero-head, and available-checksum checks.
Restore the existing stale-profile matcher, remove matching-only retrieval
policy and location-map accessors, and reject known checksum mismatches in
root fallback. Move the synthetic moved-probe tests with the extension while
retaining the basic recovery and negative checksum tests.
This commit is directly on top of 76cd07eceb984b3c248387a1c8f6ee0e891e7343,
so the published recovery commit does not need to be rewritten. The stacked
follow-up restores the original combined source tree exactly.
Assisted-by: OpenAI
[SampleProfile] Retrieve root profiles for inlined functions
Pre-link inlining can leave an inline frame whose samples are stored in a
separate root. Reading profiles only for surviving Function objects misses
that root. Looking only under the caller also fails when the profile and
IR inline trees disagree, including when an inner function is inlined first.
Put selective inline-root retrieval in the sample-profile reader so sample
loading and stale matching can both use it. Collect inline frames once,
prefer matching nested profiles, and batch missing-root reads by depth.
Do not let a missing outer profile hide a deeper frame or repeatedly request
names that are absent from the profile.
Let stale matching collect anchors inside eliminated inline frames and
reuse its existing matching algorithm and location-map distribution. For
MD5 profiles, resolve known callee hashes before the comparison loop.
Keep retrieval separate from permission to reuse sample counts. Post-link
fallback still checks the caller's count and probe checksum. Reject zero-head
[4 lines not shown]
[lld][MachO][NFC] Move validateSymbolRelocation() into Writer.cpp
`Writer::scanRelocations()` is the only caller of
`validateSymbolRelocation()`. Move it as-is into `Writer.cpp` as a
`static` helper in preparation for #246903 (which optimizes
`Writer::scanRelocations()` and includes the full benchmark results).
[LoongArch] Prefer ALSL + LD/ST over SLLI + LDX/STX when the address is materialized anyway (#238715)
When (add Base, (shl Index, 1..4)) also has users other than the base
address of loads/stores, the add is selected as ALSL anyway. Folding it
into LDX/STX then needs a separate SLLI for the index, so use the ALSL
result with a zero offset instead:
```
alsl.d $a2, $a1, $a0, 3 alsl.d $a2, $a1, $a0, 3
slli.d $a1, $a1, 3 => ld.d $a3, $a2, 0
ldx.d $a3, $a0, $a1 ld.d $a2, $a2, 8
ld.d $a2, $a2, 8
```
rustc-perf fmt-write-str on LA664: 3988.1M -> 3973.1M instructions
(-0.38%).
Assisted-By: LLM