223 Commits

Author SHA1 Message Date
Jie Fu
a3ab11007b [TableGen] Silence a warning (NFC)
/llvm-project/llvm/utils/TableGen/Common/CodeGenTarget.cpp:286:12:
 error: variable 'SkippedInsts' set but not used [-Werror,-Wunused-but-set-variable]
  unsigned SkippedInsts = 0;
           ^
1 error generated.
2025-11-19 10:04:32 +08:00
Matt Arsenault
bfb953926c
TableGen: Support target specialized pseudoinstructions (#159880)
Allow a target to steal the definition of a generic pseudoinstruction
and remap the operands. This works by defining a new instruction, which
will simply swap out the emitted entry in the InstrInfo table.

This is intended to eliminate the C++ half of the implementation
of PointerLikeRegClass. With RegClassByHwMode, the remaining usecase
for PointerLikeRegClass are the common codegen pseudoinstructions.
Every target maintains its own copy of the generic pseudo operand
definitions anyway, so we can stub out the register operands with
an appropriate class instead of waiting for runtime resolution.

In the future we could probably take this a bit further. For example,
there is a similar problem for ADJCALLSTACKUP/DOWN since they depend
on target register definitions for the stack pointer register.
2025-11-19 01:22:07 +00:00
Sergei Barannikov
e413343ca7
[SelectionDAG] Verify SDTCisVT and SDTCVecEltisVT constraints (#150125)
Teach `SDNodeInfoEmitter` TableGen backend to process `SDTypeConstraint`
records and emit tables for them. The tables are used by
`SDNodeInfo::verifyNode()` to validate a node being created.

This PR only adds validation code for `SDTCisVT` and `SDTCVecEltisVT`
constraints to keep it smaller.

Pull Request: https://github.com/llvm/llvm-project/pull/150125
2025-11-16 18:26:03 +03:00
serge-sans-paille
af146462f9
Remove unused <iterator> inclusion
Per https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible
this improves compilation time, while not being too intrusive on the
codebase.
2025-11-11 13:33:38 +01:00
serge-sans-paille
45a2320372
Remove unused <utility> inclusion
Per https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible this improves compilation time, while not being too intrusive on the codebase.
2025-11-11 13:33:33 +01:00
serge-sans-paille
28d9f99a27
Remove unused standard headers: <string>, <optional>, <numeric>, <tuple> (#167232) 2025-11-10 12:17:12 +00:00
Kazu Hirata
02976f5ffa
[TableGen] Use "using" instead of "typedef" (NFC) (#167168)
Identified with modernize-use-using.
2025-11-08 13:09:03 -08:00
Kazu Hirata
707bab651f
[llvm] Remove redundant typename (NFC) (#166087)
Identified with readability-redundant-typename.
2025-11-02 13:15:16 -08:00
Kazu Hirata
83195d9541
[TableGen] Use "= default" (NFC) (#165968)
Identified with modernize-use-equals-default.
2025-11-01 09:25:04 -07:00
Kazu Hirata
042ac912b1
[llvm] Add "override" where appropriate (NFC) (#165168)
Note that "override" makes "virtual" redundant.

Identified with modernize-use-override.
2025-10-26 13:34:32 -07:00
Kazu Hirata
378d5ea290
[llvm] Use iterator_range<T>(Container &&) (NFC) (#165117)
This patch simplifies construction of iterator_range<T> by using:

  iterator_range<T>(Container &&)

instead of:

  iterator_range<T>(T begin_iterator, T end_iterator)
2025-10-25 15:46:44 -07:00
Kazu Hirata
f2306b6304
[llvm] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (#163507)
This patch replaces LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]].  Note
that this patch adjusts the placement of [[maybe_unused]] to comply
with the C++17 language.
2025-10-15 06:54:14 -07:00
Rahul Joshi
bd7e228fa4
[NFC][TableGen] Fix namespace usage in various files (#161839)
- Move standalone functions and variables out of anonymous namespace and
make them static.
- Eliminate `namespace llvm {}` wrapping all code in .cpp files, and
instead use namespace qualifier to define such functions
(https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions)
- Add namespace for X86DisassemblerShared.h.
2025-10-03 09:27:04 -07:00
Matt Arsenault
3c6cd732eb
CodeGen: Do not store RegisterClass copy costs as a signed value (#161786)
Tolerate setting negative values in tablegen, and store them as a
saturated uint8_t value. This will allow naive uses of the copy cost
to directly add it as a cost without considering the degenerate negative
case. The degenerate negative cases are only used in InstrEmitter / DAG
scheduling, so leave the special case processing there. There are also
fixmes about this system already there.

This is the expedient fix for an out of tree target regression
after #160084. Currently targets can set a negative copy cost to mark
copies as "impossible". However essentially all the in-tree uses only
uses this for non-allocatable condition registers. We probably should
replace the InstrEmitter/DAG scheduler uses with a more direct check
for a copyable register but that has test changes.
2025-10-04 00:10:02 +09:00
Owen Anderson
b05101b864
[TableGen, CodeGen, CHERI] Add support for the cPTR wildcard value type. (#158426)
cPTR is a wildcard CHERI capability value type, used analogously to iPTR. This allows TableGen patterns to abstract over CHERI capability widths.

Co-authored-by: Jessica Clarke <jrtc27@jrtc27.com>
2025-09-25 22:49:40 +09:00
Rahul Joshi
b7908e3841
[NFC][MC][CodeEmitterGen] Extract error reporting into a helper function (#159778)
Extract error reporting code emitted by CodeEmitterGen into
MCCodeEmitter static members functions.
Additionally, remove unused ErrorHandling.h header from several files.
2025-09-23 09:05:10 -07:00
Sergei Barannikov
6a43c669d1
[TableGen][DecoderEmitter][RISCV] Always handle bits<0> (#159951)
Previously, `bits<0>` only had effect if `ignore-non-decodable-operands`
wasn't specified. Handle it even if the option was specified. This
should allow for a smoother transition to the option removed.

The change revealed a couple of inaccuracies in RISCV compressed
instruction definitions.
* `C_ADDI4SPN` has `bits<5> rs1` field, but `rs1` is not encoded. It
should be `bits<0>`.
* `C_ADDI16SP` has `bits<5> rd` in the base class, but it is unused
since `Inst{11-7}` is overwritten with constant bits.
We should instead set `rd = 2` and `Inst{11-7} = rd`. There are a couple
of alternative fixes, but this one is the shortest.
2025-09-22 20:50:17 +03:00
Craig Topper
678dcf13d8
[IR] Fix a few implicit conversions from TypeSize to uint64_t. NFC (#159894) 2025-09-20 14:18:47 -07:00
Sergei Barannikov
386301cd5c
[TableGen] Remove unused Target from InstructionEncoding methods (NFC) (#159833) 2025-09-20 03:05:55 +03:00
Matt Arsenault
6b54c92be0
CodeGen: Add RegisterClass by HwMode (#158269)
This is a generalization of the LookupPtrRegClass mechanism.
AMDGPU has several use cases for swapping the register class of
instruction operands based on the subtarget, but none of them
really fit into the box of being pointer-like.

The current system requires manual management of an arbitrary integer
ID. For the AMDGPU use case, this would end up being around 40 new
entries to manage.

This just introduces the base infrastructure. I have ports of all
the target specific usage of PointerLikeRegClass ready.
2025-09-19 20:08:51 +09:00
Matt Arsenault
e79f4511a2
TableGen: Replace assertion with error for unexpected pattern inputs (#159687) 2025-09-19 03:57:50 +00:00
Fabian Ritter
9df83619fb
[GlobalISelMatchTable] Don't hoist C++ predicates over operand recorders (#159329)
The pattern optimizations in GlobalISelMatchTable.cpp can extract common
predicates out of pattern alternatives by putting the pattern alternatives into
a GroupMatcher and moving common predicates into the GroupMatcher's predicate
list. This patch adds checks to avoid hoisting a common predicate before
matchers that record named operands that the predicate uses, which would lead
to segfaults when the imported patterns are matched.

See the added test for a concrete example inspired by the AMDGPU backend.

This fixes a bug encountered in #143881.
2025-09-18 09:52:10 +02:00
Rahul Joshi
b5e06b5ede
[NFC][DecoderEmitter] Predicate generation code cleanup (#158140)
Eliminate `doesOpcodeNeedPredicate` and instead have
`emitPredicateMatch` return true if any predicates were generated.
Delegate actual predicate generation in `emitPredicateMatch` to
`SubtargetFeatureInfo::emitMCPredicateCheck`. Additionally, remove the
redundant parenthesis around the predicate conditions in the generated
`checkDecoderPredicate` function.

Note that for ARM/AMDGPU this reduces the total # of predicates
generated by a few. It seems the old code would sometimes generate
duplicate predicates which were identical in semantics but one had an
extra pair of parentheses (i..e, `X` and `(X)`). `emitMCPredicateCheck`
does not seems to have that issue.
2025-09-15 19:23:07 -07:00
Sergei Barannikov
de8030e63c
[TableGen] Extract InstructionEncoding class into a separate file (NFC) (#158505)
So that it can be used in CodeEmitterGen / VarLenCodeEmitterGen.
2025-09-15 21:17:54 +03:00
Sergei Barannikov
7f4c297e94
[TableGen][CodeGen] Remove feature string from HwMode (#157600)
`Predicates` and `Features` fields serve the same purpose. They should
be kept in sync, but not all predicates are based on features. This
resulted in introducing dummy features for that only reason.

This patch removes `Features` field and changes TableGen emitters to use
`Predicates` instead.

Historically, predicates were written with the assumption that the
checking code will be used in `SelectionDAGISel` subclasses, meaning
they will have access to the subclass variables, such as `Subtarget`.
There are no such variables in the generated
`GenSubtargetInfo::getHwModeSet()`, so we need to provide them. This can
be achieved by subclassing `HwModePredicateProlog`, see an example in
`Hexagon.td`.
2025-09-10 12:39:47 +03:00
Sergei Barannikov
dc1037335a
[TableGen] Fix a couple of crashes related to sub-operand dags (#156179)
The added tests used to crash when attempting to dereference a nullptr
MIOpInfo or call MIOpInfo->getArg(0) on an empty MIOpInfo dag.
2025-09-05 18:47:55 +03:00
Rahul Joshi
e5e57363e4
[NFC][TableGen] Fix GlobalISel TableGen backend namespace usage (#156986) 2025-09-05 07:27:57 -07:00
Rahul Joshi
927eba2456
[NFC][TableGen] Adopt CodeGenInstruction::getName() (#156968)
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-09-04 16:49:26 -07:00
Rahul Joshi
78fbca4a33
[NFC][InstrInfoEmitter] Include location of inst definition in comment (#156927)
Print the source location of the instruction definition in comment next
to the enum value for each instruction. To make this more readable,
change formatting of the instruction enums to be better aligned.

Example output:

```
    VLD4qWB_register_Asm_8                 = 573, // (ARMInstrNEON.td:8849)
    VMOVD0                                 = 574, // (ARMInstrNEON.td:6337)
    VMOVDcc                                = 575, // (ARMInstrVFP.td:2466)
    VMOVHcc                                = 576, // (ARMInstrVFP.td:2474)
    VMOVQ0                                 = 577, // (ARMInstrNEON.td:6341)
```
2025-09-04 15:06:40 -07:00
Sergei Barannikov
981f25a8a8
[TableGen] Require complex operands in InstAlias to be specified as DAGs (#136411)
Currently, complex operands of an instruction are flattened in the resulting DAG of `InstAlias`.
This change makes it required to specify complex operands in `InstAlias` as sub-DAGs:

```
InstAlias<"foo $rd, $rs1, $rs2", (Inst RC:$rd, (ComplexOp RC:$rs1, GR0, 42), SimpleOp:$rs2)>;
```

instead of

```
InstAlias<"foo $rd, $rs1, $rs2", (Inst RC:$rd, RC:$rs1, GR0, 42, SimpleOp:$rs2)>;
```

The advantages of the new syntax are improved readability and more robust type checking, although it is a bit more verbose.
2025-08-30 18:45:07 +03:00
Sergei Barannikov
cc5e8967ab
[TableGen][CodeGen] Remove DisableEncoding field of Instruction class (#156098)
I believe it became no-op with the removal of the "positionally encoded
operands" functionality (b87dc356 is the last commit in the series).

There are no changes in the generated files.
2025-08-30 04:44:20 +00:00
Kyle Krüger
5d0294fcb6
[llvm] Support building with c++23 (#154372)
closes #154331 

This PR addresses all minimum changes needed to compile LLVM and MLIR
with the c++23 standard.
It is a work in progress and to be reviewed for better methods of
handling the parts of the build broken by c++23.
2025-08-29 12:52:07 +00:00
Sergei Barannikov
7dbdb66a5d
[TableGen] Avoid field lookup in a performance critical place (NFC) (#154871)
`Target.getInstructions()` is called by virtually all TableGen backends.
It is slow, and one of the two factors is the use of an expensive
predicate in `llvm::sort`. This change speeds up sorting by 10x.
2025-08-25 18:47:48 +03:00
Sergei Barannikov
6462223853 [TableGen] Make ParseOperandName method const (NFC)
Also change its name to start with a lowercase letter and update
the doxygen comment to conform to the coding standard.
2025-08-20 03:21:15 +03:00
Piotr Fusik
3784bfa129
[TableGen] Fix GIMT_Encode8 with a large argument (#153429)
error: integer literal is too large to be represented
    in a signed integer type, interpreting as unsigned
    [-Werror,-Wimplicitly-unsigned-literal]

Introduced in #153391
2025-08-13 18:08:56 +02:00
Piotr Fusik
e50372c14c
[TableGen] Emit integers in GlobalISelMatchTable as unsigned (#153391)
The numbers are stored in an `uint8_t` array, either directly
or via `GIMT_Encode2/4/8` macros
(see `getEncodedEmitStr` and `emitEncodingMacrosDef`).
Passing negative numbers only adds confusion and results in a warning
for the `INT64_MIN` value (C++ parses `-9223372036854775808` as two
tokens: a unary minus and an unsigned integer, triggered in #151687).

BTW, parenthesize parameters in `GIMT_Encode2/4/8` macros
and avoid unnecessary casts.
2025-08-13 16:22:05 +02:00
Sergei Barannikov
2f9f92ad01
[TableGen] Use getValueAsOptionalDef to simplify code (NFC) (#153170) 2025-08-12 17:44:01 +03:00
Jay Foad
3be44e2580
[TableGen] Add some -time-phases support in CodeGenRegisters (#149309) 2025-07-18 22:05:54 +01:00
Shaoce SUN
0c75e09381
[TableGen] Add getName() to error messages for better debugging (#149531)
Including the name helps quickly locate the corresponding Instruction
that caused the issue.
2025-07-19 00:44:16 +08:00
Jay Foad
4355356d96
[TableGen] Add a bitvector of members of CodeGenRegisterClass (#149122)
This makes CodeGenRegisterClass::contains fast. Use this to simplify
inferMatchingSuperRegClass.
2025-07-16 20:31:32 +01:00
Jay Foad
362594a10f
[TableGen] Remove unnecessary sortAndUniqueRegisters (#149125)
Each of the SRSets is already sorted and unique because it is a filtered
version of RC->getMembers() which is already sorted and unique.
2025-07-16 20:27:50 +01:00
Jay Foad
2fd37c9f33
[TableGen] Remove RegUnitIterator. NFC. (#147483)
TableGen's RegUnitIterator is a strange contraption that iterates over a
range of registers as well as the regunits of each register. Since it is
only used in one place in a `for` loop, it is much simpler to use two
nested loops instead.
2025-07-08 16:18:30 +01:00
Rahul Joshi
5f2e88a125
[NFC][TableGen] Rename CodeGenTarget instruction accessors (#146767)
Rename `getXYZInstructionsByEnumValue()` to just `getXYZInstructions`
and drop the `ByEnumValue` in the name.
2025-07-07 08:01:14 -07:00
Austin
a550fef906
[llvm] Use llvm::fill instead of std::fill(NFC) (#146911)
Use llvm::fill instead of std::fill
2025-07-04 14:10:28 +08:00
Rahul Joshi
a880c8e670
[NFC][TableGen] Add accessors for various instruction subclasses (#146615)
- Add various instruction subclass/sub-slice accessors to
`CodeGenTarget`.
- Delete unused `inst_begin` and `inst_end` iterators.
- Rename `Instructions` to `InstructionMap` and `getInstructions` to
`getInstructionMap` to better represent their meaning.
- Use these new accessors in InstrInfoEmitter
2025-07-02 12:49:27 -07:00
Kazu Hirata
3d5903c4d8
[llvm] Use llvm::is_contained (NFC) (#145844)
llvm::is_contained is shorter than llvm::all_of plus a lambda.
2025-06-26 08:41:18 -07:00
Rahul Joshi
f608716b09
[LLVM][TableGen] Minor cleanup in CGIOperandList (#142721)
- Change `hadOperandNamed` to return index as std::optional and rename
it to `findOperandNamed`.
- Change `SubOperandAlias` to return std::optional and rename it to
`findSubOperandAlias`.
2025-06-24 18:47:53 -07:00
Rahul Joshi
fba63e3281
[NFC][TableGen] Use ArrayRef instead of const vector reference (#145323)
- Use `ArrayRef` instead of `SmallVector` reference in a few places.
- Drop redundant `llvm::` in a few places.
2025-06-24 07:30:00 -07:00
Rahul Joshi
f626620e33
[LLVM][TableGen] Use StringRef for CodeGenInstruction::AsmString (#144440) 2025-06-16 18:19:17 -07:00
Jay Foad
39ad3151e0
[TableGen] Use default member initializers. NFC. (#144349)
Automated with clang-tidy -fix -checks=-*,modernize-use-default-member-init
2025-06-16 15:26:47 +01:00