aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-03-25[RFC][TableGen] Restructure TableGen Source (#80847)Pierre van Houtryve1-4784/+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-15[TableGen][NFCI] Simplify TypeSetByHwMode::intersect and make extensible ↵Jessica Clarke1-76/+81
(#81688) The current implementation considers both iPTR+iN and everything else all in one go, which leads to more special casing when iPTR is present in only one set than is described in the comment block. Moreover this makes it very difficult to add any new iPTR-like wildcards due to the exponential combinatorial explosion that occurs. Logically, iPTR+iN handling is entirely independent from everything else, so rewrite the code to do them separately. This removes special cases, making the core of the implementation more succinct, whilst more clearly implementing exactly what is described in the comment block, and allows for any number of (non-overlapping) wildcards to be added to the list, as needed by CHERI LLVM downstream (due to having a new capability type which, much like a normal integer pointer in LLVM, varies in size between targets and modes). In testing, this change results in identical TableGen output for all in-tree backends (including those in LLVM_ALL_EXPERIMENTAL_TARGETS), and it is intended that this implementation is entirely equivalent to the old one.
2024-02-14[TableGen] Stop using make_pair and make_tuple. NFC. (#81730)Jay Foad1-17/+17
These are unnecessary since C++17.
2024-02-09[TableGen][NFC] convert TreePatternNode pointers to references (#81134)Tomas Matheson1-182/+182
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-299/+280
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
2024-01-09[SelectionDAG] Add and use SDNode::getAsAPIntVal() helper (#77455)Alex Bradbury1-1/+1
This is the logical equivalent for #76710 for APInt and uses the same naming scheme. Converted existing users through: `git grep -l "cast<ConstantSDNode>\(.*\).*getAPIntValueValue" | xargs sed -E -i 's/cast<ConstantSDNode>\((.*)\)->getAPIntValue/\1->getAsAPIntVal/'`
2023-07-09Revert "[TableGen] Use heap allocated arrays instead of vectors for ↵Tomas Matheson1-12/+12
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-3/+3
Differential Revision: https://reviews.llvm.org/D154780
2023-07-09[NFC] make TypeInfer::MergeInTypeInfo constTomas Matheson1-1/+1
Differential Revision: https://reviews.llvm.org/D154779
2023-05-23[TableGen] Filter duplicate predicates in PatternToMatch::getPredicateRecords.Craig Topper1-0/+3
Recent changes to RISC-V cause the same predicate to appear in the predicate list multiple times in some cases. This patch filters the duplicates to reduce the number of predicate string variations.
2023-05-10[TableGen] Print message about dropped patterns with -debugKrzysztof Parzyszek1-2/+13
A selection pattern can be silently dropped if type inference fails to deduce some types. Print a message when that happens, and -debug was applied.
2023-05-09[TableGen] Fix null pointer dereferences in TreePattern::ParseTreePattern()Alexey Vishnyakov1-3/+8
Bugs were found by Svace static analysis tool. Null pointers are dereferenced right after error checking that does not return from function. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D147706
2023-04-26TableGen: Replace `IntrinsicEmitter::ComputeFixedEncoding()` and cleanupNAKAMURA Takumi1-6/+8
Depends on D146915 Differential Revision: https://reviews.llvm.org/D145937
2023-04-26ReformatNAKAMURA Takumi1-2/+2
2023-04-23[TableGen] Remove unused ForceMode and CodeGen fields from TypeInfer. NFCCraig Topper1-2/+1
As well as the ForceMode field in PatternToMatch.
2023-04-21[TableGen] Early exit from ExpandHwModeBasedTypes when there are no HwModes.Craig Topper1-0/+3
Most targets don't use HwModes. For these targets we can skip collecting the HwModes and copying all the pattern pointers.
2023-04-21[TableGen] Remove some unnecessary TreePatternNodePtrs. NFCCraig Topper1-5/+5
The patterns we're referring are still owned by the PatternToMatch object. We don't need to increment their reference count here.
2023-04-19[TableGen] Use heap allocated arrays instead of vectors for ↵Craig Topper1-12/+12
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-6/+6
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] Call std::vector::reserve to preallocate memory before a loop of ↵Craig Topper1-0/+1
push_back. NFC
2023-04-17[TableGen] clang-format some recent changes. NFCCraig Topper1-5/+4
2023-04-16[TableGen] Use PointerUnion for Operator and Val in TreePatternNode.Craig Topper1-2/+2
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-5/+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-27/+26
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-12/+12
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-11[TableGen] Call std::vector::reserve to preallocate memory before a loop of ↵Craig Topper1-0/+1
push_back. NFC
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] Simplify how commuted variants are generated in ↵Craig Topper1-11/+4
GenerateVariantsOf. NFC We don't need to copy the ChildVariants vector into a new vector. We're using std::move on every entry we copy so they clearly aren't needed again. We can swap entries in the vector and reuse it instead.
2023-04-10[TableGen] Pass size to std::vector constructor instead of using resize. NFCCraig Topper1-8/+6
2023-04-10[TableGen] Make TreePatternNode::InlinePatternFragments a static method. NFCCraig Topper1-23/+23
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-4/+4
2023-04-09[TableGen] Use map::try_emplace to construction DAGInstruction in the ↵Craig Topper1-5/+3
Instructions map. NFC We add entries to the map in two places. One already used std::piecewise_construct with map::emplace. The other was using map::insert. Change both to map::try_emplace.
2023-04-09[TableGen] Remove TypeSetByHwMode::isDefaultOnly(). Use ↵Craig Topper1-4/+4
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-04-09[TableGen] Reorder some checks in TreePatternNode::isIsomorphicTo to speedup ↵Craig Topper1-3/+11
-gen-dag-isel for RISC-V. Comparing types is quite expensive when hardware modes are being used. Checking the operator first can let us detect mismatches earlier without checking types.
2023-04-08[TableGen] Use InfoByHwMode::getSimple() in place of *InfoByHwMode::begin(). NFCCraig Topper1-1/+1
2023-04-08[TableGen] Simplify TypeInfer::expandOverloads. NFCCraig Topper1-50/+35
Directly test the 5 overloaded types instead of doing extra set creation and iteration.
2023-03-31[TableGen] Enable "Type set is empty for each HW mode" error in non-debug buildsJay Foad1-7/+4
Differential Revision: https://reviews.llvm.org/D147127
2023-03-14[llvm] Use *{Set,Map}::contains (NFC)Kazu Hirata1-3/+2
2023-03-14[TableGen][RISCV][Hexagon][LoongArch] Add a list of Predicates to HwMode.Craig Topper1-4/+4
Use the predicate condition instead of checkFeatures in *GenDAGISel.inc. This makes the code similar to isel pattern predicates. checkFeatures is still used by code created by SubtargetEmitter so we can't remove the string. Backends need to be careful to keep the string and predicates in sync, but I don't think that's a big issue. I haven't measured it, but this should be a compile time improvement for isel since we don't have to do any of the string processing that's inside checkFeatures. Reviewed By: kparzysz Differential Revision: https://reviews.llvm.org/D146012
2023-02-26[TableGen] Use raw_svector_ostream and ListSeparator to simplify some code. NFCCraig Topper1-10/+5
2023-02-17llvm-tblgen: Apply IWYU partiallyNAKAMURA Takumi1-0/+1
2023-02-10[RFC][GISel] Add a way to ignore COPY instructions in InstructionSelectorPierre van Houtryve1-0/+6
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-11[NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize()Guillaume Chatelet1-4/+4
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2023-01-09[reland][NFC] Vastly simplifies TypeSizeGuillaume Chatelet1-5/+3
Simplifies the implementation of `TypeSize` while retaining its interface. There is no need for abstract concepts like `LinearPolyBase`, `UnivariateLinearPolyBase` or `LinearPolySize`. Differential Revision: https://reviews.llvm.org/D140263
2023-01-06Revert D140263 "[NFC] Vastly simplifies TypeSize"Guillaume Chatelet1-3/+5
This broke some build bots : https://lab.llvm.org/buildbot/#/builders/16/builds/41419/steps/5/logs/stdio This reverts commit 4670d5ece57d9b030597da679072f78bb3f4d419.
2023-01-06Revert D141134 "[NFC] Only expose getXXXSize functions in TypeSize"Guillaume Chatelet1-2/+2
The patch should be discussed further. This reverts commit dd56e1c92b0e6e6be249f2d2dd40894e0417223f.
2023-01-06[NFC] Only expose getXXXSize functions in TypeSizeGuillaume Chatelet1-2/+2
Currently 'TypeSize' exposes two functions that serve the same purpose: - getFixedSize / getFixedValue - getKnownMinSize / getKnownMinValue source : https://github.com/llvm/llvm-project/blob/bf82070ea465969e9ae86a31dfcbf94c2a7b4c4c/llvm/include/llvm/Support/TypeSize.h#L337-L338 This patch offers to remove one of the two and stick to a single function in the code base. Differential Revision: https://reviews.llvm.org/D141134
2023-01-06[NFC] Vastly simplifies TypeSizeGuillaume Chatelet1-5/+3
Simplifies the implementation of `TypeSize` while retaining its interface. There is no need for abstract concepts like `LinearPolyBase`, `UnivariateLinearPolyBase` or `LinearPolySize`. Differential Revision: https://reviews.llvm.org/D140263
2022-11-14[TableGen] Use MemoryEffects to represent intrinsic memory effects (NFCI)Nikita Popov1-8/+9
The TableGen implementation was using a homegrown implementation of FunctionModRefInfo. This switches it to use MemoryEffects instead. This makes the code simpler, and will allow exposing the full representational power of MemoryEffects in the future. Among other things, this will allow us to map IntrHasSideEffects to an inaccessiblemem readwrite, rather than just ignoring it entirely in most cases. To avoid layering issues, this moves the ModRef.h header from IR to Support, so that it can be included in the TableGen layer. Differential Revision: https://reviews.llvm.org/D137641
2022-07-08GlobalISel: Allow forming atomic/volatile G_ZEXTLOADMatt Arsenault1-8/+16
SelectionDAG has a target hook, getExtendForAtomicOps, which it uses in the computeKnownBits implementation for ATOMIC_LOAD. This is pretty ugly (as is having a separate load opcode for atomics), so instead allow making use of atomic zextload. Enable this for AArch64 since the DAG path defaults in to the zext behavior. The tablegen changes are pretty ugly, but partially helps migrate SelectionDAG from using ISD::ATOMIC_LOAD to regular ISD::LOAD with atomic memory operands. For now the DAG emitter will emit matchers for patterns which the DAG will not produce. I'm still a bit confused by the intent of the isLoad/isStore/isAtomic bits. The DAG implementation rejects trying to use any of these in combination. For now I've opted to make the isLoad checks also check isAtomic, although I think having isLoad and isAtomic set on these makes most sense.