558 Commits

Author SHA1 Message Date
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
5f2e88a125
[NFC][TableGen] Rename CodeGenTarget instruction accessors (#146767)
Rename `getXYZInstructionsByEnumValue()` to just `getXYZInstructions`
and drop the `ByEnumValue` in the name.
2025-07-07 08:01:14 -07:00
Fangrui Song
0255ae81ba AsmMatcher: Use getAsmInfo() 2025-06-28 12:12:20 -07:00
Fangrui Song
e878b7e349 MCParsedAsmOperand::print: Add MCAsmInfo parameter
so that subclasses can provide the appropriate MCAsmInfo to print
MCExpr objects.

At present, llvm/utils/TableGen/AsmMatcherEmitter.cpp constucts a
generic MCAsmInfo.
2025-06-28 12:05:33 -07:00
Rahul Joshi
f608716b09
[LLVM][TableGen] Minor cleanup in CGIOperandList (#142721)
- Change `hadOperandNamed` to return index as std::optional and rename
it to `findOperandNamed`.
- Change `SubOperandAlias` to return std::optional and rename it to
`findSubOperandAlias`.
2025-06-24 18:47:53 -07:00
Jay Foad
39ad3151e0
[TableGen] Use default member initializers. NFC. (#144349)
Automated with clang-tidy -fix -checks=-*,modernize-use-default-member-init
2025-06-16 15:26:47 +01:00
Longsheng Mou
52360d195b
[NFC] Use llvm::includes instead of std::includes (#143542)
This PR follows up #143297.
2025-06-12 09:27:27 +08:00
Rahul Joshi
b5e3d8ec08
[LLVM][TableGen] Use StringRef for various members CGIOperandList::OperandInfo (#140625)
- Change `Name`, `SubopNames`, `PrinterMethodName`, and
`EncoderMethodNames` to be stored as StringRef.
- Also changed `CheckComplexPatMatcher::Name` to StringRef as a fallout
from the above.

Verified that all the tablegen generated files within LLVM are
unchanged.
2025-05-21 06:23:01 -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
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
Craig Topper
733c250bd5 [TableGen] Fix typo in comment. NFC 2025-04-18 10:45:49 -07: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
e81f7ca637
[TableGen] Avoid repeated hash lookups (NFC) (#127373) 2025-02-16 08:16:10 -08:00
Rahul Joshi
d6cf04c401
[NFC][TableGen] Make AsmMatcherEmitterCat static (#125881) 2025-02-05 11:47:23 -08:00
Craig Topper
0e4a10dff8 [MC] Add MCRegister::isPhysical. NFC 2025-01-18 22:28:37 -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
Jinsong Ji
2e30df740e
[TableGen] Fix validateOperandClass for non Phyical Reg (#118146)
https://github.com/llvm/llvm-project/commit/b71704436e61
Rewrote the register operands handling,
but the Table only contains physical regs, we will SEGV when there are
non physical regs.

---------

Co-authored-by: Sergei Barannikov <barannikov88@gmail.com>
2024-11-30 12:07:15 -05:00
Jay Foad
89b08c8ee7
[TableGen] Simplify generated code for isSubclass (#117351)
Implement isSubclass with direct lookup into some tables instead of
nested switches.

Part of the motivation for this is improving compile time when clang-18
is used as a host compiler, since it seems to have trouble with very
large switch statements.
2024-11-28 08:52:02 +00:00
Jay Foad
b71704436e
[TableGen] Simplify generated code for validateOperandClass (#117889)
Implement the register operand handling in validateOperandClass with a
table lookup instead of a potentially huge switch.

Part of the motivation for this is improving compile time when clang-18
is used as a host compiler, since it seems to have trouble with very
large switch statements.
2024-11-27 16:49:35 +00:00
Jay Foad
535247841d
[TableGen] Remove comments from generated validateOperandClass (#117352)
This generated comments like:

  // 'BoolReg' class
  case MCK_BoolReg: {

which seem redundant because the name is always repeated on the next
line as part of the MCK_ enumerator.
2024-11-25 12:11:01 +00:00
Jay Foad
285754d799 [TableGen] Fix closing brace indentation in validateOperandClass 2024-11-22 17:42:39 +00:00
Fangrui Song
9bb5af8a42 [TableGen] Replace StringRef::slice with substr. NFC 2024-10-30 22:27:12 -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
Rahul Joshi
8a36eb83e5
[LLVM][TableGen] Change AsmMatcherEmitter to use const RecordKeeper (#109174)
Change AsmMatcherEmitter 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-20 04:20:52 -07:00
Rahul Joshi
cb5f81dc94
[LLVM][TableGen] Use range for loops in AsmMatcherEmitter (#108914)
Use range for loops in AsmMatcherEmitter.
Convert some Record pointers to const.
2024-09-18 04:57:15 -07:00
Rahul Joshi
8783bd5faa
[LLVM][TableGen] Change CodeGenInstAlias to use const Record pointers (#108753)
Change CodeGenInstAlias to use const Record pointers.

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 07:27:41 -07:00
Craig Topper
520ddf22b2
[TableGen] Remove duplicate code in applyMnemonicAliases when target uses DefaultAsmParserVariant. (#108494)
The DefaultAsmParserVariant has an empty name. MnemonicAlias uses an
empty string to mean the alias applies to all variants.

Targets that uses DefaultAsmParserVariant were emitting the same code
inside the variant loop and after the variant loop because an empty
string got passed to emitMnemonicAliasVariant in both places.

This patch detects the empty variant name in the loop and skips the
emission.
2024-09-12 23:38:31 -07:00
Rahul Joshi
7c6592f5a3
[TableGen] Change CodeGenRegister to use const Record pointer (#108027)
Change CodeGenRegister to use 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-09-11 08:53:47 -07:00
Rahul Joshi
2b452b455e
[TableGen] Change SubtargetFeatureInfo to use const Record pointers (#108013)
Change SubtargetFeatureInfo to use const Record pointers.

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-11 08:53:21 -07:00
Rahul Joshi
3786568196
[TableGen] Change CodeGenInstruction record members to const (#107921)
Change CodeGenInstruction::{TheDef, InfereredFrom} to const pointers.

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-11 08:52:26 -07:00
Rahul Joshi
bdf02249e7
[TableGen] Change CGIOperandList::OperandInfo::Rec to const pointer (#107858)
Change CGIOperandList::OperandInfo::Rec and CGIOperandList::TheDef to
const 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-09-09 14:33:21 -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
Kazu Hirata
71eebe9daa
[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#106190)
S.substr(N, M) is simpler than S.slice(N, N + M).  Also, substr is
probably better recognizable than slice thanks to
std::string_view::substr.
2024-08-27 06:46:20 -07:00
Kazu Hirata
33e7cd6ff2
[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#105943)
S.substr(N) is simpler than S.slice(N, StringRef::npos) and
S.slice(N, S.size()). Also, substr is probably better recognizable
than slice thanks to std::string_view::substr.
2024-08-25 11:30:49 -07:00
Rahul Joshi
1193f7d648
[NFC] Use const members of StringToOffsetTable (#105824) 2024-08-25 05:40:21 -07:00
Youngsuk Kim
caf26b9437
[llvm][utils] Avoid 'raw_string_ostream::str()' (NFC) (#97160)
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-06-29 18:50:52 -04:00
Kazu Hirata
d9293519bc
[TableGen] Use llvm::unique (NFC) (#94163) 2024-06-02 11:52:12 -07:00
Kazu Hirata
bb6df0804b
[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  70 under llvm/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-08 10:33:53 -07:00
Freddy Ye
f4509cf284
[X86][MC] Support enc/dec for SETZUCC and promoted SETCC. (#86473)
apx-spec: https://cdrdv2.intel.com/v1/dl/getContent/784266
apx-syntax-recommendation:
https://cdrdv2.intel.com/v1/dl/getContent/817241
2024-04-11 10:18:29 +08:00
Pierre van Houtryve
fa3d789df1
[RFC][TableGen] Restructure TableGen Source (#80847)
Refactor of the llvm-tblgen source into:
- a "Basic" library, which contains the bare minimum utilities to build
`llvm-min-tablegen`
- a "Common" library which contains all of the helpers for TableGen
backends. Such helpers can be shared by more than one backend, and even
unit tested (e.g. CodeExpander is, maybe we can add more over time)

Fixes #80647
2024-03-25 09:40:35 +01:00
Sergei Barannikov
5e5b656102
[MC] Make MCParsedAsmOperand::getReg() return MCRegister (#86444) 2024-03-25 05:13:48 +03:00
Benjamin Kramer
c18fc4fcf3 Remove unused include. NFC 2024-03-18 12:51:42 +01:00
Alfie Richards
295cdd5c3d
[ARM][TableGen][MC] Change the ARM mnemonic operands to be optional for ASM parsing (#83436)
This changs the way the assembly matcher works for Aarch32 parsing.
Previously there was a pile of hacks which dictated whether the CC,
CCOut, and VCC operands should be present which de-facto chose if the
wide/narrow (or thumb1/thumb2/arm) instruction version were chosen.

This meant much of the TableGen machinery present for the assembly
matching was effectively being bypassed and worked around.

This patch makes the CC and CCOut operands optional which allows the ASM
matcher operate as it was designed and means we can avoid doing some of
the hacks done previously. This also adds the option for the target to
allow the prioritizing the smaller instruction encodings as is required
for Aarch32.
2024-03-18 11:25:13 +00:00
Alfie Richards
6854f6f1b1
[TableGen] Add PreferSmallerInstructions for Targets. (#83587)
This option means that in assembly matching instructions with smaller
encodings will be preferred.

This will be used for the ARM instruction set where this is the correct
behavior after some other refactoring.
2024-03-18 09:04:37 +00:00
Alfie Richards
3128c202f1
[TableGen] Bug fix for tied optional operands resolution (#83588)
This fixes tied operand resolution in cases where there are optional operands before the tied operand.
2024-03-18 09:03:45 +00:00
Sergei Barannikov
199bbe2b38
[MC] Teach checkAsmTiedOperandConstraints about optional operands (#81381)
At some point in the past, optional operands have become allowed in the
middle of an instruction. However, `checkAsmTiedOperandConstrains`
hasn't been modified to support this. This patch adds the support by
pulling operand offsets counting out of `convertToMCInst` and reusing it
in `checkAsmTiedOperandConstrains`.
2024-03-01 13:00:39 +03:00
Sergei Barannikov
1e4c76cdc9
[MC][AsmParser] Make MatchRegisterName return MCRegister (NFC) (#81408)
`MCRegister` is preferred over `unsigned` nowadays.
2024-02-18 13:59:49 +03:00
Jay Foad
f723260a80
[TableGen] Stop using make_pair and make_tuple. NFC. (#81730)
These are unnecessary since C++17.
2024-02-14 13:16:20 +00:00
Jay Foad
5e5e51e906 Make use of std::inserter. NFC. 2024-02-13 14:34:58 +00:00