627 Commits

Author SHA1 Message Date
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
Youngsuk Kim
d31e314131 [llvm] Don't call raw_string_ostream::flush() (NFC)
Don't call raw_string_ostream::flush(), which is essentially a no-op.
As specified in the docs, raw_string_ostream is always unbuffered.
( 65b13610a5226b84889b923bae884ba395ad084d for further reference )
2024-09-20 12:19:59 -05:00
Jay Foad
e03f427196
[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)
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-09-19 16:16:38 +01:00
Rahul Joshi
47c3df2a7f
[LLVM][TableGen] Change CallingConvEmitter to use const RecordKeeper (#108955)
Change CallingConvEmitter to use const RecordKeeper.

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-18 07:19:40 -07:00
Rahul Joshi
ef71226fcd
[LLVM][TableGen] Change WebAsm Emitter to use const RecordKeeper (#109051)
Change WebAssemblyDisassemblerEmitter to use const RecordKeeper.

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-18 05:37:54 -07:00
Rahul Joshi
3ae71d154e
[LLVM][TableGen] Change CodeGenSchedule to use const RecordKeeper (#108617)
Change CodeGenSchedule to use const RecordKeeper.

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-15 04:55:29 -07:00
Rahul Joshi
1651014960
[TableGen] Change SetTheory set/vec to use const Record * (#107692)
Change SetTheory::RecSet/RecVec to use const Record pointers.
2024-09-09 08:47:42 -07:00
Rahul Joshi
ce3c58e104
[NFC][TableGen] Replace DefInit::get() with Record::getDefInit() (#107762)
Eliminate DefInit::get() as its a duplicate of Record::getDefInit(). 
Use early return in `VarDefInit::instantiate`.
2024-09-08 12:18:53 -07:00
Rahul Joshi
98563b19c2
[libc][TableGen] Migrate libc-hdrgen backend to use const RecordKeeper (#107542)
Migrate libc-hdrgen backend to use const RecordKeeper
2024-09-07 15:14:07 -07:00
Rahul Joshi
0ceffd362b
[TableGen] Add PrintError family overload that take a print function (#107333)
Add PrintError and family overload that accepts a print function. This
avoids constructing potentially long strings for passing into these
print functions.
2024-09-07 05:13:54 -07:00
Rahul Joshi
16df489fda
[TableGen] Add const variants of accessors for backend (#106658)
Split RecordKeeper `getAllDerivedDefinitions` family of functions into
two variants:
  (a) non-const ones that return vectors of `Record *` and 
  (b) const ones, that return vector/ArrayRef of `const Record *`.

This will help gradual migration of TableGen backends to use 
`const RecordKeeper` and by implication change code to work 
with const pointers and better const correctness.

Existing backends are not yet compatible with the const family of
functions, so change them to use a non-constant `RecordKeeper` 
reference, till they are migrated.
2024-09-05 18:35:55 -07:00
Rahul Joshi
30f1cfb4d0
[TableGen] Print memory stats in detailed record emitter (#106990)
Print memory allocation and related statistics when dumping detailed
record information.
2024-09-04 07:04:32 -07:00
Rahul Joshi
bcde45bae8
[NFC][TableGen] Refactor JSON and detailed record emitter (#105770)
- Fix JSON and detailed record emitters to use const reference and pointers.
- Fix code to use C++ structured bindings and range-based loops, including reverse() range for locations.
- Eliminate `NL` define for "\n".
- Change JSON emitter to populate `instance_list` in an earlier loop over superclasses instead of a separate loop.
- Rename variables in JSON emitter to conform to LLVM naming conventions.
- Eliminate unused headers in detailed record emitter.
2024-08-26 16:57:18 -07:00
Rahul Joshi
34dee0a961
[TableGen] Allow emitter callbacks to use const RecordKeeper & (#104716)
- Refactor TableGen backend options to allow specifying a callback
  function that takes either a const reference or a non-const reference
  to `RecordKeeper`. This will enable gradual migration of code to use
  const references and pointers to `RecordKeeper` and  `Record` in the
  TableGen backends. 

- Refactor handling of the callback command line options. Move variable
  for the command line option from the header to the CPP file, and add a
  function `ApplyCallback` to apply the selected callback.

- Change callbacks in TableGen.cpp to take const reference. They use the
  `Opt` class to register their callbacks.

- Change IntrinsicEmitter to use the `OptClass` to define its callbacks.
  It already uses a const reference in the implementation.
2024-08-26 12:10:33 -07:00
Rahul Joshi
d7da79f2cd
[NFC][SetTheory] Refactor to use const pointers and range loops (#105544)
- Refactor SetTheory code to use const pointers when possible.
- Use auto for variables initialized using dyn_cast<>.
- Use range based for loops and early continue.
2024-08-22 05:47:31 -07:00
Rahul Joshi
e6751bfbf7
[NFC][TableGen] Elminate use of isalpha/isdigit from TGLexer (#104837)
- Replace use of std::isalpha, std::isdigit, std:isxdigit with LLVM's
StringExtras versions, to avoid possibly locale dependent behavior (e.g.
glibc).
- Create helper function for common checks for valid identifier
characters.
2024-08-20 09:54:12 -07:00
Rahul Joshi
340fb65971
[TableGen] Detect invalid -D arguments and fail (#102813)
- Detect invalid macro names specified on command line and fail if one
found.
- Specifically, -DXYZ=1 for example, will fail instead is being silently
accepted.
2024-08-19 10:15:52 -07:00
Akshat Oke
576aa3a509
[TableGen] Resolve References at top level (#104578)
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-08-19 21:05:39 +05:30
Akshat Oke
82fdfd4aa7
[TableGen] Print Error and not crash on dumping non-string values (#104568)
Co-authored-by: Akshat Oke <Akshat.Oke@amd.com>
2024-08-19 09:59:47 +05:30
Rahul Joshi
b68df879c6
[TableGen] Fix build failure by using int type for NextChar (#103000)
Fixes an issue in https://github.com/llvm/llvm-project/pull/102967, 
which inddvertently changed the type of `NextChar` from int to char,
causing ppc64le build failures.
2024-08-13 07:47:30 +03:00
Rahul Joshi
b8fc97fdc1
[NFC][TableGen] Refactor preprocessor directive handling (#102967)
- Make `PreprocessorDirs` array constexpr, move its definition outside
the anonymous namespace, and make it static.
- Change `Word` field to a StringRef.
- Simplify `prepIsDirective` to use StringRef comparison and early
`continue` per LLVM coding standards.
- Use C++17 structured bindings to iterate over the array.
2024-08-13 07:05:07 +03:00
Kazu Hirata
94e6786b80
[llvm] Construct SmallVector with ArrayRef (NFC) (#102799) 2024-08-11 08:13:11 -07:00
Kazu Hirata
2e9d2f183f
[TableGen] Construct SmallVector with ArrayRef (NFC) (#101870) 2024-08-04 08:54:07 -07:00
Kazu Hirata
837dc3b179
[TableGen] Use range-based for loops (NFC) (#97678) 2024-07-09 05:55:08 +09:00
Youngsuk Kim
82f9a5ba96 [llvm] Avoid 'raw_string_ostream::str' (NFC)
Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO comment to remove `raw_string_ostream::str()`.
2024-07-03 06:37:48 -05:00
Craig Topper
2a4ee605b0 [TableGen] Use LessRecord() for the sort in getAllDerivedDefinitions instead of re-implementing it. NFC 2024-05-16 15:42:16 -07:00
Fangrui Song
a1ed821b49 [TableGen] Simplify prepSkipToLineEnd for preprocessing
The MemoryBuffer is created using `RequiresNullTerminator`, so we can
safely skip the `CurPtr != CurBuf.end()` check. The redundant check
causes a cppcheck report. In addition, elsewhere, including `*CurPtr ==
'#'` below, makes the null terminator assumption as well.

Close #81120
2024-02-08 10:56:00 -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
Visoiu Mistrih Francis
fef2fc3400
[TableGen] Support non-def operators in !getdagop (#77531)
`!getdagop` expects the dag operator to be a def, and errors out if it's
not.

While that's true in most cases, when multiclasses are involved, the
late resolution of the dag operator can result in it not being a def
yet, but still have a proper type, wich is required to check against the
optional parameter Ty in `!getdagop<Ty>`.

e.g, in the following dag:
```
(!cast<TestInstruction>(TestInstructionAndPattern::NAME) foo)
```
the operator is a UnOpInit, but all we need here is to check its type.

This fixes a bug where !getdagop is used to query the dag operator that
is dependent on the multiclass, which is not yet resolved to a def. Once
the folding is performed, the field becomes a record that can be
queried.
2024-01-10 06:59:38 -08:00
Kazu Hirata
dc1f208346 [TableGen] Remove unnecessary includes (NFC)
Identified with clangd.
2023-12-07 21:03:55 -08:00
Kazu Hirata
92c2529ccd [llvm] Stop including vector (NFC)
Identified with clangd.
2023-12-03 22:32:21 -08:00
Kazu Hirata
0d55ea25a6 [llvm] Stop including llvm/ADT/DenseMapInfo.h (NFC)
Identified with clangd.
2023-11-11 00:13:29 -08:00
Kazu Hirata
f9306f6de3
[ADT] Rename llvm::erase_value to llvm::erase (NFC) (#70156)
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 23:03:13 -07:00
Wang Pengcheng
d1d3aa34ec
[TableGen][NFC] Add record kind to Record class (#69919)
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-24 14:28:38 +08:00
Wang Pengcheng
1e43975652
[TableGen][NFC] Remove MultiClass argument and Scoper in QualifyName (#69297)
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-23 11:22:15 +08: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
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
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
Shao-Ce SUN
b0e28eb832
[llvm][tblgen] Add Source Filename for emitSourceFileHeader (#65744)
I think this is very helpful for reading generated `.inc` files.
2023-09-26 13:40:56 +08:00
NAKAMURA Takumi
c84f9f9a81 Reformat 2023-09-26 12:29:21 +09:00
Min-Yih Hsu
a09f09c618 [TableGen] Fix incorrect handling of nested #ifndef directives
TableGen's lexer was unable to handle nested #ifndef when the outer
`#ifdef` / `#ifndef` scope is subject to skip. This was caused by returning
the canonicalized token when it should have returned the original one.

Fix #65100.

Differential Revision: https://reviews.llvm.org/D159236
2023-09-07 12:42:22 -07:00
Senran Zhang
cd7280b6e6 [TableGen] Fix wrong lex result on 64-bit integer boundaries
Binary and decimal values were reconginzed by strtoll, which returns
error when the msb is 1, and the error was ignored, resulting to wrong
results.

This patch fixes the issue.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D157079
2023-08-20 21:46:36 -07:00
Kazu Hirata
c74b20602a [TableGen] Modernize SubMultiClassReference (NFC) 2023-08-19 07:56:32 -07:00
Kazu Hirata
9517afe21e [TableGen] Modernize SubClassReference (NFC) 2023-08-19 07:56:31 -07:00
wangpc
eb6987027e [TableGen] Improve error report of unspecified arguments
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-03 17:22:34 +08:00
wangpc
ebf394fdfc [TableGen][NFC] Group tokens with same attribute togather
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-08-01 22:00:21 +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
wangpc
aa84326694 [TableGen][NFC] Remove unreachable code
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-20 15:24:09 +08:00
wangpc
6251adc64d [TableGen] Refactor the implementation of arguments to introduce 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 11:42:07 -07:00