324 Commits

Author SHA1 Message Date
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
Craig Topper
44000181fd [RISCV] Model all 3 arithmetic sources of vector FMA at MC layer.
For the most part, MC version of vector instructions don't model when
the destination is also a source. This primarily occurs for mask/tail
undisturbed. The MC layer can't see the policy bits so this kind of
makes sense.

We also lumped FMA instructions into this, but the destination of
FMA is an arithmetic source not just an undisturbed value. This needs
to be correct for llvm-mca to understand the dependency for the FMA
instructions. Though every other instruction is still wrong for
tail/mask undisturbed.

This patch models the FMA instructions correctly at the MCA layer.
This necessitates changes to the assembler to offset operand numbers.

I've added the extra sched class operand and fixed the operand order
for the scalar read class.

Reviewed By: rogfer01

Differential Revision: https://reviews.llvm.org/D151850
2023-08-04 09:08:16 -07:00
4vtomat
d664541788 [RISCV] Remove zvk uimm constraints
Since the spec doesn't describe these behaviors as invalid,
the llvm-mc should just make them take care by hardware.

Differential Revision: https://reviews.llvm.org/D155669
2023-07-25 03:44:28 -07:00
Garvit Gupta
0d3eee33f2 [RISCV] Add support for custom CSRs for Sifive S76.
Support for below CSRs is addeed -
1. Branch Prediction Mode CSR
2. Feature Disable CSR
3. Power Dial CSR
4. RNMI CSRs

spec:https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf

This patch removes AltName field from SysReg class because we are now using
separate class for custom vendor CSRs. Also, all use of AltName have been changed
to DeprecatedName because both were interchangeably used for old names which are
not in use in latest RISCV spec.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D153499
2023-07-14 09:51:15 -07:00
Craig Topper
40779e8400 [RISCV] Correct even register check for amocas.
We were checking that the encoding within our internal list of
registers was even. This worked today because X0 happens to have
an even value in that enum. This can break if any registers are
added before X0.

The correct check is to make sure it has an even offset from X0.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D155104
2023-07-12 12:58:01 -07:00
Alex Bradbury
29f630a1dd [RISCV][MC] MC layer support for the experimental zacas extension
This implements the v1.0-rc1 draft extension.

amocas.d on RV32 and amocas.q have the restriction that rd and rs2 must
be even registers. I've opted to implement this restriction in
RISCVAsmParser::validateInstruction even though for codegen we'll need a
new register class and can then remove this validation. This also
sidesteps, for now, the issue of amocas.d being different on rv32 vs
rv64.

See <https://github.com/riscv-non-isa/riscv-c-api-doc/issues/37> for the
issue of needing an agreed asm register constraint for register pairs.

Differential Revision: https://reviews.llvm.org/D149248
2023-07-10 08:26:31 +01:00
Sergei Barannikov
b4b532a956 [RISCV] Replace OperandMatchResultTy with ParseStatus (NFC)
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: asb

Differential Revision: https://reviews.llvm.org/D154291
2023-07-04 22:32:22 +03:00
Garvit Gupta
1a715d9b33 [RISCV] Support constant operand for la and lla pseudoinstruction.
This patch improves compatibility with GNU assembler by adding support for
constant immediate in la and lla pseudo instruction, and expanding it in the
same way as we currently expands li pseudo instruction.

Links to discussion related to the above issue in the community -
https://github.com/riscv-non-isa/riscv-arch-test/issues/105
https://github.com/riscv-non-isa/riscv-arch-test/issues/108
https://github.com/riscv-non-isa/riscv-arch-test/issues/106

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D150133
2023-07-03 15:55:04 -07:00
Sergei Barannikov
32e5d6173f [RISCV] Use parseDirective returning ternary status (NFC)
The new method was introduced in D154101.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D154276
2023-07-03 14:48:11 +03:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Craig Topper
08f1aa8728 [RISCV] Move Zca/Zcb/Zcd/Zcf/Zcmp/Zcmt out of experimental status.
According to https://wiki.riscv.org/display/HOME/Recently+Ratified+Extensions
these were ratified in April 2023.

