Commit Graph

5623 Commits

Author SHA1 Message Date
Kazu Hirata
1daf2994de [llvm] Use StringRef::contains (NFC) 2023-12-23 22:21:52 -08:00
Lucas Duarte Prates
b652674dd0 [AsmWriter] Ensure getMnemonic doesn't return invalid pointers (#75783)
For instructions that don't map to a mnemonic string, the implementation
of MCInstPrinter::getMnemonic would return an invalid pointer due to the
result of the calculation of the instruction's position in the `AsmStrs`
table. This patch fixes the issue by ensuring those cases return a
`nullptr` value instead.

Fixes #74177.
2023-12-20 10:09:29 +00:00
XinWang10
037c220702 [X86][MC] Support Enc/Dec for EGPR for promoted SHA instruction (#75582)
R16-R31 was added into GPRs in
https://github.com/llvm/llvm-project/pull/70958,
This patch supports the encoding/decoding for promoted SHA instruction
in EVEX space.

RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
2023-12-20 13:54:50 +08:00
Wang Pengcheng
9348d437f5 [SelectionDAG] Add space-optimized forms of OPC_EmitRegister (#73291)
The followed byte of `OPC_EmitRegister` is a MVT type, which is
usually i32 or i64.

We add `OPC_EmitRegisterI32` and `OPC_EmitRegisterI64` so that we
can reduce one byte.

Overall this reduces the llc binary size with all in-tree targets by
about 10K.
2023-12-19 17:31:49 +08:00
Michael Liao
33d5f4314f [TableGen] AsmParser: Keep consistent naming. NFC 2023-12-18 16:08:43 -05:00
darkbuck
d14ee76181 [GISel][TableGen] Enhance default ops support (#75689)
- Instead of checking the default ops directly, this change queries DAG
default operands collected during patterns reading. It does not only
simplify the code but also handle few cases where integer values are
converted from convertible types, such as 'bits'.
- A test case is added GlobalISelEmitter.td as the regression test of
default 'bits' values.
2023-12-17 15:02:10 -05:00
XinWang10
295415e720 [X86][MC] Support Enc/Dec for EGPR for promoted MOVDIR instruction (#74713)
R16-R31 was added into GPRs in
https://github.com/llvm/llvm-project/pull/70958,
This patch supports the encoding/decoding for promoted MOVDIR
instruction in EVEX space.

RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
2023-12-15 16:03:17 +08:00
Simon Pilgrim
bcee4a9363 [X86] Rename VPERMI2/VPERMT2 to VPERMI2*Z/VPERMT2*Z (#75192)
Add missing AVX512 Z prefix to conform to the standard naming convention and simplify matching in X86FoldTablesEmitter::addBroadcastEntry etc.
2023-12-14 09:55:18 +00:00
David Spickett
1e53386690 [llvm][TableGen][Docs] Add tools/resources links
This adds a link from the main docs page back to the README where
I have previously added a list of useful resources.

To that list, I've added a link to my recent llvm blog post.
2023-12-13 09:53:03 +00:00
Pierre van Houtryve
a160536f8d [TableGen][GlobalISel] Add specialized opcodes (#74823)
Most users of AddImm and CheckConstantInt only use 1 byte immediates, so
I added an opcode variants for those. That way all those instructions
save 7 bytes.
Also added an opcode for AddTempRegister for the cases where there are
no register flags.

Space savings:
    - AMDGPUGenGlobalISel: 470180 bytes to 422564 (-10%)
    - AArch64GenGlobalISel.inc: 383893 bytes to 374046
2023-12-13 09:09:32 +01:00
Pierre van Houtryve
a110e991c6 [GlobalISel] Change MatchTable entries to 1 byte each (#74429)
See
https://discourse.llvm.org/t/rfc-make-globalisel-match-table-entries-1-byte-instead-of-8/75411

This helps reduce llc's binary size, at the cost of some added
complexity to the MatchTable machinery.
2023-12-13 08:48:56 +01:00
Wang Pengcheng
97181bf9a0 [TableGen] Use getSizeInBits (#75157)
We know the type is scalar type.
2023-12-12 20:40:20 +08:00
wangpc
bbc7f09959 [TableGen][NFC] Remove leading spaces 2023-12-12 18:17:13 +08:00
wangpc
0c2a3d6033 [TableGen][NFC] Format parts of DAGISelMatcher.h/DAGISelMatcherGen.cpp
To reduce the diff in #73310
2023-12-12 18:11:38 +08:00
Wang Pengcheng
714417455d [SelectionDAG] Add OPC_MoveSibling (#73643)
There are a lot of operations to move current node to parent and
then move to another child.

So `OPC_MoveSibling` and its space-optimized forms are added to do
this "move to sibling" operations.

These new operations will be generated when optimizing matcher in
`ContractNodes`. Currently `MoveParent+MoveChild` will be optimized
to `MoveSibling` and sequences `MoveParent+RecordChild+MoveChild`
will be transformed into `MoveSibling+RecordNode`.

Overall this reduces the llc binary size with all in-tree targets by
about 30K.
2023-12-12 17:48:45 +08:00
Wang Pengcheng
0d5f1cc4d0 [SelectionDAG] Add space-optimized forms of OPC_EmitNode/OPC_MorphNodeTo (#73502)
If there is only one bit set in EmitNodeInfo, then we can encode it
implicitly to save one byte.

Overall this reduces the llc binary size with all in-tree targets by
about 168K.
2023-12-12 17:45:32 +08:00
Wang Pengcheng
6111f5c592 [SelectionDAG] Add instantiated OPC_CheckChildType (#73297)
The most common type is i32 or i64 so we add `OPC_CheckChildTypeI32`
and `OPC_CheckChildTypeI64` to save one byte.

Overall this reduces the llc binary size with all in-tree targets by
about 70K.
2023-12-12 17:31:12 +08:00
Wang Pengcheng
cbf1d58820 [SelectionDAG] Add space-optimized forms of OPC_EmitCopyToReg (#73293)
These new opcodes implicitly indicate the RecNo.

The old `OPC_EmitCopyToReg2` is renamed to `OPC_EmitCopyToRegTwoByte`.

Overall this reduces the llc binary size with all in-tree targets by
about 33K (most are from RISCV target).
2023-12-12 17:25:33 +08:00
Wang Pengcheng
50c174f99f [SelectionDAG] Add space-optimized forms of OPC_EmitConvertToTarget (#73286)
These new opcodes implicitly indicate the RecNo.

Overall this reduces the llc binary size with all in-tree targets by
about 13K.
2023-12-12 17:13:43 +08:00
Wang Pengcheng
e052c68869 [SelectionDAG] Add instantiated OPC_CheckType (#73283)
The most common type is i32 or i64 so we add `OPC_CheckTypeI32` and
`OPC_CheckTypeI64` to save one byte.

Overall this reduces the llc binary size with all in-tree targets by
about 29K.
2023-12-12 17:12:08 +08:00
Anatoly Trosinenko
78623b079b [GISel][TableGen] Fix accidental operand name clashes in patterns (#74492)
When importing instruction selection patterns into GlobalISel, the
operands matched in the "source" DAG are copied into corresponding
operands of the "destination" DAG according to their names (such as Rd).
If multiple operands in the source DAG share the same name, a
GIM_CheckIsSameOperand predicate makes instruction selector check the
corresponding operands for equality (at compiler run-time) as part of
matching the source pattern.

The Def operands of the root node of the destination DAG are handled
specially. The operands of the instruction corresponding to the root
node are taken and GIM_CheckRegBankForClass predicates are
tablegen-erated accordingly. If by coincidence the Def operand in
question has the same name as one of the named operands in the pattern,
a GIM_CheckIsSameOperand predicate is automatically added that is likely
to prevent matching the source of otherwise applicable selection pattern
at compiler run-time.

This patch mangles the Def operand names taken from the instruction
corresponding to the root of the destination DAG (for example, "Rd"
becomes "DstI[Rd]") preventing unexpected name clashes with pattern's
named operands.

The patch consists of three sets of changes:
* changes to the GlobalISelEmitter.cpp file are the actual fix
* a test case is added to GlobalISelEmitter.td file as a regression test
* everything else is the biggest and least interesting part - updates to
  the existing test cases: renames of the form Rd -> DstI[Rd] inside the
  inline comments in tablegen-erated code
2023-12-10 13:25:11 +03:00
Kazu Hirata
dc1f208346 [TableGen] Remove unnecessary includes (NFC)
Identified with clangd.
2023-12-07 21:03:55 -08:00
Shengchen Kan
f17e766972 [X86][NFC] Clang-format X86DisassemblerTables.cpp for #74713 2023-12-07 20:59:21 +08:00
Pierre van Houtryve
54b6bc42aa [TableGen][GlobalISel] Emit Comment with MatchTable Size (#74701) 2023-12-07 09:41:37 +01:00
Philip Reames
e817966718 [RISCV] Collapse fast unaligned access into a single feature [nfc-ish] (#73971)
When we'd originally added unaligned-scalar-mem and
unaligned-vector-mem, they were separated into two parts under the
theory that some processor might implement one, but not the other. At
the moment, we don't have evidence of such a processor. The C/C++ level
interface, and the clang driver command lines have settled on a single
unaligned flag which indicates both scalar and vector support unaligned.
Given that, let's remove the test matrix complexity for a set of
configurations which don't appear useful.

Given these are internal feature names, I don't think we need to provide
any forward compatibility. Anyone disagree?

Note: The immediate trigger for this patch was finding another case
where the unaligned-vector-mem wasn't being properly serialized to IR
from clang which resulted in problems reproducing assembly from clang's
-emit-llvm feature. Instead of fixing this, I decided getting rid of the
complexity was the better approach.
2023-12-01 11:00:59 -08:00
Shengchen Kan
a4e1aa256b [X86][tablgen] Auto-gen broadcast tables (#73654)
1. Add TB_BCAST_SH for FP16
2. Auto-gen 4 broadcast tables BroadcastTable[1-4]

issue: https://github.com/llvm/llvm-project/issues/66360
2023-11-30 22:24:31 +08:00
Shengchen Kan
e78a45dd10 [X86][NFC] Refine code in X86FoldTablesEmitter.cpp
Split NFC in #73654 into a seperate commit.
2023-11-30 18:46:20 +08:00
wangpc
d0c8d41e10 [TableGen][NFC] Format getOpcodeString and remove unreachable breaks 2023-11-29 14:58:54 +08:00
Shengchen Kan
3c0f87147d [X86][fold-table] Add an assertion in addEntryWithFlags, NFCI 2023-11-28 21:47:57 +08:00
Shengchen Kan
bafa51c8a5 [X86] Rename X86MemoryFoldTableEntry to X86FoldTableEntry, NFCI
b/c it's used for element that folds a load, store or broadcast.
2023-11-28 19:49:14 +08:00
Shengchen Kan
c66c15a76d [X86] Rename some variables for memory fold and format code, NFCI
1. Rename the names of tables to simplify the print
2. Align the abbreviation in the same file Instr -> Inst
3. Clang-format
4. Capitalize the first char of the variable name
2023-11-28 19:07:44 +08:00
Pierre van Houtryve
dd0973be58 [TableGen] Split GlobalISelCombinerEmitter into multiple files (#73325)
Split MatchDataInfo, CXXPredicates and the Pattern hierarchy into their
own files.

This should help with maintenance a bit, and make the API easier to
navigate.
I hope this encourages a bit more experimentation with MIR patterns,
e.g. I'd like to try getting them in ISel at some point.

Currently, this is pretty much only moving code around. There is no
significant refactoring in there.
I want to split the Combiner backend even more at some point though,
e.g. by separating the TableGen parsing logic into yet another file so
other backends could very easily parse patterns themselves.

Note: I moved the responsibility of managing string lifetimes into the
backend instead of the Pattern class.
e.g. Before you'd do `P.addOperand(Name)` but now it's
`P.addOperand(insertStrRef(Name))`.
I verified this was done correctly by running the tests with UBSan/ASan.
2023-11-28 11:48:24 +01:00
Shengchen Kan
f3d2a31d7d [X86][CodeGen] Cleanup code for EVEX2VEX pass, NFCI
1. Remove unused variables, e.g X86Subtarget object in performCustomAdjustments
2. Define checkVEXInstPredicate directly instead of generating it b/c
   the function is small and it's unlikely we have more instructions to
   check the predicate in the future
3. Check the tables are sorted only once for each function
4. Remove some blanks and clang-format code
2023-11-28 13:11:15 +08:00
Wang Pengcheng
2e6c01be0d [SelectionDAG] Add instantiated OPC_EmitInteger and OPC_EmitStringInteger (#73241)
These two opcodes are used to be followed by a MVT operand, which is
always one of i8/i16/i32/i64.

We add instantiated `OPC_EmitInteger` and `OPC_EmitStringInteger` with
i8/i16/i32/i64 so that we can reduce one byte.

We reserve `OPC_EmitInteger` and `OPC_EmitStringInteger` in case that
we may need them someday, though I haven't found one usage after this
change.

Overall this reduces the llc binary size with all in-tree targets by
about 200K.
2023-11-27 11:08:28 +08:00
Shengchen Kan
8c2537fde6 [X86][MC] Support encoding/decoding for PUSH2[P]/POP2[P] (#73233)
PUSH2 and POP2 are two new instructions for (respectively)
pushing/popping 2 GPRs at a time to/from
the stack. The opcodes of PUSH2 and POP2 are those of “PUSH r/m” and
“POP r/m” from legacy map 0, but we
require ModRM.Mod = 3 in order to disallow memory operand. 

The 1-bit Push-Pop Acceleration hint described in #73092 applies to
PUSH2/POP2 too, then we have PUSH2P/POP2P.

For AT&T syntax, PUSH2[P] pushes the registers from right to left onto
the stack. POP2[P] pops the stack to registers from right to left. Intel
syntax has the opposite order - from left to right.

The assembly syntax is aligned with GCC & binutils
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/637718.html
2023-11-24 12:29:56 +08:00
Shengchen Kan
dab7684ad1 [NFC][X86] Clang-format X86RecognizableInstr.h (#73279) 2023-11-24 11:56:57 +08:00
Shengchen Kan
39124f525a [NFC][X86] Clang-format X86RecognizableInstr.cpp (#73278) 2023-11-24 11:45:23 +08:00
Shengchen Kan
42d484082c [X86][MC] Support encoding/decoding for JMPABS (#72835)
JMPABS is a 64-bit only ISA extension, and acts as a near-direct branch
with an absolute target. The 64-bit immediate operand is treated an as
absolute effective address, which is subject to canonicality checks. It
is in legacy map 0 and requires REX2 prefix with `REX2.M0=0` and
`REX2.W=0`. All other REX2 payload bits are ignored.

blog: https://kanrobert.github.io/rfc/All-about-APX-JMPABS/

This patch
1. Extends `ExplicitVEXPrefix` to `ExplicitOpPrefix` for instrcutions
requires explicit `REX2` or `EVEX`
2. Adds `ATTR_REX2` and `IC_64BIT_REX2` to put `JMPABS` , `MOV EAX,
moffs32` in different tables to avoid opcode conflict

NOTE:
1. `ExplicitREX2Prefix` can be reused by the following PUSHP/POPP
instructions.
2. `ExplicitEVEXPrefix` will be used by the instructions promoted to
EVEX space for EGPR.
2023-11-22 10:26:23 +08:00
Nikita Popov
0a0e06f291 [TableGen] Fix prefix detection with anchor (NFC) (#71379)
instregex uses an optimization, where the constant prefix of the regex
is extracted to perform a binary search first. However, this
optimization currently mainly fails to apply, because most instregex
uses have an explicit ^ anchor, which gets counted as a meta char and
disables the optimization.

Make sure the anchor is skipped when determining the prefix. Also fix an
implementation bug this exposes, where the pick a too long prefix if the
first meta character is a quantifier.

This cuts the time needed to generate files like X86GenInstrInfo.inc by
half.
2023-11-13 15:47:15 +01:00
Kazu Hirata
fcb160eabc [llvm] Stop including llvm/ADT/DenseMap.h (NFC)
Identified with clangd.
2023-11-11 22:46:28 -08:00
Kazu Hirata
01702c3f7f [llvm] Stop including llvm/ADT/SmallSet.h (NFC)
Identified with clangd.
2023-11-11 12:32:15 -08:00
Kazu Hirata
2ca3b6f6b7 [TableGen] Include <set> (NFC)
This patch adds "#include <set>" to several files that are relying on
transitive includes of <set>.  It in turn unblocks the removal of
unnecessary includes of llvm/ADT/SmallSet.h in several other files.
2023-11-11 12:14:24 -08:00
Pierre van Houtryve
96e9786414 [TableGen][GlobalISel] Add MIFlags matching & rewriting (#71179)
Also disables generation of MutateOpcode. It's almost never used in
combiners anyway.
If we really want to use it, it needs to be investigated & properly
fixed (see TODO)
    
Fixes #70780
2023-11-08 10:31:49 +01:00
Pierre van Houtryve
573fa770d0 [TableGen][GlobalISel] Add rule-wide type inference (#66377)
The inference is trivial and leverages the MCOI OperandTypes encoded in
CodeGenInstructions to infer types across patterns in a CombineRule.
It's thus very limited and only supports CodeGenInstructions (but that's the
main use case so it's fine).

We only try to infer untyped operands in apply patterns when they're
temp reg defs, or immediates. Inference always outputs a `GITypeOf<$x>` where
$x is a named operand from a match pattern.

This allows us to drop the `GITypeOf` in most cases without any errors.
2023-11-08 08:10:22 +01:00
Yeting Kuo
75d6795e42 [RISCV][Clang][TargetParser] Support getting feature unaligned-scalar-mem from mcpu. (#71513)
This patch reference ac1ffd3cac to suppot
a soft coding way to identify whether a cpu has a feature
`unaligned-scalar-mem` by `RISCVProcessors.td`.
This patch does not provide test case since there is no risc-v cpu
support `unaligned-scalar-mem` in llvm upstream now.
2023-11-08 00:05:16 +08:00
David Spickett
93b8f5695b [llvm][TableGen] Fix value description made by OptRSTEmitter
When this was ported to clang-tblen for https://reviews.llvm.org/D123682,
some of the refactoring for the clang copy was backported to llvm,
but used .front instead of .back as clang does.

This means that if you have values "a, b, c" you get
"must be 'a', ' b' or 'a'." instead of "must be 'a', ' b' or 'c'.".
2023-11-06 10:35:38 +00:00
Simon Pilgrim
141122ece3 [TableGen] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.
startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-11-03 17:53:56 +00:00
Craig Topper
1021404619 [GISel] Make RegBank constructor constexpr. NFC (#71109)
RegBanks are constructed as global objects. Making the constructor
constexpr helps the compiler construct it without a global
constructor.
    
clang's optimizer seems to figure this out on its own, but at
least gcc 8 does not.
2023-11-02 18:05:05 -07:00
Shengchen Kan
860f9e5170 [NFC][X86] Reorder the registers to reduce unnecessary iterations (#70222)
* Introduce field `PositionOrder` for class `Register` and
`RegisterTuples`
* If register A's `PositionOrder` < register B's `PositionOrder`, then A
is placed before B in the enum in X86GenRegisterInfo.inc
* The new order of registers in the enum for X86 will be
      1. Registers before AVX512,
      2. AVX512 registers (X/YMM16-31, ZMM0-31, K registers)
      3. AMX registers (TMM)
      4.  APX registers (R16-R31)
* Add a new target hook `getNumSupportedRegs()` to return the number of
registers for the function (may overestimate).
* Replace `getNumRegs()` with `getNumSupportedRegs()` in LiveVariables
to eliminate iterations on unsupported registers

This patch can reduce 0.3% instruction count regression for sqlite3
during compile-stage (O3) by not iterating on APX registers
for #67702
2023-11-02 00:12:05 +08:00
David Spickett
61b9176cf7 [llvm][TableGen] Add Compiler Explorer link to README
As Compiler Explorer now has trunk llvm-tblgen available.
2023-10-31 09:11:50 +00:00