aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/DecoderEmitter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-05[NFC][TableGen] Print DecodeIdx for DecodeOps in DecoderEmitter (#142963)Rahul Joshi1-6/+8
Print DecodeIdx associated with Decode MCD ops in the generated decoder tables. This can help in debugging decode failures by first mapping the Op -> DecodeIdx and then inspecting the code in `decodeToMCInst` associated with that DecodeIdx.
2025-06-05[LLVM][MC] Introduce `OrFail` variants of MCD ops (#138614)Rahul Joshi1-81/+172
Introduce `OrFail` variants for all MCD Decoder Ops that have `NumToSKip` encoded with them. This is intended to capture the common case of jumps to the end of the decoder table which has a `OP_Fail` at the end. Using the `OrFail` variants of these ops avoid encoding the `NumToSkip` jump offset for these cases, resulting in a reduction in the size of the decoder tables (from 5 - 17%). Additionally, for the AArch64 target, the table size reduces enough to switch to using 2-byte `NumToSkip` encoding instead of existing 3-bytes, resulting in a net 30% reduction in the size of the decoder table. The total reduction in the size of the decoder tables for different targets is as follows (computed using the following command: `for i in *.inc; do echo -n ``basename $i: ``; grep "MCD::OPC_Fail," $i | awk '{sum += $2} END { print sum}'; done`) ``` Target Old Size New Size % Reduction ================================================ AArch64 153268 106987 30.20 AMDGPU 412056 340856 17.28 ARC 5061 4605 9.01 ARM 73831 60847 17.59 AVR 1306 1158 11.33 BPF 1927 1795 6.85 CSKY 8692 6922 20.36 Hexagon 41965 34759 17.17 Lanai 982 924 5.91 LoongArch 21629 20035 7.37 M68k 13461 11689 13.16 MSP430 3716 3384 8.93 Mips 31415 25771 17.97 PPC 28931 24771 14.38 RISCV 34800 28352 18.53 Sparc 7432 6236 16.09 SystemZ 32248 29716 7.85 VE 42873 36923 13.88 XCore 2316 2196 5.18 Xtensa 3443 2793 18.88 ```
2025-05-24[TableGen] Remove unused includes (NFC) (#141356)Kazu Hirata1-1/+0
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-21[LLVM][TableGen] Use StringRef for various members ↵Rahul Joshi1-18/+18
`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-12[TableGen] Fix a warningKazu Hirata1-0/+1
This patch fixes an unused parameter warning with gcc7 under the release configuration.
2025-05-12[NFC][TableGen] Use StringRef::str() instead of casting (#139332)Rahul Joshi1-7/+6
- Also eliminate unneeded std::string() around some literal strings.
2025-04-28[TableGen] Use StringRef::empty() instead of comparing to an empty string. ↵Craig Topper1-2/+2
NFC (#137673)
2025-04-27[TableGen] Simplify insertBits (NFC) (#137538)Kazu Hirata1-10/+8
We can use "constexpr if" to combine the two variants of functions.
2025-04-23[NFC][LLVM][TableGen] Eliminate inheritance from std::vector (#136573)Rahul Joshi1-8/+22
2025-04-21[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter (#136456)Rahul Joshi1-50/+57
- 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-18[NFC][LLVM][TableGen] Adjust pointer increments in DecoderEmitter (#136230)Rahul Joshi1-18/+12
- 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[LLVM][TableGen] Fix Windows failure in DecoderEmitter (#136310)Rahul Joshi1-4/+5
- 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[NFC][LLVM][TableGen] Use `decodeULEB128` for `OPC_SoftFail` emission (#136220)Rahul Joshi1-32/+18
- Use `decodeULEB128` to decode +ve/-ve mask in OPC_SoftFail case. - Use current `I`/`E` iterators as inputs to `decodeULEB128`.
2025-04-18[LLVM][TableGen] Move DecoderEmitter output to anonymous namespace (#136214)Rahul Joshi1-2/+2
- 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-16Revert "Reapply "[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter" ↵Rahul Joshi1-65/+50
(#136017)" (#136068) Reverts llvm/llvm-project#136019 Expensive checks tests are failing, so reverting.
2025-04-16Reapply "[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter" ↵Rahul Joshi1-50/+65
(#136017) (#136019) This reverts commit 7fd0c8acd4659ccd0aef5486afe32c8ddf0f2957, and fixes the assert condition in `patchNumToSkip`.
2025-04-16Revert "[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter" (#136017)Rahul Joshi1-65/+50
Reverts llvm/llvm-project#135882 Causing assert failures for AArch64 backend
2025-04-16[LLVM][TableGen] Parameterize NumToSkip in DecoderEmitter (#135882)Rahul Joshi1-50/+65
- 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-15[NFC][TableGen] DecoderEmitter optimize scope stack in ↵Rahul Joshi1-20/+22
`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-14[NFC][TableGen] Refactor DecoderEmitter.cpp (#135510)Rahul Joshi1-139/+96
- 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-03-31[TableGen] Use size returned by encodeULEB128 to simplify some code. NFC ↵Craig Topper1-14/+8
(#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-30[TableGen] Use llvm::append_range (NFC) (#133649)Kazu Hirata1-8/+4
2025-03-10[TableGen] Reduce the number of vectors passed to getIslands. NFC (#130402)Craig Topper1-42/+26
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-07[TableGen] Use uint8_t for bit_value_t enum. NFCCraig Topper1-2/+2
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[TableGen] Use isUInt to simplify some asserts. NFCCraig Topper1-5/+4
2025-03-07[TableGen] Remove push_back from loop. NFCCraig Topper1-4/+2
We can initialize the vector to the right size and then assign over some entries in the loop.
2025-03-07[TableGen] Remove unnecessary const_cast. NFCCraig Topper1-1/+1
2025-03-07[TableGen] Use reference instead of pointer for FilterChooser in Filter. NFCCraig Topper1-17/+17
2025-03-07[TableGen] Simplify emitULEB128 in DecoderEmitter.cpp. NFC (#130214)Craig Topper1-18/+10
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-03[TableGen] Fix incorrect comment. NFCCraig Topper1-1/+1
2025-03-03[TableGen] Remove unnecessary use of utostr to print a byte. NFCCraig Topper1-1/+1
We can cast to unsigned instead.
2025-03-03[NFC]Make file-local cl::opt global variables static (#126486)chrisPyr1-1/+1
#125983
2025-02-26[TableGen] Update comment for size of NumToSkip field in DecoderEmitter. NFCCraig Topper1-1/+1
NumToSkip is 24 bits. It used to be 16 bits.
2025-01-16[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)Jay Foad1-10/+10
Also use brace initialization and emplace to avoid explicitly constructing std::pair, and the same for std::tuple.
2025-01-15[TableGen] Use `std::move` to avoid copy (#123088)abhishek-kaushik221-1/+1
2024-11-21[TableGen] Use `std::move` to avoid copy (#113061)abhishek-kaushik221-5/+5
2024-10-18[LLVM][TableGen] Change all `Init` pointers to const (#112705)Rahul Joshi1-18/+18
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[LLVM][TableGen] Adopt `indent` for indentation (#109275)Rahul Joshi1-66/+63
Adopt `indent` for indentation DAGISelMatcher and DecoderEmitter.
2024-09-20[LLVM][TableGen] Change DisassemblerEmitter to use const RecordKeeper (#109177)Rahul Joshi1-8/+4
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-19[NFC] Rename variables to conform to LLVM coding standards (#109166)Rahul Joshi1-101/+95
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-18[LLVM][TableGen] Change DecoderEmitter to use const RecordKeeper (#109040)Rahul Joshi1-14/+14
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-09[TableGen] Change CGIOperandList::OperandInfo::Rec to const pointer (#107858)Rahul Joshi1-7/+8
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-07[TableGen] Add PrintError family overload that take a print function (#107333)Rahul Joshi1-6/+5
Add PrintError and family overload that accepts a print function. This avoids constructing potentially long strings for passing into these print functions.
2024-07-15[NFC] [AArch64] Refactor predicate register class decode functions (#97412)Max Beck-Jones1-1/+2
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-14[TableGen][NFC] Use `decodeULEB128AndIncUnsafe` in `decodeInstruction` (#98619)Piotr Fusik1-6/+2
2024-05-08[Support] Add end/error to decode[US]LEB128AndIncFangrui Song1-8/+8
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-04-01[TableGen] Introduce a less aggressive suppression for HwMode Decoder… ↵superZWT1231-20/+84
(#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-03-25[RFC][TableGen] Restructure TableGen Source (#80847)Pierre van Houtryve1-5/+5
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-19[Support] Add decodeULEB128AndInc/decodeSLEB128AndIncFangrui Song1-23/+10
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-13[CodeGen][Tablegen] Fix uninitialized var and shift overflow. (#84896)mahesh-attarde1-2/+2
Fix uninitialized var and shift overflow.