summaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/DAGISelMatcherGen.cpp
AgeCommit message (Collapse)Author
2025-11-22[TableGen] Use MVT instead of MVT::SimpleValueType. NFC (#169180)Craig Topper
This improves type safety and is less verbose. Use SimpleTy only where an integer is needed like switches or emitting a VBR. --------- Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
2025-11-23[TableGen] Constify CodeGenInstruction where possible (NFC) (#169193)Sergei Barannikov
2025-09-19CodeGen: Add RegisterClass by HwMode (#158269)Matt Arsenault
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-06-16[TableGen] Use default member initializers. NFC. (#144349)Jay Foad
Automated with clang-tidy -fix -checks=-*,modernize-use-default-member-init
2025-06-15[TableGen] Use range-based for loops (NFC) (#144283)Kazu Hirata
2025-06-05[TableGen] Make more use of findSubRegIdx. NFCI. (#142996)Jay Foad
Outside of CodeGenRegisters itself, we only want to find existing SubRegIdxs, not create new ones. Change findSubRegIdx to assert and use it consistently for this purpose.
2025-05-21[LLVM][TableGen] Use StringRef for various members ↵Rahul Joshi
`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[NFC][TableGen] Use StringRef::str() instead of casting (#139332)Rahul Joshi
- Also eliminate unneeded std::string() around some literal strings.
2025-02-01[TableGen] Use range-based for loop. NFCCraig Topper
2025-01-16[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)Jay Foad
Also use brace initialization and emplace to avoid explicitly constructing std::pair, and the same for std::tuple.
2024-12-13[TableGen] Add TreePatternNode::children and use it in for loops (NFC) (#119877)Sergei Barannikov
2024-11-17[Tablegen] Add more comments for result numbers to DAGISelEmitter.cpp (#116533)Craig Topper
Print what result number the Emit* nodes are storing their results in. This makes it easy to track the inputs of later opcodes that consume these results.
2024-11-09[TableGen][SelectionDAG] Remove the `implicit` DAG node (#115295)Sergei Barannikov
The node was introduced in 59c39dc1 and was intended to allow writing patterns like this: `[(set AL, (mul AL, GR8:$src1)), (implicit EFLAGS)]` However, it does not introduce new functionality because the same pattern can be equivalently expressed as: `[(set AL, EFLAGS, (mul AL, GR8:$src1))]` The latter form is also more flexible as it allows reordering output operands. In most places uses of `implicit` were redundant -- removing them didn't change anything in the generated DAG tables. The only three cases where it did have effect are in X86InstrArithmetic.td and X86InstrSystem.td -- those were rewritten to use `set` node. Removing `implicit` from some patterns made them importable by GISel, hence the change in a test.
2024-10-18[LLVM][TableGen] Change all `Init` pointers to const (#112705)Rahul Joshi
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-23[LLVM][TableGen] Use const record pointers in TableGen/Common files (#109467)Rahul Joshi
Use const record pointers in TableGen/Common files. 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[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)Jay Foad
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
2024-09-18[LLVM][TableGen] Change DAGISel code to use const RecordKeeper (#109038)Rahul Joshi
Change DAGISel code 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-15[LLVM][TableGen] Change CodeGenDAGPatterns to use const RecordKeeper (#108762)Rahul Joshi
Change CodeGenDAGPatterns 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-11[TableGen] Change CodeGenInstruction record members to const (#107921)Rahul Joshi
Change CodeGenInstruction::{TheDef, InfereredFrom} to const 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 Joshi
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-07-19[TableGen][SelectionDAG] Make CheckValueTypeMatcher use MVT::SimpleValueType ↵Brandon Wu
(#99537) The original `CheckValueTypeMatcher` stores StringRef as the member variable type, however it's more efficient to use use MVT::SimpleValueType since it prevents string comparison in isEqualImpl, it also reduce the memory consumption in each object.
2024-03-25[RFC][TableGen] Restructure TableGen Source (#80847)Pierre van Houtryve
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-14[TableGen] Stop using make_pair and make_tuple. NFC. (#81730)Jay Foad
These are unnecessary since C++17.
2024-02-09[TableGen][NFC] convert TreePatternNode pointers to references (#81134)Tomas Matheson
Almost all uses of `*TreePatternNode` expect it to be non-null. There was the occasional check that it wasn't, which I have removed. Making them references makes it clear that they exist. This was attempted in 2018 (1b465767d6ca69f4b7201503f5f21e6125fe049a) for `TreePatternNode::getChild()` but that was reverted.
2024-02-09[NFC] clang-format utils/TableGen (#80973)Pierre van Houtryve
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
2023-12-12[TableGen][NFC] Remove leading spaceswangpc
2023-12-12[TableGen][NFC] Format parts of DAGISelMatcher.h/DAGISelMatcherGen.cppwangpc
To reduce the diff in #73310
2023-08-03[TableGen][NFC] Refine obtaining qualified register class ids.Ivan Kosarev
Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D156110
2023-07-09Revert "[TableGen] Use heap allocated arrays instead of vectors for ↵Tomas Matheson
TreePatternNode::Types and ResultPerm. NFC" While working on DAGISelMatcherEmitter I've hit several runtime errors caused by accessing TreePatternNode::Types out of bounds. These were difficult to debug because the switch from std::vector to unique_ptr removes bounds checking. I don't think the slight reduction in class size is worth the extra debugging and memory safety problems, so I suggest we revert this. This reverts commit d34125a1a825208b592cfa8f5fc3566303d691a4. Differential Revision: https://reviews.llvm.org/D154781
2023-04-23[TableGen] Make getRegisterValueType stricter about HwModes.Craig Topper
I don't think this code would work correctly if the register class used used HwModes. Add asserts to make sure it's not used with HwModes. Also fix a long outdated comment on the function.
2023-04-23[TableGen] Remove unused ForceMode and CodeGen fields from TypeInfer. NFCCraig Topper
As well as the ForceMode field in PatternToMatch.
2023-04-19[TableGen] Use heap allocated arrays instead of vectors for ↵Craig Topper
TreePatternNode::Types and ResultPerm. NFC These vectors are resized in the constructor and never change size. We can manually allocate two arrays instead. This reduces the size of TreePatternNode by removing the unneeded capacity end pointer fields from the std::vector.
2023-04-12[TableGen] Store CodeGenInstruction reference in EmitNodeMatcherCommon. NFCCraig Topper
Instead of storing a string containing the instruction name, store a reference to the instruction. We can use that reference to print the instruction name when we emit the table. The only slightly annoying part is that we have to find the CodeGenInstruction for IMPLICIT_DEF. GlobalISel is doing a similar thing.
2023-04-11[NFC] add check for potentially dereferencing null return valueBing1 Yu
Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D147771
2023-03-31[TableGen] Simplify some code. NFCCraig Topper
This code was creating 1 entry or 0 entry std::array to pass to to ArrayRef arguments. ArrayRef has a constructor from a single object and we can use std::nullopt for an empty ArrayRef.
2023-03-31[TableGen] Reduce code duplication. NFCCraig Topper
2023-02-26[TableGen] Remove duplicate call to getPredicateCheck. NFCCraig Topper
2023-02-17llvm-tblgen: Apply IWYU partiallyNAKAMURA Takumi
2023-02-15Use llvm::has_single_bit<uint32_t> (NFC)Kazu Hirata
This patch replaces isPowerOf2_32 with llvm::has_single_bit<uint32_t> where the argument is wider than uint32_t.
2022-03-11Cleanup include: TableGenserge-sans-paille
This also includes a few cleanup from Support. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121331
2021-12-10utils: Remove some no-op raw_string_ostream flush calls, NFCDuncan P. N. Exon Smith
Since 65b13610a5226b84889b923bae884ba395ad084d, raw_string_ostream has been unbuffered by default. Based on an audit of llvm/utils/, this commit removes every call to `raw_string_ostream::flush()` and any call to `raw_string_ostream::str()` whose result is ignored or that doesn't help with clarity. I left behind a few calls to `str()`. In these cases, the underlying std::string was declared pretty far away and never used again, whereas stream recently had its last write. The code is easier to read as-is; the no-op call to `flush()` inside `str()` isn't harmful, and when https://reviews.llvm.org/D115421 lands it'll be gone anyway.
2021-02-06[TableGen] Make all the fields in PatternToMatch private. NFCICraig Topper
Add the few missing accessor methods. Use accessor methdods everywhere.
2021-01-09[SelectionDAG] Extend immAll(Ones|Zeros)V to handle ISD::SPLAT_VECTORFraser Cormack
The TableGen immAllOnesV and immAllZerosV helpers implicitly wrapped the ISD::isBuildVectorAll(Ones|Zeros) helper functions. This was inhibiting their use for targets such as RISC-V which use ISD::SPLAT_VECTOR. In particular, RISC-V had to define its own 'vnot' fragment. In order to extend the scope of these nodes to include support for ISD::SPLAT_VECTOR, two new ISD predicate functions have been introduced: ISD::isConstantSplatVectorAll(Ones|Zeros). These effectively supersede the older "isBuildVector" predicates, which are now simple wrappers for the new functions. They pass a defaulted boolean toggle which preserves the old behaviour. It is hoped that in time all call-sites can be ported to the "isConstantSplatVector" functions. While the use of ISD::isBuildVectorAll(Ones|Zeros) has not changed, the behaviour of the TableGen immAll(Ones|Zeros)V **has**. To test the new functionality, the custom RISC-V TableGen fragment has been removed and replaced with the built-in 'vnot'. To test their use as pattern-roots, two splat patterns have been updated accordingly. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D94223
2020-11-06[TableGen] Indentation and whitespace fixes in generated code. NFC.Jay Foad
Some of these were found by running clang-format over the generated code, although that complains about far more issues than I have fixed here. Differential Revision: https://reviews.llvm.org/D90937
2020-05-13[TableGen] Fix register class handling in TableGen's DAG ISel Matcher GeneratorVictor Campos
Summary: In TableGen's instruction selection table generator, references to register classes were handled by generating a matcher table entry in the form of "EmitStringInteger, MVT::i32, 'RegisterClassID'". This ID is in fact the enum integer value corresponding to the register class. However, both the table generator and the table consumer (SelectionDAGISel) assume that this ID is less than or equal to 127, i.e. at most 7 bits. Values greater than this threshold cause completely wrong behaviours in the instruction selection process. This patch adds a check to determine if the enum integer value is greater than the limit of 127. In finding so, the generator emits an "EmitInteger" instead, which properly supports values with arbitrary sizes. Commit f8d044bbcfdc9e1ddc02247ffb86fe39e1f277f0 fixed the very same bug for register subindices. The present patch now extends this cover to register classes. Reviewers: rampitec Reviewed By: rampitec Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79705
2020-02-12[TBLGEN] Fix subreg value overflow in DAGISelMatcherStanislav Mekhanoshin
Tablegen's DAGISelMatcher emits integers in a VBR format, so if an integer is below 128 it can fit into a single byte, otherwise high bit is set, next byte is used etc. MatcherTable is essentially an unsigned char table. When SelectionDAGISel parses the table it does a reverse translation. In a situation when numeric value of an integer to emit is unknown it can be emitted not as OPC_EmitInteger but as OPC_EmitStringInteger using a symbolic name of the value. In this situation the value should not exceed 127. One of the situations when OPC_EmitStringInteger is used is if we need to emit a subreg into a matcher table. However, number of subregs can exceed 127. Currently last defined subreg for AMDGPU is 192. That results in a silent bug in the ISel with matcher reading from an invalid offset. Fixed this bug to emit actual VBR encoded value for a subregs which value exceeds 127. Differential Revision: https://reviews.llvm.org/D74368
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-11-06TableGen: Remove assert that pattern results match input numberMatt Arsenault
AMDGPU has some atomic instructions that do not return the previous result, and can only be selected if there are no uses. The source pattern will only match if the use is empty, so it should be safe to discard the result.
2019-08-25[TableGen] Correct comments for end of namespace. NFCBjorn Pettersson
Summary: Update end-of-namespace comments generated by tablegen emitters to fulfill the rules setup by clang-tidy's llvm-namespace-comment checker. Fixed a few end-of-namespace comments in the tablegen source code as well. Reviewers: craig.topper Reviewed By: craig.topper Subscribers: craig.topper, stoklund, dschuff, sbc100, jgravelle-google, aheejin, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66396 llvm-svn: 369865
2019-07-22TableGen: Support physical register inputs > 255Matt Arsenault
This was truncating register value that didn't fit in unsigned char. Switch AMDGPU sendmsg intrinsics to using a tablegen pattern. llvm-svn: 366695