691 Commits

Author SHA1 Message Date
Rahul Joshi
e31e6f259e
[TableGen] Print assert message inline with assert failure (#111184)
Print assert message after the "assertion failed" message instead of
printing it as a separate note. This makes the assert failure reporting
less verbose and also more useful to see the failure message inline with
the "assertion failed" message.
2024-10-04 13:21:50 -07:00
Rahul Joshi
b91f0def6f
[TableGen] Change backend callback to require const RecordKeeper (#111064)
Change TableGen backend callback function to require a const
RecordKeeper argument (by changing it from function_ref to just a
function pointer). This undoes parts of
https://github.com/llvm/llvm-project/pull/104716 which was added to
enable gradual migration of TableGen backends to use const RecordKeeper
(by allowing either const or non-const references). Now that all
backends have been migrated to const reference, we do not need this.

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-04 09:24:48 -07:00
Rahul Joshi
d883ef1076
[TableGen] Factor out timer code into a new TGTimer class (#111054)
Factor out the timer related functionality from `RecordKeeper` to a new
`TGTimer` class in a new file.
2024-10-04 09:23:55 -07:00
Rahul Joshi
04540fac5b
[TableGen] Print record location when record asserts fail (#111029)
When record assertions fail, print an error message with the record's
location, so it's easier to see where the record that caused the assert
to fail was instantiated. This is useful when the assert condition in a
class depends on a template parameter, so we need to know the context of
the definition to determine why the assert failed.

Also enhanced the assert.td test to check for these context messages,
and also add checks for some assert failures that were missing in the
test.
2024-10-04 05:45:45 -07:00
Rahul Joshi
667815ccf4
[NFC][TableGen] Change RecordKeeper::getDef() to return const pointer (#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 08:18:43 -07:00
Rahul Joshi
b78bfe7169
[TableGen] Delete non-const overloads of getAllDerivedDefinitions (#110990)
Now that all TableGen backends have transitioned to const versions of
these functions, we do not need the non-const versions anymore.

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 08:18:04 -07:00
Rahul Joshi
241f93658a
[TableGen] Fix source location for anonymous records (#110935)
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-03 06:16:56 -07: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
d256b9e88b
[TableGen] Change DefInit::Def to a const Record pointer (#110747)
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-02 09:48:26 -07:00
Rahul Joshi
a140931be5
[TableGen] Change getValueAsListOfDefs to return const pointer vector (#110713)
Change `getValueAsListOfDefs` to return a vector of const Record
pointer, and remove `getValueAsListOfConstDefs` that was added as a
transition aid.

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 14:30:38 -07:00
Rahul Joshi
9d95e2614e
[TableGen] Change all type pointers to const (#110602)
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 06:54:17 -07:00
Rahul Joshi
a86e966a20
[TableGen] Change TableGenMain to use const RecordKeeper (#110578)
Change TableGenMain's `MainFn` argument to be a function that accepts a
const reference to 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-10-01 06:51:07 -07:00
Stephen Chou
ec61311e77
[LLVM][TableGen] Support type casts of nodes with multiple results (#109728)
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-10-01 11:17:00 +04:00
Rahul Joshi
7ac474baad
[LLVM][TableGen] Change SeachableTableEmitter to use const RecordKeeper (#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-30 10:08:48 -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
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