aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/CodeGenDAGPatterns.h
AgeCommit message (Collapse)AuthorFilesLines
2024-03-25[RFC][TableGen] Restructure TableGen Source (#80847)Pierre van Houtryve1-1263/+0
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[TableGen][NFC] convert TreePatternNode pointers to references (#81134)Tomas Matheson1-10/+10
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-113/+96
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
2023-07-09Revert "[TableGen] Use heap allocated arrays instead of vectors for ↵Tomas Matheson1-22/+16
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-07-09[NFC] make TypeInfer::expandOverloads constTomas Matheson1-5/+5
Differential Revision: https://reviews.llvm.org/D154780
2023-07-09[NFC] make TypeInfer::MergeInTypeInfo constTomas Matheson1-6/+7
Differential Revision: https://reviews.llvm.org/D154779
2023-04-30[TableGen] Forward declare CodeGenRegister et al. (NFC)Sergei Barannikov1-1/+2
2023-04-23[TableGen] Remove unused ForceMode and CodeGen fields from TypeInfer. NFCCraig Topper1-7/+3
As well as the ForceMode field in PatternToMatch.
2023-04-19[TableGen] Use heap allocated arrays instead of vectors for ↵Craig Topper1-17/+22
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-18[TableGen] Reduce the amount of storage space used for AddrSpaces in ↵Craig Topper1-1/+1
TypeSetByHwMode. NFC We reserved 16 AddrSpaces in every TypeSetByHwMode. But we only ever use the first one on targets that make use of the AddrSpace feature. The vector was populated by pushing for each entry in the ArrayRef passed to the TypeSetByHwMode constructor. Each entry is a ValueTypeByHwMode that stores one VT for each HwMode. The vector is accessed by a loop in TypeSetByHwMode::getValueTypeByHwMode. That loop is over HwModes with in the TypeSetByHwMode. This is unrelated to how the vector was created. The entries in the vector don't represent HwModes. The targets that use AddrSpace don't make use of HwModes so the loop in getValueTypeByHwMode will only run 1 iteration. So we only the first entry in the vector is meaningful used. This patch simplifies things by storing only 1 AddrSpace in TypeSetByMode. Reducing the memory used by TypeSetByHwMode. More work will be needed to support HwModes with AddrSpace if we need a different AddrSpace for each HwMode. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D148194
2023-04-18[TableGen] Const-correct TreePatternNode::getChild. NFCCraig Topper1-1/+4
Make the const version return a const TreePatterNode* and add a non-const version to return a non-const TreePatternNode*.
2023-04-16[TableGen] Use PointerUnion for Operator and Val in TreePatternNode.Craig Topper1-14/+17
These fields are never set at the same time so we can store them using a single PointerUnion.
2023-04-16[TableGen] Avoid extra IntrusiveRefCntPtr when calling SimplifyTree. NFCCraig Topper1-0/+3
Add a helper to get modifiable access to the IntrusiveRefCntPtr stored in the Children array. This avoids copying and overwriting the child.
2023-04-14[TableGen] Make InlinePatternFragments a member of TreePatternNode again. NFCCraig Topper1-4/+3
Now that we use IntrusiveRefCntPtr instead of std::shared_ptr we don't need to pass a TreePatternNodePtr to this method.
2023-04-14[TableGen] Replace std::shared_ptr with InstrusiveRefCntPtr for ↵Craig Topper1-2/+3
TreePatternNode. NFC An intrusive reference counter uses less memory than the control block of std::shared_ptr. This should allow some additional code simplifications if we don't need to pass around shared_ptr in order to create new shared_ptrs.
2023-04-10[TableGen] Avoid vector copy in TreePatter::InlinePatternFragments. NFCCraig Topper1-4/+4
Instead of copying a vector and clearing the original, we can swap with an empty vector.
2023-04-10[TableGen] Pass TreePatternNodePtr to InlinePatternFragments by const ↵Craig Topper1-1/+1
reference. NFC Not all paths through this function require the reference count to be incremened. Pass by reference so we don't increase the count unnecessarily.
2023-04-10[TableGen] Make TreePatternNode::InlinePatternFragments a static method. NFCCraig Topper1-4/+4
Previously we were passing 'this' and the std::shared_ptr version of 'this'. This replaces all uses of 'this' with the shared_ptr and makes the method static.
2023-04-10[TableGen] Move vectors into DAGInstruction instead of copying them. NFCCraig Topper1-5/+6
2023-04-09[TableGen] Remove TypeSetByHwMode::isDefaultOnly(). Use ↵Craig Topper1-7/+2
InfoByHwMode<T>::isSimple(). NFC InfoByHwMode is the base class of TypeSetByHwMode. The two methods did the same thing. No reason to have two ways to do it. Also use the getSimple() access instead of Map.begin()->second.
2023-03-31[TableGen] Enable "Type set is empty for each HW mode" error in non-debug buildsJay Foad1-4/+0
Differential Revision: https://reviews.llvm.org/D147127
2023-02-10[RFC][GISel] Add a way to ignore COPY instructions in InstructionSelectorPierre van Houtryve1-0/+7
RFC to add a way to ignore COPY instructions when pattern-matching MIR in GISel. - Add a new "GISelFlags" class to TableGen. Both `Pattern` and `PatFrags` defs can use it to alter matching behaviour. - Flags start at zero and are scoped: the setter returns a `SaveAndRestore` object so that when the current scope ends, the flags are restored to their previous values. This allows child patterns to modify the flags without affecting the parent pattern. - Child patterns always reuse the parent's pattern, but they can override its values. For more examples, see `GlobalISelEmitterFlags.td` tests. - [AMDGPU] Use the IgnoreCopies flag in BFI patterns, which are known to be bothered by cross-regbank copies. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D136234
2023-01-23[llvm] Use llvm::countr_zero instead of findFirstSet (NFC)Kazu Hirata1-2/+2
At each call to findFirstSet in this patch, the argument is known to be nonzero, so we can safely switch to llvm::countr_zero, which will become std::countr_zero once C++20 is available.
2023-01-22Use llvm::popcount instead of llvm::countPopulation(NFC)Kazu Hirata1-1/+1
2022-09-25[llvm] Use std::underlying_type_t (NFC)Kazu Hirata1-1/+1
2022-08-20Revert "Use std::is_same_v instead of std::is_same (NFC)"Kazu Hirata1-4/+4
This reverts commit c5da37e42d388947a40654b7011f2a820ec51601. This patch seems to break builds with some versions of MSVC.
2022-08-20Use std::is_same_v instead of std::is_same (NFC)Kazu Hirata1-4/+4
2022-07-08[GlobalISel][SelectionDAG] Implement the HasNoUse builtin predicateAbinav Puthan Purayil1-0/+3
This change introduces the HasNoUse builtin predicate in PatFrags that checks for the absence of use of the first result operand. GlobalISelEmitter will allow source PatFrags with this predicate to be matched with destination instructions with empty outs. This predicate is required for selecting the no-return variant of atomic instructions in AMDGPU. Differential Revision: https://reviews.llvm.org/D125212
2022-07-07[TableGen] Move printing to stream directly to MachineValueTypeSetKrzysztof Parzyszek1-1/+4
2022-03-12Cleanup includes: DebugInfo & CodeGenserge-sans-paille1-1/+0
Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121332
2021-10-12[TableGen] Fix both sides of '&&' are sameCraig Topper1-2/+5
The operand of the second any_of in EnforceSmallerThan should be B not S like the FP code in the if below. Unfortunately, fixing that causes an infinite loop in the build of RISCV. So I've added a workaround for that as well. Fixes PR44768. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D111502
2021-04-28[TableGen] Store predicates in PatternToMatch as ListInit *. Add string for ↵Craig Topper1-64/+13
HwModeFeatures This uses to be how predicates were handled prior to HwMode being added. When the Predicates were converted to a std::vector it significantly increased the cost of a compare in GenerateVariants. Since ListInit's are uniquified by tablegen, we can use a simple pointer comparison to check for identical lists. In order to store the HwMode, we now add a separate string to PatternToMatch. This will be appended separately to the predicate string in getPredicateCheck. A new getPredicateRecords is added to allow GlobalISel and getPredicateCheck to both get the sorted list of Records. GlobalISel was ignoring any HwMode predicates before and still is. There is one slight change here, ListInits with different predicate orders aren't sorted so the filtering in GenerateVariants might fail to detect two isomorphic patterns with different predicate orders. This doesn't seem to be happening in tree today. My hope is this will allow us to remove all the BitVector tracking in GenerateVariants that was making up for predicates beeing expensive to compare. There's a decent amount of heap allocations there on large targets like X86, AMDGPU, and RISCV. Differential Revision: https://reviews.llvm.org/D100691
2021-04-16[TableGen] Predicate::operator== needs to compare the HwMode feature name in ↵Craig Topper1-1/+2
addition to the HwMode flag. This was causing GenerateVariants to lose some variants since HwMode is expanded first. We were mistakenly thinking the HwMode predicate matched and finding the variant was isomorphic to a pattern in another HwMode and discarding it. Found while investigating it if would be better to generate variants before expanding HwModes to improve RISCV build time. I noticed an increase in the number of Opc_MorphNodeTo in the table which indicated that the number of patterns had changed.
2021-04-15[TableGen] Reduce the number of map lookups in TypeSetByHwMode::getOrCreate. ↵Craig Topper1-3/+1
NFCI hasMode was looking up the map once. Then we'd either call get which would look up again, or we'd insert into the map which requires walking the map to find the insertion point. I believe the hasMode was needed because get has a special case to look for DefaultMode if the mode being asked for doesn't exist. We don't want that here so we were using hasMode to make sure we wouldn't hit that case. Simplify to a regular operator[] access which will default construct a SetType if the lookup fails.
2021-02-06[TableGen] Make all the fields in PatternToMatch private. NFCICraig Topper1-9/+11
Add the few missing accessor methods. Use accessor methdods everywhere.
2021-01-07[TableGen] Make CodeGenDAGPatterns::getSDNodeNamed take a StringRef instead ↵Craig Topper1-1/+1
of const std::string &. All callers use a string literal and the getDef method the string is passed to already takes a StringRef.
2020-12-06[TableGen] Delete 11 unused declarationsFangrui Song1-2/+0
2020-07-20CodeGenDAGPatterns.h - remove unnecessary ComplexPattern forward ↵Simon Pilgrim1-1/+0
declaration. NFCI. This is defined in CodeGenTarget.h which we have to explicitly include already.
2020-07-20CodeGenDAGPatterns.h - remove unused CodeGenHwModes.h include. NFCI.Simon Pilgrim1-1/+0
2020-07-16[TableGen] Change std::vector to SmallVectorNadav Rotem1-1/+1
The size of VTList that is pushed into this container is usually 1, but often 6 or 7. Change the vector to SmallVector to eliminate frequent mallocs. This happens hundreds of thousands of times in each tablegen execution during the LLVM/clang build. https://reviews.llvm.org/D83849
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-3/+4
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.
2020-01-09TableGen: Remove unused codeMatt Arsenault1-6/+0
2019-12-11[TableGen] Remove unused target intrinsic generation logicReid Kleckner1-9/+0
AMDGPU was the last in tree target to use this tablegen mode. I plan to split up the global intrinsic enum similar to the way that clang diagnostics are split up today. I don't plan to build on this mode. Reviewers: arsenm, echristo, efriedma Reviewed By: echristo Differential Revision: https://reviews.llvm.org/D71318
2019-11-23Reland 'Fixed -Wdeprecated-copy warnings. NFCI.'Dávid Bolvanský1-0/+1
Fixed hashtable copy ctor.
2019-11-23Revert 'Fixed -Wdeprecated-copy warnings. NFCI.'Dávid Bolvanský1-1/+0
pdbutil's test is failing.
2019-11-23Fixed -Wdeprecated-copy warnings. NFCI.Dávid Bolvanský1-0/+1
2019-07-31TableGen: Add MinAlignment predicateMatt Arsenault1-0/+1
AMDGPU uses some custom code predicates for testing alignments. I'm still having trouble comprehending the behavior of predicate bits in the PatFrag hierarchy. Any attempt to abstract these properties unexpectdly fails to apply them. llvm-svn: 367373
2019-07-30AMDGPU: Avoid emitting "true" predicatesMatt Arsenault1-0/+3
Empty condition strings are considerde always true. This removes a lot of clutter from the generated matcher tables. This shrinks the source size of AMDGPUGenDAGISel.inc from 7.3M to 6.1M. llvm-svn: 367326
2019-07-15TableGen: Add address space to matchersMatt Arsenault1-0/+2
Currently AMDGPU uses a CodePatPred to check address spaces from the MachineMemOperand. Introduce a new first class property so that the existing patterns can be easily modified to uses the new generated predicate, which will also be handled for GlobalISel. I would prefer these to match against the pointer type of the instruction, but that would be difficult to get working with SelectionDAG compatbility. This is much easier for now and will avoid a painful tablegen rewrite for all the loads and stores. I'm also not sure if there's a better way to encode multiple address spaces in the table, rather than putting the number to expect. llvm-svn: 366128
2019-07-04[TableGen] Allow DAG isel patterns to override default operands.Simon Tatham1-0/+5
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