[MLIR][docs] Document the CMake infrastructure
Describe MLIR's TableGen, library, visibility, aggregation,
installation, and generated-header conventions in one infrastructure
guide. Explain library owners, explicit generators, and compile-only
header requirements.
Link the guide from CreatingADialect.md. Use
add_mlir_dialect_tablegen_target in the AttributesAndTypes.md example.
Assisted-by: Codex
[MLIR][CMake] Stop depending on mlir-generic-headers by default
Remove the default mlir-generic-headers dependency from ordinary and
example libraries, and migrate their generated-interface requirements to
library owners. Keep the compatibility aggregate and registrations.
MLIRIR now owns MLIRInferIntRangeInterfaceIncGen, which Matchers.h
includes. Add the Transform/Interfaces generator-to-generator
dependency. MLIRDialectUtils switches from MLIRArithOpsIncGen to
COMPILE_ONLY:MLIRArithDialect because ReshapeOpsUtils.h includes
Arith.h.
Extend the release note and aggregate regression test.
Assisted-by: Codex
[CMake] Migrate CIR and Flang generated-header dependencies
Replace CIR's mlir-headers dependencies and Flang's global MLIR library
lists with their actual library dependencies. Let owners provide
generated headers through the link graph, and remove duplicate ordering
dependencies on foreign IncGen targets.
Declare CIR interface and header ownership explicitly. Keep source
shards, bytecode tables and lowering tables private to their consumers.
Scope accumulated TableGen variables and keep implementation-only
lowering tables out of Clang's global TableGen aggregate.
Include only the dialects and conversion passes registered by Flang.
Preserve the supported registrations and retain MLIR_DEPS for downstream
compatibility. Use compile-only owner links for header-only
dependencies.
Assisted-by: Codex
[MLIR][CMake] Stop depending on mlir-headers by default
Remove the default mlir-headers dependency from the dialect, conversion,
extension, and translation library helpers. Keep the aggregate target,
its registrations, and explicit compatibility dependencies available.
Replace redundant foreign generator edges with actual library links or
compile-only header owners. Add generator-to-generator add_dependencies
edges when one generated header includes another. Add regression
coverage that rejects an implicit dependency on the aggregate.
Add a release note explaining downstream migration, the temporary
DEPENDS mlir-headers fallback, and clean generated-file dependency
audits.
Assisted-by: Codex
[mlir][vector] Require matching element types for vector xfers (#239164)
`vector.transfer_read` and `vector.transfer_write` currently accept
source and vector types with different elemental types when their
bitwidths are compatible. This packing behavior is not supported by the
Vector dialect.
With this PR, we require source and vector elemental types to match, and
update the affected tests to reject unsupported transfers.
This also removes outdated packing cases from:
- `mlir/test/Dialect/Vector/ops.mlir`
- `mlir/test/Dialect/Vector/vector-transfer-permutation-lowering.mlir`
Fixes: #237545
---------
Signed-off-by: Federico Bruzzone <federico.bruzzone.i at gmail.com>
[docs] Update AI tool policy for textual communication (#243459)
Update the AI tool policy for the approved RFC:
https://discourse.llvm.org/t/rfc-forbid-ai-generated-communication/92414
The tl;dr is that PR descriptions must be human-written, and we have
stronger restrictions on LLM-generated text in other communication
channels.
I mostly tried to preserve the old text and put this into a new section.
Additionally, as the policy is getting quite long, I've added a summary
of the points that are most likely to be relevant to people. In the
interest of brevity, the summary intentionally omits the finer details,
so if someone wants to know if their use of LLM translation is allowed,
they'll just have to read the full policy.
Revert "[AArch64][GlobalISel] Turn ANDs that keep the low bits of a vector into fmov (#243591)" (#248834)
This reverts commit d97c4a496eeaf325f5303519e747967b681c29db, which
broke check-llvm:
FAIL: LLVM :: CodeGen/AArch64/and-keep-low-bits.ll
Commit ce6bab09e864bb4462487ebf995dd91a0dd88662 (#240841) already
rewrites the single-lane zero mask in and_v2i64_keep_low_64 into
G_INSERT_VECTOR_ELT during AArch64PostLegalizerCombiner. That pass
runs before AArch64PostLegalizerLowering. As a result, GlobalISel
emits:
mov v0.d[1], xzr
The test expects:
fmov d0, d0
[4 lines not shown]
[LoongArch] Support memcmp expansion for vectors and combine for i128/i256 setcc
This commit enables memcmp expansion for lsx/lasx. After doing
this, i128 and i256 loads which are illegal types on LoongArch
will be generated. Without process, they will be splited to
legal scalar type.
So this commit also enable combination for `setcc` to bitcast
i128/i256 types to vector types before type legalization and
generate vector instructions.
Inspired by x86 and riscv.
[mlir][ArmSME] Legalize writes in `vector.mask` (#246947)
ArmSME legalization creates new ops inside a `vector.mask` region which
is invalid IR.
A write has no passthru, so `vector.mask { transfer_write }` is
equivalent to the mask operand.
The patterns now take the mask from the _operand_ (will be deleted via
#239511) or from the enclosing `vector.mask`, and replace the
`Xfer_write` first and then the `vector.mask`.
Part of #239511 and #240114 (item 16).
RFC:
https://discourse.llvm.org/t/rfc-unify-masking-in-the-vector-dialect/92675
This supersedes the bailouts of #246463.
---------
Signed-off-by: Federico Bruzzone <federico.bruzzone.i at gmail.com>
[mlir][linalg] Add `operands_to_pack` to `structured.pack` (#241195)
`linalg.pack` packs every operand that uses a packed iterator dimension,
so there is no way to pack only some of the operands of an op.
With this PR we add an optional list of operand numbers,
`operands_to_pack`. If it is absent, all operands are packed as before.
If it is present, only the listed operands are packed. Every other
operand is not packed: its packed dimensions are split in place into
`[outer, inner]` with a `tensor.expand_shape`, and the result for an
init is collapsed back with a `tensor.collapse_shape` - i.e., no data is
moved.
The tile sizes must be constants. The packed dimensions of an unpacked
operand may be static or dynamic. A static one must be a multiple of its
tile, otherwise the pack fails. A dynamic one cannot be checked: it is
assumed to be a multiple, which the payload must guarantee, otherwise is
UB.
[20 lines not shown]
[NFC][clang][test] Rename strlen-inline-builtin.c to inline-builtin-attrs.c (#248820)
The file will also test other attributes on inline builtins.
Assisted-by: Gemini
[LoongArch] Enable SelectOptimize for LA464 and LA664 (#233466)
Enable SelectOptimize for LA464/LA664 under O3 by default, which will
convert select or select-like instructions, e.g. `or(zext(icmp))`, back
to branch for better use the CPU's speculative execution. See
https://github.com/llvm/llvm-project/pull/77284 and
[D138990](https://reviews.llvm.org/D138990) for more detailed
explaination.
The up-coming [LoongArch sched-model
PR](https://github.com/llvm/llvm-project/pull/226064) has introduced
`MispredictPenalty = 14` for LA464 and LA664, which will have some
impact on the heuristic algorithm of this pass, but I didn't see any
changes in SPEC CPU2006.
Here are the SPEC CPU2006 results, running on Loongson 3B6000, with
`-mtune=la664 -O3 -mlsx -fuse-ld=lld`. Only benchmarks which codes
changed after the pass are listed:
[31 lines not shown]
[VectorCombine] Fix invalid bitcast after peeking through bitcasts
foldBitcastShuffle looks through the bitcasts of the shuffle operands
and bitcasts their sources to the new shuffle type. Some sources can't
be bitcast to it, e.g. an integer vector to a pointer vector, which
fails with "Invalid cast!". For such a source, bitcast the operand
itself. Don't fold if that leaves no operand looked through, which is
always the case for a unary shuffle: the new bitcast of a bitcast can
be turned back into the original form by foldShuffleToIdentity, which
loops for repeat and extract masks.
Assisted-by: Claude Code (Claude Opus 5.5)
[VectorCombine] Fix crash on bitcasts of pointer vectors
foldBitcastShuffle divides by the scalar sizes of the source and
destination element types, which are zero for pointers. A bitcast of a
shuffled pointer vector, or one between a byte vector and a pointer
vector, then crashes with a division by zero. Take the sizes from the
DataLayout, so these bitcasts are folded too.
Fixes #246659
Assisted-by: Claude Code (Claude Opus 5.5)
[orc-rt] Add LoaderEngine skeleton and SPS create interface. (#248819)
LoaderEngine will be responsible for loading JIT'd images in the ORC
runtime. For now it only logs its construction and destruction, so that
creation via the controller interface can be verified.
The new orc_rt_ci_sps_LoaderEngine_create wrapper constructs a
LoaderEngine, publishes it as the orc_rt_LoaderEngine_Instance instance
symbol, transfers ownership to the calling Session via an on-shutdown
callback, and returns the instance address. Since the instance symbol
name is fixed, create succeeds at most once per Session.
[TableGen][SystemZ] Only inherit sub-register indices at offset 0 or unknown (#246675)
When a register inherits the sub-registers of one of its explicit
sub-registers, TableGen reused each inherited sub-register's index
unless that index was already in use. That is only correct if the
inherited sub-register is at the same offset in the register as it is
in the explicit sub-register. For example, with:
def hi16 : SubRegIndex<16, 16>;
def hi32 : SubRegIndex<32, 32>;
R32 = [R16 at hi16]
R64 = [R32 at hi32]
R64 got R16 as its hi16 sub-register, although hi16 has offset 16 and
R16 is at offset 48 in R64.
Now a sub-register only keeps its index if it is inherited from an
explicit sub-register whose index has offset 0 or an unknown offset.
[23 lines not shown]
[mlir][bufferization] Add allocation-op option to buffer deallocation passes (#246893)
Currently, `bufferization-lower-deallocations` deallocates every
`memref` with `memref.dealloc`, no matter which operation allocated it.
This PR adds an `allocation-op` option to the buffer deallocation passes
and pipeline. It names a target operation (default `memref.alloc`) that
implements `AllocationOpInterface`:
* `ownership-based-buffer-deallocation` owns the allocations of that
target
* `bufferization-lower-deallocations` builds each deallocation with the
target's `buildDealloc`
With the default, an allocation of some other operation is no longer
deallocated, so `@dealloc_existing_clones` changes a bit.
Since `buildDealloc` can build operations from any dialect,
`bufferization-lower-deallocations`'s conversion target now treats
unknown operations as legal. As a side effect, it no longer folds
[8 lines not shown]
[cmake] Fix LLD detection when compiler ABI detection fails (#248417)
#246222 and #247156 replaced `CMAKE_LINKER` matching in
HandleLLVMOptions.cmake with checks on
`CMAKE_C_COMPILER_LINKER_{ID,FRONTEND_VARIANT}`.
Those CMake variables are only populated when compiler ABI detection
succeeds. During cross-compilation of Windows runtimes (e.g. aarch64 or
i386 on an x86_64 host with `LLVM_WINSYSROOT`), ABI detection fails
because `/winsysroot:` is only added later in HandleLLVMOptions.cmake,
leaving `CMAKE_C_COMPILER_LINKER_*` empty. As a result,
`clang_rt.profile` was silently built without hardware atomics:
- `LINKER_IS_LLD_LINK` evaluated to FALSE even though
`LLVMExternalProjectUtils.cmake` passed `-DCMAKE_LINKER=.../lld-link`.
- `/winsysroot:` was omitted from linker flags.
- Subsequent `compiler-rt` `try_compile` checks failed (including
`COMPILER_RT_TARGET_HAS_ATOMICS`), falling back to non-atomic
`lprofBoolCmpXchg` / `lprofPtrFetchAdd`.
[18 lines not shown]