395 Commits

Author SHA1 Message Date
jyli0116
7e00a7c021
[GlobalISel] Fixes unused variable error in testMOPredicate_MO (#143364)
Solves unused variable error in generated Global ISel code due to
changes from #140935
2025-06-09 13:37:38 +01:00
Jay Foad
592e59667a
[TableGen] Move getSuperRegForSubReg into CodeGenRegBank. NFC. (#142979)
This method doesn't use anything from CodeGenTarget, so it seems to
belong in CodeGenRegBank.
2025-06-09 12:03:29 +01:00
jyli0116
f3ffee601c
[GISel][AArch64] Allow PatLeafs to be imported in GISel which were 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-09 09:02:56 +01:00
Jay Foad
63244932fa
[TableGen] Make more use of findSubRegIdx. NFCI. (#142996)
Outside of CodeGenRegisters itself, we only want to find existing
SubRegIdxs, not create new ones. Change findSubRegIdx to assert and use
it consistently for this purpose.
2025-06-05 18:06:57 +01:00
Rahul Joshi
b5e3d8ec08
[LLVM][TableGen] Use StringRef for various members 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-21 06:23:01 -07:00
Rahul Joshi
3932360b14
[LLVM][TableGen] Rename ListInit::getValues() to getElements() (#140289)
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-19 12:16:33 -07:00
Rahul Joshi
9981afc5f9
[NFC][TableGen] Use StringRef::str() instead of casting (#139332)
- Also eliminate unneeded std::string() around some literal strings.
2025-05-12 15:41:27 -07:00
Rahul Joshi
2e8b539e71
[NFC][TableGen] Add {} for else when if body has {} (#139420) 2025-05-12 08:34:12 -07:00
Kazu Hirata
fda8b751bd
[llvm] Use llvm::copy_if (NFC) (#137480) 2025-04-26 18:17:56 -07:00
Craig Topper
9cf08b409c
[TableGen][SelectionDAG][GISel][RISCV] Support IsNonExtLoad for IsAtomic PatFrags. (#137401)
Use it for RISC-V as a demonstration. Other targets will follow.
2025-04-25 15:45:43 -07:00
Craig Topper
2ca071b1de
[TableGen][RISCV][AArch64][GISel] Properly implement 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-24 08:27:38 -07:00
Craig Topper
d43ce35048
[TableGen][GISel] Allow isTrivialOperatorNode to import patterns with isStore and a memory VT. (#137080)
This removes the need to explicitly set isTruncStore on truncstorei8 and
other similar PatFrags that include truncstore in their frags DAG.

This allows some new patterns to be imported for AMDGPU as you can see
in the changed test.

The extra isTruncStore were added in ae2b36e8bdfa6, along with some
other tablegen changes to look for MemoryVT along with isTruncStore. I
did not remove the code, because I'm not sure if any out of tree users
have become dependent on it. It's no longer exercised in tree.
2025-04-24 08:10:07 -07:00
chrisPyr
71f4c7dabe
[NFC]Make file-local cl::opt global variables static (#126486)
#125983
2025-03-03 13:46:33 +07:00
David Green
5a81a559d6
[GISel] Explicitly disable BF16 tablegen patterns. (#124113)
We currently have an issue where bf16 patters can be used to match fp16
types, as GISel does not know about the difference between the two. This
patch explicitly disables them to make sure that they are never used.

The opposite can also happen too, where fp16 patterns are used for
operators that should be bf16. So this also changes any operations with
bf16 types to now cause a fallback to SDAG.

The pass setup for GISel has been slightly adjusted to make sure that a
verify pass does not get added between AMD-SDAG and SIFixSGPRCopiesPass,
which otherwise can cause verifier issues when falling back.
2025-01-27 22:21:12 +00:00
Evgenii Kudriashov
a242880371
[TableGen][GlobalISel] Reorder atomic predicate to preserve the order (#121806)
Since there are no opcodes for atomic loads and stores comparing to
SelectionDAG, we add `CheckMMOIsNonAtomic` predicate immediately after
the opcode predicate to make a logical combination of them. Otherwise
when `IPM_AtomicOrderingMMO` is inserted after `IPM_GenericPredicate`,
the patterns without predicates get a higher priority as
`IPM_AtomicOrderingMMO` has higher priority than `IPM_GenericPredicate`.

This is important to preserve an order of aligned/unaligned patterns on
X86 because aligned memory operations have an additional alignment
predicate and should be checked first according to their placement in td
file.

Closes #121446
2025-01-16 17:06:21 +01:00
Kazu Hirata
618ac908db
[TableGen] Avoid repeated hash lookups (NFC) (#123018) 2025-01-15 07:57:30 -08:00
Evgenii Kudriashov
2bbdce9a42
[GlobalISel] Support physical register inputs in nested patterns (#121239)
When importing nested patterns, we create InsnMatcher for each pattern
and miss them if consider only the top level InsnMatcher. Iterate
PhysRegOperands instead.

Change the type of PhysRegOperands from DenseMap to SmallMapVector to
have stable generation. Also drop PhysRegInputs member from InsnMatcher
as there are no users of it.
2025-01-05 01:10:25 +01:00
Sergei Barannikov
c56b74315f
[TableGen][GISel] Reuse importNodeRenderer for OperandWithDefaultOps (#121285)
This avoids some code duplication (handling `Register`, `zero_reg` and
immediate operands).
2025-01-05 00:11:24 +03:00
Sergei Barannikov
6cbc64ed92
[TableGen][GISel] Fix IMPLICIT_DEF operand being added as a use (#121283)
`IMPLICIT_DEF` has one operand that is a def, not a use.
2024-12-29 16:29:55 +03:00
Sergei Barannikov
4a92c27f9d
[TableGen][GISel] Remove check for LLT when emitting renderers (#121144)
Types used in the destination DAG of a pattern should not matter for
GlobalISel. All necessary checks are emitted in the form of matchers
when traversing the source DAG.

In particular, the check prevented importing patterns containing iPTR in
the middle of the destination DAG.

This reduces the number of skipped patterns on Mips and RISCV:
```
Mips   1270  -> 1212  (-58)
RISCV 42165 -> 42088  (-77)
```

Most of these patterns are for atomic operations.
2024-12-26 17:45:29 +03:00
Sergei Barannikov
a0e1fcc093
[TableGen][GISel] Refactor node renderers emission (#121071)
Split importExplicitUseRenderer into several smaller functions and
add a bunch of TODOs and FIXMEs.

This is an NFCI change to simplify review of future functional changes.

Pull Request: https://github.com/llvm/llvm-project/pull/121071
2024-12-26 08:40:47 +03:00
Sergei Barannikov
6f72d28dd9
[TableGen][GISel] Don't copy dead def from a sub-instruction to the root (#121094)
Sub-instruction can have a def with the same name as a def in a
top-level instruction.
Previously this could result in both defs copied to the instruction
being built.
2024-12-26 08:36:35 +03:00
Sergei Barannikov
4884b1b08a
[TableGen][GISel] Simplify checks for BasicBlockSDNode (NFC) (#121098) 2024-12-25 13:32:02 +03:00
Sergei Barannikov
bda7aadfcd
[TableGen][GISel] Fix importing frameindex node (#120921)
The existing test case is not representative. Even though TableGen
doesn't complain, the code generated from it is invalid and fails
verification with the message "Use not jointly dominated by defs.".

There is no way to magically transform `frameindex` to `tframeindex`
as it happens for some other leaf nodes. `frameindex` can only be
selected by custom C++ code or by using an `SDNodeXForm`.

This patch makes the test representative one and fixes the handling of
`G_FRAME_INDEX`, which shouldn't have set the operand's name.

It also fixes the type of the result of `G_FRAME_INDEX` in order to get
the correct type check (`GIM_CheckPointerToAny` instead of
`GIM_CheckType` with a scalar LLT argument).
2024-12-23 11:04:40 +03:00
Sergei Barannikov
b2d7312d52
[TableGen][GISel] Add const to some member functions & reformat (NFC) (#120899)
Add const to `import*Renderer` member functions and recursively to
functions called from them.
I didn't do that for `import*Matcher` functions because they mutate
class variables.
2024-12-22 18:09:20 +03:00
Sergei Barannikov
a7cd660bd7
[TableGen][GISel] Learn to import patterns with optional defs (#120470)
The number of skipped patterns reduces for ARM from 4278 to 4257.
This is the only in-tree target that makes use of OptionalDefOperand.

Pull Request: https://github.com/llvm/llvm-project/pull/120470
2024-12-21 05:24:57 +03:00
Sergey Barannikov
44514316bd
[TableGen][GISel] Delete unused Src arguments (NFC) (#120445)
The last uses were removed in #120332 and #120426.

When emitting renderers, we shouldn't look at the source DAG at all. The
required information is provided by the destination DAG and by the
instructions referenced in that DAG. Sometimes, we do want to know if a
result was referenced in the source DAG; this can be checked by calling
`RuleMatcher::hasOperand`. Any other use of the source DAG when emitting
renderers is likely an error.

Pull Request: https://github.com/llvm/llvm-project/pull/120445
2024-12-21 03:16:17 +03:00
Sergei Barannikov
d3750412aa
[TableGen][GISel] Improve dead register handling (#120426)
A dead implicit def wasn't marked as dead if it is also an implicit use.
The new approach should also be more straightforward and simplifies
future changes for supporting optional defs and physical register defs.

Pull Request: https://github.com/llvm/llvm-project/pull/120426
2024-12-18 18:58:37 +03:00
Sergei Barannikov
1941f34172
[TableGen][GISel] Import more "multi-level" patterns (#120332)
Previously, if the destination DAG has an untyped leaf, we would import
the pattern only if that leaf is defined by the *top-level* source DAG.
This is an unnecessary restriction.

Here is an example of such pattern:
```
def : Pat<(add (mul v8i16:$vA, v8i16:$vB), v8i16:$vC),
          (VMLADDUHM $vA, $vB, $vC)>;
```

Previously, it failed to import because `add` doesn't define neither
`$vA` nor `$vB`.

This change reduces the number of skipped patterns as follows:

```
AArch64: 8695 ->  8548 (-147)
AMDGPU: 11333 -> 11240 (-93)
ARM:     4297 ->  4278 (-1)
PowerPC: 3955 ->  3010 (-945)
```

Other GISel-enabled targets are unaffected.
2024-12-18 14:44:55 +03:00
Sergei Barannikov
cf4375d107
[TableGen][GISel] Extract common function for determining MI's regclass (#120135)
Add some comments that hopefully clarify a few things.

This was supposed to be NFC, but there is a difference in the inferred
register class for EXTRACT_SUBREG.

Pull Request: https://github.com/llvm/llvm-project/pull/120135
2024-12-17 18:03:22 +03:00
Sergei Barannikov
73eecb70c2
[TableGen][GISel] Don't use std::optional with pointers (NFC) (#120026)
Pointers already have a well-defined null value.
2024-12-16 04:45:06 +03:00
Sergei Barannikov
d1f51c67fd
[TableGen] Add TreePatternNode::children and use it in for loops (NFC) (#119877) 2024-12-13 22:05:57 +03:00
Kazu Hirata
b9fb6b6cb5
[llvm] Migrate away from PointerUnion::{is,get,dyn_cast} (NFC) (#115681)
Note that PointerUnion::{is,get,dyn_cast} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>
2024-11-11 00:00:07 -08:00
Craig Topper
09b372aa60
[GISel][AArch64][RISCV] Allow G_SEXT_INREG patterns to be imported. (#115576)
SelectionDAG uses VTSDNode to store the extension type. GlobalISel uses
a literal constant operand.

For vectors, SelectionDAG uses a type with the same number of elements
as other operand of the sext_inreg. I assume for GISel we would just use
the scalar size.
2024-11-08 22:26:56 -08:00
Sergei Barannikov
3bdd71137e
[TableGen][GISel] Extract helper function for constraining operands (#115148)
As a side effect, this fixes COPY_TO_REGCLASS not being constrained
if it is not top-level (the reason for changes in tests).
2024-11-07 07:16:54 +03:00
Jerry Sun
00ca2071e0
[TableGen] [NFC] Remove unused includes in TableGen BE (#113725)
split PR as requested from
https://github.com/llvm/llvm-project/pull/113318.

Removes unused imports in TableGen BE
2024-10-28 20:26:10 -07:00
Rahul Joshi
62e2c7fb2d
[LLVM][TableGen] Change all Init pointers to const (#112705)
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-18 07:50:22 -07:00
JL2210
8f6d4913bb
[llvm][TableGen] Count implicit defs as well as explicit ones in the GlobalISel TableGen emitter (#112673)
`NumDefs` only counts the number of registers in `(outs)`, not any
implicit defs specified with `Defs = [...]`

This causes patterns with physical register defs to fail to import here
instead of later where implicit defs are rendered.

Add on `ImplicitDefs.size()` to count both and create `DstExpDefs` to
count only explicit defs, used later on.
2024-10-18 10:50:44 +01:00
Rahul Joshi
bfa8519bbb
[LLVM][TableGen] Change GlobalISelEmitter to use const RecordKeeper (#110109)
Change GlobalISelEmitter 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-30 06:37:36 -07:00
Rahul Joshi
3138eb500c
[LLVM][TableGen] Use const record pointers in TableGen/Common files (#109467)
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-23 13:07:31 -07:00
Rahul Joshi
23123aa4ec
[LLVM][TableGen] Change InstrInfoEmitter to use const RecordKeeper (#109189)
Change InstrInfoEmitter 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-18 22:27:26 -07:00
Rahul Joshi
3786568196
[TableGen] Change CodeGenInstruction record members to const (#107921)
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-11 08:52:26 -07:00
Rahul Joshi
bdf02249e7
[TableGen] Change CGIOperandList::OperandInfo::Rec to const pointer (#107858)
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-09 14:33:21 -07:00
Rahul Joshi
16df489fda
[TableGen] Add const variants of accessors for backend (#106658)
Split RecordKeeper `getAllDerivedDefinitions` family of functions into
two variants:
  (a) non-const ones that return vectors of `Record *` and 
  (b) const ones, that return vector/ArrayRef of `const Record *`.

This will help gradual migration of TableGen backends to use 
`const RecordKeeper` and by implication change code to work 
with const pointers and better const correctness.

Existing backends are not yet compatible with the const family of
functions, so change them to use a non-constant `RecordKeeper` 
reference, till they are migrated.
2024-09-05 18:35:55 -07:00
Pierre van Houtryve
972c02929b
[GlobalISel][TableGen] MIR Pattern Variadics (#100563)
Allow for matching & rewriting a variable number of arguments in an
instructions.

Solves #87459
2024-08-01 08:30:20 +02:00
Craig Topper
24f8d1009e [TableGen] Add an explicit cast to allow one TypeSetByHwMode constructor to be removed. NFC
This constructor was taking a ValueTypeByMode by value to create
an ArrayRef. By adding an explicit cast from ValueTypeByHwMode
to TypeSetByHwMode we allow the ArrayRef to be implicitly converted
from a single element.
2024-07-31 14:52:05 -07:00
Kazu Hirata
d9293519bc
[TableGen] Use llvm::unique (NFC) (#94163) 2024-06-02 11:52:12 -07:00
jofrn
d0dc29c208
[TableGen] HasOneUse builtin predicate on PatFrags (#91578)
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-05-20 06:18:49 -08:00
Pierre van Houtryve
7d81062352
[GlobalISel] Refactor Combiner MatchData & Apply C++ Code Handling (#92239)
Combiners that use C++ code in their "apply" pattern only use that. They
never mix it with MIR patterns as that has little added value.

This patch restricts C++ apply code so that if C++ is used, we cannot
use MIR patterns or builtins with it. Adding this restriction allows us
to merge calls to match and apply C++ code together, which in turns
makes it so we can just have MatchData variables on the stack.

So before, we would have
```
  GIM_CheckCxxInsnPredicate // match
  GIM_CheckCxxInsnPredicate // apply
  GIR_Done
```
Alongside a massive C++ struct holding the MatchData of all rules
possible (which was a big space/perf issue).

Now we just have
```
GIR_DoneWithCustomAction
```

And the function being ran just does
```
unsigned SomeMatchData;
if (match(SomeMatchData))
  apply(SomeMatchData)
```

This approach solves multiple issues in one:
- MatchData handling is greatly simplified and more efficient, "don't
pay for what you don't use"
  - We reduce the size of the match table
- Calling C++ code has a certain overhead (we need a switch), and this
overhead is only paid once now.

Handling of C++ code inside PatFrags is unchanged though, that still
emits a `GIM_CheckCxxInsnPredicate`. This is completely fine as they
can't use MatchDatas.
2024-05-16 13:39:00 +02:00
Kai Nacke
413f6b95a4
[TableGen][GISel][NFC] clang-tidy GlobalISelEmitter.cpp (#90492)
Fixes a couple of style issues, such as:

- unused includes
- variable naming
- `else if` after `return`
2024-04-29 14:47:46 -04:00