aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/DAGISelMatcherGen.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-19CodeGen: Add RegisterClass by HwMode (#158269)Matt Arsenault1-1/+1
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 Foad1-5/+4
Automated with clang-tidy -fix -checks=-*,modernize-use-default-member-init
2025-06-15[TableGen] Use range-based for loops (NFC) (#144283)Kazu Hirata1-15/+12
2025-06-05[TableGen] Make more use of findSubRegIdx. NFCI. (#142996)Jay Foad1-1/+0
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 Joshi1-1/+1
`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 Joshi1-1/+1
- Also eliminate unneeded std::string() around some literal strings.
2025-02-01[TableGen] Use range-based for loop. NFCCraig Topper1-3/+3
2025-01-16[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)Jay Foad1-2/+2
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 Barannikov1-7/+7
2024-11-17[Tablegen] Add more comments for result numbers to DAGISelEmitter.cpp (#116533)Craig Topper1-11/+18
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 Barannikov1-3/+1
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 Joshi1-1/+1
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 Joshi1-4/+4
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 Foad1-2/+2
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 Joshi1-10/+10
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 Joshi1-1/+1
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 Joshi1-4/+4
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 Joshi1-1/+1
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 Wu1-1/+1
(#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 Houtryve1-7/+7
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 Foad1-3/+3
These are unnecessary since C++17.
2024-02-09[TableGen][NFC] convert TreePatternNode pointers to references (#81134)Tomas Matheson1-141/+140
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 Houtryve1-155/+149
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
2023-12-12[TableGen][NFC] Remove leading spaceswangpc1-17/+17
2023-12-12[TableGen][NFC] Format parts of DAGISelMatcher.h/DAGISelMatcherGen.cppwangpc1-18/+19
To reduce the diff in #73310
2023-08-03[TableGen][NFC] Refine obtaining qualified register class ids.Ivan Kosarev1-1/+1
Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D156110
2023-07-09Revert "[TableGen] Use heap allocated arrays instead of vectors for ↵Tomas Matheson1-1/+1
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 Topper1-6/+6
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 Topper1-19/+12
As well as the ForceMode field in PatternToMatch.
2023-04-19[TableGen] Use heap allocated arrays instead of vectors for ↵Craig Topper1-1/+1
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 Topper1-7/+6
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 Yu1-5/+6
Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D147771
2023-03-31[TableGen] Simplify some code. NFCCraig Topper1-4/+3
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 Topper1-14/+7
2023-02-26[TableGen] Remove duplicate call to getPredicateCheck. NFCCraig Topper1-2/+3
2023-02-17llvm-tblgen: Apply IWYU partiallyNAKAMURA Takumi1-0/+3
2023-02-15Use llvm::has_single_bit<uint32_t> (NFC)Kazu Hirata1-1/+2
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-paille1-1/+2
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 Smith1-1/+1
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 Topper1-2/+2
Add the few missing accessor methods. Use accessor methdods everywhere.
2021-01-09[SelectionDAG] Extend immAll(Ones|Zeros)V to handle ISD::SPLAT_VECTORFraser Cormack1-2/+6
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 Foad1-1/+1
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 Campos1-3/+13
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 Mekhanoshin1-0/+12
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 Kramer1-1/+1
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 Arsenault1-1/+0
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 Pettersson1-1/+1
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 Arsenault1-2/+6
This was truncating register value that didn't fit in unsigned char. Switch AMDGPU sendmsg intrinsics to using a tablegen pattern. llvm-svn: 366695
2019-07-04[TableGen] Allow DAG isel patterns to override default operands.Simon Tatham1-4/+17
When a Tablegen instruction description uses `OperandWithDefaultOps`, isel patterns for that instruction don't have to fill in the default value for the operand in question. But the flip side is that they actually //can't// override the defaults even if they want to. This will be very inconvenient for the Arm backend, when we start wanting to write isel patterns that generate the many MVE predicated vector instructions, in the form with predication actually enabled. So this small Tablegen fix makes it possible to write an isel pattern either with or without values for a defaulted operand, and have the default values filled in only if they are not overridden. If all the defaulted operands come at the end of the instruction's operand list, there's a natural way to match them up to the arguments supplied in the pattern: consume pattern arguments until you run out, then fill in any missing instruction operands with their default values. But if defaulted and non-defaulted operands are interleaved, it's less clear what to do. This does happen in existing targets (the first example I came across was KILLGT, in the AMDGPU/R600 backend), and of course they expect the previous behaviour (that the default for those operands is used and a pattern argument is not consumed), so for backwards compatibility I've stuck with that. Reviewers: nhaehnle, hfinkel, dmgreen Subscribers: mehdi_amini, javed.absar, tpr, kristof.beyls, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63814 llvm-svn: 365114
2019-06-03[TableGen] Fix std::array initializer to avoid warnings with older tool ↵Mikael Holmen1-1/+1
chains. NFC A std::array is implemented as a template with an array inside a struct. Older versions of clang, like 3.6, require an extra set of curly braces around std::array initializations to avoid warnings. The C++ language was changed regarding this by CWG 1270. So more modern tool chains does not complain even if leaving out one level of braces. llvm-svn: 362360