473 Commits

Author SHA1 Message Date
Jessica Clarke
de6fad5146
[TableGen][NFCI] Simplify TypeSetByHwMode::intersect and make extensible (#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-15 04:02:30 +00:00
Jay Foad
f723260a80
[TableGen] Stop using make_pair and make_tuple. NFC. (#81730)
These are unnecessary since C++17.
2024-02-14 13:16:20 +00:00
Tomas Matheson
a9e546cc71
[TableGen][NFC] convert TreePatternNode pointers to references (#81134)
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 13:35:42 +00:00
Pierre van Houtryve
b9079baadd
[NFC] clang-format utils/TableGen (#80973)
```
find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i
```

Split from #80847
2024-02-09 09:27:04 +01:00
Alex Bradbury
2d54ec36f7
[SelectionDAG] Add and use SDNode::getAsAPIntVal() helper (#77455)
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/'`
2024-01-09 14:27:07 +00:00
Tomas Matheson
6d4a3e917c Revert "[TableGen] Use heap allocated arrays instead of vectors for 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 10:14:48 +01:00
Tomas Matheson
4c66b03259 [NFC] make TypeInfer::expandOverloads const
Differential Revision: https://reviews.llvm.org/D154780
2023-07-09 09:19:06 +01:00
Tomas Matheson
b25572137e [NFC] make TypeInfer::MergeInTypeInfo const
Differential Revision: https://reviews.llvm.org/D154779
2023-07-09 09:11:59 +01:00
Craig Topper
d91f65ea36 [TableGen] Filter duplicate predicates in PatternToMatch::getPredicateRecords.
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-23 13:32:18 -07:00
Krzysztof Parzyszek
1b18064069 [TableGen] Print message about dropped patterns with -debug
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-10 14:51:57 -07:00
Alexey Vishnyakov
9c07aa75b9 [TableGen] Fix null pointer dereferences in TreePattern::ParseTreePattern()
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-05-09 18:06:10 -07:00
NAKAMURA Takumi
24706aff15 TableGen: Replace IntrinsicEmitter::ComputeFixedEncoding() and cleanup
Depends on D146915

Differential Revision: https://reviews.llvm.org/D145937
2023-04-26 23:49:08 +09:00
NAKAMURA Takumi
5540e29a0a Reformat 2023-04-26 23:47:15 +09:00
Craig Topper
7a6dc3d24c [TableGen] Remove unused ForceMode and CodeGen fields from TypeInfer. NFC
As well as the ForceMode field in PatternToMatch.
2023-04-23 20:32:14 -07:00
Craig Topper
63f6e70be9 [TableGen] Early exit from ExpandHwModeBasedTypes when there are no HwModes.
Most targets don't use HwModes. For these targets we can skip
collecting the HwModes and copying all the pattern pointers.
2023-04-21 17:27:25 -07:00
Craig Topper
8769a945eb [TableGen] Remove some unnecessary TreePatternNodePtrs. NFC
The patterns we're referring are still owned by the PatternToMatch
object. We don't need to increment their reference count here.
2023-04-21 17:11:09 -07:00
Craig Topper
d34125a1a8 [TableGen] Use heap allocated arrays instead of vectors for 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-19 15:22:58 -07:00
Craig Topper
83507644ed [TableGen] Reduce the amount of storage space used for AddrSpaces in 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 15:34:22 -07:00
Craig Topper
c446f2dbab [TableGen] Call std::vector::reserve to preallocate memory before a loop of push_back. NFC 2023-04-18 00:31:38 -07:00
Craig Topper
528b25c64a [TableGen] clang-format some recent changes. NFC 2023-04-17 20:26:47 -07:00
Craig Topper
73925b3a0c [TableGen] Use PointerUnion for Operator and Val in TreePatternNode.
These fields are never set at the same time so we can store them
using a single PointerUnion.
2023-04-16 20:10:51 -07:00
Craig Topper
f0c3dfdbf1 [TableGen] Avoid extra IntrusiveRefCntPtr when calling SimplifyTree. NFC
Add a helper to get modifiable access to the IntrusiveRefCntPtr
stored in the Children array. This avoids copying and overwriting the child.
2023-04-16 18:57:27 -07:00
Craig Topper
56fdac60aa [TableGen] Make InlinePatternFragments a member of TreePatternNode again. NFC
Now that we use IntrusiveRefCntPtr instead of std::shared_ptr
we don't need to pass a TreePatternNodePtr to this method.
2023-04-14 19:43:44 -07:00
Craig Topper
40e356d67f [TableGen] Replace std::shared_ptr with InstrusiveRefCntPtr for 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-14 10:56:36 -07:00
Craig Topper
bb2e9f23ca [TableGen] Call std::vector::reserve to preallocate memory before a loop of push_back. NFC 2023-04-11 00:07:57 -07:00
Craig Topper
dea417f75e [TableGen] Pass TreePatternNodePtr to InlinePatternFragments by const 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 15:04:24 -07:00
Craig Topper
6de3afeaef [TableGen] Simplify how commuted variants are generated in 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 11:29:01 -07:00
Craig Topper
58dd265d25 [TableGen] Pass size to std::vector constructor instead of using resize. NFC 2023-04-10 00:17:41 -07:00
Craig Topper
551bfca86f [TableGen] Make TreePatternNode::InlinePatternFragments a static method. NFC
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 00:17:29 -07:00
Craig Topper
2e6c72d341 [TableGen] Move vectors into DAGInstruction instead of copying them. NFC 2023-04-10 00:03:44 -07:00
Craig Topper
af27138315 [TableGen] Use map::try_emplace to construction DAGInstruction in the 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 16:32:54 -07:00
Craig Topper
ab84a93287 [TableGen] Remove TypeSetByHwMode::isDefaultOnly(). Use 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 10:56:06 -07:00
Craig Topper
0ab1559a3d [TableGen] Reorder some checks in TreePatternNode::isIsomorphicTo to speedup -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-09 00:54:50 -07:00
Craig Topper
11fdaffc3e [TableGen] Use InfoByHwMode::getSimple() in place of *InfoByHwMode::begin(). NFC 2023-04-08 12:07:01 -07:00
Craig Topper
09fecbbf54 [TableGen] Simplify TypeInfer::expandOverloads. NFC
Directly test the 5 overloaded types instead of doing extra
set creation and iteration.
2023-04-08 00:04:09 -07:00
Jay Foad
a80b830e48 [TableGen] Enable "Type set is empty for each HW mode" error in non-debug builds
Differential Revision: https://reviews.llvm.org/D147127
2023-03-31 09:03:22 +01:00
Kazu Hirata
b595eb83e5 [llvm] Use *{Set,Map}::contains (NFC) 2023-03-14 18:56:07 -07:00
Craig Topper
81a150656b [TableGen][RISCV][Hexagon][LoongArch] Add a list of Predicates to HwMode.
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-03-14 13:00:38 -07:00
Craig Topper
0a341a1eda [TableGen] Use raw_svector_ostream and ListSeparator to simplify some code. NFC 2023-02-26 19:36:34 -08:00
NAKAMURA Takumi
afde3f549d llvm-tblgen: Apply IWYU partially 2023-02-17 00:32:46 +09:00
Pierre van Houtryve
70924673af [RFC][GISel] Add a way to ignore COPY instructions in InstructionSelector
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-02-10 08:37:42 +01:00
Guillaume Chatelet
fbd207fd6f [NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize()
This change is one of a series to implement the discussion from
https://reviews.llvm.org/D141134.
2023-01-11 16:29:29 +00:00
Guillaume Chatelet
59b029238a [reland][NFC] Vastly simplifies TypeSize
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-09 08:43:37 +00:00
Guillaume Chatelet
16c1c9fdcc Revert D140263 "[NFC] Vastly simplifies TypeSize"
This broke some build bots : https://lab.llvm.org/buildbot/#/builders/16/builds/41419/steps/5/logs/stdio

This reverts commit 4670d5ece57d9b030597da679072f78bb3f4d419.
2023-01-06 15:33:00 +00:00
Guillaume Chatelet
87b6b347fc Revert D141134 "[NFC] Only expose getXXXSize functions in TypeSize"
The patch should be discussed further.

This reverts commit dd56e1c92b0e6e6be249f2d2dd40894e0417223f.
2023-01-06 15:27:50 +00:00
Guillaume Chatelet
dd56e1c92b [NFC] Only expose getXXXSize functions in TypeSize
Currently 'TypeSize' exposes two functions that serve the same purpose:
 - getFixedSize / getFixedValue
 - getKnownMinSize / getKnownMinValue

source : bf82070ea4/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 15:24:52 +00:00
Guillaume Chatelet
4670d5ece5 [NFC] Vastly simplifies TypeSize
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-06 13:19:32 +00:00
Nikita Popov
feda983ff8 [TableGen] Use MemoryEffects to represent intrinsic memory effects (NFCI)
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-11-14 10:52:04 +01:00
Matt Arsenault
1ee6ce9bad GlobalISel: Allow forming atomic/volatile G_ZEXTLOAD
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.
2022-07-08 11:55:08 -04:00
Abinav Puthan Purayil
c42fe5bd7a [GlobalISel][SelectionDAG] Implement the HasNoUse builtin predicate
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-08 09:47:33 +05:30