6258 Commits

Author SHA1 Message Date
Rahul Joshi
7005a76638
[NFC][TableGen] Print DecodeIdx for DecodeOps in DecoderEmitter (#142963)
Print DecodeIdx associated with Decode MCD ops in the generated decoder
tables. This can help in debugging decode failures by first mapping the
Op -> DecodeIdx and then inspecting the code in `decodeToMCInst`
associated with that DecodeIdx.
2025-06-05 21:57:26 -07:00
Krzysztof Parzyszek
4dcc159485
[utils][TableGen] Implement clause aliases as alternative spellings (#141765)
Use the spellings in the generated clause parser. The functions
`get<lang>ClauseKind` and `get<lang>ClauseName` are not yet updated.

The definitions of both clauses and directives now take a list of
"Spelling"s instead of a single string. For example
```
def ACCC_Copyin : Clause<[Spelling<"copyin">,
                          Spelling<"present_or_copyin">,
                          Spelling<"pcopyin">]> { ... }
```

A "Spelling" is a versioned string, defaulting to "all versions".

For background information see

https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
2025-06-05 12:35:30 -05: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
Jay Foad
f8714666b1
[TableGen] Remove last remnant of CompositeIndices (#142960)
The rest of the support was removed in 2012 by:
599593630999 "Remove support for 'CompositeIndices' and sub-register cycles."
2025-06-05 17:01:55 +01:00
Krzysztof Parzyszek
463a2bd159
[utils][TableGen] Treat clause aliases equally with names (#141763)
The code in DirectiveEmitter that generates clause parsers sorted clause
names to ensure that longer names were tried before shorter ones, in
cases where a shorter name may be a prefix of a longer one. This matters
in the strict Fortran source format, since whitespace is ignored there.

This sorting did not take into account clause aliases, which are just
alternative names. These extra names were not protected in the same way,
and were just appended immediately after the primary name.

This patch generates a list of pairs Record+Name, where a given record
can appear multiple times with different names. Sort that list and use
it to generate parsers for each record. What used to be
```
  ("fred" || "f") >> construct<SomeClause>{} ||
  "foo" << construct<OtherClause>{}
```
is now
```
  "fred" >> construct<SomeClause>{} ||
  "foo" >> construct<OtherClause>{} ||
  "f" >> construct<SomeClause>{}
```
2025-06-05 09:05:16 -05:00
Rahul Joshi
e53ccb78e4
[LLVM][MC] Introduce OrFail variants of MCD ops (#138614)
Introduce `OrFail` variants for all MCD Decoder Ops that have
`NumToSKip` encoded with them. This is intended to capture the common
case of jumps to the end of the decoder table which has a `OP_Fail` at
the end. Using the `OrFail` variants of these ops avoid encoding the
`NumToSkip` jump offset for these cases, resulting in a reduction in the
size of the decoder tables (from 5 - 17%). Additionally, for the AArch64
target, the table size reduces enough to switch to using 2-byte
`NumToSkip` encoding instead of existing 3-bytes, resulting in a net 30%
reduction in the size of the decoder table.

The total reduction in the size of the decoder tables for different
targets is as follows (computed using the following command: `for i in
*.inc; do echo -n ``basename $i: ``; grep "MCD::OPC_Fail," $i | awk
'{sum += $2} END { print sum}'; done`)

```
Target         Old Size   New Size   % Reduction
================================================
AArch64           153268     106987       30.20
AMDGPU            412056     340856       17.28
ARC                 5061       4605        9.01
ARM                73831      60847       17.59
AVR                 1306       1158       11.33
BPF                 1927       1795        6.85
CSKY                8692       6922       20.36
Hexagon            41965      34759       17.17
Lanai                982        924        5.91
LoongArch          21629      20035        7.37
M68k               13461      11689       13.16
MSP430              3716       3384        8.93
Mips               31415      25771       17.97
PPC                28931      24771       14.38
RISCV              34800      28352       18.53
Sparc               7432       6236       16.09
SystemZ            32248      29716        7.85
VE                 42873      36923       13.88
XCore               2316       2196        5.18
Xtensa              3443       2793       18.88
```
2025-06-05 06:17:50 -07:00
Rahul Joshi
43bc5ea7fd
[NFC][TableGen] Manually format StringSwitch in X86RecognizableInstr.cpp (#141615)
Use manual formatting of code for `StringSwitch` with less indentation.
2025-06-05 06:16:58 -07:00
Krzysztof Parzyszek
2b3e07f485
[utils][TableGen] Unify converting names to upper-camel case (#141762)
There were 3 different functions in DirectiveEmitter.cpp doing
essentially the same thing: taking a name separated with _ or whitepace,
and converting it to the upper-camel case. Extract that into a single
function that can handle different sets of separators.
2025-06-05 07:34:28 -05:00
Krzysztof Parzyszek
57500cd6a0
[utils][TableGen] Clarify usage of ClauseVal, rename to EnumVal (#141761)
The class "ClauseVal" actually represents a definition of an enumeration
value, and in itself it is not bound to any clause. Rename it to EnumVal
and add a comment clarifying how it's translated into an actual enum
definition in the generated source code.

There is no change in functionality.
2025-06-04 08:16:21 -05:00
Jay Foad
f8b561a07d [TableGen] Fix typo in error message 2025-06-04 11:41:59 +01:00
Tomer Shafir
47c04c735a
[TableGen] Remove wrong comment for CodeGenTarget ctor (#141024) 2025-05-27 23:45:41 -07:00
Kazu Hirata
252bd80871
[TableGen] Remove unused includes (NFC) (#141356)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-24 09:37:40 -07: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
Krzysztof Parzyszek
70f9a8163f
[utils][TableGen] Clean up code in DirectiveEmitter (#140772)
Remove most redundant function calls. Unify enum identifier name
generation (via getIdentifierName), and namespace qualification (via
getQualifier).
2025-05-21 07:35:05 -05:00
Krzysztof Parzyszek
46ab684bdd
[utils][TableGen] Unify name qualifications in DirectiveEmitter (#140606)
Remove extraneous qualifications from names when
- the name is explicitly enclosed by corresponding namespaces, and
- the name is in a body of a function defined in corresponding
namespaces. Otherwise add missing qualifications.

This applies to individual sections of TableGen output, and makes name
lookup independent of the context in which these sections are included.
2025-05-20 07:56:59 -05:00
Krzysztof Parzyszek
90539473ec
[utils][TableGen] Remove unused parameter in DirectiveEmitter, NFC (#140605) 2025-05-20 07:56:39 -05:00
Iris Shi
bdf03fcff3
Revert "[llvm][NFC] Use llvm::sort()" (#140668) 2025-05-20 11:27:03 +08:00
Kazu Hirata
195e640846 [TableGen] Fix the build
This patch fixes:

  llvm/utils/TableGen/Common/CodeGenRegisters.cpp:653:57: error:
  'getValues' is deprecated: Use getElements instead
  [-Werror,-Wdeprecated-declarations]
2025-05-19 12:34:57 -07:00
Rahul Joshi
29fd76777d
[NFC][TableGen] Create valid Dag in VarLenCodeEmitter (#140283)
- Set the Dag ArgNames correctly when normalizing the Dag for slice.
- Add unit test to exercise the "slice" hi/lo swap case.
2025-05-19 12:27:18 -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
0f38543df5
[NFC][TableGen] Use SmallVector range constructor when possible (#140284)
Initialize vectors using constructor instead of llvm::append_range when
possible.
2025-05-19 12:15:43 -07:00
Iris Shi
061a7699f3
[llvm][NFC] Use llvm::sort() (#140335) 2025-05-17 14:49:46 +08:00
Rahul Joshi
7674d6fa9e
[LLVM][TableGen] Simplify DagInit::get (#140056)
- Add `DagInit::get` overloads that do not need ValName to be specified.
- Fix some calls to either not create temporary arrays for DAG args or
use the std::pair<> overload.
2025-05-16 09:45:58 -07:00
Krzysztof Parzyszek
8e2ac7d619
[llvm][OpenMP] Add "SourceLanguages" property to Directive (#139960)
The official languages that OpenMP recognizes are C/C++ and Fortran.
Some OpenMP directives are language-specific, some are C/C++-only, some
are Fortran-only.

Add a property to the TableGen definition of Directive that will be the
list of languages that allow the directive.

The TableGen backend will then generate a bitmask-like enumeration
SourceLanguages, and a function
  SourceLanguages getDirectiveLanguages(Directive D);
2025-05-15 07:36:53 -05:00
Rahul Joshi
2110faaf55
[NFC][TableGen][X86] Use StringSwitch to map from string -> enum (#139929)
Use StringSwitch instead of macro to map from a string to enum values in
X86RecognizableInstr.cpp.
2025-05-15 05:31:05 -07:00
Rahul Joshi
5ee67ee6bc
[LLVM][TableGen] Code cleanup in FastISelEmitter.cpp (#139644)
- Use StringRef instead of std::string for `InstructionMemo::Name`.
- Use range for loops, zip_equal and structured bindings in loops.
- Use llvm::any_of instead of manual loops.
- Use ListSeparator.
- Remove {} around single-line if-else chains.
- Use ArrayRef<> instead of const vector reference for function args.
- Change `getLegalCName` to accept a `StringRef` to avoid
StringRef->std::string casting in several places.
- Use StringRef instead of std::string for `OpcodeName` (and in
associated maps).

Tested by verifying no changes in .inc files with and without this
change.
2025-05-14 12:51:07 -07:00
Rahul Joshi
2f2c327017
[NFC][TableGen] Use StringRef in X86RecognizableInstr (#139648)
- Use `StringRef` instead of `std::string` in several functions.
- Fix some variable names to conform to LLVM coding standard.
- Use llvm::function_ref instead of function pointer for `handleOperand`
argument.
2025-05-14 06:06:08 -07:00
Jie Fu
195fe59c11 [TableGen] Fix a warning in GlobalISelCombinerEmitter.cpp (NFC)
/llvm-project/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp:2612:14:
error: variable 'ExpectedID' set but not used [-Werror,-Wunused-but-set-variable]
    unsigned ExpectedID = 0;
             ^
1 error generated.
2025-05-13 21:48:17 +08:00
pvanhout
6c6413f3f9 [TableGen] Fixup #139715
The increment must be after the assert, not before, otherwise the assert fails everytime.
2025-05-13 14:22:07 +02:00
Pierre van Houtryve
8be514cc96
[TableGen] Avoid assignmentInAssert warning (#139715)
ExpectedID should be optimized out anyway if built without assertions
because nothing reads its value.

Fixes #90327
2025-05-13 14:08:33 +02:00
Pengcheng Wang
9570bf978d
[TableGen][MacroFusion] Predicate if the first inst has the same register (#137778)
We rename `SameReg` to `SecondInstHasSameReg ` and add
`FirstInstHasSameReg `
which has the logic but applies to the first instruction.

We have some cases that require the first instruction has the same
input/output register.
2025-05-13 19:05:42 +08:00
Jay Foad
28b7d6621a
[TableGen][CodeGen] Give every leaf register a unique regunit (#139526)
Give every leaf register a unique regunit, even if it has ad hoc
aliases.

Previously only leaf registers *without* ad hoc aliases would get a
unique regunit, but that caused situations where regunits could not be
used to distinguish a register from its subregs. For example:

- Registers A and B alias. They both get regunit 0 only.
- Register C has subregs A and B. It inherits regunits from its subregs,
  so it also gets regunit 0 only.

After this fix, registers A and B will get a unique regunit in addition
to the regunit representing the alias, for example:

- A will get regunits 0 and 1.
- B will get regunits 0 and 2.
- C will get regunits 0, 1 and 2.
2025-05-13 10:52:36 +01:00
Kazu Hirata
294eb7670f [TableGen] Fix a warning
This patch fixes an unused parameter warning with gcc7 under the
release configuration.
2025-05-12 23:18:30 -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
Krzysztof Parzyszek
4b29ee407e
[LLVM][OpenMP] Add "version" parameter to getOpenMPDirectiveName (#139114)
Some OpenMP directives have different spellings in different versions of
the OpenMP spec. To use the proper spelling for a given spec version
pass "version" as a parameter to getOpenMPDirectiveName.

This parameter won't be used at the moment, and will have a default
value to allow callers not to pass it, for gradual adoption in various
components.

RFC:
https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
2025-05-09 07:41:27 -05:00
Jason Eckhardt
9692dff7b7
[TableGen][NFC] Use early exit to simplify large block in emitAction. (#138220)
Most of the processing in emitAction is in an unneeded else-block--
reduce indentation by exiting after the recursive call.

`XXXGenCallingConv.inc` are identical before and after this patch for
all targets.
2025-05-08 12:12:15 -05:00
Kazu Hirata
806a79abd0
[llvm] Drop "const" from "const ArrayRef" (NFC) (#138818) 2025-05-07 09:53:20 -07:00
Rahul Joshi
9281947a7d
[NFC][TableGen] Code cleanup in CodeGenRegister (#137994)
- Use range for loops.
- Wrap complex LLVM_DEBUG() macros in {} to have clang-format format the
contents similar to regular code.
- Extract repeated code snippets for debug dumping into helper lambda.
- Add `BitsInit::getBits()` to get all contained bits.
2025-05-05 14:05:59 -07:00
Kazu Hirata
c51a3aa6ce
[llvm] Remove unused local variables (NFC) (#138467) 2025-05-04 13:05:18 -07:00
Carl Ritson
c63687c04f
[MC][TableGen] Expand ImplicitOffset field of MCInstrDesc (#138127)
Increase width of ImplicitOffset to `int` from `short` to allow more
table capacity.
Reorder the elements to maintain natural alignment.
2025-05-03 14:50:06 +09:00
Krzysztof Parzyszek
52c62364e7
[OpenMP] Remove "alternativeName" from Clause and Directive classes (#138179)
The "alternativeName" was introduced ~5 years ago in D82405, and at the
moment it has only one use, the one that the original change introduced.

OpenMP 6.0 spec has introduced different spellings of some directives,
but the "alternativeName" is not an adequate mechanism to implement it.

For those reasons remove the "alternativeName" member from both Clause
and Directive in DirectiveBase.td.

Since the alternativeName text appeared in a number of clang OpenMP
tests, implement `getOpenMPClauseNameForDiag` in SemaOpenMP.cpp to
preserve the text of the diagnostics.
2025-05-02 13:02:24 -05:00
Kazu Hirata
4ec473e0e1
[llvm] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#138236) 2025-05-02 08:53:53 -07:00
David Green
9b1051281e
[DAG] Use SDValue for PatFrag checks (#137519)
If the SDNode is used it can pick up the wrong results number, for
example looking at the known bits of the first result where it should be
looking at the second. The SDValue is already present as the
SelectCodeCommon checks move from parent to child, pass the SDValue
through to CheckNodePredicate as Op so that it can use it if necessary.
SDNode *N is still generated, keeping most PatFrags the same.

Fixes #137274
2025-05-01 08:58:59 +01:00
Jason Eckhardt
7d05f67a73
[TableGen][CallingConv] Add CCAssignToRegTuple for synthetic registers. (#137826)
Currently CCAssignToReg takes a list<Register>. There are tuple-heavy
back-ends where we would like to reference any register-- whether those
are singletons or those defined by RegisterTuples. However, the latter
are synthesized during tuple expansion and are not visible outside of
the register info emitter.

The problem is that the parser will see tuple registers as undefined
variables before the calling convention emitter is ever reached. To
defer evaluation of the symbol, we introduce CCAssignToRegTuple which
takes list<string> instead. This allows us to defer the actual
register name lookup until the emitter runs-- where we also validate
that the register actually exists.

This is currently used in a downstream back-end which will be upstreamed
very soon. In the meantime, a unit test is provided to exercise the
feature.
2025-04-30 18:32:37 -05:00
Min-Yih Hsu
951292be2c
[TableGen] Print a warning when a Processor contains duplicate Features / TuneFeatures (#137864)
I don't think a processor should normally contains duplicate features. This patch prints a warning whenever that happens in either the features or tune features.
2025-04-29 16:22:48 -07:00
Jason Eckhardt
e33cf4b078
[TableGen][NFC] Refactor/deduplicate emitAction. (#137434)
Currently there is a fair amount of code duplication in various parts of
emitAction. This patch factors out commonality among CCAssignToReg,
CCAssignToRegAndStack, CCAssignToRegWithShadow, and CCAssignToStack.

`XXXGenCallingConv.inc` are identical before and after this patch for
all targets.
2025-04-29 05:24:23 -05:00
Craig Topper
afbd2ce80f
[TableGen] Use StringRef::empty() instead of comparing to an empty string. NFC (#137673) 2025-04-28 16:47:52 -07:00
Kazu Hirata
044ff78adc
[TableGen] Simplify a string comparison (NFC) (#137584) 2025-04-28 09:34:27 -07:00
Kazu Hirata
f4d3a0cb6a
[TableGen] Simplify insertBits (NFC) (#137538)
We can use "constexpr if" to combine the two variants of functions.
2025-04-27 12:35:54 -07:00