321 Commits

Author SHA1 Message Date
Sam Elliott
408659c5b5
[RISCV] Merge GPRPair and GPRF64Pair (#116094)
As suggested by Craig, this tries to merge the two sets of register
classes created in #112983, GPRPair* and GPRF64Pair*.

- I added some explicit annotations to `RISCVInstrInfoD.td` which fixed
the type inference issues I was seeing from tablegen for select
patterns.
- I've had to make the behaviour of `splitValueIntoRegisterParts` and
`joinRegisterPartsIntoValue` cover more cases, because you cannot
bitcast to/from untyped (the bitcast would otherwise have been inserted
automatically by TargetLowering code).
- I apparently didn't need to change `getNumRegisters` again, which
continues to tell me there's a bug in the code for tied inputs. I added
some more test coverage of this case but it didn't seem to help find the
asserts I was finding before - I think the difference is between the
default behaviour for integers which doesn't apply to floats.
- There's still a difference between BuildGPRPair and BuildPairF64 (and
the same for SplitGPRPair and SplitF64). I'm not happy with this, I
think it's quite confusing, as they're very similar, just differing in
whether they give a `untyped` or a `f64`. I haven't really worked out
how the DAGCombiner copes if one meets the other, I know we have some of
this for the f64 variants already, but they're a lot more complex than
the GPRPair variants anyway.
2024-11-20 10:08:55 +00:00
Sam Elliott
4615cc38f3
[RISCV] Inline Assembly Support for GPR Pairs ('R') (#112983)
This patch adds support for getting even-odd general purpose register
pairs into and out of inline assembly using the `R` constraint as
proposed in riscv-non-isa/riscv-c-api-doc#92

There are a few different pieces to this patch, each of which need their
own explanation.

- Renames the Register Class used for f64 values on rv32i_zdinx from
  `GPRPair*` to `GPRF64Pair*`. These register classes are kept broadly
  unmodified, as their primary value type is used for type inference
  over selection patterns. This rename affects quite a lot of files.

- Adds new `GPRPair*` register classes which will be used for `R`
  constraints and for instructions that need an even-odd GPR pair. This
  new type is used for `amocas.d.*`(rv32) and `amocas.q.*`(rv64) in
  Zacas, instead of the `GPRF64Pair` class being used before.

- Marks the new `GPRPair` class legal as for holding a `MVT::Untyped`.
  Two new RISCVISD node types are added for creating and destructing a
  pair - `BuildGPRPair` and `SplitGPRPair`, and are introduced when
  bitcasting to/from the pair type and `untyped`.

- Adds functionality to `splitValueIntoRegisterParts` and
  `joinRegisterPartsIntoValue` to handle changing `i<2*xlen>` MVTs into
  `untyped` pairs.

- Adds an override for `getNumRegisters` to ensure that `i<2*xlen>`
  values, when going to/from inline assembly, only allocate one (pair)
  register (they would otherwise allocate two). This is due to a bug in
  SelectionDAGBuilder.cpp which other backends also work around.

- Ensures that Clang understands that `R` is a valid inline assembly
  constraint.

- This also allows `R` to be used for `f64` types on `rv32_zdinx`
  architectures, where doubles are stored in a GPR pair.
2024-11-18 17:45:58 +00:00
Mark Zhuang
6eb93d04e5
[RISCV][MC] Support imm symbol in parseCSRSystemRegister (#112007)
Co-authored-by: Alex Richardson <alexrichardson@google.com>
2024-10-23 16:30:35 +08:00
Craig Topper
0850e721ab
[RISCV] Convert C_ADDI_NOP to C_NOP in the assembler. (#112314)
Make it a pseudoinstruction so we can convert it to C_NOP. This makes
the printing from the assembler consistent with what we get from
llvm-objdump.

I tried to do this with an InstAlias, but I don't think it can drop
operands.
2024-10-16 09:47:06 -07:00
Sam Elliott
429387a71c
[RISCV] Support Expressions in .insn Directives (#111893)
When assembling raw instructions, often you want to or together several
fields for clarity, or because you're using an assembly macro with
separate arguments.

This brings the use of `.insn` closer into line with what can be done
with the binutils assembler.

The 64-bit instruction test here explicitly sets the top bit to make
sure this works, even though the assembler is really using `int64_t`
in most places internally.
2024-10-14 14:07:35 +01:00
Sam Elliott
f93f925d4f
[RISCV][MC] Support Assembling 48- and 64-bit Instructions (#110022)
This adds `.insn` support for assembling instructions of 48- and
64-bits (only when giving an explicit length). Disassembly already
knows to bunch up the instruction bits for these instructions.

This changes some error messages so they are a little clearer.

Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2024-10-08 14:09:07 +01:00
Craig Topper
bc91f3cdd5
[RISCV] Add 32 bit GPR sub-register for Zfinx. (#108336)
This patches adds a 32 bit register class for use with Zfinx instructions. This makes them more similar to F instructions and allows us to only spill 32 bits.
    
I've added CodeGenOnly instructions for load/store using GPRF32 as that gave better results than insert_subreg/extract_subreg.
    
Function arguments use this new GPRF32 register class for f32 arguments with Zfinx. Eliminating the need to use RISCVISD::FMV* nodes.
    
This is similar to #107446 which adds a 16 bit register class.
2024-10-01 22:09:27 -07:00
Craig Topper
8a7843ca0f
[RISCV] Add 16 bit GPR sub-register for Zhinx. (#107446)
This patches adds a 16 bit register class for use with Zhinx
instructions. This makes them more similar to Zfh instructions and
allows us to only spill 16 bits.

I've added CodeGenOnly instructions for load/store using GPRF16 as that
gave better results than insert_subreg/extract_subreg. I'm using FSGNJ
for GPRF16 copy with Zhinx as that gave better results. Zhinxmin will
use ADDI+subreg operations.

Function arguments use this new GPRF16 register class for f16 arguments
with Zhinxmin. Eliminating the need to use RISCVISD::FMV* nodes.

I plan to extend this idea to Zfinx next.
2024-09-26 22:56:12 -07:00
Craig Topper
b47af5d148 [MC] Replace some comparisons of MCRegister and literal 0. NFC
We can convert the MCRegister to bool instead. I think this should
allows us to remove MCRegister::operator==(int). All other comparisons
in tree are unsigned.
2024-09-21 23:25:24 -07:00
Lei Huang
4b524088a8
[NFC] Update function names in MCTargetAsmParser.h (#108643)
Update function names to adhere to LLVM coding standard.
2024-09-18 11:43:49 -04:00
Craig Topper
5537ae87b3 [RISCV] Fix fneg.d/fabs.d aliasing handling for Zdinx. Add missing fmv.s/d aliases.
We were missing test coverage for fneg.d/fabs.d for Zdinx. When I
added it revealed it only worked on RV64. The assembler was not
creating a GPRPair register class on RV32 so the alias couldn't match.
The disassembler was also not using GPRPair registers preventing the
aliases from printing in disassembly too.

I've fixed the assembler by adding new parsing methods in an attempt
to get decent diagnostics. This is hard since the mnemonics are
ambiguous between D and Zdinx. Tests have been adjusted for some
differences in what errors are reported first.
2024-09-10 11:44:04 -07:00
Craig Topper
8c5d53f8de [RISCV] Use MCRegister instead of unsigned in RISCVAsmParser.cpp. NFC
Rename RegNo to Reg.
2024-08-31 01:02:50 -07:00
Craig Topper
e59c8241fa [RISCV] Remove unused tablegen classes from unratified Zbp instructions. NFC
These weren't removed when we removed Zbp.
2024-08-17 23:41:18 -07:00
Jesse Huang
107f3efdbe
[RISCV][MC] Make error message of CSR with wrong extension more detailed (#104424)
Make the error message of lacking an extension for a CSR more
detailed and update related tests
2024-08-18 02:59:46 +08:00
Garvit Gupta
062844615d
[RISCV] Enable framework to resolve encoding conflicts among vendor-specific CSRs (#97287)
This PR is a follow-up of PR #96174 which added the framework to resolve
encoding conflicts among vendor specific CSRs. This PR explicitly
enables this only for the RISCV target.
2024-07-11 20:12:17 -07:00
R
3c5f929ad0
[RISCV] Add QingKe "XW" compressed opcode extension (#97925)
This extension consists of 8 additional 16-bit compressed forms for
existing standard load/store opcodes.

These opcodes are found in some RISC-V microcontrollers from WCH /
Nanjing Qinheng Microelectronics.

As discussed in the Discourse forums, this uses incompatible extension
and opcode names vs the vendor binary toolchain. The chosen names
instead follow the conventions for other vendor extensions listed on the
"riscv-non-isa" project.
2024-07-11 11:10:02 +08:00
Yingwei Zheng
2a086dce69
[RISCV][MC] Add support for hardcode encoding of .insn directive (#98030)
This patch adds support for the following two hardcode encodings of
.insn directive:
```
.insn <insn-length>, <value>
.insn <value>
```

See also gas's patch
a262b82fdb
NOTE: This patch doesn't support long instructions. 

Closes https://github.com/llvm/llvm-project/issues/97498.
2024-07-10 00:39:51 +08:00
Pengcheng Wang
876c6204f1
[RISCV][MC] Warn if SEW/LMUL may not be compatible
According to RVV spec:
> In general, the requirement is to support LMUL ≥ SEWMIN/ELEN,
> where SEWMIN is the narrowest supported SEW value and ELEN is
> the widest supported SEW value.
>
> For a given supported fractional LMUL setting, implementations
> must support SEW settings between SEWMIN and LMUL * ELEN, inclusive.

We print a warning if these requirements are not met.

Reviewers: kito-cheng, asb, frasercrmck, jrtc27, michaelmaitland, lukel97

Reviewed By: lukel97

Pull Request: https://github.com/llvm/llvm-project/pull/94313
2024-06-11 14:28:51 +08:00
Liao Chunyu
2afea72968
[RISCV] Codegen support for XCVmem extension (#76916)
All post-Increment load/store, register-register load/store

spec:

https://github.com/openhwgroup/cv32e40p/blob/master/docs/source/instruction_set_extensions.rst

Contributors: @CharKeaney, @jeremybennett, @lewis-revill,
@NandniJamnadas, @PaoloS02, @serkm, @simonpcook, @xingmingjie, @realqhc
2024-06-07 21:45:49 +08:00
Palmer Dabbelt
b04c07bf27
[RISCV] Only allow up to e64 in vsetvli (#92010)
These larger SEWs aren't in the ratified V spec. Thanks to dzaima and
sorear on IRC for pointing this one out.

Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2024-05-14 10:11:20 -07:00
Fangrui Song
5f7477a72b
RISCVAsmParser: Make diagnostics more conventional
Most diagnostics obey
https://llvm.org/docs/CodingStandards.html#error-and-warning-messages
but some diverge. Fix them.

While here, adjust some diagnostics.

Pull Request: https://github.com/llvm/llvm-project/pull/92024
2024-05-14 10:07:13 -07:00
Yeting Kuo
d70267fbae
[RISCV] Teach .option arch to support experimental extensions. (#89727)
Previously `.option arch` denied extenions are not belongs to RISC-V
features. But experimental features have experimental- prefix, so
`.option arch` can not serve for experimental extension.
This patch uses the features of extensions to identify extension
existance.
2024-05-06 13:55:37 +08:00
Craig Topper
733a87783c
[RISCV] Split code that tablegen needs out of RISCVISAInfo. (#89684)
This introduces a new file, RISCVISAUtils.cpp and moves the rest of
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.
2024-04-23 15:12:36 -07:00
Craig Topper
25a391c771
[RISCV] Sink some repeated code into parseVTypeToken. NFC (#89694)
Both calls to parseVTypeToken were proceeded by check for an Identifier
token and a call to getIdentifier. Sync those into the parseVTypeToken
to reduce repetition.
2024-04-22 21:13:12 -07:00
Craig Topper
016ce9ed5c
[RISCV] Rename FeatureRVE to FeatureStdExtE. NFC (#89174)
Planning to declare all extensions in tablegen so we can generate the
tables for RISCVISAInfo.cpp. This requires making "e" consistent with
other extensions.
2024-04-19 12:39:32 -07:00
Craig Topper
cd0c94bb85
[RISCV] Remove IsEABI from RISCVZC::getStackAdjBase. (#89177)
The usage of IsEABI was only valid for RV32E. For RV64E, the stack
adjust
base needs to be 32 when ra,s0-s1 are being saved. Since it takes more
than 16 bytes to save 3 64-bit registers.
    
The spec lists the rv32e behavior explicitly, but not rv64e. My
assumption is that the only thing that changes with rv64e is which
registers can be used in the register list, but not how the register
list affects the stack_adj_base.
2024-04-18 08:01:56 -07:00
Craig Topper
158401493a
[RISCV] Check that the stack adjust immediate for cm.push/pop* has the correct sign and is divisible by 16. (#85295)
To do this I've added a new AsmOperand for cm.push to expect a negative
value. We also use that to customize the print function so that we don't
need to detect cm.push opcode to add the negative sign.

I've renamed some places that used Spimm to be StackAdj since that's
what is being parsed. I'm still not about where we should use Spimm or
StackAdj.

I've removed the printSpimm helper function which in one usage printed
the sp[5:4]<<4 value and the other usage printed the full stack
adjustment. There wasn't anything interesting about how it was printed
it just passed the value to the raw_stream. If there was something
special needed, it's unclear whether it would be the same for the two
different usages so I inlined it.

One open question is whether we need to support stack adjustments
expressed as an expression rather than a literal integer.
2024-03-26 13:31:21 -07:00
Sergei Barannikov
5e5b656102
[MC] Make MCParsedAsmOperand::getReg() return MCRegister (#86444) 2024-03-25 05:13:48 +03:00
Sacha Coppey
d2f8ba7d6d
[RISCV][NFC] Add generateMCInstSeq in RISCVMatInt (#84462)
This allows to avoid duplicating the code handling the instructions
outputted by `generateInstSeq` when emitting `MCInst`s.
2024-03-23 01:08:13 +08:00
Craig Topper
274db64558 [RISCV] Replace a hardcoded 16 with RISCVZC::INVALID_RLIST. NFC 2024-03-13 21:47:25 -07:00
Craig Topper
84420a2ab3
[RISCV] Move matchRegisterNameHelper into the RISCVAsmParser and remove IsRVE argument. NFC (#85172)
With it in the class we can use isRVE() inside the function instead of
making the callers do it.
2024-03-13 21:25:09 -07:00
Craig Topper
66dd38e8df [RISCV] Use references to avoid unnecessary struct copies. NFC 2024-03-13 11:42:51 -07:00
Craig Topper
417324a6c1 [RISCV] Remove unnecessary ArrayRef. NFC 2024-03-13 11:38:09 -07:00
Craig Topper
ab9564c315
[RISCV] Add SMLoc to expanded vector pseudoinstructions in AsmParser. (#84875)
This is needed for llvm-mca to correctly apply vsetvli instruments to
these instructions.

Fixes #84799.
2024-03-13 10:51:48 -07:00
Craig Topper
e197b957ce [RISCV] Fix typo in call to clearFeatureBits.
We had "+zca" instead of "zca". The previous line used "c", not "+c".

This may not be a functional change. I think the function we pass this
to strips any '+' or '-'.
2024-02-06 12:19:27 -08:00
Yeting Kuo
0716d31649
[RISCV][NFC] Use maybe_unused instead of casting to void to fix unused variable warning. (#80651) 2024-02-06 14:41:47 +08:00
Paul Kirth
03a61d34eb
[RISCV] Support TLSDESC in the RISC-V backend (#66915)
This patch adds basic TLSDESC support in the RISC-V backend.

Specifically, we add new relocation types for TLSDESC, as prescribed in 
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373, and add a
new pseudo instruction to simplify code generation.

This patch does not try to optimize the local dynamic case, which can be
improved in separate patches. 

Linker side changes will also be handled separately.

The current implementation is only enabled when passing the new
`-enable-tlsdesc` codegen flag.
2024-01-23 16:16:07 -08:00
Craig Topper
c053e9f0f4
[RISCV] Re-implement Zacas MC layer support to make it usable for CodeGen. (#77418)
This changes the register class to GPRPair and adds the destination
register as a source with a tied operand constraint.
    
Parsing for the paired register is done with a custom parser that
checks for even register and converts it to its pair version. A
bit of care needs to be taken so that we only parse as a pair register
based on which instruction we're parsing and the mode in the subtarget.
This allows amocas.w to be parsed correcty in both modes.
    
I've added a FIXME to note that we should be creating pair registers
for Zdinx on RV32 to match the instructions CodeGen generates.
2024-01-10 09:18:40 -08:00
Craig Topper
c9da4dc77f
[RISCV] Refactor GPRF64 register class to make it usable for Zacas. (#77408)
-Rename to GPRPair.
-Rename registers to be named like X10_X11 instead of X10_PD. Except X0
 which is now X0_Pair since it is not paired with X1.
-Use unknown size and offset for the subreg indices. This might
 be a functional change, but does not affect any lit tests.
2024-01-09 09:21:27 -08:00
Fangrui Song
eabaee0c59
[RISCV] Omit "@plt" in assembly output "call foo@plt" (#72467)
R_RISCV_CALL/R_RISCV_CALL_PLT distinction is not necessary and
R_RISCV_CALL has been deprecated. Since https://reviews.llvm.org/D132530
`call foo` assembles to R_RISCV_CALL_PLT. The `@plt` suffix is not
useful and can be removed now (matching AArch64 and PowerPC).

GNU assembler assembles `call foo` to RISCV_CALL_PLT since 2022-09
(70f35d72ef04cd23771875c1661c9975044a749c).

Without this patch, unconditionally changing MO_CALL to MO_PLT could
create `jump .L1@plt, a0`, which is invalid in LLVM integrated assembler
and GNU assembler.
2024-01-07 12:09:44 -08:00
Craig Topper
16dc82122b [RISCV] Remove isGPRF64AsFPR and isGPRPF64AsFPR functions from AsmParser. NFC
These are identical to isGPRAsFPR. By overriding the PredicateMethod
on the AsmOperands in tblgen we can share a single function.
2024-01-04 22:13:40 -08:00
Craig Topper
6dc5ba4cca [RISCV] Remove XSfcie extension.
This reverts 0d3eee33f262402562a1ff28106dbb2f59031bdb and
4c37d30e22ae655394c8b3a7e292c06d393b9b44.

XSfcie is not an official SiFive extension name. It stands for
SiFive Custom Instruction Extension, which is mentioned in the S76
manual, but then elsewhere in the manual says it is not supported
for S76.

LLVM had various instructions and CSRs listed as part of this
extension, but as far as SiFive is concerned, none of them are part
of it. There are no documented extension names for these instructions
and CSRs either externally or internally.

If these are important to LLVM users, I can facilitate creating
extension names for them and have them documented. For now I'm
removing everything.

Unfortunately, these instructions and CSRs are in LLVM 17 so this
is an incompatible change.
2023-12-28 13:54:15 -08:00
Kazu Hirata
586ecdf205
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-11 21:01:36 -08:00
LiaoChunyu
71a7108ee9 [RISCV][MC] MC layer support for xcvmem and xcvelw extensions
This commit is part of a patch-set to upstream the 7 vendor specific extensions of CV32E40P.
Several other extensions have been merged.
Spec:
https://github.com/openhwgroup/cv32e40p/blob/master/docs/source/instruction_set_extensions.rst
Contributors: @CharKeaney, @jeremybennett, @lewis-revill, Nandni Jamnadas, @PaoloS, @simoncook, @xmj, @realqhc, @melonedo, @adeelahmad81299

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D158824
2023-11-16 09:46:11 +08:00
Kazu Hirata
1564c225ef [llvm] Stop including llvm/ADT/SmallString.h (NFC)
Identified with clangd.
2023-11-11 12:32:13 -08:00
Wang Pengcheng
e179b125fb
[RISCV][NFC] Pass MCSubtargetInfo instead of FeatureBitset in RISCVMatInt (#71770)
The use of `hasFeature` is more descriptive and the callers of
`RISCVMatInt` have no need to call `getFeatureBits()` any more.
2023-11-09 15:15:23 +08:00
Alex Bradbury
b28d83eec4
[RISCV][MC] Recognise that fcvt.d.s with frm != 0b000 is valid (#67555)
This seems to be an issue common to both GCC and LLVM. There are various
RISC-V FCVT instructions where the frm field makes no difference to the
output as the result is always exact (e.g. fcvt.d.s, fcvt.s.h,
fcvt.d.h). As with GCC, we always generate a form of these fcvt
instructions where frm=0b000. However, the ISA manual _doesn't_ state
that frm values are invalid, and we should ensure we can accept them.
This patch does so by adding the frm field to fcvt.d.s and adding an
InstAlias so that if no frm is specified, it defaults to rne (0b000).

This patch just corrects fcvt.d.s in order to allow the approach to be
reviewed, before applying it to the other affected instructions.

I haven't added tests to llvm/test/MC/Disassembler/RISCV, because it
doesn't seem necessary to test there in addition to our usual round-trip
tests in llvm/test/MC/RISCV. But feedback is welcome.

Recently added tests ensure that the default `rne` rounding mode is
printed as desired.
2023-09-30 21:49:52 +01:00
Sergei Barannikov
a479be0f39 [MC] Change tryParseRegister to return ParseStatus (NFC)
This finishes the work of replacing OperandMatchResultTy with
ParseStatus, started in D154101.
As a drive-by change, rename some RegNo variables to just Reg
(a leftover from the days when RegNo had 'unsigned' type).
2023-09-06 10:28:12 +03:00
imkiva
4235bc0112
[RISCV] Fix vmsge{u}.vx lowering by not adding the mask operand if vd == v0
According to `riscv-v-spec-1.0.pdf` page 52:

> masked va >= x, vd == v0
>   pseudoinstruction: vmsge{u}.vx vd, va, x, v0.t, vt
>   expansion: vmslt{u}.vx vt, va, x; vmandn.mm vd, vd, vt

The resulting `vmslt{u}.vx` is not masked. This patch fixes the logic in `RISCVAsmParser`, to make the behavior consistent with the case "masked va >= x, any vd" in the later part of the code, where no mask op is added.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D158392
2023-08-25 13:27:16 +08:00
Yeting Kuo
818e76d6f2 [RISCV] Add MC layer support for Zicfilp.
This adds extension Zicfilp and support pseudo instruction lpad.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D157362
2023-08-16 08:52:51 +08:00