aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/InstrInfoEmitter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-19CodeGen: Add RegisterClass by HwMode (#158269)Matt Arsenault1-7/+94
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-08CodeGen: Pass SubtargetInfo to TargetGenInstrInfo constructors (#157337)Matt Arsenault1-3/+4
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-04[NFC][TableGen] Use `BitsInit::convertInitializerToInt` in a few places ↵Rahul Joshi1-9/+5
(#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[NFC][TableGen] Adopt `CodeGenInstruction::getName()` (#156968)Rahul Joshi1-9/+8
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-09-04[NFC][InstrInfoEmitter] Include location of inst definition in comment (#156927)Rahul Joshi1-5/+17
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[TableGen] Don't print the instruction enum value in multiple comments in ↵Craig Topper1-6/+6
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-08-25[TableGen] Implement getOperandIdxName (#154944)Robert Imschweiler1-39/+106
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-07-30[TableGen] Implement getNamedOperandIdx with another table lookup. NFC. ↵Jay Foad1-24/+27
(#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-25[TableGen] Use MapVector in InstrInfoEmitter::emitOperandNameMappings (#150630)Jay Foad1-9/+4
This changes the order of names/numbers in the OpName enum, but that should not cause any change in behaviour.
2025-07-07[NFC][TableGen] Rename `CodeGenTarget` instruction accessors (#146767)Rahul Joshi1-5/+5
Rename `getXYZInstructionsByEnumValue()` to just `getXYZInstructions` and drop the `ByEnumValue` in the name.
2025-07-02[NFC][TableGen] Add accessors for various instruction subclasses (#146615)Rahul Joshi1-13/+16
- 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-06-07[TableGen] Use `emplace` instead of `insert` and similar. NFC. (#143164)Jay Foad1-3/+4
2025-05-03[MC][TableGen] Expand ImplicitOffset field of MCInstrDesc (#138127)Carl Ritson1-3/+5
Increase width of ImplicitOffset to `int` from `short` to allow more table capacity. Reorder the elements to maintain natural alignment.
2025-02-18[NFC][TableGen] Cleanup iterators in CodeGenSchedule.h (#127401)Rahul Joshi1-1/+1
- Use range for loops for processor models and schedule classes. - Cleanup duplicated or unused iterators in CodeGenSchedule.h
2025-02-12[TableGen] Emit OpName as an enum class instead of a namespace (#125313)Rahul Joshi1-7/+11
- 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-11[NFC][TableGen] Code cleanup in InstrInfoEmitter.cpp (#126578)Rahul Joshi1-39/+40
- 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-10[NFC][TableGen] Delete `getLogicalOperandType` from InstrInfoEmitter (#125951)Rahul Joshi1-93/+0
Delete `getLogicalOperandType` function from InstrInfoEmitter as no backend seems to use it.
2025-02-10[TableGen][InstrInfo] Cull mapping that have not been enabled/not needed ↵Rahul Joshi1-75/+98
(#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-06[NFC][TableGen] Adopt `Emitter::OptClass` in InstrInfoEmitter (#125971)Rahul Joshi1-11/+8
- Use `Emitter::OptClass` to invoke `InstrInfoEmitter::run` and eliminate the `EmitInstrInfo` function.
2025-01-31[TableGen] Restore OpName::OPERAND_LAST emission in InstrInfoEmitter (#125265)Rahul Joshi1-0/+1
- 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-30[TableGen] Improvements to Named operands in InstrInfoEmitter (#124960)Rahul Joshi1-67/+57
- 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-24[NFC][TableGen] Emit nested namespaces in InstrInfoEmitter (#124210)Rahul Joshi1-62/+27
- Emit C++17 nested namespaces in InstrInfoEmitter.
2025-01-16[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)Jay Foad1-2/+1
Also use brace initialization and emplace to avoid explicitly constructing std::pair, and the same for std::tuple.
2024-10-18[LLVM][TableGen] Change all `Init` pointers to const (#112705)Rahul Joshi1-2/+2
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-04[TableGen] Factor out timer code into a new `TGTimer` class (#111054)Rahul Joshi1-18/+21
Factor out the timer related functionality from `RecordKeeper` to a new `TGTimer` class in a new file.
2024-09-26[LLVM][TableGen] Change InstrInfoEmitter to use const RecordKeeper (#110110)Rahul Joshi1-1/+1
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-24[NFC][TableGen] Adopt scaled indent in PredicateExpander (#109801)Rahul Joshi1-2/+2
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-18[LLVM][TableGen] Change InstrInfoEmitter to use const RecordKeeper (#109189)Rahul Joshi1-23/+24
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[LLVM][TableGen] Change CodeGenSchedule to use const Record pointers (#108782)Rahul Joshi1-1/+2
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-11[TableGen] Change SubtargetFeatureInfo to use const Record pointers (#108013)Rahul Joshi1-9/+12
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-09[TableGen] Change CGIOperandList::OperandInfo::Rec to const pointer (#107858)Rahul Joshi1-3/+3
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-06-02[TableGen] Use llvm::unique (NFC) (#94163)Kazu Hirata1-3/+1
2024-04-16[TableGen][InstrInfoEmitter] Count sub-operands on def operandsMichael Liao1-1/+7
- 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-03-25[RFC][TableGen] Restructure TableGen Source (#80847)Pierre van Houtryve1-8/+8
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-02-09[NFC] clang-format utils/TableGen (#80973)Pierre van Houtryve1-70/+108
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
2024-02-07[TableGen][NFC] Replace hardcoded opcode numbering. (#81065)Jason Eckhardt1-2/+3
This patch uses the recently introduced CodeGenTarget::getInstrIntValue to replace hardcoded opcode enum value numbering in a few places.
2023-09-27[TableGen] Optimize SizeToOperandName iteration. NFCFangrui Song1-2/+3
2023-08-21Make global variable const. NFC.Benjamin Kramer1-1/+1
2023-08-02[llvm-exegesis] Prevent llvm-exegesis from using unsupported opcodesPavel Kosov1-1/+22
When generating snippets for AArch64 with --opcode-index=-1, the code generator asserts on opcodes that are not supported according to CPU features. The same assertion can be triggered even when generating a serial snippet for a supported opcode if SERIAL_VIA_NON_MEMORY_INSTR execution mode is used and an unsupported instruction is chosen as the "other instruction". Unlike the first case, this one may result in flaky failures because the other instruction is randomly chosen from the instructions suitable for serializing execution. This patch adjusts TableGen emitter for *GenInstrInfo.inc to make possible to query for opcode availability instead of just asserting on unsupported ones. ~~ Huawei RRI, OS Lab Reviewed By: courbet Differential Revision: https://reviews.llvm.org/D146303
2023-06-07[TableGen] Emit separate computeRequiredFeatures() functionPavel Kosov1-32/+44
A function is already emitted in *GenInstrInfo.inc that takes Opcode number and a set of supported Features and reports fatal error if some of the required features are missing. The information about features required by the particular opcode can be reused by llvm-exegesis, so move its computation info a separate computeRequiredFeatures() function. Then verifyInstructionPredicates() can just compare the sets of available and required features computed by the other functions. This commit moves the definition of FeatureBitsets[] as well as CEFBS_* enumerator values (that are indices into FeatureBitsets[] array) inside the computeRequiredFeatures() function because these are implementation details of that function. The inclusion of potentially huge computeRequiredFeatures() function is now controlled by a dedicated macro that is set for simplicity by TableGen-erated code itself if `defined(ENABLE_INSTR_PREDICATE_VERIFIER) && !defined(NDEBUG)`. ~~ Huawei RRI, OS Lab Reviewed By: courbet Differential Revision: https://reviews.llvm.org/D148516
2023-03-27[MC] Store operand info immediately after the TargetInsts table. NFC.Jay Foad1-47/+68
This shrinks MCInstrDesc (and hence the whole TargetInsts table) because we can store a 16-bit offset value to access the operands info, instead of a pointer. This also reduces the number of relocs that need to be applied when LLVM is compiled as position-independent code. Differential Revision: https://reviews.llvm.org/D142219
2023-03-27[MC] Store implicit ops immediately after the TargetInsts table. NFC.Jay Foad1-48/+57
This shrinks MCInstrDesc (and hence the whole TargetInsts table) because we can store a 16-bit offset value to access the implicit operands, instead of a pointer. This also reduces the number of relocs that need to be applied when LLVM is compiled as position-independent code. Differential Revision: https://reviews.llvm.org/D142218
2023-03-21llvm-tblgen: Rewrite emitters to use `TableGen::Emitter`NAKAMURA Takumi1-4/+3
Each emitter became self-contained since it has the registration of option. Differential Revision: https://reviews.llvm.org/D144351
2023-02-22[TableGen] Emit static const globals in getOperandTypeMichael Liao1-3/+3
- That saves the overhead of operand type querying.
2023-02-19llvm-tblgen: ReformatNAKAMURA Takumi1-2/+2
2023-01-24[MC] Store target Insts table in reverse order. NFC.Jay Foad1-5/+4
This will allow an entry in the table to access data that is stored immediately after the end of the table, by adding its opcode value to its address. Differential Revision: https://reviews.llvm.org/D142217
2023-01-24[MC] Store number of implicit operands in MCInstrDesc. NFC.Jay Foad1-22/+16
Combine the implicit uses and defs lists into a single list of uses followed by defs. Instead of 0-terminating the list, store the number of uses and defs. This avoids having to scan the whole list to find the length and removes one pointer from MCInstrDesc (although it does not get any smaller due to alignment issues). Remove the old accessor methods getImplicitUses, getNumImplicitUses, getImplicitDefs and getNumImplicitDefs as all clients are using the new implicit_uses and implicit_defs. Differential Revision: https://reviews.llvm.org/D142216
2023-01-23[TableGen] Avoid repeated lookups of Uses and Defs records. NFC.Jay Foad1-15/+16
2022-10-07[MachineInstr] Use unsigned int for opcode (NFC)Christudasan Devadasan1-3/+4
The opcode field in most places uses unsigned type. InstrInfoEmitter still uses signed int for the custom opcodes like CFSetupOpcode. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D135140
2022-07-14[CodeGen] Move instruction predicate verification to emitInstructionDavid Green1-4/+150
D25618 added a method to verify the instruction predicates for an emitted instruction, through verifyInstructionPredicates added into <Target>MCCodeEmitter::encodeInstruction. This is a very useful idea, but the implementation inside MCCodeEmitter made it only fire for object files, not assembly which most of the llvm test suite uses. This patch moves the code into the <Target>_MC::verifyInstructionPredicates method, inside the InstrInfo. The allows it to be called from other places, such as in this patch where it is called from the <Target>AsmPrinter::emitInstruction methods which should trigger for both assembly and object files. It can also be called from other places such as verifyInstruction, but that is not done here (it tends to catch errors earlier, but in reality just shows all the mir tests that have incorrect feature predicates). The interface was also simplified slightly, moving computeAvailableFeatures into the function so that it does not need to be called externally. The ARM, AMDGPU (but not R600), AVR, Mips and X86 backends all currently show errors in the test-suite, so have been disabled with FIXME comments. Recommitted with some fixes for the leftover MCII variables in release builds. Differential Revision: https://reviews.llvm.org/D129506