691 Commits

Author SHA1 Message Date
Sergei Barannikov
c69355e7d1
[TableGen] Use getValueInit to reduce code duplication (NFC) (#153167) 2025-08-12 17:18:00 +03:00
Rahul Joshi
7b9786b4a6
[NFC][TableGen] Capitalize comments in TGLexer.cpp (#152224) 2025-08-05 17:26:08 -07:00
Rahul Joshi
315e1f59c8
[NFC] Run clang-format on TGLexer and TGParser (#151509)
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-08-05 16:37:29 -07:00
Nemanja Ivanovic
144ae251aa
[TableGen] Improve handling for dag op names (#149248)
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-29 09:05:17 +02:00
Jay Foad
b9f5b39e04
[TableGen] Remove explicit recursion in LexToken (#143697)
When profiling a Release+Asserts build of llvm-tblgen I noticed that it
was recursing hundreds of times to lex a sequence of hundreds of space
characters.
2025-07-16 21:54:49 +01:00
Slava Zakharin
e685e4a771
TableGen: Fixed the string table definitions visibility. (#148946)
This fixes the buildbots issues reported in #148839.
2025-07-15 14:32:48 -07:00
Matt Arsenault
8db92a7d99
TableGen: Avoid emitting trailing whitespace in StringToOffsetTable (#148840) 2025-07-15 23:26:58 +09:00
Matt Arsenault
af56fd0c1a
TableGen: Use StringOffsetTable for RuntimeLibcall names (#148839) 2025-07-15 23:24:46 +09:00
Rahul Joshi
2366573679
[TableGen] Minor cleanup in StringToOffsetTable (#147712)
Make `AppendZero` a class member instead of an argument to
`GetOrAddStringOffset` to reflect the intended usage that for a given
`StringToOffsetTable`, all strings must use the same value of
`AppendZero`.

Modify `EmitStringTableDef` to drop the `Indent` argument as its always
set to `""`, and to fail if it's called for a table with
non-null-terminated strings.
2025-07-09 12:22:29 -07:00
Rahul Joshi
e5cd9bdfea
[NFC][TableGen] Delete extra spaces in comments (#147004) 2025-07-04 07:06:41 -07:00
Rahul Joshi
9382a95e65
[NFC][TableGen] Adopt ArrayRef::consume_front() in PrintMessage (#146775)
Adopt `ArrayRef::consume_front()` in `PrintMessage`, and convert the
loop in that function to a range for loop.
2025-07-02 19:18:21 -07:00
Rahul Joshi
fba63e3281
[NFC][TableGen] Use ArrayRef instead of const vector reference (#145323)
- Use `ArrayRef` instead of `SmallVector` reference in a few places.
- Drop redundant `llvm::` in a few places.
2025-06-24 07:30:00 -07:00
Min-Yih Hsu
ecdb549e6d
[TableGen] Avoid evaluating RHS of a BinOp until short-circuit is complete (#144021)
This patch adds an even more aggressive short-circuit on `!and` and
`!or` that completely avoids the evaluation of RHS operand until short
circuiting decisions are made.
2025-06-13 10:36:09 -07:00
Kazu Hirata
228f66807d
[llvm] Remove unused includes (NFC) (#142733)
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-06-04 12:30:52 -07:00
Adam Nemet
9f5a670297
[TableGen] !subst on a dag should retain name of operator (#141195)
Without this patch the !subst in the test drops the name "$frag" from
(one_frag:$frag ...) and returns:

```
(set FPR32_NEW:$dst, (one_frag FPR32_NEW:$a, FPR32_NEW:$b))
```
2025-05-23 12:03:56 -07:00
Adam Nemet
1a4d588738
[TableGen] Add missing $ before the dag operator name (#140969)
This way the dump output is roundtripable.
2025-05-22 16:21:19 -07:00
Rahul Joshi
523d6c3b69
[NFC][TableGen] Code cleanup in StringMatcher (#141118)
- Use ArrayRef instead of const vector reference.
- Use range for loops with enumerate and structured bindings.
2025-05-22 15:55:33 -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
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
Rahul Joshi
7c57e82456
[NFC][TableGen] Code cleanup in Record.h/cpp (#138876)
- Use range for loops in several places.
- Change some variable names to conform to LLVM coding standard.
- Use ListSeparator instead of manual code to generate comma interleaved
strings.
- Remove unnecessary copies in SETDAGOP evaluation in BinOpInit::Fold.
- Eliminate duplicated code in the 2 overloads of RecordVal::setValue.
- Use explicit type in some range for loops.
- Tested by verifying that all the .inc files generated by building all
the *CommonTableGen targets stay unchanged.
2025-05-14 06:10:00 -07:00
Kazu Hirata
298ace7dff
[TableGen] Use std::string::find (NFC) (#139681)
This patch partially reverts #139661 for a better solution.
Specifically, we can take advantage of the fact that std::string::find
accepts anything that can be converted to std::string_view, including
StringRef, starting with C++17.  This way, we do not need to cast Val
to StringRef or LHSs->getValue() to std::string.
2025-05-13 15:50:09 -07:00
Kazu Hirata
c95745f2db
[llvm] Use StringRef::{starts_with,find} (NFC) (#139661)
Calling find/contains in the StringRef domain allows us to avoid
creating temporary instances of std::string.
2025-05-12 23:24:07 -07:00
Rahul Joshi
86c5112409
[NFCI][LLVM/MLIR] Adopt TrailingObjects convenience API (#138554)
Adopt `TrailingObjects` convenience API that was added in
https://github.com/llvm/llvm-project/pull/138970 in LLVM and MLIR code.
2025-05-12 16:17:43 -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
Rahul Joshi
7245e21e89
[NFC][Support] Add llvm::uninitialized_copy (#138174)
Add `llvm::uninitialized_copy` that accepts a range instead of start/end
iterator for the source of the copy.
2025-05-07 17:37:38 -07:00
Rahul Joshi
74ca51eac3
[NFC][TableGen] Use private inheritance for TrailingObjects (#138027)
- Use private inheritance for `TrailingObjects` as suggested in the
documentation for `TrailingObjects` class.
- Move std::uninitialized_copy calls from various `get` functions to the
constructors of respective classes.
- Eliminate `NumArgNames` from `DagInit`. Its always equal to `NumArgs`.
- Eliminate unused `name_size/name_empty` from `DagInit`.
2025-05-02 04:51:56 -07:00
Jay Foad
2bc6f9d4b6
[TableGen] Only store direct superclasses in Record (#123072)
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-04-24 18:57:51 +01:00
Reid Kleckner
0a27c4e318
[StrTable] Use string literal emission for intrinsics on non-MSVC platforms (#124856)
This mainly transitions the LLVM intrinsic string table from character
emission to string literal emission, which I confirmed happens for me
locally.

I moved the guts of StringToOffsetTable to a cpp file so I could move
the `EmitLongStrLiterals` cl::opt global to a non-vague linkage home in
the `TableGen` library. I had to add missing FormatVariadic.h includes
to account for moving other includes to a cpp file.
2025-04-13 17:58:53 +02:00
Kazu Hirata
6257621f41
[llvm] Use llvm::append_range (NFC) (#133658) 2025-03-30 18:43:02 -07:00
Pengcheng Wang
883612859b
[TableGen] Add !instances operator to get defined records (#129680)
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-28 16:31:00 +08:00
Kazu Hirata
599005686a
[llvm] Use *Set::insert_range (NFC) (#132325)
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently
gained C++23-style insert_range.  This patch replaces:

  Dest.insert(Src.begin(), Src.end());

with:

  Dest.insert_range(Src);

This patch does not touch custom begin like succ_begin for now.
2025-03-20 22:24:06 -07:00
Krzysztof Drewniak
193866bc24
[tblgen] Fix behavior of !isa to prevent premature folding (#130442)
The test included with this commit shows a case where, even though a
record's true type was !isa<> some unrelated class, the isa<> operator
wolud use the declared type of the argument it was examining in order to
conclude that the !isa<> expression had to be be false.

The issues is fixed by checking to make sure that the argument to the
!isa operator is fully concrete before declaring its result to be false.
2025-03-18 20:05:37 -07:00
Pengcheng Wang
376e3b62cd
[TableGen] Add !match operator to do regex matching (#130759)
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-03-13 12:13:09 +08:00
Rahul Joshi
aca08a8515
[TableGen] Add assert to validate Objects list for HwModeSelect (#123794)
- 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-27 13:44:44 -08:00
Craig Topper
76ed4b1cec
[TableGen] Add StringInit pools to RecordKeeperImpl::dumpAllocationStats. (#124164)
Remove duplicate print of TheBitsInitPool.

I don't know who or what uses this information. I happened to notice
TheBitsInitPool was printed twice which lead to auditing the whole list.
2025-01-23 12:53:13 -08:00
Jay Foad
4e8c9d2813
[TableGen] Use std::pair instead of std::make_pair. NFC. (#123174)
Also use brace initialization and emplace to avoid explicitly 
constructing std::pair, and the same for std::tuple.
2025-01-16 13:20:41 +00:00
Haojian Wu
d2ba364440 Fix an unused-variable warning in release build. 2025-01-13 12:03:35 +01:00
Jay Foad
a3b3c26048
[TableGen] Use assert instead of PrintFatalError in TGLexer. NFC. (#122303)
Do not use the PrintFatalError diagnostic machinery for conditions that
can never happen with any input.
2025-01-13 10:30:55 +00:00
Markus Böck
97ea0aba15
[TableGen] Do not exit in template argument check (#121636)
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.
2025-01-06 21:06:17 +01:00
Jay Foad
cb2eafe6ac
[TableGen] Use SmallVectors for preprocessor include stack. NFC. (#121571)
This is just a minor cleanup and a small step in the direction of using
LLVM containers in preference to STL containers in lib/TableGen.
2025-01-03 19:37:58 +00: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
David Spickett
1db2d571b5
[llvm][TableGen] Fix misleading error for invalid use of let (#118616)
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-12-09 13:21:46 +00: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
a18af41c20
[LLVM] Change error messages to start with lower case (#113748)
Change LLVM Asm and TableGen Lexer/Parser error messages to begin with
lower case.
2024-10-29 12:26:33 -07:00
Rahul Joshi
743f839a88
[NFC][LLVM][TableGen] Change RecordKeeper::getClass to return const 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-23 11:32:05 -07:00
Rahul Joshi
f58ce11527
[NFC][TableGen] Use auto when initializing variables with cast<> (#113171)
Use `auto` when initializing a variable with `cast<>`. Remove some
unneeded `const_cast` (since all Init pointers are now const).
2024-10-21 11:02:38 -07:00
Rahul Joshi
62e2c7fb2d
[LLVM][TableGen] Change all Init pointers to const (#112705)
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-18 07:50:22 -07:00
Jay Foad
68efaaafe4 [TableGen] Remove unused tokens FalseKW and TrueKW
These were introduced in https://reviews.llvm.org/D90635 but never used.
2024-10-18 15:41:22 +01:00