Reviewed By: VincentWu

Differential Revision: https://reviews.llvm.org/D153161
2023-06-22 09:22:58 -07:00
Fangrui Song
4c2fc26d33 [RISCV] Use parseOptionalToken. NFC 2023-06-15 11:35:00 -07:00
Craig Topper
0ce8163f18 [RISCV] Use const reference when looping over RISCVMatInt::InstSeq. NFC 2023-06-06 14:27:28 -07:00
Jessica Clarke
db1d72b155 [RISCV] Don't persist invalid feature state on .option arch error
Otherwise subsequent .option arch, +foo directives (but not -, since
those have their own separate validation) fail the parseFeatureBits
check, leading to cascading errors.

Reviewed By: luismarques, MaskRay

Differential Revision: https://reviews.llvm.org/D152273
2023-06-06 20:15:12 +01:00
Jessica Clarke
06e253c10d [RISCV] Rework .option arch target streamer interface
The current interface requires some rather ugly tracking of state due to
splitting up the calls for each argument. Instead, pack them all into a
single call by passing an ArrayRef. Also clean up the dodgy whitespace
emitted for the directive whilst here; there was a stray space between
the tab and .option, and there was a tab rather than a space after the
first comma for some strange reason.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D152193
2023-06-06 14:56:20 +01:00
Jessica Clarke
2c11768eee [RISCV] Make .option arch parser less mind-bending
Currently the early-return flow in the infinite loop makes it hard to
find the non-error termination points amongst the sea of errors. Rewrite
it with a more conventional control flow that has a clear loop guard (in
place of one of the early returns) and a break (in place of the other),
and with greater code reuse.

This has a small effect on the errors given for malformed input, as seen
in the affected test, and is probably more helpful as a result. Note
that we also bail early now if parseComma fails, as is standard.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D152192
2023-06-06 14:56:20 +01:00
Jessica Clarke
9b55e5d420 [RISCV] Add new lga pseudoinstruction
This mirrors lla and is always GOT-relative, allowing an explicit
request to use the GOT without having to expand the instruction. This
then means la is just defined in terms of lla and lga in the assembler,
based on whether PIC is enabled, and at the codegen level we replace la
entirely with lga since we only ever use la there when we want to load
from the GOT (and assert that to be the case).

See https://github.com/riscv-non-isa/riscv-asm-manual/issues/50

Reviewed By: asb, MaskRay

Differential Revision: https://reviews.llvm.org/D107278
2023-05-31 18:48:21 +01:00
Craig Topper
ac1df22315 [RISCV] Merge emitDirectiveOptionArchPlus and emitDirectiveOptionArchMinus into a single interface. NFC
Probably going to do some other refactors after this, but this one
was easy and clearly reduces duplicate code.

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D151771
2023-05-30 22:45:42 -07:00
luxufan
9e8ed3403c [RISCV] Support '.option arch' directive
The proposal of '.option arch' directive is https://github.com/riscv-non-isa/riscv-asm-manual/pull/67

Note: For '.option arch, +/-' directive, version number is not yet supported.

Reviewed By: luismarques, craig.topper

Differential Revision: https://reviews.llvm.org/D123515
2023-05-26 18:39:41 +08:00
Craig Topper
fd6cd1a249 [RISCV] Refactor parseVTypeI and use ParseFail if we parsed more than one identifier.
Previously we lexed into a SmallVector and unlexed the tokens if
the parsing failed.

This patch gets rid of the SmallVector and the unlexing.

If the first token fails to parse, return MatchFail. This allows us
to fallback to parsing as an immediate. If we successfully parsed the
first token, use ParseFail if any later tokens fail to parse. This
avoids needing to UnLex the tokens.

I've used a state machine to keep track of what component we've
parsed so far.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D150753
2023-05-17 10:31:39 -07:00
Job Noorman
d045f1d393 [RISCV] Allow LI with symbol difference as constant
This patch lets the assembler accept code like the following:

