345 Commits

Author SHA1 Message Date
sstipano
5ec5701db3
Reapply "[MC][TableGen] Expand Opcode field of MCInstrDesc" (#180321) (#180954)
Difference from the previous version is that this one doesn't actually
encode opcodes in matcher tables as 32 bits, but still as 16 bits.
2026-02-12 09:17:02 +01:00
Vladimir Vereschaka
19d681177f
Revert "[MC][TableGen] Expand Opcode field of MCInstrDesc" (#180321)
Reverts llvm/llvm-project#179652

This PR causes the out-of-memory build failures on many Windows
builders.
2026-02-06 21:58:50 -08:00
sstipano
13d8870d45
[MC][TableGen] Expand Opcode field of MCInstrDesc (#179652)
Increase width of Opcode to `int` from `short` to allow more capacity.
2026-02-06 20:21:48 +01:00
Alexander Richardson
700d1f029d
[TableGen] Support RegClassByHwMode in CompressPat
This does not yet handle all cases but at least for the simple
cases such as:
```
def : CompressPat<(PTR_MOV PtrRC:$dst, PtrRC:$src),
                  (PTR_MOV_SMALL PtrRC:$dst, PtrRC:$src)>;
```
tablegen generates sensible code instead of emitting confusing errors.

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/171061
2026-01-08 11:32:30 -08:00
Alexander Richardson
7275817739
[TableGen] Improve generated comments for RegClassByHwMode tables
Adding a comment for which RegClassByHwMode the entry refers to is
helpful when staring at this generated table.

Pull Request: https://github.com/llvm/llvm-project/pull/171716
2025-12-11 22:09:29 -08:00
Jay Foad
857b68f112
[MC] Reorder TARGETInstrTable to shrink MCInstrDesc::ImplicitOffset (#171199)
Put ImplicitOps[] before OperandInfo[] in the generated
TARGETInstrTable. This means that offsets to entries into the (small)
ImplicitOps table do not need to skip over the (large) OperandInfo
table.

This allows shrinking ImplicitOffset from 32 bits to 16 bits
(effectively reverting #138127) which will allow expanding Opcode
instead without increasing the size of MCInstrDesc.
2025-12-10 07:17:58 +00:00
Matt Arsenault
9b88cd9945
CodeGen: Remove PointerLikeRegClass handling from codegen (#159883)
All uses have been migrated to RegClassByHwMode. This is now
an implementation detail of InstrInfoEmitter for pseudoinstructions.
2025-11-26 10:14:37 -05:00
Matt Arsenault
7bf459bce3
CodeGen: Make target overrides of PointerLikeRegClass mandatory (#159882)
Most targets should now use the convenience multiclass to fixup
the operand definitions of pointer-using pseudoinstructions:

defm : RemapAllTargetPseudoPointerOperands<target_ptr_regclass>;
2025-11-26 10:13:41 -05:00
Rahul Joshi
139f726c84
[NFC][TableGen] Add IfGuardEmitter and adopt it in InstrInfoEmitter (#168616)
Add a RAII `IfGuardEmitter` to insert simple #if guards and adopt it in
InstrInfoEmitter.
2025-11-19 07:33:37 -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
Matt Arsenault
11ab23c33d
CodeGen: Keep reference to TargetRegisterInfo in TargetInstrInfo (#158224)
Both conceptually belong to the same subtarget, so it should not
be necessary to pass in the context TargetRegisterInfo to any
TargetInstrInfo member. Add this reference so those superfluous
arguments can be removed.

Most targets placed their TargetRegisterInfo as a member
in TargetInstrInfo. A few had this owned by the TargetSubtargetInfo,
so unify all targets to look the same.
2025-11-10 22:40:39 +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
Rahul Joshi
a1640c1e89
[NFC][TableGen] Adopt CodeGenHelpers in InstrInfoEmitter (#166442)
Adopt `IfDefEmitter` and `NamespaceEmitter` in InstrInfoEmitter
2025-11-06 07:49:43 -08:00
Abhishek Kaushik
dec57c87f6
[NFC][TableGen] emitGetOperandIdxName: Pass arg by const& (#164563)
Take `OperandNameToID` by const& to avoid copying
2025-10-22 07:33:20 +00:00
Simon Tatham
8da0df4956
[TableGen] List the indices of sub-operands (#163723)
Some instances of the `Operand` class used in Tablegen instruction
definitions expand to a cluster of multiple operands at the MC layer,
such as complex addressing modes involving base + offset + shift, or
clusters of operands describing conditional Arm instructions or
predicated MVE instructions. There's currently no convenient way for C++
code to know the offset of one of those sub-operands from the start of
the cluster: instead it just hard-codes magic numbers like `index+2`,
which is hard to read and fragile.

This patch adds an extra piece of output to `InstrInfoEmitter` to define
those instruction offsets, based on the name of the `Operand` class
instance in Tablegen, and the names assigned to the sub-operands in the
`MIOperandInfo` field. For example, if target Foo were to define

  def Bar : Operand {
    let MIOperandInfo = (ops GPR:$first, i32imm:$second);
    // ...
  }

then the new constants would be `Foo::SUBOP_Bar_first` and
`Foo::SUBOP_Bar_second`, defined as 0 and 1 respectively.

As an example, I've converted some magic numbers related to the MVE
predication operand types (`vpred_n` and its superset `vpred_r`) to use
the new named constants in place of the integer literals they previously
used. This is more verbose, but also clearer, because it explains why
the integer is chosen instead of what its value is.
2025-10-21 09:29:18 +01: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
727e9f5ea5
CodeGen: Pass SubtargetInfo to TargetGenInstrInfo constructors (#157337)
This will make it possible for tablegen to make subtarget
dependent decisions without adding new arguments to every
target.

---------

Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
2025-09-08 12:12:19 +09:00
Rahul Joshi
ca6ac74751
[NFC][TableGen] Use BitsInit::convertInitializerToInt in a few places (#156973)
- Replace manual code to convert a `BitsInit` to a uint64_t by using
`convertInitializerToInt` where applicable.
- Add `BitsInit::convertKnownBitsToInt` to handle existing patterns in
DFAEmitter.cpp and RegisterInfoEmitter.cpp.
- Consolidate 3 copies of the same function in X86 emitters into a
single function.
2025-09-04 21:26:41 -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
Craig Topper
93373446b2
[TableGen] Don't print the instruction enum value in multiple comments in GenInstrInfo.inc. (#156960)
The name is most interesting and if you really need the number you can
use the name to find the entry in the enum or use the first field of the
table row.
2025-09-04 13:26:57 -07:00
Robert Imschweiler
2d5a3c8c08
[TableGen] Implement getOperandIdxName (#154944)
This is meant as the inverse of getNamedOperandIdx and returns the
OpName for a given operand index for a given opcode.

---------

Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2025-08-25 12:10:02 +02:00
Jay Foad
807a82d407
[TableGen] Implement getNamedOperandIdx with another table lookup. NFC. (#151116)
Use direct table lookup instead of a switch over all opcodes.

In my Release+Asserts build this reduced the code size for
AMDGPU::getNamedOperandIdx from 11422 to 80 bytes, and the total size of
all its tables (including the jump table for the switch) from 243564 to
155020 bytes.
2025-07-30 14:03:26 +01:00
Jay Foad
e5202027c5
[TableGen] Use MapVector in InstrInfoEmitter::emitOperandNameMappings (#150630)
This changes the order of names/numbers in the OpName enum, but that
should not cause any change in behaviour.
2025-07-25 21:04:48 +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
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
Jay Foad
432c5f2c60
[TableGen] Use emplace instead of insert and similar. NFC. (#143164) 2025-06-07 09:32:36 +01:00
Carl Ritson
c63687c04f
[MC][TableGen] Expand ImplicitOffset field of MCInstrDesc (#138127)
Increase width of ImplicitOffset to `int` from `short` to allow more
table capacity.
Reorder the elements to maintain natural alignment.
2025-05-03 14:50:06 +09:00
Rahul Joshi
1fd06001a9
[NFC][TableGen] Cleanup iterators in CodeGenSchedule.h (#127401)
- Use range for loops for processor models and schedule classes.
- Cleanup duplicated or unused iterators in CodeGenSchedule.h
2025-02-18 08:57:22 -08:00
Rahul Joshi
bee9664970
[TableGen] Emit OpName as an enum class instead of a namespace (#125313)
- Change InstrInfoEmitter to emit OpName as an enum class
  instead of an anonymous enum in the OpName namespace.
- This will help clearly distinguish between values that are 
  OpNames vs just operand indices and should help avoid
  bugs due to confusion between the two.
- Rename OpName::OPERAND_LAST to NUM_OPERAND_NAMES.
- Emit declaration of getOperandIdx() along with the OpName
  enum so it doesn't have to be repeated in various headers.
- Also updated AMDGPU, RISCV, and WebAssembly backends
  to conform to the new definition of OpName (mostly
  mechanical changes).
2025-02-12 08:19:30 -08:00
Rahul Joshi
dbe1dafdbd
[NFC][TableGen] Code cleanup in InstrInfoEmitter.cpp (#126578)
- Use range for loops and `enumerate` in a few places.
- Use `StringRef` for `TargetName` in `InstrInfoEmitter::run`.
- Use `\n` character for new line instead of string.
- Use StringRef in `InstrNames` (instead of std::string) and 
  avoid string copies.
2025-02-11 07:02:37 -08:00
Rahul Joshi
55015e150b
[NFC][TableGen] Delete getLogicalOperandType from InstrInfoEmitter (#125951)
Delete `getLogicalOperandType` function from InstrInfoEmitter as no
backend seems to use it.
2025-02-10 09:08:49 -08:00
Rahul Joshi
8380b5c749
[TableGen][InstrInfo] Cull mapping that have not been enabled/not needed (#126137)
- Detect whether logical operand mapping/named operand mappings have 
  been enabled in a previous pass over instructions and execute the
  relevant emission code only if those mappings are enabled.
- For these mappings, skip the fixed set of predefined instructions as
  they won't have these mappings enabled.
- Emit operand type mappings only for X86 target, as they are only used
  by X86 and look for X86 specific `X86MemOperand`.
- Cleanup `emitOperandTypeMappings` code: remove code to handle empty
  instruction list and use range for loops.
2025-02-10 08:16:12 -08:00
Rahul Joshi
337604ee7e
[NFC][TableGen] Adopt Emitter::OptClass in InstrInfoEmitter (#125971)
- Use `Emitter::OptClass` to invoke `InstrInfoEmitter::run` and
eliminate the `EmitInstrInfo` function.
2025-02-06 10:45:05 -08:00
Rahul Joshi
91e77d88a4
[TableGen] Restore OpName::OPERAND_LAST emission in InstrInfoEmitter (#125265)
- Looks like this sentinel value is used in some downstream backends, so
restore emitting it.
- It now also has the correct value (earlier code may have emitted an
incorrect value for OPERAND_LAST and hence it was removed in
https://github.com/llvm/llvm-project/pull/124960)
2025-01-31 13:19:11 -08:00
Rahul Joshi
fdfd97959e
[TableGen] Improvements to Named operands in InstrInfoEmitter (#124960)
- Assign `OpName` enum values in the same alphabetical order in which
they are emitted.
- Get rid of OPERAND_LAST which is not used anywhere.
- Inline `initOperandMapData` into `emitOperandNameMappings` to help see
clearly how various maps are computed.
- Emit the static `OperandMap` table as int8_t when possible. This
should help reduce the static size by 50% in the common case.
- Change maps/vectors to use StringRef instead of std::string to avoid
unnecessary copies.
2025-01-30 13:04:06 -08:00
Rahul Joshi
7842374103
[NFC][TableGen] Emit nested namespaces in InstrInfoEmitter (#124210)
- Emit C++17 nested namespaces in InstrInfoEmitter.
2025-01-24 08:20:35 -08:00
Jay Foad
4e8c9d2813
[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)
Also use brace initialization and emplace to avoid explicitly 
constructing std::pair, and the same for std::tuple.
2025-01-16 13:20:41 +00:00
Rahul Joshi
62e2c7fb2d
[LLVM][TableGen] Change all Init pointers to const (#112705)
This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-18 07:50:22 -07:00
Rahul Joshi
d883ef1076
[TableGen] Factor out timer code into a new TGTimer class (#111054)
Factor out the timer related functionality from `RecordKeeper` to a new
`TGTimer` class in a new file.
2024-10-04 09:23:55 -07:00
Rahul Joshi
f9cba2eea4
[LLVM][TableGen] Change InstrInfoEmitter to use const RecordKeeper (#110110)
Change InstrInfoEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-26 07:33:53 -07:00
Rahul Joshi
c92137e474
[NFC][TableGen] Adopt scaled indent in PredicateExpander (#109801)
Adopt scaled indent in PredicateExpander.
Added pre/post inc/dec operators to `indent` and related unit tests.
Verified by comparing *.inc files generated by LLVM build with/without
the change.
2024-09-24 22:05:51 -07:00
Rahul Joshi
23123aa4ec
[LLVM][TableGen] Change InstrInfoEmitter to use const RecordKeeper (#109189)
Change InstrInfoEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-18 22:27:26 -07:00
Rahul Joshi
c29dfb3346
[LLVM][TableGen] Change CodeGenSchedule to use const Record pointers (#108782)
Change CodeGenSchedule to use const Record pointers.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-18 04:45:49 -07:00
Rahul Joshi
2b452b455e
[TableGen] Change SubtargetFeatureInfo to use const Record pointers (#108013)
Change SubtargetFeatureInfo to use const Record pointers.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-11 08:53:21 -07:00
Rahul Joshi
bdf02249e7
[TableGen] Change CGIOperandList::OperandInfo::Rec to const pointer (#107858)
Change CGIOperandList::OperandInfo::Rec and CGIOperandList::TheDef to
const pointer.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-09 14:33:21 -07:00
Kazu Hirata
d9293519bc
[TableGen] Use llvm::unique (NFC) (#94163) 2024-06-02 11:52:12 -07:00
Michael Liao
62853a246e [TableGen][InstrInfoEmitter] Count sub-operands on def operands
- If a def operand includes multiple sub-operands, count them when
  generating instr info.
- Found issues in x86 and sparc backends, where memory operands of
  store or store-like instructions are wrongly placed in the output
  list.

Reviewers: jayfoad, arsenm, Pierre-vh

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/88972
2024-04-16 20:34:20 -04:00
Pierre van Houtryve
fa3d789df1
[RFC][TableGen] Restructure TableGen Source (#80847)
Refactor of the llvm-tblgen source into:
- a "Basic" library, which contains the bare minimum utilities to build
`llvm-min-tablegen`
- a "Common" library which contains all of the helpers for TableGen
backends. Such helpers can be shared by more than one backend, and even
unit tested (e.g. CodeExpander is, maybe we can add more over time)

Fixes #80647
2024-03-25 09:40:35 +01:00
Pierre van Houtryve
b9079baadd
[NFC] clang-format utils/TableGen (#80973)
```
find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i
```

Split from #80847
2024-02-09 09:27:04 +01:00