[mlir][ODS] Register the operations of a dialect by default
Dialects registered their ODS operations by expanding `GET_OP_LIST` into
`addOperations` in `initialize`, while sharded and partitioned dialects
had to call the generated `register<Dialect>Operations` themselves.
This was not only an inconsistent interface but also boilerplate for every dialect definition.
Like attributes and types do since https://github.com/llvm/llvm-project/pull/243481, operations are now only registered by a generated
`register<Dialect>Operations` hook that the generated dialect
constructor calls, for all generated files whether sharded, partitioned
or neither (i.e., we are consistent again!).
Contrary to attributes and types, this is the default, as
almost every dialect defines operations in ODS. Dialects without
operations, or that register them manually, set
`useDefaultOperationRegistration` to 0. `-op-registration-name` names the
hooks of dialects whose operations are generated from several files.
Dialects whose `initialize` would now be empty can set `hasInitializer`
to 0 instead of defining an empty one.
[9 lines not shown]
[mlir][ODS] Add partitions for attributes and types (#241935)
Allow attributes and types to be grouped into named partitions, like
ops. Each def can set `partition` to a `Partition` record. Passing
`-attrdefs-partition=<name>` or `-typedefs-partition=<name>` to the
attrdef/typedef decls and defs generators then emits only the defs of
that partition. A large dialect can thus split its attributes and types
over several compilation units with narrower headers.
The implementation mirrors the approach used in op partitioning with a
`register<DialectClass>Attributes` function (or Types) is used to
register every attribute (or type) of the dialect and dispatches to
partition specific functions.
The `generated{Parser,Printer}` function saw the biggest change. It is
now generated as
`generated<DialectClass>{Attribute,Type}{Parser,Printer}` which is a
method with public linkage. This method is also generated for
non-partitioned dialects and the old `generated{Parser,Printer}`
function soft-deprecated (but for now retained for migration purposes).
[14 lines not shown]
Revert "Reapply "[AMDGPU] Support the RF and m inline asm constraints (#195123)" (#241996)" (#245558)
This reverts commit 510874d1f795996f948a21ee1820acfd5fbec63c.
EXPENSIVE_CHECKS builds were failing several AMDGPU CodeGen tests with
"Bad machine code: inlineasm operand has incorrect register class."
[AMDGPU] Honor !nontemporal on atomic load/store and AV ops intrinsics. (#234494)
LangRef currently states that !nontemporal "does not have any defined
semantics" for atomic load and store, and the AMDGPU backend follows
that. The hint is silently dropped on load atomic / store atomic and
similarly for AV ops which are lowered as monotonic atomics.
Atomicity and temporality are two orthogonal components, where atomics
atomicity is correctness property and !nontemporal is a performance
hint. Neither affects the other, and the hardware encodes them as
separate fields.
This patch sets the target's nontemporal cache-policy bits on atomic
loads and stores, in addition to the bits selected by the syncscope.
Fixes: LCOMPILER-2932
[LV] Keep costs in InstructionCost form as long as possible (#245275)
There are a few places in LoopVectorize.cpp where we call
InstructionCost::getValue() too early and in doing so lose precision. We
should be minimising calls to getValue() where possible and doing as
much arithmetic as we can using the InstructionCost class itself.
I have deliberately left isOutsideLoopWorkProfitable alone in this PR
since it's more complicated, but would like to handle in a follow-on PR.
[OpenMP] Don't emit explicit flushes for atomic constructs (#245222)
Clang and the OpenMPIRBuilder followed every atomic construct that has a
memory ordering other than relaxed with a call to `__kmpc_flush`, which
is a full memory barrier. However the LLVM LangRef specifies that an
atomic operation itself can provide the ordering "rather than an
explicit fence", so this isn't actually necessary.
It seems the calls are emitted based on a reading of the spec describing
*implied* flushes to mean that flushes should be literally emitted; an
alternative reading (here) is that the flushes are implied by the atomic
operation itself. See e.g. OpenMP 6.0 "17.8.5 atomic Construct" or
equivalent passages in 5.0 through 5.2. The flushes in question are the
"with a list" type for seq_cst, i.e. relating only to the memory
locations used in the atomic. For acquire/release atomics,
synchronization happens through the atomic's variable.
The `__kmpc_flush` call was also only emitted after the atomic
operation, so in some cases we're *already* relying on the ordering
[28 lines not shown]
[AMDGPU] Ignore edges from the def block in PhiIncomingAnalysis (#232297)
PhiIncomingAnalysis inserts the def block into the set of reachable
blocks so that it acts as an end point for the traversal, but it also
counted it as a reachable predecessor when deciding whether an incoming
block is a source. An edge from the def block to an incoming block
starts a new trip around a loop through the def block, so it does not
mean that some lanes may have taken their value from an earlier incoming
block.
This affects lane mask phis in loops where the header has a divergent
branch to the latch: the header phi merged the value from the latch, and
the latch phi merged the value from the header, even though EXEC is the
same at the end of the header and at the end of the latch, so the merged
bits could only belong to lanes that had already left the loop.
This relies on the incoming block's terminator not enabling any lanes
that were inactive in the block. The only terminator that could do that
is SI_ELSE, and a structurized CFG never puts an SI_ELSE block in a cycle
[2 lines not shown]
[MLIR][Vector] Lower fixed two-stream transposes to interleave ops (#237937)
Lower fixed-size rank-2 `vector.transpose` operations with a dimension
of size two to fixed-size `vector.interleave` or `vector.deinterleave`
operations. This keeps the lowering entirely VLS: it introduces no
scalable vectors, `vscale`, runtime loops, masks, or scratch buffers.
Preserving the transpose as structured vector operations avoids
elementwise expansion. For `vector<64x2xf32>`, this eliminates 128
`extractelement` and 128 `insertelement` operations. In an end-to-end
load–transpose–store benchmark on Neoverse N2, the generated assembly
decreased from 78 to 54 instructions, stack usage from 128 to 64 bytes,
compilation improved by 10.9× in MLIR and 2.1× in `llc`
The transformation remains opt-in because profitability depends on the
shape and target. It is exposed through the Transform dialect and tested
in both transpose directions, including unsupported and scalable-vector
cases.
Assisted by: GPT-5.6 Sol
[LVI][CVP] Consider pointer provenance when pointer equality is assumed (#239218)
Similarly to what GVN and SCCP already account for, make sure pointer
substitutions pass through canReplacePointersIfEqual(), subject to its
approximations. When LVI derives a pointer constant from an equality
predicate, such a constant may have different or non-existent pointer
provenance than the original value, and may therefore not be freely
substituted for it.
Fixes: https://github.com/llvm/llvm-project/issues/163144.
[mlir][vector] Add `getUnrollOrder` to `VectorUnrollOpInterface` (#243527)
In essence, the unrolling order depends on the underlying Op, so it is
natural to add `getUnrollOrder` to `VectorUnrollOpInterface`. This
change helps us unify unrolling patterns in `VectorUnroll.cpp`.
In addition, `UnrollVectorOptions` gains two new fields:
1) `bool reverseDefaultTraversalOrder = false;`
2) `SmallVector<int64_t> unrollOrderForContractOp`
The first one is self-explanatory. The second one is currently driven by
the test pipeline option, e.g.:
* `-test-vector-unrolling-patterns="unroll-based-on-type
unroll-order=2,0,1"`
The provided unrolling order is only used when unrolling ContractionOp,
hence `unrollOrderForContractOp` rather than some more generic name. It
effectively replaces `traversalOrderCallback`, which was mostly used in
TestVectorTransforms.cpp (the remaining user in `GPUTransformOps.cpp`
[16 lines not shown]
[RelLookupTableConverter] Add support for multiple uses (#244625)
This adds support for uses of the lookup table in multiple gep+load
pairs (including in different functions), as long as *all* of them can
be converted.
I've factored out the use analysis logic to make it easier to extend
this to support uses through phis/selects in the future.
[mlir][ODS] Register the operations of a dialect by default
Dialects registered their ODS operations by expanding `GET_OP_LIST` into
`addOperations` in `initialize`, while sharded and partitioned dialects
had to call the generated `register<Dialect>Operations` themselves.
This was not only an inconsistent interface but also boilerplate for every dialect definition.
Like attributes and types do since https://github.com/llvm/llvm-project/pull/243481, operations are now only registered by a generated
`register<Dialect>Operations` hook that the generated dialect
constructor calls, for all generated files whether sharded, partitioned
or neither (i.e., we are consistent again!).
Contrary to attributes and types, this is the default, as
almost every dialect defines operations in ODS. Dialects without
operations, or that register them manually, set
`useDefaultOperationRegistration` to 0. `-op-registration-name` names the
hooks of dialects whose operations are generated from several files.
Dialects whose `initialize` would now be empty can set `hasInitializer`
to 0 instead of defining an empty one.
[9 lines not shown]
[mlir][ODS] Add partitions for attributes and types
Allow attributes and types to be grouped into named partitions, like
ops. Each def can set `partition` to a `Partition` record. Passing
`-attrdefs-partition=<name>` or `-typedefs-partition=<name>` to the
attrdef/typedef decls and defs generators then emits only the defs of
that partition. A large dialect can thus split its attributes and types
over several compilation units with narrower headers.
The implementation mirrors the approach used in op partitioning
with a `register<DialectClass>Attributes` function (or Types) is used to register every attribute (or type) of the dialect and dispatches to partition specific functions.
The `generated{Parser,Printer}` function saw the biggest change.
It is not generated as `generated<DialectClass>{Attribute,Type}{Parser,Printer}` which is a method with public linkage.
This method is also generated for non-partitioned dialects and the old `generated{Parser,Printer}` function soft-deprecated (but for now retained for migration purposes).
The additional testing, the test dialect's attributes and types are split into the
partitions `Core` and `Syntax`.
This roughly halves the compile time (15.1s -> 6.7s + 6.9s) and peak memory (721 MiB -> 385 and
376 MiB) of the largest test dialect attribute compilation unit.
[2 lines not shown]
[mlir] Fix scalable index handling and support scalable forall tiling (#235596)
Fixes https://github.com/llvm/llvm-project/issues/150203.
`tile_using_forall` accepts `tile_sizes [[8], 1]`, but the parser drops
the scalable flag and prints it back as `[8, 1]`. At `vscale = 2`, this
requests a tile size of 8 instead of 16. The bug changes the requested
tiling even when numerical results remain correct.
Preserve the flags in `scalable_sizes` and use the SCF tile-size
callback to materialize each nonzero scalable factor times
`vector.vscale`, after checking the target's tiling interface and tensor
semantics. Materialization happens separately for each payload target to
preserve SSA dominance across functions. Zero sizes remain untiled, and
omitted flags retain fixed-size behavior.
Parser overloads that cannot return scalable flags now diagnose scalable
indices instead of discarding them. Previously accepted markers in SCF
bounds and pack/unpack inner tiles are now rejected intentionally.
[28 lines not shown]
[BOLT][DWARF] Do not modify file name entries in CU line tables (#241862)
When rewriting a compile unit's line table, we should make sure that we
don't modify the file name list. In turn, this means that BOLT doesn't
have to update `DW_AT_decl_file` and `DW_AT_call_file` values when
rewriting debug info, as the same index should be used in both the input
and the output.
For this, we explicitly require that the same index is assigned to the
file name entries in the output table as in the input by passing a
non-zero index to `BinaryContext::getDwarfFile`.
Additionally, DWARF 5 requires that a compile unit's `DW_AT_comp_dir`
and `DW_AT_name` attributes match the corresponding directory and file
name entries in the CU's associated line table. However, input files may
not always have correct DWARF debug info.
Instead of relying on the inputs being correct, we should use the file
name from the input line table as the correct value so that we don't
[3 lines not shown]
Fix nits in the tests and MayFoldRegister's doc
MayFoldRegister's doc didn't name the operands it leaves out. In the tests,
the FastISel RUN lines in inline-asm-callbase.ll gave the same output as the
SelectionDAG ones, asm-constraints-rm-i686.ll had an unused CHECK prefix, and
the torture test's early-clobber cases had the "=m" cases' labels. The
pressure test scrubbed the stack offsets that show two operands sharing a
slot, and it didn't print the tied inputs, which show each tie keeping its
output's location.
Assisted-by: Claude Opus 5.5
Generate the checks for the tied fold tests
update_mir_test_checks.py can't check debugValueSubstitutions, so
debug_instr_number moves to its own test, which keeps its hand-written
checks, and the tied tests' checks are generated.
Assisted-by: Claude Opus 5.5
Give each asm in the error tests its own srcloc
Several functions report the same error, so their CHECK lines were
identical, and a change in which of them errors would go unnoticed. With a
!srcloc, each error names its asm's line.
Assisted-by: Claude Opus 5.5