5550 Commits

Author SHA1 Message Date
Shengchen Kan
503e3a4130
[X86] Remove _REV instructions from the EVEX2VEX tables (#65752)
_REV instruction should not appear before encoding optimization, so
there is no chance to compress it during MIR optimizations.
2023-09-11 09:54:05 +08:00
Wang Pengcheng
2f780812ed
[TableGen] Add a field to filter out GenericTable entries (#65458)
A field `FilterClassField` is added to `GenericTable` class, which
is an optional bit field of `FilterClass`. If specified, only those
records with this field being true will have corresponding entries
in the table.
2023-09-08 16:27:11 +08:00
Phoebe Wang
2e44b07e24
[X86] Do not directly fold for VINSERTPS (#65718)
We have already customized folding for VINSERTPS by 7e6606f4f1, which do
the folding when alignment >= 4 bytes.

We cannot arbitrarily fold it like others because we need to calculate
the source offset.
2023-09-08 15:35:44 +08:00
pvanhout
844c0da777 [TableGen][GlobalISel] Add MIR Pattern Builtins
Adds a new feature to MIR patterns: builtin instructions.
They offer some additional capabilities that currently cannot be expressed without falling back to C++ code.
There are two builtins added with this patch, but more can be added later as new needs arise:
 - GIReplaceReg
 - GIEraseRoot

Depends on D158714, D158713

Reviewed By: arsenm, aemerson

Differential Revision: https://reviews.llvm.org/D158975
2023-09-05 08:19:07 +02:00
pvanhout
4e513f69a1 [GlobalISel] Cleanup Combine.td
Now that the old backend is gone, clean-up a few things that no longer make sense and tidy up the file a bit.

Depends on D158710

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D158714
2023-09-05 08:19:06 +02:00
pvanhout
aaf6755631 [GlobalISel] Refactor Combiner API
Remove CodeGen leftovers from the old combiner backend and adapt the API to fit the new backend better.
It's now quite a bit closer to how InstructionSelector works.

- `CombinerInfo` is now a simple "options" struct.
- `Combiner` is now the base class of all TableGen'd combiner implementation.
    - Many fields have been moved from derived classes into that class.
    - It has been refactored to create & own the Observer and Builder.
- `tryCombineAll` TableGen'd method can now be renamed, which allows targets to implement the actual `tryCombineAll` call manually and do whatever they want to do before/after it.

Note: `CombinerHelper` needs to be mutable because none of its methods are const. This can be revisited later.

Depends on D158710

Reviewed By: aemerson, dsanders

Differential Revision: https://reviews.llvm.org/D158713
2023-09-05 08:19:05 +02:00
Fangrui Song
111fcb0df0 [llvm] Fix duplicate word typos. NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 18:25:16 -07:00
Matt Arsenault
ad9d13d535 SelectionDAG: Swap operands of atomic_store
Irritatingly, atomic_store had operands in the opposite order from
regular store. This made it difficult to share patterns between
regular and atomic stores.

There was a previous incomplete attempt to move atomic_store into the
regular StoreSDNode which would be better.

I think it was a mistake for all atomicrmw to swap the operand order,
so maybe it's better to take this one step further.

https://reviews.llvm.org/D123143
2023-08-31 17:30:10 -04:00
pvanhout
54d0cf58fb [TableGen] Remove & Replace old GICombiner Backend
The MatchTable-based GlobalISel Combiner backend is the new default. There are no in-tree users left of the old backend.

- Removed implementation of old MatchDAG-based Combiner, including tests, the backend itself and all supporting code.
- Renamed MatchTable backend to `GlobalISelCombinerEmitter.cpp` + removed "-matchtable" from its CL option.
    - no need to have a verbose name as it's the only backend left now.

Reviewed By: aemerson

Differential Revision: https://reviews.llvm.org/D158710
2023-08-31 13:16:07 +02:00
Danila Kutenin
bf2f9d2b64 [TableGen] Make OpcodeMappings sort comparator strict weak ordering compliant
This did not satisfy equivalence of transitivity. There was an attempt
to fix it in https://reviews.llvm.org/D58687 but it was not fully
correct. Masks might not be equivalent but be equal according to LessThan lambda

Reviewed By: aeubanks, MaskRay

Differential Revision: https://reviews.llvm.org/D157955
2023-08-29 13:54:51 -07:00
Michael Maitland
85e3875ad7 [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics
D150312 added a TODO:

TODO: consider renaming the field `StartAtCycle` and `Cycles` to
`AcquireAtCycle` and `ReleaseAtCycle` respectively, to stress the
fact that resource allocation is now represented as an interval,
relatively to the issue cycle of the instruction.

This patch implements that TODO. This naming clarifies how to use these
fields in the scheduler. In addition it was confusing that `StartAtCycle` was
singular but `Cycles` was plural. This renaming fixes this inconsistency.

This commit as previously reverted since it missed renaming that came
down after rebasing. This version of the commit fixes those problems.

Differential Revision: https://reviews.llvm.org/D158568
2023-08-24 19:21:36 -07:00
Michael Maitland
71bfec762b Revert "[TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics"
This reverts commit 5b854f2c23ea1b000cb4cac4c0fea77326c03d43.

Build still failing.
2023-08-24 15:37:27 -07:00
Michael Maitland
5b854f2c23 [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics
D150312 added a TODO:

TODO: consider renaming the field `StartAtCycle` and `Cycles` to
`AcquireAtCycle` and `ReleaseAtCycle` respectively, to stress the
fact that resource allocation is now represented as an interval,
relatively to the issue cycle of the instruction.

This patch implements that TODO. This naming clarifies how to use these
fields in the scheduler. In addition it was confusing that `StartAtCycle` was
singular but `Cycles` was plural. This renaming fixes this inconsistency.

This commit as previously reverted since it missed renaming that came
down after rebasing. This version of the commit fixes those problems.

Differential Revision: https://reviews.llvm.org/D158568
2023-08-24 15:25:42 -07:00
Michael Maitland
4d27dffb43 Revert "[TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics"
This reverts commit 030d33409568b2f0ea61116e83fd40ca27ba33ac.

This commit is causing build failures
2023-08-24 11:58:53 -07:00
Michael Maitland
030d334095 [TableGen] Rename ResourceCycles and StartAtCycle to clarify semantics
D150312 added a TODO:

TODO: consider renaming the field `StartAtCycle` and `Cycles` to
`AcquireAtCycle` and `ReleaseAtCycle` respectively, to stress the
fact that resource allocation is now represented as an interval,
relatively to the issue cycle of the instruction.

This patch implements that TODO. This naming clarifies how to use these
fields in the scheduler. In addition it was confusing that `StartAtCycle` was
singular but `Cycles` was plural. This renaming fixes this inconsistency.

Differential Revision: https://reviews.llvm.org/D158568
2023-08-24 11:20:37 -07:00
pvanhout
0a59e1a85c [GlobalIsSel] Allow using PatFrags with multiple defs as the root of a combine rule
I had to tighten the restrictions on PatFrags a bit to make it consistent: instructions that
define the root of a PF can only have one def.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D157700
2023-08-24 09:09:24 +02:00
Craig Topper
8b82ae0b8d [GlobalISel][RISCV][TableGen] Teach GlobalISelEmitter about HwMode.
Similar to SelectionDAG, this patch treats HwMode as an additional
predicate that needs to be satisfied for GIM_CheckFeatures.

The existing predicate passes around Record * that point to predicate
records. While HwMode expansion creates a string that needs to be
checked.

Each HwMode predicate string is uniqued by a new map that assigns
it an index. Each Rule stores the index, or -1 if HwMode doesn't
apply.

The HwMode indices each create a new Predicate feature bit and the
check string from the HwMode is used to set the feature bit.
GIM_CheckFeatures is emitted when the rule has Predicates or the HwModeIdx
is not -1.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D158660
2023-08-23 21:14:16 -07:00
Craig Topper
e1a0e8258f [GlobalISel] Copy the implementation of SubtargetFeature and use it for PredicateBitset.
PredicateBitset currently uses std::bitset, but std::bitset doesn't
have a constexpr constructor or any constexpr methods until C++23.
Each target that supports GlobalIsel has as an array of PredicateBitset
objects that currently use a global constructor.

SubtargetFeature used by the MC layer for feature bits, has its own
implementation of std::bitset that has constexpr constructor and methods
that provides all the capabilities that PredicateBitset needs.

This patch copies the implementation from SubtargetFeature, makes
it a template class, and puts it in ADT. I'll migrate SubtargetFeature
in a separate patch. Adapting all existing users to it being a template
was distracting from the goal of this patch.

This reduces the binary size of llc built with gcc 8.5.0 on my local
build by ~15k.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D158576
2023-08-23 15:55:44 -07:00
Craig Topper
dc6e68a839 [TableGen] Add const to SubtargetFeatures reference in emitSubtargetFeatureBitEnumeration. NFC
emitSubtargetFeatureBitEnumeration doesn't modify the map so we should
use const reference.
2023-08-23 10:21:39 -07:00
Craig Topper
a886870bc8 [TableGen] Use std::map::try_emplace to simplify code in GlobalISelEmitter. NFC 2023-08-22 10:10:35 -07:00
Benjamin Kramer
a4202e65cf Move VTList pointer out of RegClassInfos
Store it in TargetRegisterInfo instead. Worth 54k on llc size.
2023-08-21 17:40:40 +02:00
Benjamin Kramer
11bbfa12bd Make global variable const. NFC. 2023-08-21 17:40:40 +02:00
Justin Bogner
dcb6d212fd Reapply "[Option] Add "Visibility" field and clone the OptTable APIs to use it"
This reverts commit 4e3b89483a6922d3f48670bb1c50a37f342918c6, with
fixes for places I'd missed updating in lld and lldb. I've also
renamed OptionVisibility::Default to "DefaultVis" to avoid ambiguity
since the undecorated name has to be available anywhere Options.inc is
included.

Original message follows:

This splits OptTable's "Flags" field into "Flags" and "Visibility",
updates the places where we instantiate Option tables, and adds
variants of the OptTable APIs that use Visibility mask instead of
Include/Exclude flags.

We need to do this to clean up a bunch of complexity in the clang
driver's option handling - there's a whole slew of flags like
CoreOption, NoDriverOption, and FlangOnlyOption there today to try to
handle all of the permutations of flags that the various drivers need,
but it really doesn't scale well, as can be seen by things like the
somewhat recently introduced CLDXCOption.

Instead, we'll provide an additive model for visibility that's
separate from the other flags. For things like "HelpHidden", which is
used as a "subtractive" modifier for option visibility, we leave that
in "Flags" and handle it as a special case.

Note that we don't actually update the users of the Include/Exclude
APIs here or change the flags that exist in clang at all - that will
come in a follow up that refactors clang's Options.td to use the
increased flexibility this change allows.

Differential Revision: https://reviews.llvm.org/D157149
2023-08-15 01:16:58 -07:00
Justin Bogner
4e3b89483a Revert "[Option] Add "Visibility" field and clone the OptTable APIs to use it"
this is failing on bots, reverting to investigate.

This reverts commit a16104e6da6f36f3d72dbf53d10ba56495a0d65a.
2023-08-14 13:31:02 -07:00
Justin Bogner
a16104e6da [Option] Add "Visibility" field and clone the OptTable APIs to use it
This splits OptTable's "Flags" field into "Flags" and "Visibility",
updates the places where we instantiate Option tables, and adds
variants of the OptTable APIs that use Visibility mask instead of
Include/Exclude flags.

We need to do this to clean up a bunch of complexity in the clang
driver's option handling - there's a whole slew of flags like
CoreOption, NoDriverOption, and FlangOnlyOption there today to try to
handle all of the permutations of flags that the various drivers need,
but it really doesn't scale well, as can be seen by things like the
somewhat recently introduced CLDXCOption.

Instead, we'll provide an additive model for visibility that's
separate from the other flags. For things like "HelpHidden", which is
used as a "subtractive" modifier for option visibility, we leave that
in "Flags" and handle it as a special case.

Note that we don't actually update the users of the Include/Exclude
APIs here or change the flags that exist in clang at all - that will
come in a follow up that refactors clang's Options.td to use the
increased flexibility this change allows.

Differential Revision: https://reviews.llvm.org/D157149
2023-08-14 13:24:54 -07:00
Jay Foad
6551cfa8eb [CodeGen] Set regunitmasks for leaf regs to all instead of none
This simplifies every use of MCRegUnitMaskIterator.

Differential Revision: https://reviews.llvm.org/D157864
2023-08-14 15:22:35 +01:00
Karl-Johan Karlsson
01dcad0406 [GlobalISel] Silence gcc warning [NFC]
Without the fix gcc complains with:
../utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp:251:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
2023-08-14 13:35:27 +02:00
pvanhout
3a1eefae4b [GlobalISel] Do not discard InstructionPattern::checkSemantics result 2023-08-11 11:09:54 +02:00
pvanhout
65336f8070 [GlobalISel] Fix use of std::vector with forward decl
Some implementations of the STL don't allow it.
2023-08-11 09:09:09 +02:00
pvanhout
63afb70503 [RFC][GlobalISel] Overhauled MIR Patterns Support for Combiners
See https://discourse.llvm.org/t/rfc-overhauled-mir-patterns-for-globalisel-combiners/72264

This is a complete overrhaul of the recently-added GlobalISel Match Table backend which adds
support for MIR patterns for both match and apply patterns.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D156315
2023-08-11 08:54:56 +02:00
pvanhout
490a867f16 [GlobalISel] Also set dead flags of implicit defs added by BuildMI
BuildMI automatically adds the implicit operands of the
instruction. This meant we couldn''t set the dead flag on
dead implicit defs in that case.

Fix it by introducing an opcode to mark a given implicit
def as dead.

Fixes #64565

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D157515
2023-08-11 08:38:37 +02:00
Jon Roelofs
25e2b4aa1e
Revert "Revert "cmake: add missing dependencies on Attributes.inc""
This reverts commit d462f65b8242a82d2430605a741825bf10ebaca0.

It breaks the modules build again, but also may inhibit the use of `-DLLVM_TABLEGEN=`.

See the discussion here: https://reviews.llvm.org/D150144#4578311

rdar://113696899
2023-08-10 14:54:22 -07:00
Jon Roelofs
d462f65b82
Revert "cmake: add missing dependencies on Attributes.inc"
This reverts commit 30b4351c7c75296dc60fc887212cdc98e85e9996.

This caused a dependency cycle that the Swift build picked up on:

```
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
  "llvm-tblgen" of type EXECUTABLE
    depends on "LLVMCodeGenTypes" (weak)
    depends on "LLVMTableGenGlobalISel" (weak)
    depends on "intrinsics_gen" (strong)
  "LLVMTableGenGlobalISel" of type STATIC_LIBRARY
    depends on "LLVMCodeGenTypes" (weak)
    depends on "vt_gen" (strong)
  "vt_gen" of type UTILITY
    depends on "llvm-tblgen" (strong)
  "autogen_intrinsics_RISCV" of type UTILITY
    depends on "llvm-tblgen" (strong)
  "intrinsics_gen" of type UTILITY
    depends on "llvm-tblgen" (strong)
    depends on "autogen_intrinsics_RISCV" (strong)
  "LLVMCodeGenTypes" of type STATIC_LIBRARY
    depends on "vt_gen" (strong)
```

rdar://113636528
2023-08-09 10:45:11 -07:00
Jan Svoboda
501f92d343 [llvm] Construct option's prefixed name at compile-time
Some Clang command-line handling code could benefit from the option's prefixed name being a `StringLiteral`. This patch changes the `llvm::opt` TableGen backend to generate and emit that into the .inc file.

Depends on D157028.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D157029
2023-08-09 09:52:34 -07:00
pvanhout
c3cfbbc416 [GlobalISel] Add dead flags to implicit defs in ISel
Checks for implicit defs that are unused within a pattern and mark them as dead.

This is done directly at the TableGen level forr efficiency.
The instructions are directly created with the "dead" operand and no further analysis is needed later.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D157273
2023-08-09 14:20:51 +02:00
Craig Topper
a3a7e76893 [SelectionDAG] Add Opc_CheckPatternPredicate2 to support targets with more than 256 predicates.
This is an alternative to D156967 where I suggested the author
could use a VBR type.

This patch takes inspirations from Opc_EmitRegister2 that is used
for two byte registers.

I'm assuming 1 or 2 byte predicates should be enough so we don't
need the fully generality of VBR.

This avoids impacting the table size on targets that have more than
128 predicates already like X86.

Reviewed By: bogner

Differential Revision: https://reviews.llvm.org/D157196
2023-08-05 16:59:45 -07:00
pvanhout
2532b68f68 [TableGen] Do not compile CombineRuleBuilder::verify in release builds
Avoids a warning about the function being unused.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D157085
2023-08-04 13:59:53 +02:00
David Spickett
5850124ffd [LLVM][TableGen][Jupyter] Add first tutorial notebook
This first notebook covers the basics.
* classes
* defs
* basic types
* let in various forms

Everything up to multiclass, which will be the
start of the 2nd part of the tutorial.

I'd like to keep them in logical sections as
far as possible, so they are easy to digest.

Differential Revision: https://reviews.llvm.org/D137085
2023-08-04 11:22:19 +01:00
David Spickett
fbec83cbe3 [llvm][TableGen][Jupyter] Add configurable default reset behaviour
Often you are doing one of 2 things:
* Building a larger example from many small cells.
* Showing many small isolated examples.

The default so far has followed iPython, where cells are connected
by default (in its case, the interpreter state backing them sticks
around).

This change adds a new magic `%config` where you can change the setting
`cellreset` to change that behaviour (this is currently the only setting).

Also added is a `%noreset` magic so that along with `%reset` you can
override the default for one particular cell.

The default is equivalent to `%config cellreset off`. If you then
wanted to reset in a cell, you can just do %reset to override it.

(this is what the current notebooks do)

If you instead do `%config cellreset on`, cells always reset and
you can choose not to using `%noreset`.

The setting is named `cellreset` not `reset` to differentiate it
a bit more from the one off command `reset`.

The demo notebook has been updated with examples of this in action.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D149055
2023-08-04 11:16:43 +01:00
Ivan Kosarev
4e814b10ec [TableGen][NFC] Refine obtaining qualified register class ids.
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D156110
2023-08-03 11:07:57 +01:00
Pavel Kosov
37ef640785 [llvm-exegesis] Prevent llvm-exegesis from using unsupported opcodes
When generating snippets for AArch64 with --opcode-index=-1, the code
generator asserts on opcodes that are not supported according to CPU
features.

The same assertion can be triggered even when generating a serial
snippet for a supported opcode if SERIAL_VIA_NON_MEMORY_INSTR execution
mode is used and an unsupported instruction is chosen as the "other
instruction". Unlike the first case, this one may result in flaky
failures because the other instruction is randomly chosen from the
instructions suitable for serializing execution.

This patch adjusts TableGen emitter for *GenInstrInfo.inc to make
possible to query for opcode availability instead of just asserting on
unsupported ones.

~~

Huawei RRI, OS Lab

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D146303
2023-08-02 15:44:14 +03:00
Sameer Sahasrabuddhe
d9847cde48 [GlobalISel] convergent intrinsics
Introduced the convergent equivalent of the existing G_INTRINSIC opcodes:

- G_INTRINSIC_CONVERGENT
- G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS

Out of the targets that currently have some support for GlobalISel, the patch
assumes that the convergent intrinsics only relevant to SPIRV and AMDGPU.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D154766
2023-07-31 12:15:39 +05:30
Ivan Kosarev
5775db2e7b [TableGen][RegisterInfoEmitter] Make entries of base register class tables human-readable.
Helps tracking changes in the tables on adding new register classes and
updating BaseClassOrder values.

Also eliminates tables translating base register class indexes into
TargetRegisterClass pointers.

Reviewed By: critson

Differential Revision: https://reviews.llvm.org/D156097
2023-07-27 10:42:21 +01:00
pvanhout
fc12fd71cf [TableGen][GlobalISel] Fix unused variable warnings
Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D156208
2023-07-26 09:12:05 +02:00
pvanhout
32e7d42a5f [TableGen][GlobalISel] Fix warning when casting to void * 2023-07-24 10:28:39 +02:00
pvanhout
d7c6d057ef [TableGen][GlobalISel] Guarantee stable iteration order for stop-after-parse
Builds on top of 6de2735c2428 to fix remaining issues with iteration order in the MatchTable Combiner backend.
See D155789 as well.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D155821
2023-07-24 09:10:50 +02:00
Ilya Leoshkevich
c05eff2f92 [TableGen][CodeEmitterGen] Avoid empty OpNum switches in getOperandBitOffset()
getOperandBitOffset() causes the following warning on MSVC:

	E:\llvm\ninja\lib\Target\SystemZ\SystemZGenMCCodeEmitter.inc(15414): warning C4060: switch statement contains no 'case' or 'default' labels

Do not emit empty OpNum switches.

Reviewed By: RKSimon, uweigand

Differential Revision: https://reviews.llvm.org/D155805
2023-07-20 13:28:35 +02:00
Ilya Leoshkevich
8b655e1f0a [TableGen][CodeEmitterGen] Add support for querying operand bit offsets
In order to generate relocations or to apply fixups after the layout
has been computed, the targets need to know the offsets of the
respective operands. There are indirect ways to figure them out in some
cases, for example, on SystemZ, the first memory operand is always at
offset 2, and the second one is always at offset 4. But there are no
such tricks for the immediate operands on SystemZ, so one has to refer
to individual instruction encodings.

This information, however, is available to TableGen. Generate
the getOperandBitOffset() method to access it, and use it to simplify
getting memory operand offsets on SystemZ. This also paves the way for
implementing symbolic immediates on this platform.

For the multi-lit operands, getOperandBitOffset() returns the offset of
the first lit.

An alternative way to obtain offsets would be to pass them to the
encoder methods, but this would require reworking all targets. Also,
VarLenCodeEmitter already does this, but adopting it requires
reworking the respective targets without other significant benefits.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155329
2023-07-20 10:10:45 +02:00
Fangrui Song
6de2735c24 [TableGen][GlobalISel] Use MapVector to stabilize iteration order after D153757
StringMap iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).
2023-07-19 21:21:26 -07:00
pvanhout
b50fe313e8 [TableGen] Deprecate old GI Combiner Emitter
Will be removed in a month or so.

Reviewed By: aemerson

Differential Revision: https://reviews.llvm.org/D154939
2023-07-19 13:17:02 +02:00