.Lbuf: ...
.set .Lbuf_len, . - .Lbuf
li a0, .Lbuf_len

It works by translating such instances of LI into an ADDI and inserting
the correct constant value via a new fixup.

Note that this means that the constant value is restricted to 12 bits
since we cannot insert new instructions during the relaxation stage.
Binutils seems to have the same restriction though.

This patch also fixes a small issue where the SMLoc of an LI wasn't
propagated when translated to ADDI. While this is technically unrelated
to the main functionality of this patch, it improves error messages
related to the new use of LI.

This patch does _not_ allow I-type instructions to take such symbolic
constants as well. While technically possible (and allowed by binutils),
it's probably better to implement this in another patch.

Fixes #57461

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D135960
2023-05-17 11:35:20 +02:00
Craig Topper
8cb8262de2 [RISCV] Fix crash if you use an immediate as part of a vtype operand list. 2023-05-11 16:50:00 -07:00
Craig Topper
9896d72233 [RISCV] Use parseToken to simplify code. Add missing check for Identifier token. 2023-05-08 10:46:21 -07:00
Craig Topper
455cb2e578 [RISCV] Simplify matchRegisterNameHelper interface. NFC
This previously returned a bool to indicate success or failure and
returns a register through an output parameter.

Some callers used the bool to check for success. Some callers checked
for RISCV::NoRegister.

To make everything uniform, return the MCRegister directly and update
all callers to use MCRegister::isValid().

Reviewed By: barannikov88

Differential Revision: https://reviews.llvm.org/D150049
2023-05-08 09:48:08 -07:00
WuXinlong
6b55e9117e [RISCV] Add MC support of RISCV zcmp Extension
This patch add the instructions of zcmp extension.

Instructions in zcmp extension try to optimise `mv` inst and the prologue & epilogue in functions

co-author: @Scott Egerton, @ZirconLiu, @Lukacma, @Heda Chen, @luxufan, @heyiliang, @liaochunyu

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D132819
2023-05-08 14:29:50 +08:00
Craig Topper
b2420c67e4 [RISCV] Restrict valid indices for cm.jalt to be in [32,255].
Reviewed By: jrtc27

Differential Revision: https://reviews.llvm.org/D149901
2023-05-04 18:02:06 -07:00
Fangrui Song
eb7bff4fe7 RISCVAsmParser: Simplify with parseToken. NFC 2023-04-28 00:41:59 -07:00
Craig Topper
cd1ed648c4 [RISCV] Add version of generateImmOutOfRangeError that takes an SMLoc.
Have the ErrorInfo version call it after looking up ErrorInfo in
the Operands.

Use the new function in a few places that don't have ErrorInfo and
were also generating out of range messages.
2023-04-26 11:10:08 -07:00
Craig Topper
7ad4b2622a [RISCV][CSKY][Loong] Pass Twine by const reference instead of by value. NFC
I think RISCV was the original here and the CSKY and Loong copied it.
2023-04-26 10:43:55 -07:00
Craig Topper
328cfa840d [RISCV] Add an option to emit the Tag_RISCV_arch attribute based on the assembler's subtarget
This adds an option to emit the command line -mattr/-march into the
attributes of an object file. This can be useful to get objdump to
disassemble instructions that aren't in the base without forcing
users to add a .attribute to the assembly file.

The binutils assembler does this by default.

Similar option exists for ARM. I will wire it to a clang option in
another patch. Similar to https://reviews.llvm.org/D31813

Reviewed By: asb, kito-cheng

Differential Revision: https://reviews.llvm.org/D148782
2023-04-20 10:00:30 -07:00
Craig Topper
fdaa23a7bd [RISCV] Remove VConstraintType enum and getConstraint. NFC
Fold the 3 flag defines into the enum that defines TSFlags. Then
we don't have to extract them we can just test the bits directly
in TSFlags.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D148765
2023-04-20 00:21:24 -07:00
Alex Bradbury
522c7b1e76 [RISCV][NFC] Consistently use Opcode local variable in RISCVAsmParser::validateInstruction
As we already do `unsigned Opcode = Inst.getOpcode();`, we may as well
use that variable.
2023-04-19 06:31:10 +01:00
Nelson Chu
0b9a620b83 [RISCV] Support assembler and dis-assembler for VCIX extension.
Spec: https://sifive.cdn.prismic.io/sifive/c3829e36-8552-41f0-a841-79945784241b_vcix-spec-software.pdf

