163 Commits

Author SHA1 Message Date
Craig Topper
5ee8418057 [Docs][TableGen] Remove ReturnRange from the SearchIndex documentation. NFC
SearchIndex doesn't support ReturnRange. It is only supported for
the primary key.
2025-01-03 11:19:23 -08:00
Krzysztof Drewniak
b24caf3d2b
[llvm][TableGen] Add a !initialized predicate to allow testing for ? (#117964)
There are cases (like in an upcoming patch to MLIR's `Property` class)
where the ? value is a useful null value. However, existing predicates
make ti difficult to test if the value in a record one is operating is ?
or not.

This commit adds the !initialized predicate, which is 1 on concrete,
non-? values and 0 on ?.

---------

Co-authored-by: Akshat Oke <Akshat.Oke@amd.com>
2024-12-17 20:34:35 -06:00
Min-Yih Hsu
e8b70e9744
[TableGen] Make !and and !or short-circuit (#113963)
The idea is that by preemptively simplifying the result of `!and` and `!or`, we can fold
some of the conditional operators, like `!if` or `!cond`, as early as
possible.
2024-11-07 10:22:03 -08:00
Rahul Joshi
65e69f7436
[NFC][TableGen] Change Record::getSuperClasses to use const Record* (#110845)
Change `Record::getSuperClasses` to return a const pointer to the
superclass records.

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-02 13:24:46 -07:00
Rahul Joshi
66c8dce82e
[TableGen] Add a !listflatten operator to TableGen (#109346)
Add a !listflatten operator that will transform an input list of type
`list<list<X>>` to `list<X>` by concatenating elements of the
constituent lists of the input argument.
2024-09-24 06:01:34 -07:00
Garvit Gupta
6c903f05f3
[TableGen] Add support for emitting new function definition to return a range of results for Primary Key (#96174)
In the RISC-V architecture, multiple vendor-specific Control and Status
Registers (CSRs) share the same encoding. However, the existing lookup
function, which currently returns only a single result, falls short.
During disassembly, it consistently returns the first CSR encountered,
which may not be the correct CSR for the subtarget.

To address this issue, we modify the function definition to return a
range of results. These results can then be iterated upon to identify
the CSR that best fits the subtarget’s feature requirements. The
behavior of this new definition is controlled by a variable named
`ReturnRange`, which defaults to `false`.

Specifically, this patch introduces support for emitting a new lookup
function for the primary key. This function returns a pair of iterators
pointing to the first and last values, providing a comprehensive range
of values that satisfy the query
2024-07-11 10:54:31 -07:00
Piotr Fusik
a2cd846b7b
[TableGen][Docs] Clarify TokCode definition. (#96201)
"shortest" would be an empty sequence and the rule would never match.
2024-06-21 06:35:28 +02:00
Piotr Fusik
c659e3a3f8
[TableGen][Docs] Fix !range markup (#95540) 2024-06-17 16:53:57 +02:00
Jay Foad
18ec885a26
[RFC][AMDGPU] Remove old llvm.amdgcn.buffer.* and tbuffer intrinsics (#93801)
They have been superseded by llvm.amdgcn.raw.buffer.* and
llvm.amdgcn.struct.buffer.*.
2024-06-10 12:14:51 +01:00
Jason Eckhardt
8ae0485070
[TableGen] Extend direct lookup to instruction values in generic tables. (#80486)
Currently, for some tables involving a single primary key field which is
integral and densely numbered, a direct lookup is generated rather than
a binary search. This patch extends the direct lookup function
generation to instructions, where the integral value corresponds to the
instruction's enum value.

While this isn't as common as for other tables, it does occur in at
least one downstream backend and one in-tree backend.

Added a unit test and minimally updated the documentation.
2024-02-07 12:49:39 +08:00
Wang Pengcheng
acf6811d0f
[TableGen] Support type aliases via new keyword deftype
We can use `deftype` (not using `typedef` here to be consistent
with `def`, `defm`, `defset`, `defvar`, etc) to define type aliases.

Currently, only primitive types and type aliases are supported to be
the source type and `deftype` statements can only appear at the top
level.

Reviewers: fpetrogalli, Artem-B, nhaehnle, jroelofs

Reviewed By: jroelofs, nhaehnle, Artem-B

Pull Request: https://github.com/llvm/llvm-project/pull/79570
2024-02-02 17:41:47 +08:00
ostannard
56602a48c7
[TableGen] Include source location in JSON dump (#79028)
This adds a '!loc' field to each record containing the file name and
line number of the record declaration.
2024-01-24 17:07:20 +00:00
Kazu Hirata
211f5d00e2 [llvm] Fix typos in documentation 2023-12-17 15:36:44 -08: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
Francesco Petrogalli
db9b6f4987
[Tablegen] Add keyword dump. (#68793)
The keyword is intended for debugging purpose. It prints a message to
stderr.

This patch is based on code originally written by Adam Nemet, and on the
feedback received by the reviewers in
https://reviews.llvm.org/D157492.
2023-10-19 09:26:36 +02:00
Aaron Ballman
670034c4b8 Fix LLVM sphinx bot 2023-10-11 08:42:52 -04:00
Francesco Petrogalli
cacfac416c
[TableGen] New bang operator !repr. (#68716)
The !repr operator represents the content of a variable or of a record
as a string.

This patch is based on code originally written by Adam Nemet, and on the
feedback received by the reviewers in
https://reviews.llvm.org/D157492.
2023-10-11 13:11:48 +02:00
wangpc
a904bb464f [TableGen] Format !range doc 2023-09-27 15:24:21 +08:00
Wang Pengcheng
df330d7496
[TableGen] Enhance !range bang operator (#66489)
We add a third argument `step` to `!range` bang operator to make it
with the same semantics as `range` in Python.

`step` can be negative. `step` is 1 by default and `step` can't be
0. If `start` < `end` and `step` is negative, or `start` > `end`
and `step` is positive, the result is an empty list.
2023-09-27 12:07:36 +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
wangpc
91ccbc6c1c [TableGen] Support named arguments
We provide a way to specify arguments in the form of `name=value`
so that we don't have to specify all optional arguments before the
one we'd like to change. Required arguments can alse be specified
in this way.

Note that the argument can only be specified once regardless of
the way (named or positional) to specify and positional arguments
should be put before named arguments.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D152998
2023-07-20 16:03:17 +08:00
Michael Liao
dcc8f9490f [TableGen] Add !setdagarg and !setdagname
- This patch proposes to add `!setdagarg` and `!setdagname` bang
  operators to produce a new DAG node after replacing the specified
  argument value/name from the given input DAG node. E.g.,
  `!setdagarg((foo 1, 2), 0, "x")` produces `(foo "x", 2)` and
  `!setdagname((foo 1:$a, 2:$b), 1, "c")` produces `(foo 1:$a, 2:$c)`.

Reviewed By: simon_tatham

Differential Revision: https://reviews.llvm.org/D151842
2023-06-07 09:37:40 -04:00
Michael Liao
26d7b7bb8f [TableGen] Add !getdagarg and !getdagname
- This patch proposes to add `!getdagarg` and `!getdagname` bang
  operators as the inverse operation of `!dag`. They allow us to examine
  arguments of a given dag.

Reviewed By: simon_tatham

Differential Revision: https://reviews.llvm.org/D151602
2023-05-31 10:54:43 -04:00
wangpc
45ea4d6256 [TableGen] Unify the priority of variables
In D148197, we have made `defvar` statement able to refer to class
template arguments. However, the priority of class/multiclass
template argument is higher than variables defined by `defvar`, which
is a little counterintuitive.

In this patch, we unify the priority of variables. Each pair of
braces introduces a new scope, which may contain some additional
variables like template arguments, loop iterators, etc. We can
define local variables inside this scope via `defvar` and these
variables are of higher priority than additional variables. This
means that `defvar` will shadow additional variables with the same
name. The scope can be nested, and we use the innermost variable.

This make variables defined by `defvar` prior to class/multiclass
template arguments, loop iterators, etc. The shadow rules now are:

* `V` in a record body shadows a global `V`.

* `V` in a record body shadows template argument `V`.

* `V` in template arguments shadows a global `V`.

* `V` in a `foreach` statement list shadows any `V` in surrounding record or global scopes.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D149016
2023-05-24 12:44:14 +08:00
Kazu Hirata
96ddbd6dd8 [llvm] Fix typos in documentation 2023-05-12 23:47:46 -07:00
NAKAMURA Takumi
f98192af55 TableGen: Let expressions available to list subscriptions and list slices
This enables indexing in `!foreach` and permutation with `list[permlist]`.

Enhancements in syntax:

  - `list<int>` is applicable as a slice element.
  - `list[int,]` is evaluated as not `ElemType` but `list<ElemType>`
    with a single element.

Part of D145872

FIXME: I didn't apply new semantics to BitSlice.
2023-04-26 23:47:16 +09:00
NAKAMURA Takumi
cc20ca741b TableGen/ProgRef.rst: Fix copypasto in the description of !range 2023-04-26 23:47:15 +09:00
NAKAMURA Takumi
ab2187d786 TableGen: Introduce !range operator for half-opened interval
`!range(a, b)` generates a list `[a,b)`. `a` is optional and `0` by default.

  - `!range(-1, 4)` generates `[-1, 0, 1, 2, 3]`
  - `!range(4)` generates `[0, 1, 2, 3]`
  - `!range(2, 2)` generates `[]<list<int>>`

`!range(list)` is equivalent to `!range(0, !size(list))`.

Differential Revision: https://reviews.llvm.org/D145871
2023-04-25 22:38:20 +09:00
wangpc
41eafdf9aa [TableGen] Format document
Add missing bang operators and reorder them in alphabetical order.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D146687
2023-03-27 11:27:35 +08:00
NAKAMURA Takumi
4178ef43b2 TableGen: Introduce llvm::TableGen::Emitter to register backends
`Opt(flag, func, desc)` registers an option into `Action`.

`OptClass<EmitterC>` is also available if `EmitterC(RK).run(OS)` is capable.

`Action` is defined as `ManagedStatic<cl::opt>` to guarantee to be created
when each registration of emitter is invoked.

`llvm::TableGenMain(argv0, MainFn)` invokes `Action` instead of `MainFn`

Differential Revision: https://reviews.llvm.org/D144351
2023-03-21 16:21:27 +09:00
Zain Jaffal
d612a75279
[TableGen] add !toupper and !tolower operators to change the casing of strings.
Reviewed By: fpetrogalli

Differential Revision: https://reviews.llvm.org/D145300
2023-03-07 12:41:56 +00:00
serge-sans-paille
38818b60c5
Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ part
Use deduction guides instead of helper functions.

The only non-automatic changes have been:

1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*))
2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase.
3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated.
4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that).

Per reviewers' comment, some useless makeArrayRef have been removed in the process.

This is a follow-up to https://reviews.llvm.org/D140896 that introduced
the deduction guides.

Differential Revision: https://reviews.llvm.org/D140955
2023-01-05 14:11:08 +01:00
Simon Pilgrim
d576537109 [TableGen] Add a !listremove() bang operator
This patch proposes to add a !listremove() bang operator to allow us to prune list entries by removing any entries from the first list arg that are also contained in the second list arg.

The particular use case I have in mind is for improved analysis of x86 scheduler models for which I'm hoping to start using the CodeGenProcModel 'Unsupported' features lists, which lists the ISA features a particular model DOESN'T support - with such a diverse and growing list of x86 ISAs, I don't want to have to update all these lists with every ISA change to every model - so I'm intending to keep a single central list of all x86 features, and then have the each model "remove" the features that it supports via a !listremove() - leaving just the unsupported ones.

Differential Revision: https://reviews.llvm.org/D139642
2022-12-09 15:03:18 +00:00
Michael Maitland
64d5aedd06 [TableGen] Add log bang operator
This patch adds base 2 logarithm that returns integer result. I initially wanted to name it `!log2`,
but numbers are not permitted in the name. The documentation makes sure to clarify that it is
base 2 since it is not explicit in the operator name.

Differential Revision: https://reviews.llvm.org/D134068
2022-10-26 09:16:32 -07:00
Michael Maitland
19f8176eb6 [TableGen] Add div bang operator
This patch adds the div bang operator which performs division.

Differential Revision: https://reviews.llvm.org/D134001
2022-09-30 12:08:28 -07:00
wangpc
634484885c [TableGen] Add new operator !exists
We can cast a string to a record via !cast, but we have no mechanism
to check if it is valid and TableGen will raise an error if failed to
cast. Besides, we have no semantic null in TableGen (we have `?` but
different backends handle uninitialized value differently), so operator
like `dyn_cast<>` is hard to implement.

In this patch, we add a new operator `!exists<T>(s)` to check whether
a record with type `T` and name `s` exists. Self-references are allowed
just like `!cast`.

By doing these, we can write code like:
```
class dyn_cast_to_record<string name> {
  R value = !if(!exists<R>(name), !cast<R>(name), default_value);
}
defvar v = dyn_cast_to_record<"R0">.value; // R0 or default_value.
```

Reviewed By: tra, nhaehnle

Differential Revision: https://reviews.llvm.org/D127948
2022-06-23 11:11:47 +08:00
Ivan Kosarev
046f901735 [TableGen] Undeprecate 'field' when used with the CodeEmitterGen backend.
Differential Revision: https://reviews.llvm.org/D126290
2022-05-25 15:15:19 +01:00
Jay Foad
9293539064 [TableGen] Remove an untrue statement from the docs
You can't use foreach in a record body. This was a mistake in the
documentation dating from when it was first written in D85838.
2022-05-23 15:19:33 +01:00
Sebastian Neubauer
f4139440f1 [Docs] Fix IR and TableGen grammar inconsistencies
IR:
- globals (and functions, ifuncs, aliases) can have a partition
- catchret has a `to` before the label
- the sint/int types do not exist
- signext comes after the type
- a variable was missing its type

TableGen:
- The second value after a `#` concatenation is optional
  See e.g. llvm/lib/Target/X86/X86InstrAVX512.td:L3351
- IncludeDirective and PreprocessorDirective were never referenced in
  the grammar
- Add some missing ;
- Parent classes of multiclasses can have generic arguments.
  Reuse the `ParentClassList` that is already used in other places.

MIR:
- liveins only allows physical registers, which start with a $

Differential Revision: https://reviews.llvm.org/D116674
2022-01-13 11:55:13 +01:00
Quinn Pham
a712b661eb [NFC][llvm] Inclusive language: replace master in llvm docs
[NFC] As part of using inclusive language within the llvm project, this patch
removes instances of master in these files.

Reviewed By: ZarkoCA

Differential Revision: https://reviews.llvm.org/D114187
2021-11-25 13:36:51 -06:00
Shao-Ce SUN
0c660256eb [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
Kazu Hirata
d8e4170b0a Ensure newlines at the end of files (NFC) 2021-10-23 08:45:29 -07:00
Sylvestre Ledru
c28473fe4a Fix some typos in the llvm docs 2021-08-31 21:31:20 +02:00
Paul C. Anagnostopoulos
952c6ddd8b [TableGen] Add the !find bang operator
!find searches a source string for a target string and returns the position.

Differential Revision: https://reviews.llvm.org/D101318
2021-04-28 09:51:00 -04:00
Paul C. Anagnostopoulos
d9187f50b9 [TableGen] [docs] Improve BNF for the 'multiclass' statement [NFC] 2021-04-23 12:05:52 -04:00
Paul C. Anagnostopoulos
6a067cdb06 [TableGen] [docs] Improve description of NAME in Programmer's Reference
Also use "parent class" consistently and add a note about the term.

Differential Revision: https://reviews.llvm.org/D100867
2021-04-23 09:49:17 -04:00
Paul C. Anagnostopoulos
a5aaec8f4e [TableGen] Add support for the 'assert' statement in multiclasses
This is step 3 of adding the 'assert' statement.

Differential Revision: https://reviews.llvm.org/D99751
2021-04-19 09:01:42 -04:00
Paul C. Anagnostopoulos
9345f9fa5d [TableGen] [docs] Correct a reference in the TableGen Overview document
Differential Revision: https://reviews.llvm.org/D100382
2021-04-15 09:25:09 -04:00
Paul C. Anagnostopoulos
3f919ff250 Revert "[TableGen] Add support for the 'assert' statement in multiclasses"
This reverts commit 3b9a15d910a8c748b1444333a4a3905a996528bc.
2021-04-08 13:58:58 -04:00
Paul C. Anagnostopoulos
3b9a15d910 [TableGen] Add support for the 'assert' statement in multiclasses 2021-04-08 08:36:03 -04:00