aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-07[NFC][TableGen] Rename `CodeGenTarget` instruction accessors (#146767)Rahul Joshi1-2/+1
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)Austin1-1/+1
Use llvm::fill instead of std::fill
2025-06-24[NFC][TableGen] Use ArrayRef instead of const vector reference (#145323)Rahul Joshi1-1/+1
- 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 Foad1-10/+8
Automated with clang-tidy -fix -checks=-*,modernize-use-default-member-init
2025-06-15[TableGen] Use range-based for loops (NFC) (#144283)Kazu Hirata1-2/+2
2025-06-09[GISel][AArch64] Allow PatLeafs to be imported in GISel which were ↵jyli01161-2/+19
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 Foad1-3/+3
2025-06-07[TableGen] Use `contains` instead of `count`. NFC. (#143156)Jay Foad1-4/+4
2025-05-21[LLVM][TableGen] Use StringRef for various members ↵Rahul Joshi1-23/+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-19[LLVM][TableGen] Rename `ListInit::getValues()` to `getElements()` (#140289)Rahul Joshi1-5/+5
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 Joshi1-9/+3
- 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 Joshi1-8/+9
- Also eliminate unneeded std::string() around some literal strings.
2025-05-12[NFC][TableGen] Add {} for `else` when `if` body has {} (#139420)Rahul Joshi1-1/+2
2025-05-01[DAG] Use SDValue for PatFrag checks (#137519)David Green1-5/+5
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 Hirata1-7/+3
2025-04-25[TableGen][SelectionDAG][GISel][RISCV] Support IsNonExtLoad for IsAtomic ↵Craig Topper1-20/+23
PatFrags. (#137401) Use it for RISC-V as a demonstration. Other targets will follow.
2025-04-24[TableGen][RISCV][AArch64][GISel] Properly implement ↵Craig Topper1-10/+23
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 Topper1-2/+2
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 Hirata1-4/+2
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 Hirata1-2/+1
2025-03-20[llvm] Use *Set::insert_range (NFC) (#132325)Kazu Hirata1-1/+1
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 Topper1-7/+3
(#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 Barannikov1-24/+80
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 Foad1-4/+3
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 Hirata1-2/+1
2024-12-19[TableGen] Avoid repeated hash lookups (NFC) (#120619)Kazu Hirata1-2/+1
2024-12-19[TableGen] Avoid repeated hash lookups (NFC) (#120532)Kazu Hirata1-13/+13
2024-12-14[TableGen][SystemZ] Correctly check the range of a leaf immediate (#119931)Sergei Barannikov1-12/+8
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 Barannikov1-36/+35
2024-11-21[TableGen] Use `std::move` to avoid copy (#113061)abhishek-kaushik221-1/+2
2024-11-19[SDAG][ISel][TableGen][LoongArch] Report error for trivial bitcasts when ↵Yingwei Zheng1-0/+8
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 Barannikov1-18/+2
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 Clarke1-2/+2
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 Clarke1-1/+2
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 Joshi1-30/+31
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 Joshi1-1/+1
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 Chou1-9/+35
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 Joshi1-85/+73
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 Joshi1-44/+31
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-25/+24
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-8/+9
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 Joshi1-1/+1
Eliminate DefInit::get() as its a duplicate of Record::getDefInit(). Use early return in `VarDefInit::instantiate`.
2024-09-07[TableGen] Add PrintError family overload that take a print function (#107333)Rahul Joshi1-7/+4
Add PrintError and family overload that accepts a print function. This avoids constructing potentially long strings for passing into these print functions.
2024-09-04[TableGen] Add `CodeGenIntrinsicsMap` for on-demand intrinsic creation (#107100)Rahul Joshi1-4/+2
- Add class `CodeGenIntrinsicMap` for on-demand creation of `CodeGenIntrinsic`. - Add class `CodeGenIntrinsicContext` to capture global information required to build `CodeGenIntrinsic` objects. - Adopt GlobalISel PatternParser and SearchableTableEmitter to use it.
2024-06-02[TableGen] Use llvm::unique (NFC) (#94163)Kazu Hirata1-2/+1
2024-05-20[TableGen] HasOneUse builtin predicate on PatFrags (#91578)jofrn1-1/+6
This predicate tells GlobalISelEmitter and DAGISelEmitter to check that the instruction to emit has only one use of its result. This can be used on a PatFrag instead of defining custom predicates for both emitters per record that requires it.
2024-04-26Revert "[TableGen] Ignore inaccessible memory when checking pattern flags ↵Jay Foad1-9/+1
(#90061)" This reverts commit 6578356a4e3e6acd7983c74feab43ac96925894c. The patch had no effect due to a silly mistake and fixing the mistake causes other problems.
2024-04-26[TableGen] Ignore inaccessible memory when checking pattern flags (#90061)Jay Foad1-1/+9
In the AMDGPU backend we have some cases where we'd like to mark an intrinsic as IntrInaccessibleMemOnly to model dependencies, but the corresponding MachineInstrs use uses/defs of a special physical register to express the same thing. In this case TableGen would complain: Pattern doesn't match mayLoad/mayStore = 0 but the error is not useful.
2024-04-25[TableGen] ShouldIgnore Pattern bit to disable DAG pattern imports during ↵jofrn1-7/+9
GISel (#88382) Added GISelShouldIgnore property to class Pattern in TargetSelectionDAG.td; it's similar to FastISelShouldIgnore. This bit can be put on a record to avoid its pattern import within GlobalISelEmitter. This allows one to avoid the record's GISel .td implementation, .inc generation, and any skipped pattern warnings from -warn-on-skipped-patterns.
2024-04-04[TableGen] Fix a potential crash when operand doesn't appear in the ↵Shilei Tian1-2/+7
instruction pattern (#87663) We have a check of whether an operand is in the instruction pattern, and emit an error if it is not, but we simply continue execution, including directly dereferencing a point-like object `InVal`, which will be just created when accessing the map. It contains a `nullptr` so dereferencing it causes crash. This is a very trivial fix.