6329 Commits

Author SHA1 Message Date
Matt Arsenault
bd7db75489
TableGen: Sort RuntimeLibcallImpls secondarily by enum names (#150728)
Extracted from #150192, this hopefully fixes occasional EXPENSIVE_CHECKS
failures.
2025-07-26 11:22:59 +09:00
Craig Topper
18397f6063
[RISCV] Use Record from CompressPat in compress/uncompress functions. (#150664)
Instead of using the Record from the instruction definition, use the
Record specified in the CompressPat DAG. This will allow us to use
Records that are subsets of both the source and destination.

I want to use this to merge the C_*_HINT instructions back into their
regular non-HINT versions, but prevent those encodings from being part
of compress/uncompress. For example, we will use GPRNoX0 for the C_ADDI
CompressPat while both C_ADDI and ADDI will use GPR in their instruction
definitions.

To do this I've recorded the original DAG Record in the OperandMap using
a struct in the union to represent the 3 fields needed for an Operand.
Previously we stored TiedOpIdx outside the union, but only used it for
Operand.

There is a verification hole here where we don't have any way to check
that an immediate predicate is a subset of an instruction predicate at
tablegen time. Prior to #148660 we had this hole in one direction, but
that patch made it in two directions. I'm not sure if this patch makes
it any worse. Now we're using what is in the CompressPat where before we
were using whatever was in the instructions and ignoring the predicate
in the CompressPat.
2025-07-25 14:15:02 -07:00
Jay Foad
e5202027c5
[TableGen] Use MapVector in InstrInfoEmitter::emitOperandNameMappings (#150630)
This changes the order of names/numbers in the OpName enum, but that
should not cause any change in behaviour.
2025-07-25 21:04:48 +01:00
Craig Topper
83e51773f8 [TableGen] Improve formatting of CompressInstEmitter output. NFC 2025-07-25 09:42:19 -07:00
Craig Topper
413c0800ce [TableGen] Add const and avoid a copy in CompressInstEmitter::emitCompressInstEmitter. NFC 2025-07-25 09:16:42 -07:00
Craig Topper
ffc5385f8e [TableGen] Fix typo in CompressInstEmitter.
We should use ImmVal field instead of Imm which is from the Kind enum.

This caused us to check a value of 1 instead of of the what was
parsed.
2025-07-24 23:47:06 -07:00
Craig Topper
bd91e8a5bd
[TableGen] Strengthen check for what operands can be an immediate in CompressInstEmitter. (#150568)
Registers can be represented by RegisterOperand, not just RegisterClass.
Instead of trying to block certain classes, only allow Operand.
2025-07-24 21:54:51 -07:00
Craig Topper
076d3050f1
[RISCV] Merge verifyDagOpCount into addDagOperandMapping in CompressInstEmitter. (#150548)
This reduces the number of times we need to iterate over the operands.
2025-07-24 19:50:13 -07:00
Craig Topper
236b315a98
[RISCV] Remove extra operands from Zcb compression patterns. NFC (#150541)
Tied operands in the destination are not supposed to be listed. This
didn't cause a functional issue because none of the code noticed that
extra operand was even there.

Simplify verifyDagOpCount to catch this case.
2025-07-24 18:03:30 -07:00
Jay Foad
3be44e2580
[TableGen] Add some -time-phases support in CodeGenRegisters (#149309) 2025-07-18 22:05:54 +01:00
Shaoce SUN
0c75e09381
[TableGen] Add getName() to error messages for better debugging (#149531)
Including the name helps quickly locate the corresponding Instruction
that caused the issue.
2025-07-19 00:44:16 +08:00
Matt Arsenault
0b7a95a6fd Partially Reapply "RuntimeLibcalls: Add methods to recognize libcall names (#149001)"
This partially reverts commit a96121089b9c94e08c6632f91f2dffc73c0ffa28.

Drop the IRSymtab changes for now
2025-07-18 18:06:26 +09:00
Nikita Popov
a96121089b Revert "RuntimeLibcalls: Add methods to recognize libcall names (#149001)"
This reverts commit 45477add8dfe9851605697bd908b49f0ec244625.

This causes a significant LTO compile-time regression.
2025-07-18 10:15:19 +02:00
Matt Arsenault
45477add8d
RuntimeLibcalls: Add methods to recognize libcall names (#149001)
Also replace the current static DenseMap of preserved symbol
names in the Symtab hack with this. That was broken statefulness
across compiles, so this at least fixes that. However this is
still broken, llvm-as shouldn't really depend on the triple.
2025-07-18 08:53:32 +09:00
Krzysztof Parzyszek
661cbd5a52
[utils][TableGen] Make some non-bitmask enums iterable (#148647)
Additionally, add sentinel values <Enum>::First_ and <Enum>::Last_ to
each one of those enums.

This will allow using `enum_seq_inclusive` to generate the list of
enum-typed values of any generated scoped (non-bitmask) enum.
2025-07-17 11:27:47 -05:00
Jay Foad
4355356d96
[TableGen] Add a bitvector of members of CodeGenRegisterClass (#149122)
This makes CodeGenRegisterClass::contains fast. Use this to simplify
inferMatchingSuperRegClass.
2025-07-16 20:31:32 +01:00
Jay Foad
362594a10f
[TableGen] Remove unnecessary sortAndUniqueRegisters (#149125)
Each of the SRSets is already sorted and unique because it is a filtered
version of RC->getMembers() which is already sorted and unique.
2025-07-16 20:27:50 +01:00
Matt Arsenault
af56fd0c1a
TableGen: Use StringOffsetTable for RuntimeLibcall names (#148839) 2025-07-15 23:24:46 +09:00
Sudharsan Veeravalli
085e8f1e52
[RISCV] Relax destination instruction dag operand matching in CompresInstEmitter (#148660)
We have some 48-bit instructions in the `Xqci` spec that currently
cannot be compressed to their 32-bit variants due to the constraint in
`CompressInstEmitter` on destination instruction operands not being
allowed to mismatch with the DAG operands.

For eg. the` QC_E_ADDI` instruction can be compressed to the `ADDI`
instruction when the immediate is signed-12 bit but this is currently
not possible since the `QC_E_ADDI` instruction has `GPRNoX0` register
operands while the `ADDI` instruction has `GPR` register operands
leading to an operand type validation error.

I think we can remove the check that only source instruction operands
can mismatch with the corresponding DAG operands and rely on the fact
that we check if the DAG register operand type is a subclass of the
instruction register operand type.
2025-07-15 04:52:51 +05:30
Rahul Joshi
633728f3b5
[NFC][TableGen][DecoderEmitter] Eliminate indent for a few functions (#148718)
Eliminate the `indent` argument for functions which are always called
with `indent(0)`.
2025-07-14 15:23:41 -07:00
Rahul Joshi
b6a4621f3b
[NFC][TableGen] Minor code cleanup in SearchableTableEmitter (#147856)
- Add braces around if/else bodies per LLVM coding standards.
- Use range for loops and structured bindings.
- use auto for variables initialized with `dyn_cast`.
- Refactor `compareBy` to also use early return in the comparison loop
by extracting the comparison into lambdas.
2025-07-10 14:52:00 -07:00
Craig Topper
0f3bdc3e43
[TableGen] Remove the name from the union in OpData in PseudoLoweringEmitter and CompressInstEmitter (#147896)
We can use an anonymous union here, the name doesn't provide any
additional information.
2025-07-10 09:45:16 -07:00
Rahul Joshi
0354867cde
[NFC][TableGen] Remove small heap allocations in SearchableTableEmitter (#147845)
Change `GenericEnum` to not heap allocate its entries. Instead stash
them directly in the `Entries` vector. Change `EntryMap` to hold an
index as opposed to a pointer to the entry (the original reason why they
were unique_ptr).
2025-07-10 09:04:24 -07:00
Matt Arsenault
953416ae40
ARM: Start moving runtime libcalls into tablegen (#146084)
We still need to manually set the calling conventions of
some libcalls until the lowering is separated out.
2025-07-10 19:38:31 +09:00
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
23b4f4eb9b
[NFC][TableGen] Change DecoderEmitter insertBits to use integer types only (#147613)
The `insertBits` templated function generated by DecoderEmitter is
called with variable `tmp` of type `TmpType` which is:

```
using TmpType = std::conditional_t<std::is_integral<InsnType>::value, InsnType, uint64_t>;
```

That is, `TmpType` is always an integral type. Change the generated
`insertBits` to be valid only for integer types, and eliminate the
unused `insertBits` function from `DecoderUInt128` in
AMDGPUDisassembler.h

Additionally, drop some of the requirements `InsnType` must support as
they no longer seem to be required.
2025-07-09 08:56:07 -07:00
Jay Foad
2fd37c9f33
[TableGen] Remove RegUnitIterator. NFC. (#147483)
TableGen's RegUnitIterator is a strange contraption that iterates over a
range of registers as well as the regunits of each register. Since it is
only used in one place in a `for` loop, it is much simpler to use two
nested loops instead.
2025-07-08 16:18:30 +01:00
Matt Arsenault
a1ea9e632b TableGen: Try to fix expensive checks assert on compare
Attempt to fix regression after #144978
2025-07-08 18:23:38 +09:00
Matt Arsenault
58ad99606b
TableGen: Handle setting runtime libcall calling conventions (#144980)
Allow associating a non-default CallingConv with a set of library
functions, and applying a default for a SystemLibrary.

I also wanted to be able to apply a default calling conv
to a RuntimeLibcallImpl, but that turned out to be annoying
so leave it for later.
2025-07-08 17:12:48 +09:00
Kazu Hirata
b6249ba449
[TableGen] Remove an unnecessary cast (NFC) (#147454)
parent is already of InstructionContext.
2025-07-07 23:40:37 -07:00
Matt Arsenault
5088231e52
TableGen: Allow defining sets of runtime libraries (#144978)
Add a way to define a SystemLibrary for a complete set of
libcalls, subdivided by a predicate based on the triple.
Libraries can be defined using dag set operations, and the
prior default set can be subtracted from and added to (though
I think eventually all targets should move to explicit opt-ins.
We're still doing things like reporting ppcf128 libcalls as
available dy default on all targets).

Start migrating some of the easier targets to only use the new
system. Targets that don't define a SystemLibrary are still
manually mutating a table set to the old defaults.
2025-07-08 10:17:45 +09: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
Austin
a550fef906
[llvm] Use llvm::fill instead of std::fill(NFC) (#146911)
Use llvm::fill instead of std::fill
2025-07-04 14:10:28 +08:00
Craig Topper
965b94428c [TableGen] Use emplace_back and const correct two reference arguments. NFC 2025-07-03 18:22:32 -07:00
Craig Topper
6ff3b43700
[TableGen] More generically handle tied source operands in CompressInstEmitter. (#146183)
Move the creation of OperandMap from createDagOperandMapping to the loop
in addDagOperandMapping. Expand it to store the DAG operand number and
the MI operand number which will be different when there are tied
operands.

Rename createDagOperandMapping to checkDagOperandMapping to better
describe the remaining code.

I didn't lift the restriction that a source instruction can only have
one tied operand, but we should be able to if we have a use case.

There's a slight difference in the generate output. We now check that
operand 0 and 2 of QC_MVEQI are equal instead of operand 1 and 2. This
should be equivalent since operand 0 and 1 have a tied constraint.
2025-07-02 13:09:35 -07:00
Rahul Joshi
a880c8e670
[NFC][TableGen] Add accessors for various instruction subclasses (#146615)
- Add various instruction subclass/sub-slice accessors to
`CodeGenTarget`.
- Delete unused `inst_begin` and `inst_end` iterators.
- Rename `Instructions` to `InstructionMap` and `getInstructions` to
`getInstructionMap` to better represent their meaning.
- Use these new accessors in InstrInfoEmitter
2025-07-02 12:49:27 -07:00
Rahul Joshi
d7b8b65e23
[LLVM][TableGen][DecoderEmitter] Add wrapper struct for bit_value_t (#146248)
Add a convenience wrapper struct for the `bit_value_t` enum type to host
various constructors, query, and printing support. Also refactor related
code in several places. In `getBitsField`, use `llvm::append_range` and
`SmallVector::append()` and eliminate manual loops. Eliminate
`emitNameWithID` and instead use the `operator <<` that does the same
thing as this function. Have `BitValue::getValue()` (replacement for
`Value`) return std::optional<> instead of -1 for unset bits. Terminate
with a fatal error when a decoding conflict is encountered.
2025-07-01 07:36:17 -07:00
Rahul Joshi
92b50959da
[NFC][TableGen] Capitalize to in UseFnTableInDecodetoMCInst. (#146419) 2025-06-30 16:12:15 -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
Craig Topper
9a93de58f7 [TableGen] Simplify copying OperandMap entries for tied operands in CompressInstEmitter. NFC
Copy the whole struct instead of copying both fields.
2025-06-27 14:58:53 -07:00
Craig Topper
457c9aec9e [TableGen] Simplify how we calculate NumMIOperands in addDagOperandMapping. NFC
We can use the MIOperandNo and NumMIOperands from the last operand
instead using a loop.
2025-06-27 14:58:39 -07:00
Craig Topper
a3fcfacc35 [TableGen] Simplify verifyDagOpCount in CompressInstEmitter.cpp. NFC
We were counting the number of tied operands in two different loops.
2025-06-27 10:08:03 -07:00
Matt Arsenault
b88e1f6a79
TableGen: Generate enum for runtime libcall implementations (#144973)
Work towards separating the ABI existence of libcalls vs. the
lowering selection. Set libcall selection through enums, rather
than through raw string names.
2025-06-27 17:40:43 +09:00
Matt Arsenault
3fdf46ad60
TableGen: Add runtime libcall backend (#144972)
Replace RuntimeLibcalls.def with a tablegenerated version. This
is in preparation for splitting RuntimeLibcalls into two components.
For now match the existing functionality.
2025-06-27 17:37:03 +09:00
Kazu Hirata
3d5903c4d8
[llvm] Use llvm::is_contained (NFC) (#145844)
llvm::is_contained is shorter than llvm::all_of plus a lambda.
2025-06-26 08:41:18 -07:00
Reid Kleckner
bb7242477c
[MC] Use StringTable to reduce dynamic relocations (#144202)
Dynamic relocations are expensive on ELF/Linux platforms because they
are applied in userspace on process startup. Therefore, it is worth
optimizing them to make PIE and PIC dylib builds faster. In +asserts
builds (non-NDEBUG), nikic identified these schedule class name string
pointers as the leading source of dynamic relocations. [1]

This change uses llvm::StringTable and the StringToOffsetTable TableGen
helper to turn the string pointers into 32-bit offsets into a separate
character array.

The number of dynamic relocations is reduced by ~60%:
❯ llvm-readelf --dyn-relocations lib/libLLVM.so | wc -l
381376 # before
155156 # after

The test suite time is modestly affected, but I'm running on a shared
noisy workstation VM with a ton of cores:
https://gist.github.com/rnk/f38882c2fe2e63d0eb58b8fffeab69de
Testing Time: 100.88s   # before
Testing Time: 78.50s. # after
Testing Time: 96.25s.  # before again

I haven't used any fancy hyperfine/denoising tools, but I think the
result is clearly visible and we should ship it.

[1] https://gist.github.com/nikic/554f0a544ca15d5219788f1030f78c5a
2025-06-25 05:23:11 -07:00
quic_hchandel
deb3464192
[RISCV] Add Tied operands in Xqcicm instructions and changes to handle a single tied operand in source DAG and instruction (#145538)
Tied Operands change is required for adding codegen patterns for
Qualcomm uC Xqcicm instructions
which will be done in a follow-up PR. This change leads to one of
instructions getting compressed even
when it shouldn't be. This case was not covered in #143660. Added
changes to correctly handle this case.
2025-06-25 10:25:00 +05:30
Rahul Joshi
ed5f8f238d
[LLVM][DecoderEmitter] Add option to use function table in decodeToMCInst (#144814)
Add option `use-fn-table-in-decode-to-mcinst` to use a table of function
pointers instead of a switch case in the generated `decodeToMCInst`
function.

When the number of switch cases in this function is large, the generated
code takes a long time to compile in release builds. Using a table of
function pointers instead improves the compile time significantly (~3x
speedup in compiling the code in a downstream target). This option will
allow targets to opt into this mode if they desire for better build
times.

Tested with `check-llvm-mc` with the option enabled by default.
2025-06-24 18:49:05 -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