6126 Commits

Author SHA1 Message Date
Rahul Joshi
bee9664970
[TableGen] Emit OpName as an enum class instead of a namespace (#125313)
- Change InstrInfoEmitter to emit OpName as an enum class
  instead of an anonymous enum in the OpName namespace.
- This will help clearly distinguish between values that are 
  OpNames vs just operand indices and should help avoid
  bugs due to confusion between the two.
- Rename OpName::OPERAND_LAST to NUM_OPERAND_NAMES.
- Emit declaration of getOperandIdx() along with the OpName
  enum so it doesn't have to be repeated in various headers.
- Also updated AMDGPU, RISCV, and WebAssembly backends
  to conform to the new definition of OpName (mostly
  mechanical changes).
2025-02-12 08:19:30 -08:00
Rahul Joshi
dbe1dafdbd
[NFC][TableGen] Code cleanup in InstrInfoEmitter.cpp (#126578)
- Use range for loops and `enumerate` in a few places.
- Use `StringRef` for `TargetName` in `InstrInfoEmitter::run`.
- Use `\n` character for new line instead of string.
- Use StringRef in `InstrNames` (instead of std::string) and 
  avoid string copies.
2025-02-11 07:02:37 -08:00
Rahul Joshi
55015e150b
[NFC][TableGen] Delete getLogicalOperandType from InstrInfoEmitter (#125951)
Delete `getLogicalOperandType` function from InstrInfoEmitter as no
backend seems to use it.
2025-02-10 09:08:49 -08:00
Rahul Joshi
8380b5c749
[TableGen][InstrInfo] Cull mapping that have not been enabled/not needed (#126137)
- Detect whether logical operand mapping/named operand mappings have 
  been enabled in a previous pass over instructions and execute the
  relevant emission code only if those mappings are enabled.
- For these mappings, skip the fixed set of predefined instructions as
  they won't have these mappings enabled.
- Emit operand type mappings only for X86 target, as they are only used
  by X86 and look for X86 specific `X86MemOperand`.
- Cleanup `emitOperandTypeMappings` code: remove code to handle empty
  instruction list and use range for loops.
2025-02-10 08:16:12 -08:00
Craig Topper
04e5ea5237 [TableGen] Remove recursive walk of linked list from ContractNodes. NFC
After f9250401ef120a4605ad67bb43d3b25500900498, this function is
tail recursive so it was straightforward to convert this to iteratively
walk the linkd list.
2025-02-09 14:23:34 -08:00
Kazu Hirata
af6c6992cf
[TableGen] Avoid repeated hash lookups (NFC) (#126433) 2025-02-09 13:35:58 -08:00
Kazu Hirata
87ae9547ea
[TableGen] Avoid repeated hash lookups (NFC) (#126405) 2025-02-09 08:56:17 -08:00
Craig Topper
4aa71f0d4c [TableGen] Fix an unused variable warning. NFC 2025-02-08 16:03:44 -08:00
Craig Topper
f9250401ef [TableGen] Move formation of MoveSiblingMatcher earlier in ContractNodes. NFC
ContractNodes recursively walks forward through a linked list. During
this recursion, Matchers are combined into other Matchers.

Previously the formation of MoveSiblingMatcher was after the
recursive call so it occurred as we were unwinding. If a
MoveSiblingMatcher was formed, we would recursively walk forward
to the end of the linked list again which isn't efficient.

To make this more efficient, move the formation of MoveSiblingMatcher
to the forward pass. Add additional rules to unfold MoveSiblingMatcher
if it would be more efficient to use CheckChildType, CheckChildInteger,
CheckChildSame, etc.

As an added benefit, this makes the function tail recursive which
the compiler can better optimize.
2025-02-08 15:58:12 -08:00
Kazu Hirata
dbe812220c
[TableGen] Avoid repeated hash lookups (NFC) (#126344) 2025-02-08 00:48:30 -08:00
Rahul Joshi
d705e7e9eb
[NFC][TableGen] Code cleanup in CodeGenMapTable EmitMapTable (#126157)
- Emit C++17 nested namespaces.
- Shorten the binary search table name to just `Table` since its
declared in the scope of each search function.
- Use `using namespace XXX` in the search function to avoid emitting the
Target Inst Namespace prefix in the table entries.
- Add short-cut handling of `TableSize` == 0 case (verified in Hexagon
target).
- Use `SetVector` in `ColFieldValueMap` to get automatic deduplication
and eliminate manual deduplication code.
- Use range for loops.
2025-02-07 11:47:49 -08:00
Kazu Hirata
0afbefa282
[TableGen] Avoid repeated hash lookups (NFC) (#126190) 2025-02-07 08:00:21 -08:00
Craig Topper
01ac6fc909 [TableGen] Use range-based for loops. NFC 2025-02-06 19:14:10 -08:00
Rahul Joshi
337604ee7e
[NFC][TableGen] Adopt Emitter::OptClass in InstrInfoEmitter (#125971)
- Use `Emitter::OptClass` to invoke `InstrInfoEmitter::run` and
eliminate the `EmitInstrInfo` function.
2025-02-06 10:45:05 -08:00
Pierre van Houtryve
03478d6f2d
[GlobalISel] Prefix MatchTable Lines with their Index (#125845)
I tried to keep it readable by making the width of the column with the
index always enough to contain the largest number.
That way things don't shift to the right every time a new digit appears,
it remains consistent.

Tests don't break because this only affects the beginning of the line
and FileCheck doesn't care about what comes before for the most part.

Example of the new output:
```
     /* 758359 */   // Label 9988: @758359
     /* 758359 */   GIM_Try, /*On fail goto*//*Label 9989*/ GIMT_Encode4(758435), // Rule ID 6715 //
     /* 758364 */     GIM_CheckConstantInt8, /*MI*/0, /*Op*/2, 0,
     /* 758368 */     // MIs[0] offset
```

Fixes #119177
2025-02-06 14:00:20 +01:00
Craig Topper
5eed019080 [TableGen] Use std::copy instead of a manual copy loop. NFC 2025-02-06 00:47:18 -08:00
Rahul Joshi
d6cf04c401
[NFC][TableGen] Make AsmMatcherEmitterCat static (#125881) 2025-02-05 11:47:23 -08:00
Craig Topper
25dd93aab6
[TableGen] Add declarations to silence gcc warning. NFC (#125892)
Add declarations of SDTypeConstraint's operator== and operator< to the
llvm namespace. These are declared as friends inside the class which
makes them part of the enclosing namespace, but gcc wants it to be more
explicit.

Fixes #125537.
2025-02-05 11:22:48 -08:00
Craig Topper
31bd82cdcc [TableGen] Don't try to move CheckOpcode before CheckType/CheckChildType in ContractNodes. NFC
It appears that CheckOpcode is already emitted before CheckType so
this hasn't been doing anything on any in tree targets.
2025-02-04 21:17:20 -08:00
Kazu Hirata
a207f60727
[TableGen] Avoid repeated hash lookups (NFC) (#125635) 2025-02-04 09:10:10 -08:00
Rahul Joshi
749372ba24
[NFC][TableGen] Code cleanup in CodeGenTarget.cpp (#125569)
- Use StringRef::str() instead of std::string(StringRef).
- Use const pointers for `Candidates` in getSuperRegForSubReg().
- Make `AsmParserCat` and `AsmWriterCat` static.
- Use enumerate() in `ComputeInstrsByEnum` to assign inst enums.
- Use range-based for loops.
2025-02-03 20:04:31 -08:00
Benjamin Maxwell
82c6b8f7bb
[AArch64][SME] Spill p-regs as z-regs when streaming hazards are possible (#123752)
This patch adds a new option `-aarch64-enable-zpr-predicate-spills`
(which is disabled by default), this option replaces predicate spills
with vector spills in streaming[-compatible] functions.

For example:

```
str	p8, [sp, #7, mul vl]            // 2-byte Folded Spill
// ...
ldr	p8, [sp, #7, mul vl]            // 2-byte Folded Reload
```

Becomes:

```
mov	z0.b, p8/z, #1
str	z0, [sp]                        // 16-byte Folded Spill
// ...
ldr	z0, [sp]                        // 16-byte Folded Reload
ptrue	p4.b
cmpne	p8.b, p4/z, z0.b, #0
```

This is done to avoid streaming memory hazards between FPR/vector and
predicate spills, which currently occupy the same stack area even when
the `-aarch64-stack-hazard-size` flag is set.

This is implemented with two new pseudos SPILL_PPR_TO_ZPR_SLOT_PSEUDO
and FILL_PPR_FROM_ZPR_SLOT_PSEUDO. The expansion of these pseudos
handles scavenging the required registers (z0 in the above example) and,
in the worst case spilling a register to an emergency stack slot in the
expansion. The condition flags are also preserved around the `cmpne` in
case they are live at the expansion point.
2025-02-03 12:04:46 +00:00
Craig Topper
31db7afacf
[TableGen] Split DAGISelMatcherOpt FactorNodes into 2 functions. NFC (#125330)
The loop at the top of FactorNodes creates additional variables to deal
with needing to use a pointer to a unique_ptr instead of a reference.
Encapsulate this to its own function for better scoping.

This also allows us to directly skip this loop when we already know we
have a ScopeMatcher.
2025-02-02 19:04:59 -08:00
Craig Topper
2eabcb73c2 [TableGen] Use range-based for loop. NFC 2025-02-01 23:44:43 -08:00
Craig Topper
2d17fc4ca3 [TableGen] Reorder code in ContractNodes to prevents unnecessary recursion. NFC
The code that moves CheckOpcode before CheckType/CheckChildType/RecordDwith
was running after ContractNodes started unwinding its recursion. If a
move occurs we would start a new recursion going forward
through the list again. I don't believe this can lead to any new
combines so it was just wasted work.

This patch moves the code earlier so it doesn't start a new recursion.
2025-01-31 23:45:40 -08:00
Craig Topper
028b69009a [TableGen] Remove unnecessary check before calling SmallVector::erase. NFC
This was checking whether the erase is needed, but erase is safe
to call with equal iterators.
2025-01-31 21:42:11 -08:00
Rahul Joshi
91e77d88a4
[TableGen] Restore OpName::OPERAND_LAST emission in InstrInfoEmitter (#125265)
- Looks like this sentinel value is used in some downstream backends, so
restore emitting it.
- It now also has the correct value (earlier code may have emitted an
incorrect value for OPERAND_LAST and hence it was removed in
https://github.com/llvm/llvm-project/pull/124960)
2025-01-31 13:19:11 -08:00
Nikita Popov
e2301d6749
[TableGen] Reduce size of MatchTableRecord (NFC) (#125221)
MatchTableRecord stores a 64-bit RawValue. However, this field is only
needed by a small part of the code (jump table generation).

Create a separate RecordAndValue structure that is used in just the
necessary places.

Based on massif, this reduces memory usage on RISCVGenGlobalISel.inc by
about 100MB (to 2.15GB).
2025-01-31 17:37:17 +01:00
Rahul Joshi
fdfd97959e
[TableGen] Improvements to Named operands in InstrInfoEmitter (#124960)
- Assign `OpName` enum values in the same alphabetical order in which
they are emitted.
- Get rid of OPERAND_LAST which is not used anywhere.
- Inline `initOperandMapData` into `emitOperandNameMappings` to help see
clearly how various maps are computed.
- Emit the static `OperandMap` table as int8_t when possible. This
should help reduce the static size by 50% in the common case.
- Change maps/vectors to use StringRef instead of std::string to avoid
unnecessary copies.
2025-01-30 13:04:06 -08:00
Nikita Popov
29441e4f5f
[IR] Convert from nocapture to captures(none) (#123181)
This PR removes the old `nocapture` attribute, replacing it with the new
`captures` attribute introduced in #116990. This change is
intended to be essentially NFC, replacing existing uses of `nocapture`
with `captures(none)` without adding any new analysis capabilities.
Making use of non-`none` values is left for a followup.

Some notes:
* `nocapture` will be upgraded to `captures(none)` by the bitcode
   reader.
* `nocapture` will also be upgraded by the textual IR reader. This is to
   make it easier to use old IR files and somewhat reduce the test churn in
   this PR.
* Helper APIs like `doesNotCapture()` will check for `captures(none)`.
* MLIR import will convert `captures(none)` into an `llvm.nocapture`
   attribute. The representation in the LLVM IR dialect should be updated
   separately.
2025-01-29 16:56:47 +01:00
Craig Topper
d1997322cb [TableGen] Use MCRegister::id() to avoid an implicit conversion from MCRegister to unsigned. NFC 2025-01-28 23:41:13 -08:00
Chandler Carruth
f4de28a63c
[StrTable] Switch intrinsics to StringTable and work around MSVC (#123548)
Historically, the main example of *very* large string tables used the
`EmitCharArray` to work around MSVC limitations with string literals,
but that was switched (without removing the API) in order to consolidate
on a nicer emission primitive.

While this large string table in `IntrinsicsImpl.inc` seems to compile
correctly on MSVC without the work around in `EmitCharArray` (and that
this PR adds back to the nicer emission path), other users have
repeatedly hit this MSVC limitation as you can see in the discussion on
PR https://github.com/llvm/llvm-project/pull/120534. This PR teaches the
string offset table emission to look at
the size of the table and switch to the char array emission strategy
when the table becomes too large.

This work around does have the downside of making compile times worse
for large string tables, but that appears unavoidable until we can
identify known good MSVC versions and switch to requiring them for all
LLVM users. It also reduces searchability of the generated string table
-- I looked at emitting a comment with each string but it is tricky
because the escaping rules for an inline comment are different from
those of of a string literal, and there's no real way to turn the string
literal into a comment.

While improving the output in this way, also clean up the output to not
emit an extraneous empty string at the end of the string table, and
update the `StringTable` class to not look for that. It isn't actually
used by anything and is wasteful.

This PR also switches the `IntrinsicsImpl.inc` string tables over to the
new `StringTable` runtime abstraction. I didn't want to do this until
landing the MSVC workaround in case it caused even this example to start
hitting the MSVC bug, but I wanted to switch here so that I could
simplify the API for emitting the string table with the workaround
present. With the two different emission strategies, its important to
use a very exact syntax and that seems better encapsulated in the API.

Last but not least, the `SDNodeInfoEmitter` is updated, including its
tests to match the new output.

This PR should unblock landing
https://github.com/llvm/llvm-project/pull/120534 and letting us switch
all of
Clang's builtins to use string tables. That PR has all the details
motivating the overall effort.

Follow-up patches will try to consolidate the remaining users onto the
single interface, but those at least were easy to separate into
follow-ups and keep this PR somewhat smaller.
2025-01-28 00:17:04 -08:00
David Green
5a81a559d6
[GISel] Explicitly disable BF16 tablegen patterns. (#124113)
We currently have an issue where bf16 patters can be used to match fp16
types, as GISel does not know about the difference between the two. This
patch explicitly disables them to make sure that they are never used.

The opposite can also happen too, where fp16 patterns are used for
operators that should be bf16. So this also changes any operations with
bf16 types to now cause a fallback to SDAG.

The pass setup for GISel has been slightly adjusted to make sure that a
verify pass does not get added between AMD-SDAG and SIFixSGPRCopiesPass,
which otherwise can cause verifier issues when falling back.
2025-01-27 22:21:12 +00: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
Rahul Joshi
7842374103
[NFC][TableGen] Emit nested namespaces in InstrInfoEmitter (#124210)
- Emit C++17 nested namespaces in InstrInfoEmitter.
2025-01-24 08:20:35 -08:00
Craig Topper
e19261faf5
[TableGen] Add a SmallPtrSet to track WriteRes that are referenced by some ReadAdvance. NFC (#124160)
Use this to remove a linear scan from CodeGenProcModel::hasReadOfWrite.

This reduces build time of RISCVGenSubtargetInfo.inc on by machine from
~6 seconds to ~3 seconds.
2025-01-23 12:48:59 -08:00
Craig Topper
082b148041 [TableGen] Pass CodeGenProcModel reference instead of index to addWriteRes/addReadAdvance. NFC
2 of the 3 callers of each of these already had a reference they
converted to index. Use that reference and make the one caller
that only has an index responsible for looking up the reference from it.
2025-01-23 09:11:29 -08:00
Chandler Carruth
cd5694ecea
[StrTable] Switch the option parser to llvm::StringTable (#123308)
Now that we have a dedicated abstraction for string tables, switch the
option parser library's string table over to it rather than using a raw
`const char*`. Also try to use the `StringTable::Offset` type rather
than a raw `unsigned` where we can to avoid accidental increments or
other issues.

This is based on review feedback for the initial switch of options to a
string table. Happy to tweak or adjust if desired here.
2025-01-22 23:19:47 -08:00
Craig Topper
517334bdb8
[TableGen] Add maps from Write/ReadType to the parent WriteRes/ReadAdvance. NFC (#123876)
Use this to improve performance of SubtargetEmitter::findWriteResources
and SubtargetEmitter::findReadAdvance. Now we can do a map lookup
instead of a linear search through all WriteRes/ReadAdvance records.
    
This reduces the build time of RISCVGenSubtargetInfo.inc on my
machine from 43 seconds to 10 seconds.
2025-01-22 13:41:42 -08:00
Sergei Barannikov
6aeffcdb91
[TableGen] Add a backend generating SDNode descriptions (#123002)
This patch adds a simplistic backend that gathers all target-specific
SelectionDAG nodes and emits descriptions for most of them.

This includes generating node enumeration, node names, and information
about node "prototype" that can be used to verify that a node is valid.

The patch also extends SDNode by adding target-specific flags, which are
also included in the generated tables.

Part of #119709,
[RFC](https://discourse.llvm.org/t/rfc-tablegen-erating-sdnode-descriptions/83627).

Pull Request: https://github.com/llvm/llvm-project/pull/123002
2025-01-22 09:01:08 +03:00
Finn Plummer
011b618644
[DXIL] Define and generate DXILAttribute and DXILProperty (#117072)
- Redefines `DXILAttribute` to denote a function attribute, compatible
to how it was define in DXC/LLVM 3.7
- Fix how `DXILAttribute` is emitted to be a struct of set attributes
instead of an "or" of the enums
- Implement the lowering of `DXILAttribute` to LLVM function attributes
in `DXILOpBuilder.cpp`. A custom mapping is defined.
- Audit all current ops to specify the correct attributes consistent
with DXC. This is done here to allow for testing.
- Update testcases in `llvm/test/CodeGen/DirectX` of all ops with
attributes to match that attributes are set
- Update testcases of ops that had previously incorrectly set attributes
to check there is no attributes set
- Defines `DXILProperty` to denote the other type of attributes from DXC
used to query properties.
- Emit `DXILProperty` as a struct of set attributes.
- Updates `DXIL.td` to specify applicable `DXILProperty`s on ops

Note: `DXILProperty` was referred to as 'queryable attributes' in design
discussion. Changed to property to allow for better expression in
`DXIL.td`

Resolves #114461
Resolves #115912
2025-01-21 17:33:45 -08:00
Kazu Hirata
1714facf4f
[TableGen] Avoid repeated map lookups (NFC) (#123699) 2025-01-21 16:23:23 +08:00
Jason Eckhardt
271b3383d7
[TableGen][NFC] Factor early-out range check. (#123645)
Combine the EarlyOut and IsContiguous range check.
Also avoid "comparison is always false" warnings in emitted code when
the lower-bound check is against 0.
2025-01-20 19:13:31 -06:00
Kazu Hirata
818d6e5665
[TableGen] Avoid repeated hash lookups (NFC) (#123562) 2025-01-20 10:16:20 -08:00
Craig Topper
0e4a10dff8 [MC] Add MCRegister::isPhysical. NFC 2025-01-18 22:28:37 -08:00
Craig Topper
bc386a8268
[TableGen] Replace some uses of make_range with methods that already return a range. NFC (#123453) 2025-01-18 08:37:25 -08:00
Craig Topper
2a4c4b554b
[TableGen] Use const getter to implement non-const getter instead of the other way around. NFC (#123452)
It's better to cast away constness on the reference being returned than
to cast away constness on the this pointer.
2025-01-18 08:35:59 -08:00
Craig Topper
c3aa86c9de [TableGen] const-correct a couple CodeGenSchedule methods. NFC 2025-01-17 22:55:20 -08:00
Jie Fu
d79e3af8ad [TableGen] Fix unused-variable warnings in CodeGenSchedule.cpp (NFC)
/llvm-project/llvm/utils/TableGen/Common/CodeGenSchedule.cpp:1704:32:
 error: unused variable 'Seq' [-Werror,-Wunused-variable]
    SmallVectorImpl<unsigned> &Seq =
                               ^
/llvm-project/llvm/utils/TableGen/Common/CodeGenSchedule.cpp:1713:32:
 error: unused variable 'Seq' [-Werror,-Wunused-variable]
    SmallVectorImpl<unsigned> &Seq =
                               ^
2 errors generated.
2025-01-18 14:48:55 +08:00
Craig Topper
6628b5934d
[TableGen] Use a range-based for loop. NFC (#123443) 2025-01-17 21:41:52 -08:00