Differential Revision: https://reviews.llvm.org/D144530
2023-04-09 20:41:01 -07:00
Craig Topper
dc5679df71 [RISCV] Rename FeatureExtZc* to FeatureStdExtZc*. NFC
Even for experimental extensions, I think we always include "Std"
in the feature name.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D146997
2023-03-27 13:19:01 -07:00
Craig Topper
941667bc82 Recommit "[RISCV] Add .insn support for compressed formats."
I think the failure was caused by a mistake in an earlier patch.

Original commit message:

We've supported .insn for non-compressed for a while. This finishes the compressed supported.

Differential Revision: https://reviews.llvm.org/D146663
2023-03-27 12:30:37 -07:00
Craig Topper
1edde1c1f8 Recommit "[RISCV] Relax opcode restriction for .insn."
Original commit message:
I recently added a check to make sure the lower 2 bits of the opcode
were 0x3. A post commit comment pointed out this would be allowed
for a custom extension when C is not supported.

Note, binutils does have this restriction.
2023-03-27 11:14:12 -07:00
Craig Topper
39b64ad6db Revert "foo"
This reverts commit 4fde20b8a62ed3d850e4e770ae640039ca1a9ed8.

I failed to squash this
2023-03-27 10:57:45 -07:00
Craig Topper
3f8fe5220a Revert "[RISCV] Add .insn support for compressed formats."
This reverts commit 5e2445ae65f0a8f1ac38049bdd2f0fd5572be488.

This is failing on the build bots.
2023-03-27 10:57:45 -07:00
Craig Topper
5e2445ae65 [RISCV] Add .insn support for compressed formats.
We've supported .insn for non-compressed for a while. This finishes the compressed supported.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D146663
2023-03-27 10:37:09 -07:00
Craig Topper
4fde20b8a6 foo 2023-03-27 10:06:34 -07:00
Craig Topper
29463612d2 [RISCV] Replace RISCV -> RISC-V in comments. NFC
To be consistent with RISC-V branding guidelines
https://riscv.org/about/risc-v-branding-guidelines/
Think we should be using RISC-V where possible.

More patches will follow.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D146449
2023-03-27 09:50:17 -07:00
4vtomat
9795aa042a [RISCV] Support vector crypto extension ISA string and assembly
LLVM implements the 0.3 draft specification:
https://github.com/riscv/riscv-crypto/releases/download/v20230206/riscv-crypto-spec-vector.pdf
, and current vector crypto extension version can be found in:
https://github.com/riscv/riscv-crypto.

Differential Revision: https://reviews.llvm.org/D141672
2023-03-25 05:15:55 -07:00
Job Noorman
c39dd7c1db [RISCV][MC] Add support for RV64E
Implement MC support for the recently ratified RV64E base instruction
set.

Differential Revision: https://reviews.llvm.org/D143570
2023-03-23 12:32:25 +00:00
Craig Topper
84de01908b [RISCV] Remove AnyReg RegisterClass used by .insn instructions. Use custom operand instead.
The fake register class interferes too much with the autogenerated
register class tables. Especially the fake spill size.

I'm working on .insn support for compressed instructions and adding
AnyRegC broke CodeGen.
2023-03-22 10:31:58 -07:00
Craig Topper
087b5f3277 [RISCV] Improve validation of opcode for .insn.
The lower 2 bits of the opcode must be 0x3. If the lower 2 bits are
0-2, it's a compressed instruction.

Merge 3 slightly different error messages into 1 to reduce code. The
messages differed slightly depending on whether we parsed a string
or an expression. The message gets a little more generic, but is no
more generic than what binutils prints.
2023-03-21 16:20:30 -07:00