summaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/Common/CodeGenDAGPatterns.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-11-08[TableGen] Use "using" instead of "typedef" (NFC) (#167168)Kazu Hirata
Identified with modernize-use-using.
2025-10-03[NFC][TableGen] Fix namespace usage in various files (#161839)Rahul Joshi
- Move standalone functions and variables out of anonymous namespace and make them static. - Eliminate `namespace llvm {}` wrapping all code in .cpp files, and instead use namespace qualifier to define such functions (https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions) - Add namespace for X86DisassemblerShared.h.
2025-09-25[TableGen, CodeGen, CHERI] Add support for the cPTR wildcard value type. ↵Owen Anderson
(#158426) cPTR is a wildcard CHERI capability value type, used analogously to iPTR. This allows TableGen patterns to abstract over CHERI capability widths. Co-authored-by: Jessica Clarke <jrtc27@jrtc27.com>
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-09-19TableGen: Replace assertion with error for unexpected pattern inputs (#159687)Matt Arsenault
2025-09-10[TableGen][CodeGen] Remove feature string from HwMode (#157600)Sergei Barannikov
`Predicates` and `Features` fields serve the same purpose. They should be kept in sync, but not all predicates are based on features. This resulted in introducing dummy features for that only reason. This patch removes `Features` field and changes TableGen emitters to use `Predicates` instead. Historically, predicates were written with the assumption that the checking code will be used in `SelectionDAGISel` subclasses, meaning they will have access to the subclass variables, such as `Subtarget`. There are no such variables in the generated `GenSubtargetInfo::getHwModeSet()`, so we need to provide them. This can be achieved by subclassing `HwModePredicateProlog`, see an example in `Hexagon.td`.
2025-07-07[NFC][TableGen] Rename `CodeGenTarget` instruction accessors (#146767)Rahul Joshi
Rename `getXYZInstructionsByEnumValue()` to just `getXYZInstructions` and drop the `ByEnumValue` in the name.
2025-07-04[llvm] Use llvm::fill instead of std::fill(NFC) (#146911)Austin
Use llvm::fill instead of std::fill
2025-06-24[NFC][TableGen] Use ArrayRef instead of const vector reference (#145323)Rahul Joshi
- Use `ArrayRef` instead of `SmallVector` reference in a few places. - Drop redundant `llvm::` in a few places.
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-09[GISel][AArch64] Allow PatLeafs to be imported in GISel which were ↵jyli0116
previously causing warnings (#140935) Previously PatLeafs could not be imported, causing the following warnings to be emitted when running tblgen with `-warn-on-skipped-patterns:` ``` /work/clean/llvm/lib/Target/AArch64/AArch64InstrInfo.td:2631:1: warning: Skipped pattern: Src pattern child has unsupported predicate def : Pat<(i64 (mul top32Zero:$Rn, top32Zero:$Rm)), ^ ``` These changes allow the patterns to now be imported successfully.
2025-06-07[TableGen] Use `emplace` instead of `insert` and similar. NFC. (#143164)Jay Foad
2025-06-07[TableGen] Use `contains` instead of `count`. NFC. (#143156)Jay Foad
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-19[LLVM][TableGen] Rename `ListInit::getValues()` to `getElements()` (#140289)Rahul Joshi
Rename `ListInit::getValues()` to `getElements()` to better match with other `ListInit` members like `getElement`. Keep `getValues()` for existing downstream code but mark it deprecated.
2025-05-16[LLVM][TableGen] Simplify `DagInit::get` (#140056)Rahul Joshi
- Add `DagInit::get` overloads that do not need ValName to be specified. - Fix some calls to either not create temporary arrays for DAG args or use the std::pair<> overload.
2025-05-12[NFC][TableGen] Use StringRef::str() instead of casting (#139332)Rahul Joshi
- Also eliminate unneeded std::string() around some literal strings.
2025-05-12[NFC][TableGen] Add {} for `else` when `if` body has {} (#139420)Rahul Joshi
2025-05-01[DAG] Use SDValue for PatFrag checks (#137519)David Green
If the SDNode is used it can pick up the wrong results number, for example looking at the known bits of the first result where it should be looking at the second. The SDValue is already present as the SelectCodeCommon checks move from parent to child, pass the SDValue through to CheckNodePredicate as Op so that it can use it if necessary. SDNode *N is still generated, keeping most PatFrags the same. Fixes #137274
2025-04-26[TableGen] Use llvm::interleaved (NFC) (#137483)Kazu Hirata
2025-04-25[TableGen][SelectionDAG][GISel][RISCV] Support IsNonExtLoad for IsAtomic ↵Craig Topper
PatFrags. (#137401) Use it for RISC-V as a demonstration. Other targets will follow.
2025-04-24[TableGen][RISCV][AArch64][GISel] Properly implement ↵Craig Topper
isAnyExtLoad/isSignExtLoad/isZeroExtLoad for IsAtomic in SelectionDAG. (#137096) Support isAnyExtLoad() for IsAtomic in GISel. Modify atomic_load_az* to check for extload or zextload. And rename to atomic_load_azext* Add atomic_load_asext* and use in RISC-V. I used "asext" rather than "as" so it wouldn't be confused with the word "as".
2025-04-01[TableGen] Directly use SDNode functions to implement HasOneUse and ↵Craig Topper
HasNoUse. NFC (#133976) The SDValue functions we were calling wrap SDNode functions we can call directly.
2025-03-27[llvm] Use *Set::insert_range (NFC) (#133353)Kazu Hirata
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E.first); down to: Set.insert_range(llvm::make_first_range(Range)); In some cases, we can further fold that into the set declaration.
2025-03-23[llvm] Use range constructors for *Set (NFC) (#132636)Kazu Hirata
2025-03-20[llvm] Use *Set::insert_range (NFC) (#132325)Kazu Hirata
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2025-03-11[TableGen] Remove unnecessary const_cast and use range-based for loops. NFC ↵Craig Topper
(#130717) In order to use a range-based loop, I reduced a needed const_cast to only the one line that needed it.
2025-01-22[TableGen] Add a backend generating SDNode descriptions (#123002)Sergei Barannikov
This patch adds a simplistic backend that gathers all target-specific SelectionDAG nodes and emits descriptions for most of them. This includes generating node enumeration, node names, and information about node "prototype" that can be used to verify that a node is valid. The patch also extends SDNode by adding target-specific flags, which are also included in the generated tables. Part of #119709, [RFC](https://discourse.llvm.org/t/rfc-tablegen-erating-sdnode-descriptions/83627). Pull Request: https://github.com/llvm/llvm-project/pull/123002
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-20[TableGen] Avoid repeated hash lookups (NFC) (#120681)Kazu Hirata
2024-12-19[TableGen] Avoid repeated hash lookups (NFC) (#120619)Kazu Hirata
2024-12-19[TableGen] Avoid repeated hash lookups (NFC) (#120532)Kazu Hirata
2024-12-14[TableGen][SystemZ] Correctly check the range of a leaf immediate (#119931)Sergei Barannikov
The "Size >= 32" check probably dates back to when TableGen integers were 32-bit. Delete it and simplify code by using `isInt`/`isUInt`.
2024-12-13[TableGen] Add TreePatternNode::children and use it in for loops (NFC) (#119877)Sergei Barannikov
2024-11-21[TableGen] Use `std::move` to avoid copy (#113061)abhishek-kaushik22
2024-11-19[SDAG][ISel][TableGen][LoongArch] Report error for trivial bitcasts when ↵Yingwei Zheng
there are predicate calls (#116075) On loongarch64 with lsx extension, we select `VBITREV_W` for `v4i32 (xor X, (shl splat(1), Y))`: https://github.com/llvm/llvm-project/blob/8e6630391699116641cf390a10476295b7d4b95c/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td#L1583-L1584 And `vsplat_imm_eq_1` is defined as: https://github.com/llvm/llvm-project/blob/8e6630391699116641cf390a10476295b7d4b95c/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td#L77-L87 For the `(bitconvert (v4i32 (build_vector)))` case, the pattern is expected to be: ``` PATTERN: (xor:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, (shl:{ *:[v4i32] } (bitconvert:{ *:[v4i32] } (build_vector:{ *:[v4i32] }))<<P:Predicate_vsplat_imm_eq_1>>, v4i32:{ *:[v4i32] }:$vk)) RESULT: (VBITREV_W:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, v4i32:{ *:[v4i32] }:$vk) ``` However, `simplifyTree` drops the `bitconvert` node and its predicates: https://github.com/llvm/llvm-project/blob/8e6630391699116641cf390a10476295b7d4b95c/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp#L3036-L3062 Then llvm will match `vsplat_imm_eq_1` for any v4i32 splats and cause a miscompilation: ``` PATTERN: (xor:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, (shl:{ *:[v4i32] } (build_vector:{ *:[v4i32] }), v4i32:{ *:[v4i32] }:$vk)) RESULT: (VBITREV_W:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, v4i32:{ *:[v4i32] }:$vk) ``` This patch adds additional checks for predicates associated with the trivial bitconvert node. Unused patterns in the LoongArch target are also removed. Fixes https://github.com/llvm/llvm-project/issues/116008.
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-30[CodeGen] Rename MVT::iPTRAny to MVT::pAnyJessica Clarke
Whilst in upstream LLVM iPTRAny is only ever an integer, essentially an alias for iPTR, this is not true in CHERI LLVM, where it gets used to mean "iPTR or cPTR", i.e. either an integer address or a capability (with cPTR and cN being the capability equivalents of iPTR and iN). Moreover, iPTRAny is already not itself regarded as an integer (calling isInteger() will give false), so the "i" prefix is misleading, and it stands out as different from all the other xAny that have a single letter prefix denoting their type. Thus, rename it to pAny, reflecting that it is an overloaded pointer type, which could end up being specialised to an integer type, but does not have to be. This has been verified to have no effect on the generated files for LLVM itself or any in-tree target beyond the replacement of the identifier iPTRAny with pAny in GenVT.inc. Reviewers: arsenm Reviewed By: arsenm Pull Request: https://github.com/llvm/llvm-project/pull/113733
2024-10-30[TableGen] Remove a pointless check for iPTRAnyJessica Clarke
We've already called EnforceInteger on Types[0], and iPTRAny isn't regarded as an integer type (note that TableGen special-cases iPTR here to include that, though), so we cannot possibly still have an iPTRAny by this point. Delete the check, and let getFixedSizeInBits catch it along with all the other overloaded types if that ever becomes false. Also document why we have this check whilst here. Reviewers: arsenm Reviewed By: arsenm Pull Request: https://github.com/llvm/llvm-project/pull/113732
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-10-02[TableGen] Change `DefInit::Def` to a const Record pointer (#110747)Rahul Joshi
This change undoes a const_cast<> introduced in an earlier change to help transition to const pointers. It 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-01[LLVM][TableGen] Support type casts of nodes with multiple results (#109728)Stephen Chou
Currently, type casts can only be used to pattern match for intrinsics with a single overloaded return value. For instance: ``` def int_foo : Intrinsic<[llvm_anyint_ty], []>; def : Pat<(i32 (int_foo)), ...>; ``` This patch extends type casts to support matching intrinsics with multiple overloaded return values. As an example, the following defines a pattern that matches only if the overloaded intrinsic call returns an `i16` for the first result and an `i32` for the second result: ``` def int_bar : Intrinsic<[llvm_anyint_ty, llvm_anyint_ty], []>; def : Pat<([i16, i32] (int_bar)), ...>; ```
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-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-09-08[NFC][TableGen] Replace DefInit::get() with Record::getDefInit() (#107762)Rahul Joshi
Eliminate DefInit::get() as its a duplicate of Record::getDefInit(). Use early return in `VarDefInit::instantiate`.