6067 Commits

Author SHA1 Message Date
Kazu Hirata
76af93fbea Partially revert "[TableGen] Avoid repeated hash lookups (NFC) (#122586)"
This partially reverts commit 07ff786e39e2190449998d3af1000454dee501be.

The hunk being reverted in this patch seems to break:

  tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml

under LLVM_ENABLE_EXPENSIVE_CHECKS.
2025-01-12 23:50:58 -08:00
Kazu Hirata
07ff786e39
[TableGen] Avoid repeated hash lookups (NFC) (#122586) 2025-01-11 13:15:30 -08:00
Justin Bogner
cba9bd5cb0
[DirectX] Implement the resource.load.rawbuffer intrinsic (#121012)
This introduces `@llvm.dx.resource.load.rawbuffer` and generalizes the
buffer load docs under DirectX/DXILResources.

This resolves the "load" parts of #106188
2025-01-08 16:56:05 -08:00
Alexandros Lamprineas
8e65940161
[FMV][AArch64] Simplify version selection according to ACLE. (#121921)
Currently, the more features a version has, the higher its priority is.
We are changing ACLE https://github.com/ARM-software/acle/pull/370 as
follows:

"Among any two versions, the higher priority version is determined by
 identifying the highest priority feature that is specified in exactly
 one of the versions, and selecting that version."
2025-01-08 18:59:07 +00: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
Michael Kruse
27f3002974 [llvm-(min-)tblgen] Avoid redundant source compilation (#114494)
All the sources of `llvm-min-tblgen` are also used for `llvm-tblgen`,
with identical compilation flags. Reuse the object files of
`llvm-min-tblgen` for `llvm-tblgen` by applying the usual source
structure of an executable: One file per executable which named after
the executable name containing the (in this case trivial) main function,
which just calls the tblgen_main in TableGen.cpp. This should also clear
up any confusion (including mine) of where each executable's main
function is.

While this slightly reduces build time, the main motivation is ccache.
Using the hard_link
option, building the object files for `llvm-tblgen` will result in a
hard link to the same object file already used for `llvm-min-tblgen`. To
signal the build system that the file is new, ccache will update the
file's time stamp. Unfortunately, time stamps are shared between all
hard-linked files s.t. this will indirectly also update the time stamps
for the object files used for `llvm-tblgen`. At the next run, Ninja will
recognize this time stamp discrepancy to the expected stamp recorded in
`.ninja_log` and rebuild those object files for `llvm-min-tblgen`, which
again will also update the stamp for the `llvm-tblgen`... . This is
especially annoying for tablegen because it means Ninja will re-run all
tablegenning in every build.

I am using the hard_link option because it reduces the cost of having
multiple build-trees of the LLVM sources and reduces the wear to the SSD
they are stored on.
2025-01-03 09:41:57 +01:00
Michael Kruse
06b6161d3f Revert "[llvm-(min-)tblgen] Avoid redundant source compilation (#114494)"
This reverts commit f6cb56902c6dcafede21eb6662910b6ff661fc0f.

Buildbot failures such as https://lab.llvm.org/buildbot/#/builders/89/builds/13541:
```
/usr/bin/ld: utils/TableGen/Basic/CMakeFiles/obj.LLVMTableGenBasic.dir/ARMTargetDefEmitter.cpp.o: undefined reference to symbol '_ZN4llvm23EnableABIBreakingChecksE'
/usr/bin/ld: /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/./lib/libLLVMSupport.so.20.0git: error adding symbols: DSO missing from command line
```

Going to investigate.
2025-01-02 23:28:17 +01:00
Michael Kruse
f6cb56902c
[llvm-(min-)tblgen] Avoid redundant source compilation (#114494)
All the sources of `llvm-min-tblgen` are also used for `llvm-tblgen`,
with identical compilation flags. Reuse the object files of
`llvm-min-tblgen` for `llvm-tblgen` by applying the usual source
structure of an executable: One file per executable which named after
the executable name containing the (in this case trivial) main function,
which just calls the tblgen_main in TableGen.cpp. This should also clear
up any confusion (including mine) of where each executable's main
function is.

While this slightly reduces build time, the main motivation is ccache.
Using the hard_link
option, building the object files for `llvm-tblgen` will result in a
hard link to the same object file already used for `llvm-min-tblgen`. To
signal the build system that the file is new, ccache will update the
file's time stamp. Unfortunately, time stamps are shared between all
hard-linked files s.t. this will indirectly also update the time stamps
for the object files used for `llvm-tblgen`. At the next run, Ninja will
recognize this time stamp discrepancy to the expected stamp recorded in
`.ninja_log` and rebuild those object files for `llvm-min-tblgen`, which
again will also update the stamp for the `llvm-tblgen`... . This is
especially annoying for tablegen because it means Ninja will re-run all
tablegenning in every build.

I am using the hard_link option because it reduces the cost of having
multiple build-trees of the LLVM sources and reduces the wear to the SSD
they are stored on.
2025-01-02 23:22:20 +01: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
Kazu Hirata
b0e43f815a
[TableGen] Avoid repeated hash lookups (NFC) (#120873) 2024-12-22 01:30:27 -08: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
Kazu Hirata
0575815b70
[TableGen] Avoid repeated hash lookups (NFC) (#120681) 2024-12-20 10:28:58 -08:00
Kazu Hirata
5b5b241edf
[TableGen] Avoid repeated hash lookups (NFC) (#120619) 2024-12-19 13:02:55 -08:00
Kazu Hirata
b0a4b5b35a
[TableGen] Avoid repeated hash lookups (NFC) (#120532) 2024-12-19 08:00:02 -08: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
97c3c32372
[TableGen][SystemZ] Correctly check the range of a leaf immediate (#119931)
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-14 13:58:23 +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
Sergei Barannikov
c9070cce09
[TableGen] Allow empty terminator in SequenceToOffsetTable (#119751)
Some clients do not want to emit a terminator after each sub-sequence
(they have other means of determining the length of sub-sequences).

This moves `Term` argument from `emit` method to the constructor and
makes it optional. It couldn't be made optional while still on the
`emit` method because if the terminator wasn't specified, it has to be
taken into account in `layout` method as well.

The fact that `layout` method was called is now recorded in a dedicated
member variable, `IsLaidOut`. `Entries != 0` can no longer be used to
reliably check if `layout` method was called because it may be zero for
a different reason: the terminator wasn't specified and all added
sequences (if any) were empty.

This reduces the size of `*LaneMaskLists` and `*SubRegIdxLists` a bit
and resolves the removed TODO.
2024-12-13 19:55:11 +03:00
Chandler Carruth
dd647e3e60
Rework the Option library to reduce dynamic relocations (#119198)
Apologies for the large change, I looked for ways to break this up and
all of the ones I saw added real complexity. This change focuses on the
option's prefixed names and the array of prefixes. These are present in
every option and the dominant source of dynamic relocations for PIE or
PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of
them for the Clang driver which has a huge number of options.

This PR addresses this by building a string table and a prefixes table
that can be referenced with indices rather than pointers that require
dynamic relocations. This removes almost 7k dynmaic relocations from the
`clang` binary, roughly 8% of the remaining dynmaic relocations outside
of vtables. For busy-boxing use cases where many different option tables
are linked into the same binary, the savings add up a bit more.

The string table is a straightforward mechanism, but the prefixes
required some subtlety. They are encoded in a Pascal-string fashion with
a size followed by a sequence of offsets. This works relatively well for
the small realistic prefixes arrays in use.

Lots of code has to change in order to land this though: both all the
option library code has to be updated to use the string table and
prefixes table, and all the users of the options library have to be
updated to correctly instantiate the objects.

Some follow-up patches in the works to provide an abstraction for this
style of code, and to start using the same technique for some of the
other strings here now that the infrastructure is in place.
2024-12-11 15:44:44 -08:00
Sergei Barannikov
6b2232606d
[TableGen] Replace WantRoot/WantParent SDNode properties with flags (#119599)
These properties are only valid on ComplexPatterns. Having them as flags
is more convenient because one can now use "let = ... in" syntax to set
these flags on several patterns at a time. This is also less error-prone
as it makes it impossible to specify these properties on records derived
from SDPatternOperator.

Pull Request: https://github.com/llvm/llvm-project/pull/119599
2024-12-12 00:41:44 +03:00
Owen Anderson
6f3f08abdc
CodeGen: Eliminate dynamic relocations in the register superclass tables. (#119487)
This reapplies #119122 with a fix for UBSAN errors in the X86 backend
related
to incrementing a nullptr.
2024-12-12 10:17:32 +13:00
Owen Anderson
e940353fd2 Revert "CodeGen: Eliminate dynamic relocations in the register superclass tables. (#119122)"
Reverting due to UBSan failures in X86RegisterInfo::getLargestLegalSuperClass

This reverts commit c4873819a98f59ce4e2664f94c73c2dfec3393f8.
2024-12-11 13:45:17 +13:00
Owen Anderson
c4873819a9
CodeGen: Eliminate dynamic relocations in the register superclass tables. (#119122) 2024-12-11 12:36:51 +13:00
Jon Roelofs
b6c22a4e58
Add processor aliases back to -print-supported-cpus and -mcpu=help (#118581)
They were accidentally dropped in
https://github.com/llvm/llvm-project/pull/96249

rdar://140853882
2024-12-09 09:18:31 -08:00
Chandler Carruth
f0297ae552
Switch the intrinsic names to a string table (#118929)
This avoids the need to dynamically relocate each pointer in the table.

To make this work, this PR also moves the binary search of intrinsic
names to an internal function with an adjusted signature, and switches
the unittesting to test against actual intrinsics.
2024-12-07 17:53:59 -08:00
Sam Elliott
73731d6873
[llvm-tblgen] Increase Coverage Index Size (#118329) 2024-12-04 09:19:13 +00:00
Mason Remy
0c6457b781
[LLVM][TableGen] Refine overloaded intrinsic suffix check (#117957)
Previously the check comments indicated that [pi][0-9]+ would match as a
type suffix, however the check itself was looking for [pi][0-9]* and
hence an 'i' suffix in isolation was being considered as a type suffix
despite it not having a bitwidth.

This change makes the check consistent with the comment and looks for
[pi][0-9]+
2024-12-03 13:33:15 -05:00
Adam Yang
0a44b24d66
[DXIL] Add GroupMemoryBarrierWithGroupSync intrinsic (#114349)
fixes #112974
partially fixes #70103

An earlier version of this change was reverted so some issues could be fixed.

### Changes
- Added new tablegen based way of lowering dx intrinsics to DXIL ops.
- Added int_dx_group_memory_barrier_with_group_sync intrinsic in
IntrinsicsDirectX.td
- Added expansion for int_dx_group_memory_barrier_with_group_sync in
DXILIntrinsicExpansion.cpp`
- Added DXIL backend test case

### Related PRs
* [[clang][HLSL] Add GroupMemoryBarrierWithGroupSync intrinsic
#111883](https://github.com/llvm/llvm-project/pull/111883)
* [[SPIRV] Add GroupMemoryBarrierWithGroupSync intrinsic
#111888](https://github.com/llvm/llvm-project/pull/111888)
2024-12-01 22:31:40 -08:00
Jinsong Ji
2e30df740e
[TableGen] Fix validateOperandClass for non Phyical Reg (#118146)
https://github.com/llvm/llvm-project/commit/b71704436e61
Rewrote the register operands handling,
but the Table only contains physical regs, we will SEGV when there are
non physical regs.

---------

Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
2024-11-30 12:07:15 -05:00
Jay Foad
89b08c8ee7
[TableGen] Simplify generated code for isSubclass (#117351)
Implement isSubclass with direct lookup into some tables instead of
nested switches.

Part of the motivation for this is improving compile time when clang-18
is used as a host compiler, since it seems to have trouble with very
large switch statements.
2024-11-28 08:52:02 +00:00
Jay Foad
b71704436e
[TableGen] Simplify generated code for validateOperandClass (#117889)
Implement the register operand handling in validateOperandClass with a
table lookup instead of a potentially huge switch.

Part of the motivation for this is improving compile time when clang-18
is used as a host compiler, since it seems to have trouble with very
large switch statements.
2024-11-27 16:49:35 +00:00
Sander de Smalen
318c69de52 Reland "[AArch64] Define high bits of FPR and GPR registers (take 2) (#114827)"
The issue with slow compile-time was caused by an assert in
AArch64RegisterInfo.cpp. The assert invokes 'checkAllSuperRegsMarked'
after adding all the reserved registers. This call gets very expensive
after adding the _HI registers due to the way the function searches
in the 'Exception' list, which is expected to be a small list but isn't
(the patch added 190 _HI regs).

It was possible to rewrite the code in such a way that the _HI registers
are marked as reserved after the check. This makes the problem go away
entirely and restores compile-time to what it was before (tested for
`check-runtimes`, which previously showed a ~5x slowdown).

This reverts commits:
  1434d2ab215e3ea9c5f34689d056edd3d4423a78
  2704647fb7986673b89cef1def729e3b022e2607
2024-11-27 13:31:59 +00:00
Jay Foad
535247841d
[TableGen] Remove comments from generated validateOperandClass (#117352)
This generated comments like:

  // 'BoolReg' class
  case MCK_BoolReg: {

which seem redundant because the name is always repeated on the next
line as part of the MCK_ enumerator.
2024-11-25 12:11:01 +00:00
Vitaly Buka
1434d2ab21
Revert "[AArch64] Define high bits of FPR and GPR registers (take 2) (#114827)" (#117307)
Details in #114827

This reverts commit c1c68baf7e0fcaef1f4ee86b527210f1391b55f6.
2024-11-22 11:48:25 -08:00
Simon Pilgrim
29f11f0a32
[X86] Add missing reg/imm attributes to VRNDSCALES instruction names (#117203)
More canonicalization of the instruction names to make the predictable - more closely matches VRNDSCALEP / VROUND equivalent instructions
2024-11-22 17:45:30 +00:00
Jay Foad
285754d799 [TableGen] Fix closing brace indentation in validateOperandClass 2024-11-22 17:42:39 +00:00
Pengcheng Wang
4da960b898 [RISCV] Add mvendorid/marchid/mimpid to CPU definitions (#116202)
We can get these information via `sys_riscv_hwprobe`.

This can be used to implement `__builtin_cpu_is`.
2024-11-22 22:58:54 +08:00
Mikhail Goncharov
d1dae1e861 Revert "[RISCV] Add mvendorid/marchid/mimpid to CPU definitions (#116202)" chain
This reverts commit b36fcf4f493ad9d30455e178076d91be99f3a7d8.
This reverts commit c11b6b1b8af7454b35eef342162dc2cddf54b4de.
This reverts commit 775148f2367600f90d28684549865ee9ea2f11be.

multiple bot build breakages, e.g. https://lab.llvm.org/buildbot/#/builders/3/builds/8076
2024-11-22 14:09:13 +01:00
Pengcheng Wang
775148f236
[RISCV] Add mvendorid/marchid/mimpid to CPU definitions (#116202)
We can get these information via `sys_riscv_hwprobe`.

This can be used to implement `__builtin_cpu_is`.
2024-11-22 19:54:45 +08:00