126 Commits

Author SHA1 Message Date
Kazu Hirata
252bd80871
[TableGen] Remove unused includes (NFC) (#141356)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-24 09:37:40 -07:00
Rahul Joshi
b5e3d8ec08
[LLVM][TableGen] Use StringRef for various members CGIOperandList::OperandInfo (#140625)
- Change `Name`, `SubopNames`, `PrinterMethodName`, and
`EncoderMethodNames` to be stored as StringRef.
- Also changed `CheckComplexPatMatcher::Name` to StringRef as a fallout
from the above.

Verified that all the tablegen generated files within LLVM are
unchanged.
2025-05-21 06:23:01 -07:00
Kazu Hirata
294eb7670f [TableGen] Fix a warning
This patch fixes an unused parameter warning with gcc7 under the
release configuration.
2025-05-12 23:18:30 -07:00
Rahul Joshi
9981afc5f9
[NFC][TableGen] Use StringRef::str() instead of casting (#139332)
- Also eliminate unneeded std::string() around some literal strings.
2025-05-12 15:41:27 -07:00
Craig Topper
afbd2ce80f
[TableGen] Use StringRef::empty() instead of comparing to an empty string. NFC (#137673) 2025-04-28 16:47:52 -07:00
Kazu Hirata
f4d3a0cb6a
[TableGen] Simplify insertBits (NFC) (#137538)
We can use "constexpr if" to combine the two variants of functions.
2025-04-27 12:35:54 -07:00
Rahul Joshi
ecb0daa72c
[NFC][LLVM][TableGen] Eliminate inheritance from std::vector (#136573) 2025-04-23 08:44:35 -07:00
Rahul Joshi
e1bb7f6dde
[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter (#136456)
- Add command line option `num-to-skip-size` to parameterize the size of
`NumToSkip` bytes in the decoder table. Default value will be 2, and
targets that need larger size can use 3.
- Keep all existing targets, except AArch64, to use size 2, and change
AArch64 to use size 3 since it run into the "disassembler decoding table
too large" error with size 2.
- Additional fixes on top of earlier revert: mark `decodeNumToSkip` as
static (not necessary anymore as the generated code is now in anonymous
namespace, but doing it for consistency) and incorporate Bazel build
changes from https://github.com/llvm/llvm-project/pull/136212
- Following is a rough reduction in size for the decoder tables by
switching to size 2.

```
Target         Old Size   New Size   % Reduction
================================================
AArch64           153254     153254        0.00
AMDGPU            471566     412805       12.46
ARC                 5724       5061       11.58
ARM                84936      73831       13.07
AVR                 1497       1306       12.76
BPF                 2172       1927       11.28
CSKY               10064       8692       13.63
Hexagon            47967      41965       12.51
Lanai               1108        982       11.37
LoongArch          24446      21621       11.56
MSP430              4200       3716       11.52
Mips               36330      31415       13.53
PPC                31897      28098       11.91
RISCV              37979      32790       13.66
Sparc               8331       7252       12.95
SystemZ            36722      32248       12.18
VE                 48296      42873       11.23
XCore               2590       2316       10.58
Xtensa              3827       3316       13.35
```
2025-04-21 08:15:08 -07:00
Rahul Joshi
6182015698
[NFC][LLVM][TableGen] Adjust pointer increments in DecoderEmitter (#136230)
- In both `emitTable` and the generated `decodeInstruction` function
increment the pointer to the decoder op as a part of the switch
statement instead of later on in each case.
2025-04-18 10:08:00 -07:00
Rahul Joshi
c244daec1c
[LLVM][TableGen] Fix Windows failure in DecoderEmitter (#136310)
- Avoid dereferencing the end() iterator to get the end pointer, instead
calculate it explicitly
- Fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/136220.
- The windows build failure shows the following call stack:

```
 | Exception Code: 0x80000003
 |  #0 0x00007ff74bc05897 std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<unsigned char>>>::operator*(void) const C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.37.32822\include\vector:52:0
 |  #1 0x00007ff74bbd3d64 `anonymous namespace'::DecoderEmitter::emitTable D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\llvm\utils\TableGen\DecoderEmitter.cpp:852:0
```
2025-04-18 10:05:40 -07:00
Rahul Joshi
3ed83630b2
[NFC][LLVM][TableGen] Use decodeULEB128 for OPC_SoftFail emission (#136220)
- Use `decodeULEB128` to decode +ve/-ve mask in OPC_SoftFail case.
- Use current `I`/`E` iterators as inputs to `decodeULEB128`.
2025-04-18 05:12:35 -07:00
Rahul Joshi
6c4caae449
[LLVM][TableGen] Move DecoderEmitter output to anonymous namespace (#136214)
- Move the code generated by DecoderEmitter to anonymous namespace.
- Move AMDGPU's usage of this code from header file to .cpp file.

Note, we get build errors like "call to function 'decodeInstruction'
that is neither visible in the template definition nor found by
argument-dependent lookup" if we do not change AMDGPU.
2025-04-18 04:35:05 -07:00
Rahul Joshi
6d8bf3cf3d
Revert "Reapply "[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter" (#136017)" (#136068)
Reverts llvm/llvm-project#136019

Expensive checks tests are failing, so reverting.
2025-04-16 18:24:10 -07:00
Rahul Joshi
8ebdd9d8a1
Reapply "[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter" (#136017) (#136019)
This reverts commit 7fd0c8acd4659ccd0aef5486afe32c8ddf0f2957, and fixes
the assert condition in `patchNumToSkip`.
2025-04-16 15:40:34 -07:00
Rahul Joshi
7fd0c8acd4
Revert "[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter" (#136017)
Reverts llvm/llvm-project#135882

Causing assert failures for AArch64 backend
2025-04-16 13:16:32 -07:00
Rahul Joshi
598ec8ce2d
[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter (#135882)
- Add command line option `num-to-skip-size` to parameterize the size of
`NumToSkip` bytes in the decoder table. Default value will be 2, and
targets that need larger size can use 3.
- Keep all existing targets, except AArch64, to use size 2, and change
AArch64 to use size 3 since it run into the "disassembler decoding table
too large" error with size 2.
- Following is a rough reduction in size for the decoder tables by
switching to size 2.

```
Target         Old Size   New Size   % Reduction
================================================
AArch64           153254     153254        0.00
AMDGPU            471566     412805       12.46
ARC                 5724       5061       11.58
ARM                84936      73831       13.07
AVR                 1497       1306       12.76
BPF                 2172       1927       11.28
CSKY               10064       8692       13.63
Hexagon            47967      41965       12.51
Lanai               1108        982       11.37
LoongArch          24446      21621       11.56
MSP430              4200       3716       11.52
Mips               36330      31415       13.53
PPC                31897      28098       11.91
RISCV              37979      32790       13.66
Sparc               8331       7252       12.95
SystemZ            36722      32248       12.18
VE                 48296      42873       11.23
XCore               2590       2316       10.58
Xtensa              3827       3316       13.35
```
2025-04-16 13:07:58 -07:00
Rahul Joshi
4780658823
[NFC][TableGen] DecoderEmitter optimize scope stack in Filter::emitTableEntry (#135693)
- Create a new stack scope only in the fallthrough case.
- For the non-fallthrough cases, any fixup entries will naturally be
added to the existing scope without needing to copy them manually.
- Verified that the generated `GenDisassembler` files are identical with
and without this change.
2025-04-15 07:49:01 -07:00
Rahul Joshi
9ba65cbcb5
[NFC][TableGen] Refactor DecoderEmitter.cpp (#135510)
- Add helper functions to insert ULEB128 encoded value and NumToSkip.
- Use ArrayRef<> instead of const vector references as function
  arguments.
- Return `OpHasCompleteDecoder` by value instead of by reference.
- Use range for loops.
- Remove {} around single line if/else bodies.
- In `emitSoftFailTableEntry`, unconditionally emit the Positive and
  Negative mask values, instead of explicitly emitting a 0 byte when
  the mask is not needed.
2025-04-14 14:09:00 -07:00
Craig Topper
40c859a704
[TableGen] Use size returned by encodeULEB128 to simplify some code. NFC (#133750)
We can use the length to insert all the bytes at once instead of
partially decoding them to insert one byte at a time.
2025-03-31 15:58:36 -07:00
Kazu Hirata
2c73711995
[TableGen] Use llvm::append_range (NFC) (#133649) 2025-03-30 12:21:38 -07:00
Craig Topper
fd21d35178
[TableGen] Reduce the number of vectors passed to getIslands. NFC (#130402)
Combine the StartBits, EndBits, and FieldVals vectors into a single
vector of a struct that contains all 3 pieces of information.

Instead of storing EndBits, we store NumBits since that's what the users
want.

I've removed the BitNo variable as it was easy to construct calculate
from StartBit. I've also removed Num in favor of Islands.size().
2025-03-10 21:02:09 -07:00
Craig Topper
f2607df291 [TableGen] Use uint8_t for bit_value_t enum. NFC
This reduces the amount of space needed for vectors of bit_value_t
and allows the user of memset.

Also reorder the enum values so BIT_FALSE is 0 and BIT_TRUE is 1.
2025-03-07 23:22:45 -08:00
Craig Topper
d65719fab3 [TableGen] Use isUInt to simplify some asserts. NFC 2025-03-07 22:51:43 -08:00
Craig Topper
8370ac88af [TableGen] Remove push_back from loop. NFC
We can initialize the vector to the right size and then assign
over some entries in the loop.
2025-03-07 22:01:15 -08:00
Craig Topper
f578982490 [TableGen] Remove unnecessary const_cast. NFC 2025-03-07 21:52:29 -08:00
Craig Topper
ff033d1f28 [TableGen] Use reference instead of pointer for FilterChooser in Filter. NFC 2025-03-07 19:11:31 -08:00
Craig Topper
6a42dc694c
[TableGen] Simplify emitULEB128 in DecoderEmitter.cpp. NFC (#130214)
Instead of returning the number of bytes emitted, just take the iterator
by reference so the increments in emitULEB128 will update the copy in
the caller.

Also pass the iterator by reference to emitNumToSkip so we don't need a
separate I += 3 in the caller.
2025-03-07 11:09:34 -08:00
Craig Topper
efb880de11 [TableGen] Fix incorrect comment. NFC 2025-03-03 14:37:37 -08:00
Craig Topper
3ce67a81fa [TableGen] Remove unnecessary use of utostr to print a byte. NFC
We can cast to unsigned instead.
2025-03-03 14:37:37 -08:00
chrisPyr
71f4c7dabe
[NFC]Make file-local cl::opt global variables static (#126486)
#125983
2025-03-03 13:46:33 +07:00
Craig Topper
4059faf613 [TableGen] Update comment for size of NumToSkip field in DecoderEmitter. NFC
NumToSkip is 24 bits. It used to be 16 bits.
2025-02-26 10:12:38 -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
abhishek-kaushik22
943b212d56
[TableGen] Use std::move to avoid copy (#123088) 2025-01-15 22:50:00 +05:30
abhishek-kaushik22
31ce47b5d6
[TableGen] Use std::move to avoid copy (#113061) 2024-11-21 11:48:46 -08: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
708567ab0b
[LLVM][TableGen] Adopt indent for indentation (#109275)
Adopt `indent` for indentation DAGISelMatcher and DecoderEmitter.
2024-09-20 04:28:01 -07:00
Rahul Joshi
b594b93024
[LLVM][TableGen] Change DisassemblerEmitter to use const RecordKeeper (#109177)
Change DisassemblerEmitter 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-20 04:22:37 -07:00
Rahul Joshi
3e24dd42dd
[NFC] Rename variables to conform to LLVM coding standards (#109166)
Rename `indent` to `Indent` and `o` to `OS`.
Rename `Indentation` to `Indent`.
Remove unused argument from `emitPredicateMatch`.
Change `Indent` argument to `emitBinaryParser` to by value.
2024-09-19 04:49:12 -07:00
Rahul Joshi
2bb3621faa
[LLVM][TableGen] Change DecoderEmitter to use const RecordKeeper (#109040)
Change DecoderEmitter 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 05:35:26 -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
Rahul Joshi
0ceffd362b
[TableGen] Add PrintError family overload that take a print function (#107333)
Add PrintError and family overload that accepts a print function. This
avoids constructing potentially long strings for passing into these
print functions.
2024-09-07 05:13:54 -07:00
Max Beck-Jones
a46d60ad32
[NFC] [AArch64] Refactor predicate register class decode functions (#97412)
In a previous PR #81716, a new decoder function was added to
llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp. During
code review it was suggested that, as most of the decoder functions were
very similar in structure, that they be refactored into a single,
templated function. I have added the refactored function, removed the
definitions of the replaced functions, and replaced the references to
the replaced functions in AArch64Disassembler.cpp and
llvm/lib/Target/AArch64/AArch64RegisterInfo.td. To reduce the number of
duplicate references in AArch64RegisterInfo.td, I have also made a small
change to llvm/utils/TableGen/DecoderEmitter.cpp.
2024-07-15 16:57:42 +01:00
Piotr Fusik
35bb9f158b
[TableGen][NFC] Use decodeULEB128AndIncUnsafe in decodeInstruction (#98619) 2024-07-14 13:27:51 -07:00
Fangrui Song
efad14954c
[Support] Add end/error to decode[US]LEB128AndInc
Follow-up to #85739 to encourage error checking. We make `end` mandatory
and add decodeULEB128AndIncUnsafe to be used without `end`.

Pull Request: https://github.com/llvm/llvm-project/pull/90006
2024-05-08 09:22:30 -07:00
superZWT123
da1d3d8fb9
[TableGen] Introduce a less aggressive suppression for HwMode Decoder… (#86060)
1. Remove 'AllModes' and 'DefaultMode' suffixes for DecoderTables under
default HwMode.
2. Introduce a less aggressive suppression for HwMode DecoderTable, only
reduce necessary tables duplications. This allows encodings under
different HwModes to retain the original DecoderNamespace.
3. Change 'suppress-per-hwmode-duplicates' command option from bool type
to enum type, allowing users to choose what level of suppression to use.
2024-04-01 17:19:46 +08: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
Fangrui Song
35bf8e798d
[Support] Add decodeULEB128AndInc/decodeSLEB128AndInc
Many decodeULEB128/decodeSLEB128 users need to increment the pointer.
Add helpers to simplify this common pattern. We don't add `end` and
`error` parameters at present because many users don't need them.

Pull Request: https://github.com/llvm/llvm-project/pull/85739
2024-03-19 15:40:23 -07:00
mahesh-attarde
390f28702f
[CodeGen][Tablegen] Fix uninitialized var and shift overflow. (#84896)
Fix uninitialized var and shift overflow.
2024-03-13 22:03:15 +08:00
Jason Eckhardt
e9492ccae0
[TableGen] DecoderEmitter clean-ups and modernization. (#84832)
The decoder emitter is showing some signs of age. This patch makes a few
kinds of clean-ups:
- Use ranged-for more widely, including using enumerate() for those
loops maintaining a loop index along with the items.
- Reduce the number of arguments to fieldFromInsn (removes an out
reference parameter: CodingStandards). The insn_t argument to insnWithID
can/should probably be removed soon too since modern C++ allows us to
return a local container without a copy.
- Use raw strings for the large emitted code segments. This enhances
both readability and modifiability.
2024-03-12 16:01:58 -05:00
Jason Eckhardt
6f7e940c2d
[TableGen] More efficiency improvements for encode/decode emission. (#84647)
DecoderEmitter and CodeEmitterGen perform repeated linear walks over the
entire instruction list. This patch eliminates two more such walks.

The eliminated traversals visit every instruction merely to determine
whether the target has variable length encodings. For a target with
variable length encodings, the original any_of will terminate quickly.
But all targets other than M68k use fixed length encodings and thus
any_of must visit the entire instruction list.
2024-03-11 08:13:33 -05:00