15756 Commits

Author SHA1 Message Date
Sergei Barannikov
ed3597e2f7
[TableGen][Decoder] Decode operands with zero width or all bits known (#156358)
There are two classes of operands that DecoderEmitter cannot currently
handle:
1. Operands that do not participate in instruction encoding.
2. Operands whose encoding contains only 1s and 0s.

Because of this, targets developed various workarounds. Some targets
insert missing operands after an instruction has been (incompletely)
decoded, other take into account the missing operands when printing the
instruction. Some targets do neither of that and fail to correctly
disassemble some instructions.

This patch makes it possible to decode both classes of operands and
allows to remove existing workarounds.

For the case of operand with no contribution to instruction encoding,
one should now add `bits<0> OpName` field to instruction encoding
record. This will make DecoderEmitter generate a call to the decoder
function specified by the operand's DecoderMethod. The function has a
signature different from the usual one and looks like this:

```
static DecodeStatus DecodeImm42Operand(MCInst &Inst, const MCDisassembler *Decoder) {
  Inst.addOperand(MCOperand::createImm(42));
  return DecodeStatus::Success;
}
```

Notably, encoding bits are not passed to it (since there are none).

There is nothing special about the second case, the operand bits are
passed as usual. The difference is that before this change, the function
was not called if all the bits of the operand were known (no '?' in the
operand encoding).

There are two options controlling the behavior. Passing an option
enables the old behavior. They exist to allow smooth transition to the
new behavior. They are temporary (yeah, I know) and will be removed once
all targets migrate, possibly giving some more time to downstream
targets.

Subsequent patches in the stack enable the new behavior on some in-tree
targets.
2025-09-04 14:48:36 +00:00
Rahul Joshi
21532f0084
[NFC][MC][DecoderEmitter] Refactor code related to EncodingField (#156759) 2025-09-04 05:59:38 -07:00
Rahul Joshi
c8e760e03b
[LLVM][MC][DecoderEmitter] Fail fatally if Insn and decoder table bitwidths mismatch (#156734) 2025-09-04 05:59:13 -07:00
Rahul Joshi
bcb1a896d8
[NFC][IntrinsicEmitter] Include source location with enum definition (#156800) 2025-09-04 05:57:37 -07:00
cmtice
e20ce964f7
lit] Update internal shell lexer to remove escape on '$' only for double-quoted strings. (#156742)
PR 156125 removed the escape (backslash) in front of '$' for all quoted
strings. It has since been pointed out this should only happen for
double-quoted strings. This PR fixes that.
2025-09-03 14:31:04 -07:00
Mehdi Amini
7949c2a931 Remove Phabricator-specific handling in pre-push.py, also don't print commits beyond 10
If you push a new branch, it would tend to explode printing all the commits.
2025-09-03 12:50:10 -07:00
cmtice
527c8ff11e
[lit] Update internal shell lexer to handle LLDB persistent vars. (#156125)
LLDB allows creation of 'persistent' variables, with names that start
with '$'. The lit internal shell was escaping the '$', making it '\\$',
in some CHECK lines, which causes an LLDB test,
TestExprWithSideEffectOnConvenienceVar, to fail when using the lit
internal shell.

Further explanation of the failing LLDB test: LLDB convenience variables
start with '$'. The test passes several quoted commands that use and
update convenience variables to lldb as arguments to be run in batch
mode. The tool that packages up the complete string and passes it to the
lit internal shell lexer for lexing inserts a backslash in front of the
'$' before passing the string in for lexing. The lexer was passing this
change along, causing the tests to fail.

This PR fixes the issue by having the lexer remove the newly added
escape on the '$'.
2025-09-03 08:57:34 -07:00
Daniel Paoliello
f99b0f3de4
[NFC] RuntimeLibcalls: Prefix the impls with 'Impl_' (#153850)
As noted in #153256, TableGen is generating reserved names for
RuntimeLibcalls, which resulted in a build failure for Arm64EC since
`vcruntime.h` defines `__security_check_cookie` as a macro.

To avoid using reserved names, all impl names will now be prefixed with
`Impl_`.

`NumLibcallImpls` was lifted out as a `constexpr size_t` instead of
being an enum field.

While I was churning the dependent code, I also removed the TODO to move
the impl enum into its own namespace and use an `enum class`: I
experimented with using an `enum class` and adding a namespace, but we
decided it was too verbose so it was dropped.
2025-09-02 09:57:33 -07:00
Benjamin Maxwell
314dc33e4d
[Utils] Fix AArch64 ASM regex after #148287 (#156460)
PR #148287 removed the "\s*" before ".Lfunc_end" for AArch64, which
broke `update_llc_test_checks.py` for a number of tests including:

- `llvm/test/CodeGen/AArch64/sme-za-exceptions.ll`
- `llvm/test/CodeGen/AArch64/win-sve.ll`

This patch adds the "\s*" back.
2025-09-02 14:48:04 +00:00
Rahul Joshi
0196d7ec69
[MC][DecoderEmitter] Fix build warning: explicit specialization cannot have a storage class (#156375)
Move `InsnBitWidth` template into anonymous namespace in the generated
code and move template specialization of `InsnBitWidth` to anonymous
namespace as well, and drop `static` for them. This makes `InsnBitWidth`
completely private to each target and fixes the "explicit specialization
cannot have a storage class" warning as well as any potential linker
errors if `InsnBitWidth` is kept in the `llvm::MCD` namespace.
2025-09-02 07:28:36 -07:00
David Spickett
e591df63e5
[release] Correct download links for Windows on Arm packages (#156459)
Mistakenly repeated the https://github.com... part twice.

Found while editing the links for 21.1.0.
2025-09-02 15:13:03 +01:00
Nico Weber
9f42ba3588 [gn] Fix accidental args override from dafffe262d6d11
dafffe262d6d11 added `"-specialize-decoders-per-bitwidth",` to args,
but also added a stray `args = []` line after it.
2025-09-01 21:28:39 -04:00
Rahul Joshi
dafffe262d
[LLVM][MC][DecoderEmitter] Add support to specialize decoder per bitwidth (#154865)
This change adds an option to specialize decoders per bitwidth, which
can help reduce the (compiled) code size of the decoder code.

**Current state**:
Currently, the code generated by the decoder emitter consists of two key
functions: `decodeInstruction` which is the entry point into the
generated code and `decodeToMCInst` which is invoked when a decode op is
reached while traversing through the decoder table. Both functions are
templated on `InsnType` which is the raw instruction bits that are
supplied to `decodeInstruction`.

Several backends call `decodeInstruction` with different `InsnType`
types, leading to several template instantiations of these functions in
the final code. As an example, AMDGPU instantiates this function with
type `DecoderUInt128` type for decoding 96/128-bit instructions,
`uint64_t` for decoding 64-bit instructions, and `uint32_t` for decoding
32-bit instructions. Since there is just one `decodeToMCInst` in the
generated code, it has code that handles decoding for *all* instruction
sizes. However, the decoders emitted for different instructions sizes
rarely have any intersection with each other. That means, in the AMDGPU
case, the instantiation with InsnType == DecoderUInt128 has decoder code
for 32/64-bit instructions that is *never exercised*. Conversely, the
instantiation with InsnType == uint64_t has decoder code for
128/96/32-bit instructions that is never exercised. This leads to
unnecessary dead code in the generated disassembler binary (that the
compiler cannot eliminate by itself).

**New state**:
With this change, we introduce an option
`specialize-decoders-per-bitwidth`. Under this mode, the DecoderEmitter
will generate several versions of `decodeToMCInst` function, one for
each bitwidth. The code is still templated, but will require backends to
specify, for each `InsnType` used, the bitwidth of the instruction that
the type is used to represent using a type-trait `InsnBitWidth`. This
will enable the templated code to choose the right variant of
`decodeToMCInst`. Under this mode, a particular instantiation will only
end up instantiating a single variant of `decodeToMCInst` generated and
that will include only those decoders that are applicable to a single
bitwidth, resulting in elimination of the code duplication through
instantiation and a reduction in code size.

Additionally, under this mode, decoders are uniqued only within a given
bitwidth (as opposed to across all bitwidths without this option), so
the decoder index values assigned are smaller, and consume less bytes in
their ULEB128 encoding. As a result, the generated decoder tables can
also reduce in size.

Adopt this feature for the AMDGPU and RISCV backend. In a release build,
this results in a net 55% reduction in the .text size of
libLLVMAMDGPUDisassembler.so and a 5% reduction in the .rodata size. For
RISCV, which today uses a single `uint64_t` type, this results in a 3.7%
increase in code size (expected as we instantiate the code 3 times now).

Actual measured sizes are as follows:
```
Baseline commit: 72c04bb882ad70230bce309c3013d9cc2c99e9a7
Configuration: Ubuntu clang version 18.1.3, release build with asserts disabled.
 
AMDGPU        Before       After      Change
======================================================
.text         612327       275607     55% reduction
.rodata       369728       351336      5% reduction          

RISCV:
======================================================
.text          47407       49187      3.7% increase   
.rodata        35768       35839      0.1% increase
```
2025-09-01 13:44:18 -07:00
Aiden Grossman
0b42e117c8 [ProfCheck] Exclude some more tests
These tests are currently showing up as red on the buildbot. We have not
gotten to any of these passes yet, so add them to the exclude list for now.
2025-09-01 03:51:12 +00:00
Rahul Joshi
1f2d461e26
[NFC][MC][DecoderEmitter] Simplify loop to find the best filter (#156237)
We can just use `max_element` on the array of filters.
2025-08-31 06:23:26 -07:00
Sergei Barannikov
06d758537d
[TableGen][Decoder] Remove special case of single sub-op dag (#156175)
If a custom operand has MIOperandInfo with >= 2 sub-operands, it is
required that either the operand or its sub-operands have a decoder
method (depending on usage). Require this for single sub-operand
operands as well, since there is no good reason not to.

There are no changes in the generated files.
2025-08-31 10:07:44 +03:00
Sergei Barannikov
981f25a8a8
[TableGen] Require complex operands in InstAlias to be specified as DAGs (#136411)
Currently, complex operands of an instruction are flattened in the resulting DAG of `InstAlias`.
This change makes it required to specify complex operands in `InstAlias` as sub-DAGs:

```
InstAlias<"foo $rd, $rs1, $rs2", (Inst RC:$rd, (ComplexOp RC:$rs1, GR0, 42), SimpleOp:$rs2)>;
```

instead of

```
InstAlias<"foo $rd, $rs1, $rs2", (Inst RC:$rd, RC:$rs1, GR0, 42, SimpleOp:$rs2)>;
```

The advantages of the new syntax are improved readability and more robust type checking, although it is a bit more verbose.
2025-08-30 18:45:07 +03:00
Sergei Barannikov
cacab8a86f
[TableGen][Decoder] Simplify parseFixedLenOperands (NFCI) (#156181)
Use information from CGIOperandList instead of re-parsing operand dags
from scratch.
2025-08-30 14:17:30 +00:00
Sergei Barannikov
cc5e8967ab
[TableGen][CodeGen] Remove DisableEncoding field of Instruction class (#156098)
I believe it became no-op with the removal of the "positionally encoded
operands" functionality (b87dc356 is the last commit in the series).

There are no changes in the generated files.
2025-08-30 04:44:20 +00:00
Aiden Grossman
26bbc3a8b6 [lit] Mark shtest-umask.py as unsupported
This is causing bot failures that need later investigation, but there
are now dependent patches on top of this that would otherwise be
annoying to pull out.
2025-08-30 00:19:35 +00:00
Sergei Barannikov
ea3a3a825a
[TableGen][Decoder] Cache DecoderNamespace in InstructionEncoding (NFC) (#156059) 2025-08-29 21:23:08 +03:00
Aiden Grossman
b975a7b9ee
Reapply "[lit] Implement builtin umask (#94621)" (#155850)
This reverts commit faa4e35c622c13c7a565b979a6676d6cf3040cd4.

This was originally reverted because it was using a Python 3.9 feature
(umask in subprocess.Popen) when LLVM only requires Python 3.8. This
patch uses os.umask instead, which has been around for longer.
2025-08-29 10:50:41 -07:00
Sergei Barannikov
c9d7d10084
[TableGen][DecoderEmitter] Use StringRef in a few places (NFC) (#156051) 2025-08-29 16:37:48 +00:00
Kyle Krüger
5d0294fcb6
[llvm] Support building with c++23 (#154372)
closes #154331 

This PR addresses all minimum changes needed to compile LLVM and MLIR
with the c++23 standard.
It is a work in progress and to be reviewed for better methods of
handling the parts of the build broken by c++23.
2025-08-29 12:52:07 +00:00
Ryotaro Kasuga
6ed64df443
[SCEVDivision] Add SCEVDivisionPrinterPass with corresponding tests (#155832)
This patch introduces `SCEVDivisionPrinterPass` and registers it under
the name `print<scev-division>`, primarily for testing purposes. This
pass invokes `SCEVDivision::divide` upon encountering `sdiv`, and prints
the numerator, denominator, quotient, and remainder. It also adds
several test cases, some of which are currently incorrect and require
fixing.

Along with that, this patch added some comments to clarify the behavior
of `SCEVDivision::divide`, as follows:

- This function does NOT actually perform the division
- Given the `Numerator` and `Denominator`, find a pair 
  `(Quotient, Remainder)` s.t.
  `Numerator = Quotient * Denominator + Remainder`
- The common condition `Remainder < Denominator` is NOT necessarily
   required
- There may be multiple solutions for `(Quotient, Remainder)`, and this
   function finds one of them
  - Especially, there is always a trivial solution `(0, Numerator)`
- The following computations may wrap
  - The multiplication of `Quotient` and `Denominator`
  - The addition of `Quotient * Denominator` and `Remainder`

Related discussion: #154745
2025-08-29 10:28:02 +00:00
Omair Javaid
f875a73af9
[llvm-lit] Add Windows .cmd wrapper to make llvm-lit directly runnable (#155226)
On Linux/Mac, `llvm-lit` is configured with a shebang and made
executable so tools like LNT and the test-suite can invoke it directly.
On Windows the build only produces `llvm-lit.py` which cannot be used as
a standalone executable. This caused problems when running the LLVM
test-suite via LNT or buildbots.

This change introduces a new template file `llvm-lit.cmd.in` and updates
`llvm/utils/llvm-lit/CMakeLists.txt` so that a corresponding
`llvm-lit.cmd` is generated in the `build/bin` directory (for both
single-config and multi-config generators). The wrapper simply invokes
the configured Python interpreter on the adjacent `llvm-lit.py` and
propagates the exit code.

This ensures that `llvm-lit` can be used as a direct executable on
Windows just like on Linux without requiring external wrappers or
modifications in buildbot scripts or LNT.
2025-08-29 13:54:21 +05:00
Sergei Barannikov
ca5d19516b
[TableGen][DecoderEmitter] Simplify emitSoftFailTableEntry (NFC) (#155863) 2025-08-28 16:20:09 +00:00
LLVM GN Syncbot
13c3290099 [gn build] Port 353b5e43c647 2025-08-28 14:28:19 +00:00
LLVM GN Syncbot
c4b7715cfd [gn build] Port fa883e1d813c 2025-08-28 12:40:13 +00:00
Peter Collingbourne
8e7385a8ea gn build: Port 3f59a22711ff 2025-08-27 17:59:56 -07:00
Peter Collingbourne
7d607f49cb [gn build] Port f1ee0473209e 2025-08-27 17:59:54 -07:00
Peter Collingbourne
7f4d2c7e90 gn build: Port f1ee0473209e 2025-08-27 17:44:24 -07:00
LLVM GN Syncbot
c3b2530aeb [gn build] Port 0ae0b1657d80 2025-08-27 16:26:00 +00:00
Maryam Moghadas
242d51afe5
[PowerPC] Add DMR and WACC COPY support (#149129)
This patch updates PPCInstrInfo::copyPhysReg to support DMR and WACC
register classes and extends the PPCVSXCopy pass to handle specific WACC
copy patterns.
2025-08-27 11:07:24 -04:00
LLVM GN Syncbot
9f64a86898 [gn build] Port 8d5deadb15d7 2025-08-27 13:09:55 +00:00
LLVM GN Syncbot
644e4c3856 [gn build] Port 823e44401aaf 2025-08-27 13:09:54 +00:00
Aiden Grossman
fdde57defd
[Github] Fix revisions in code format action reproducers (#155193)
This patch makes it so the revisions that the code format action returns
in its reproducers actually work when applying them locally given the
differences in how revisions are setup in CI.

Fixes #154294
2025-08-27 06:09:41 -07:00
LLVM GN Syncbot
ab5d749df2 [gn build] Port fa5557f1254c 2025-08-27 11:19:43 +00:00
LLVM GN Syncbot
defbd5b60c [gn build] Port 90670b5ca890 2025-08-26 23:20:00 +00:00
Aiden Grossman
e423334239
[ProfCheck] Exclude new LoopVectorize Test (#155502) 2025-08-26 22:11:29 +00:00
Arthur Eubanks
1780e16a67
[gn build] Disable objc rewriter (#155479)
This is off by default in the CMake build:
b90f4ff302/clang/CMakeLists.txt (L441)
2025-08-26 19:47:20 +00:00
LLVM GN Syncbot
084fe216d5 [gn build] Port 72c04bb882ad 2025-08-26 16:21:06 +00:00
Sergei Barannikov
cdc79e32f2
[TableGen][DecoderEmitter] Optimize single-case OPC_ExtractField (#155414)
OPC_ExtractField followed by a single OPC_FilterValue is equivalent to
OPC_CheckField. Optimize this relatively common case.
2025-08-26 19:12:04 +03:00
LLVM GN Syncbot
ff4b292de0 [gn build] Port af1f06e41b05 2025-08-26 14:33:50 +00:00
LLVM GN Syncbot
3d722f5ed9 [gn build] Port 2ab4c2880db6 2025-08-26 10:03:08 +00:00
Sergei Barannikov
156c11200d
[TableGen][DecoderEmitter] Remove no longer needed MaxFilterWidth (NFC) (#155382)
11c61581 made the variable redundant.
Also remove `Target`, which is apparently unused.
2025-08-26 09:46:26 +00:00
dyung
7d35e29d7a
Fix test added in #155148 work with Windows style path separators. (#155354)
Should fix Windows build bot failures such as
https://lab.llvm.org/buildbot/#/builders/46/builds/22281.

The test (and the followup fix in #155303) did not properly account for
Windows style path separators.
2025-08-26 05:15:15 +00:00
Sergei Barannikov
e49946b27f
[TableGen][DecoderEmitter] Factor out DecoderTableBuilder (#155220)
Extract the table building methods from FilterChooser into a separate
class to relieve it of one of its responsibilities.
2025-08-26 05:10:19 +03:00
LLVM GN Syncbot
78baec318f [gn build] Port 5cdd8832330e 2025-08-26 01:11:16 +00:00
Henrik G. Olsson
31948b3a46
[Util] Make pass-test-update.py test case more resilient (NFC) (#155303)
This test case matches against python traceback output, which seems to
vary slightly between versions. This relaxes the constraints a bit to
make the test pass on buildbots.
2025-08-25 22:03:06 +00:00