aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/TableGen/TGParser.cpp
AgeCommit message (Collapse)AuthorFilesLines
7 days[NFC][TableGen] Fix namespace usage in various files (#161839)Rahul Joshi1-4/+2
- Move standalone functions and variables out of anonymous namespace and make them static. - Eliminate `namespace llvm {}` wrapping all code in .cpp files, and instead use namespace qualifier to define such functions (https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions) - Add namespace for X86DisassemblerShared.h.
2025-08-29[llvm] Support building with c++23 (#154372)Kyle Krüger1-0/+8
closes #154331 This PR addresses all minimum changes needed to compile LLVM and MLIR with the c++23 standard. It is a work in progress and to be reviewed for better methods of handling the parts of the build broken by c++23.
2025-08-05[NFC] Run clang-format on TGLexer and TGParser (#151509)Rahul Joshi1-152/+237
In https://github.com/llvm/llvm-project/pull/149248, clang-format applied some formatting to lines untouched by that PR, because the existing code is not clang-format compliant. Hence applying clang-format on the entire files here.
2025-07-29[TableGen] Improve handling for dag op names (#149248)Nemanja Ivanovic1-17/+36
There are currently no ways to add names to dag operators other than when defining them. Furthermore a !con operation as well as some others, drops the operator names. This patch propagates the name from the LHS dag for !con and adds a way to get and set the operator name for a dag (!getdagopname, !setdagopname). --------- Co-authored-by: Nemanja Ivanovic <nemanja@synopsys.com>
2025-07-04[NFC][TableGen] Delete extra spaces in comments (#147004)Rahul Joshi1-25/+23
2025-05-12[NFC][TableGen] Use StringRef::str() instead of casting (#139332)Rahul Joshi1-1/+1
- Also eliminate unneeded std::string() around some literal strings.
2025-05-12[NFC][TableGen] Add {} for `else` when `if` body has {} (#139420)Rahul Joshi1-2/+3
2025-04-24[TableGen] Only store direct superclasses in Record (#123072)Jay Foad1-9/+2
In Record only store the direct superclasses instead of all superclasses. getSuperClasses recurses to find all superclasses when necessary. This gives a small reduction in memory usage. On lib/Target/X86/X86.td I measured about 2.0% reduction in total bytes allocated (measured by valgrind) and 1.3% reduction in peak memory usage (measured by /usr/bin/time -v). --------- Co-authored-by: Min-Yih Hsu <min@myhsu.dev>
2025-03-28[TableGen] Add `!instances` operator to get defined records (#129680)Pengcheng Wang1-0/+43
The format is: `!instances<T>([regex])`. This operator produces a list of records whose type is `T`. If `regex` is provided, only records whose name matches the regular expression `regex` will be included. The format of `regex` is ERE (Extended POSIX Regular Expressions).
2025-03-13[TableGen] Add `!match` operator to do regex matching (#130759)Pengcheng Wang1-0/+8
The grammar is `!match(str, regex)` and this operator produces 1 if the `str` matches the regular expression `regex`. The format of `regex` is ERE (Extended POSIX Regular Expressions).
2025-01-27[TableGen] Add assert to validate `Objects` list for `HwModeSelect` (#123794)Rahul Joshi1-3/+5
- Bail out of TableGen if any asserts fail before running the backend. - Add asserts to validate that the `Objects` and `Modes` lists for various `HwModeSelect` subclasses are of same length. - Eliminate equivalent check in CodeGenHWModes.cpp
2025-01-16[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)Jay Foad1-4/+3
Also use brace initialization and emplace to avoid explicitly constructing std::pair, and the same for std::tuple.
2025-01-06[TableGen] Do not exit in template argument check (#121636)Markus Böck1-17/+24
The signature of `CheckTemplateArgValues` implements error handling via the `bool` return type, yet always returned false. The single possible error case instead used `PrintFatalError,` which exits the program afterward. This behavior is undesirable: It prevents any further errors from being printed and makes TableGen less usable as a library as it crashes the entire process (e.g. `tblgen-lsp-server`). This PR therefore fixes the issue by using `Error` instead and returning true if an error occurred. All callers already perform proper error handling. As `llvm-tblgen` exits on error, a test was also added to the LSP to ensure it exits normally despite the error.
2024-12-17[llvm][TableGen] Add a !initialized predicate to allow testing for ? (#117964)Krzysztof Drewniak1-9/+15
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-09[llvm][TableGen] Fix misleading error for invalid use of let (#118616)David Spickett1-1/+1
Fixes #118490 Point to the value name, otherwise it implies that the part after the '=' is the problem. Before: ``` /tmp/test.td:2:27: error: Value 'FlattenedFeatures' unknown! let FlattenedFeatures = []; ^ ``` After: ``` /tmp/test.td:2:7: error: Value 'FlattenedFeatures' unknown! let FlattenedFeatures = []; ^ ```
2024-10-23[NFC][LLVM][TableGen] Change `RecordKeeper::getClass` to return const ↵Rahul Joshi1-13/+14
pointer (#112261) Change `RecordKeeper::getClass` to return const record pointer. 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-21[NFC][TableGen] Use auto when initializing variables with cast<> (#113171)Rahul Joshi1-75/+75
Use `auto` when initializing a variable with `cast<>`. Remove some unneeded `const_cast` (since all Init pointers are now const).
2024-10-18[LLVM][TableGen] Change all `Init` pointers to const (#112705)Rahul Joshi1-208/+220
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-03[NFC][TableGen] Change `RecordKeeper::getDef()` to return const pointer ↵Rahul Joshi1-2/+2
(#110992) 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-03[TableGen] Fix source location for anonymous records (#110935)Rahul Joshi1-1/+1
Fix source location for anonymous records to be the one of the locations where that record is instantiated as opposed to the location of the class that was anonymously instantiated. Currently, when a record is anonymously instantiated (via `VarDefInit::instantiate`), we use the location of the class for the record, which is not correct. Instead, pass in the `SMLoc` for the location where the anonymous instantiation happens and use that location when the record is instantiated. If there are multiple anonymous instantiations with the same parameters, the location for the (single) record created will be one of these instantiation locations as opposed to the class location.
2024-10-02[NFC][TableGen] Change `Record::getSuperClasses` to use const Record* (#110845)Rahul Joshi1-5/+4
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[TableGen] Change `DefInit::Def` to a const Record pointer (#110747)Rahul Joshi1-1/+2
This change undoes a const_cast<> introduced in an earlier change to help transition to const pointers. It 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-01[TableGen] Change all type pointers to const (#110602)Rahul Joshi1-59/+56
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-01[LLVM][TableGen] Support type casts of nodes with multiple results (#109728)Stephen Chou1-3/+5
Currently, type casts can only be used to pattern match for intrinsics with a single overloaded return value. For instance: ``` def int_foo : Intrinsic<[llvm_anyint_ty], []>; def : Pat<(i32 (int_foo)), ...>; ``` This patch extends type casts to support matching intrinsics with multiple overloaded return values. As an example, the following defines a pattern that matches only if the overloaded intrinsic call returns an `i16` for the first result and an `i32` for the second result: ``` def int_bar : Intrinsic<[llvm_anyint_ty, llvm_anyint_ty], []>; def : Pat<([i16, i32] (int_bar)), ...>; ```
2024-09-30[LLVM][TableGen] Change SeachableTableEmitter to use const RecordKeeper ↵Rahul Joshi1-2/+2
(#110032) Change SeachableTableEmitter to use const RecordKeeper. Also change RecordRecTy to use const Record pointers for its classes. 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-09-24[TableGen] Add a !listflatten operator to TableGen (#109346)Rahul Joshi1-5/+27
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-19[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)Jay Foad1-1/+1
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
2024-08-19[TableGen] Resolve References at top level (#104578)Akshat Oke1-2/+7
Add a dummy resolver to resolve references outside records. This invokes Fold() with isFinal to force resolution. Fixes #102447 Co-authored-by: Akshat Oke <Akshat.Oke@amd.com>
2024-07-09[TableGen] Use range-based for loops (NFC) (#97678)Kazu Hirata1-3/+2
2024-02-02[TableGen] Support type aliases via new keyword deftypeWang Pengcheng1-2/+52
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
2023-11-11[llvm] Stop including llvm/ADT/DenseMapInfo.h (NFC)Kazu Hirata1-1/+0
Identified with clangd.
2023-10-24[ADT] Rename llvm::erase_value to llvm::erase (NFC) (#70156)Kazu Hirata1-1/+1
C++20 comes with std::erase to erase a value from std::vector. This patch renames llvm::erase_value to llvm::erase for consistency with C++20. We could make llvm::erase more similar to std::erase by having it return the number of elements removed, but I'm not doing that for now because nobody seems to care about that in our code base. Since there are only 50 occurrences of erase_value in our code base, this patch replaces all of them with llvm::erase and deprecates llvm::erase_value.
2023-10-24[TableGen][NFC] Add record kind to `Record` class (#69919)Wang Pengcheng1-23/+19
enum `RecordKind` is added to indicate the kind of Record (which can be a normal record definition, anonymous record definition, class or multiclass). Some arguments like `IsMC` and `IsDefm` are removed since we can get the information from `RecordKind`.
2023-10-23[TableGen][NFC] Remove MultiClass argument and Scoper in QualifyName (#69297)Wang Pengcheng1-25/+25
MultiClass argument is not used any more since aa84326. Besides, for maintainability, we should put the implementation of qualifying name in one place (that is `QualifyName` function), so `Scoper` is removed and we use `IsMC` to indicate that we are in a multiclass.
2023-10-19[Tablegen] Add keyword `dump`. (#68793)Francesco Petrogalli1-3/+65
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-11[TableGen] New bang operator `!repr`. (#68716)Francesco Petrogalli1-0/+6
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-09-27[TableGen] Enhance !range bang operator (#66489)Wang Pengcheng1-59/+103
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-08-19[TableGen] Modernize SubMultiClassReference (NFC)Kazu Hirata1-2/+2
2023-08-19[TableGen] Modernize SubClassReference (NFC)Kazu Hirata1-2/+2
2023-08-03[TableGen] Improve error report of unspecified argumentswangpc1-4/+5
Wrong error message is fixed and a note of argument is printed. Tests are added in `llvm/test/TableGen/template-args.td`. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D156966
2023-08-01[TableGen][NFC] Group tokens with same attribute togatherwangpc1-62/+8
So that we can simplify some code and simplify the implmentation when we want to add new features (like adding new bang operators). Reviewed By: fpetrogalli Differential Revision: https://reviews.llvm.org/D156502
2023-07-20[TableGen] Support named argumentswangpc1-40/+102
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[TableGen][NFC] Remove unreachable codewangpc1-5/+0
The removed code assumed that we can define classes inside a multiclass, so the name of outer multiclass is concatenated to the qualified name. But for current TableGen grammar, we can't define classes in multiclass, so it is unnecessary. This commit is requested in D152998.
2023-07-11[TableGen] Refactor the implementation of arguments to introduce ↵wangpc1-15/+15
ArgumentInit [nfc] A new Init type ArgumentInit is added to represent arguments. We currently only support positional arguments; an upcoming change will add named argument support. The index of argument in error message is removed. Differential Revision: https://reviews.llvm.org/D154066
2023-07-11[TableGen] Extract functions to resolve arguments [nfc]wangpc1-82/+65
The code to resolve class/multiclass arguments are similar, we extract them to `resolveArguments`s to simplify code. Reviewed By: tra, reames Differential Revision: https://reviews.llvm.org/D154065
2023-06-07[TableGen] Add !setdagarg and !setdagnameMichael Liao1-0/+43
- 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-05-31[TableGen] Add !getdagarg and !getdagnameMichael Liao1-0/+33
- 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-24[TableGen] Unify the priority of variableswangpc1-74/+131
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-04-26TableGen: Prune convertInitListSlice and VarListElementInitNAKAMURA Takumi1-3/+3
They were dedicated to constant version of list slice. Depends on D147401 Differential Revision: https://reviews.llvm.org/D145872
2023-04-26TableGen: Let expressions available to list subscriptions and list slicesNAKAMURA Takumi1-9/+168
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.