545 Commits

Author SHA1 Message Date
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
Jay Foad
f7cddf8006
[TableGen] Use std::move instead of swap. NFC. (#81606)
Historically TableGen has used `A.swap(B)` to move containers without
the expense of copying them. Perhaps this predated rvalue references. In
any case `A = std::move(B)` seems like a more direct way to implement
this when only A is required after the operation.
2024-02-13 14:31:54 +00:00
Jay Foad
880afa1c5d
[TableGen] Use vectors instead of sets for testing intersection. NFC. (#81602)
In a few places we test whether sets (i.e. sorted ranges) intersect by
computing the set_intersection and then testing whether it is empty. For
this purpose it should be more efficient to use a std:vector instead of
a std::set to hold the result of the set_intersection, since insertion
is simpler.
2024-02-13 13:44:31 +00:00
Pierre van Houtryve
b9079baadd
[NFC] clang-format utils/TableGen (#80973)
```
find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i
```

Split from #80847
2024-02-09 09:27:04 +01:00
Michael Liao
70f5b22050 [TableGen][AsmMatcher] Fix the range check on 'MatchClassKind'
- When selecting the minimal type for 'MatchClassKind' during the
  emission of 'MatchEntry' and 'OperandMatchEntry', two pre-defined
  kinds 'InvalidMatchClass' and 'OptionalMatchClass' are not taken into
  account.
2024-01-29 11:25:50 -05:00
Kazu Hirata
1daf2994de [llvm] Use StringRef::contains (NFC) 2023-12-23 22:21:52 -08:00
Michael Liao
33d5f4314f [TableGen] AsmParser: Keep consistent naming. NFC 2023-12-18 16:08:43 -05:00
Simon Pilgrim
141122ece3 [TableGen] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.
startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-11-03 17:53:56 +00: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
Sergei Barannikov
a16797699e [MC] Use ParseStatus in generated AsmParser methods
ParseStatus is slightly more convenient to use due to implicit
conversion from bool, which allows to do something like:
```
  return Error(L, "msg");
```
when with MatchOperandResultTy it had to be:
```
  Error(L, "msg");
  return MatchOperand_ParseFail;
```
It also has more appropriate name since parse* methods are not only for
parsing operands.

Reviewed By: kosarev

Differential Revision: https://reviews.llvm.org/D154303
2023-07-04 22:10:03 +03:00
Wang, Xin10
8a5450d322 Fix regression after D150436
llvm-clang-x86_64-expensive-checks-debian will fail after D150436 merged.
The fail occurred in X86, I changed the sort rule in AsmMatcher in Patch D150436, so x86 code will arrive line 633 first(will not affect other targets).
The logic here want to use the order record written in source file to make AsmMatcher to first use AVX instructions, it used field HasPositionOrder.
But the condition here just makes sure one of the compared record is subclass of Instruction and has field HasPositionOrder true, and didn't check another.

(Committing on behalf of @XinWang10 to unblock broken expensive-cjhecks builds)

Differential Revision: https://reviews.llvm.org/D150651
2023-05-16 13:04:44 +01:00
Wang, Xin10
9a24ba2397 Correct the sort logic in AsmMatcherEmmitter.cpp
The logic from line 633 to 640 is specific for ARM as the comments said, it will make all the targets will prefer to using instruction with more predicates when compiler do AsmMatching.
And for code from line 642 to 649, X86 want to use the order records written in source file to sort the instructions. So X86 could be affected by this logic. (These code could be arrived only by X86)
After change this, seems AVX instructions have not be affected but it exposed some other errors for instruction push and call.
CALLpcrel16 could not be used in 64 bit mode, we need add Predicate for it. And for push instruction, previously because pushi32 has predicates = [Not64bitmode], so it precede pushi16, which is incorrect here, we should get pushw here and it also align with gcc.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D150436
2023-05-16 02:44:02 -04:00
Akshay Khadse
66219728e3 [Coverity] Fix uninitialized scalar members in TableGen
This change fixes static code analysis warnings

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D148815
2023-04-21 17:42:33 +08:00
Shraiysh Vaishay
7021182d6b [nfc][llvm] Replace pointer cast functions in PointerUnion by llvm casting functions.
This patch replaces the uses of PointerUnion.is function by llvm::isa,
PointerUnion.get function by llvm::cast, and PointerUnion.dyn_cast by
llvm::dyn_cast_if_present. This is according to the FIXME in
the definition of the class PointerUnion.

This patch does not remove them as they are being used in other
subprojects.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D148449
2023-04-17 13:40:51 -05:00