318 Commits

Author SHA1 Message Date
Craig Topper
73516b355c [RISCV] Don't parse the decimal minimum value for fli.s/fli.d/fli.h.
There are a couple bugs in the current support for this:
-We do all the parsing in single precision so any value less than or
 equal to the minimum fp32 is accepted as the minimum value for f64.
-To support fp16 minimum value, getLoadFP32Imm has a special case, but
 that causes a miscompile in CodeGen.

Differential Revision: https://reviews.llvm.org/D145542
2023-03-08 09:24:58 -08:00
Craig Topper
61ae2aaf52 [RISCV] Store fli min/nan/inf in index form in RISCVOperand.
Instead of converting to FP value, store them as Index using an
immediate operand.

Do the same for the explicit index form.

This avoids using the FP32 version of these special values as the
representation for fli.h and fli.d. inf/nan aren't so bad, but
"min" is problematic as the current implementation allows fli.d and
fli.h to accept the decimal version of the fp32 minimum value. I
will submit another patch to fix that.

Differential Revision: https://reviews.llvm.org/D145535
2023-03-08 09:24:58 -08:00
Craig Topper
36bbea8037 [RISCV] Const correct some methods in RISCVOperand. NFC 2023-03-07 17:46:24 -08:00
Craig Topper
bfb180587c [RISCV] Don't accept '-min', '-inf' or '-nan' in RISCVAsmParser::parseFPImm.
We need to check for identifier before optionally parsing a minus sign.
2023-03-07 15:36:37 -08:00
Craig Topper
6e2ade23c7 [RISCV] Return MatchOperand_ParseFail instead of MatchOperand_NoMatch from parseFPImm.
MatchOperand_NoMatch will fall back to regular operand parsing.
Returning MatchOperand_ParseFail will prevent this.

We also printed our own error message which we should only do for
MatchOperand_ParseFail.
2023-03-07 14:46:47 -08:00
Jun Sha (Joshua)
8a002d40f5 [RISCV][MC] Add FLI instruction support for the experimental zfa extension
This implements experimental support for the RISCV Zfa extension as specified here: https://github.com/riscv/riscv-isa-manual/releases/download/draft-20221119-5234c63/riscv-spec.pdf, Ch. 25. This extension has not been ratified. Once ratified, it'll move out of experimental status.

This change adds assembly support for load-immediate instructions (fli.s/fli.d/fli.h). The assembly prefers decimal constants in C-like syntax. In my implementation, an integer encoding ranging from 0 to 31 can also be accepted, but for the MCInst printer, the constant is specified in decimal notation by default.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140460
2023-03-07 14:06:01 +08:00
Manolis Tsamis
bbb58a2302 [RISCV] Add vendor-defined XTheadMemPair (two-GPR Memory Operations) extension
The vendor-defined XTHeadMemPair (no comparable standard extension exists
at the time of writing) extension adds two-GPR load/store pair instructions.

It is supported by the C9xx cores (e.g., found in the wild in the
Allwinner D1) by Alibaba T-Head.

The current (as of this commit) public documentation for this
extension is available at:
  https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.2.2/xthead-2023-01-30-2.2.2.pdf

Support for these instructions has already landed in GNU Binutils:
  https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6e17ae625570ff8f3c12c8765b8d45d4db8694bd

Depends on D143847

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D144002
2023-02-21 12:21:49 +01:00
Craig Topper
34aff47521 [RISCV] Use MCSubtargetInfo::hasFeature where possible. NFC
Rather than using operator[] on getFeatureBits we can use
hasFeature to shorten the code.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D144300
2023-02-17 14:36:48 -08:00
Craig Topper
2b2b8409e6 [RISCV] For rv32, accept constants like 0xfffff800 as a valid simm12.
Internally we store constants in int64_t after parsing, but this is
kind of an implementation detail. If we only supported rv32, we might
have chosen int32_t.

For rv32, I think it makes sense to accept the constants that we
would accept if int32_t was the internal type. In fact we already
do this for the `li` alias. This patch extends this to sign
extended constants for other instructions.

This matches the GNU assembler. The difference between LLVM and gcc
was previously noted here. https://github.com/riscv-non-isa/riscv-asm-manual/pull/71

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D144166
2023-02-17 10:53:44 -08:00
Philipp Tomsich
16a66af0a0 Revert "[RISCV] Add vendor-defined XTheadMemPair (two-GPR Memory Operations) extension"
This reverts commit d2918544a7fc4b5443879fe12f32a712e6dfe325.
2023-02-17 19:45:55 +01:00
Manolis Tsamis
d2918544a7 [RISCV] Add vendor-defined XTheadMemPair (two-GPR Memory Operations) extension
The vendor-defined XTHeadMemPair (no comparable standard extension exists
at the time of writing) extension adds two-GPR load/store pair instructions.

It is supported by the C9xx cores (e.g., found in the wild in the
Allwinner D1) by Alibaba T-Head.

The current (as of this commit) public documentation for this
extension is available at:
  https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.2.2/xthead-2023-01-30-2.2.2.pdf

Support for these instructions has already landed in GNU Binutils:
  https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6e17ae625570ff8f3c12c8765b8d45d4db8694bd

Depends on D143847

Differential Revision: https://reviews.llvm.org/D144002
2023-02-17 19:45:22 +01:00
Jun Sha (Joshua)
c0947dc441 [RISCV][MC] Add support for experimental zfa extension (FLI instruction not included) (try 3)
(Opening comment by preames - submitter, not patch author)

Try 1 was reverted because it had been landed in pieces, none of which had a meaningful commit message.

Try 2 was reverted because of a buildbot failure.  It turns out this was a spurious revert on my (preames) part.  The buildbots were failing, and it was from one of my changes in this sequence, but not the recommit.  I had reverted both of the try 1 commits in a single git push, but in separate *commits*.  Some of the builders decided to build the broken state between the original try 1 commit, and I'd not noticed that.  I'd assumed the breakage was because of the try2 re-commit.  So the revert of the try 2 recommit was spurious.

Original commit message:

This implements experimental support for the RISCV Zfa extension as specified here: https://github.com/riscv/riscv-isa-manual/releases/download/draft-20221119-5234c63/riscv-spec.pdf, Ch. 25. This extension has not been ratified. Once ratified, it'll move out of experimental status.

This change adds assembly support for all instructions except load-immediate instructions (fli.s/fli.d/fli.h).  Assembly support for that instruction and codegen support will follow in separate patches.

Differential Revision: https://reviews.llvm.org/D141984
2023-02-17 09:34:36 -08:00
Philip Reames
891b0910b3 Revert "[RISCV][MC] Add support for experimental zfa extension (FLI instruction not included)"
This reverts commit f6fa5a66d8a8190002d3eb542e4b5a99deb53004.  Several buildbots are failing.  An example:
https://lab.llvm.org/buildbot#builders/196/builds/26601
2023-02-16 09:31:04 -08:00
Jun Sha (Joshua)
f6fa5a66d8 [RISCV][MC] Add support for experimental zfa extension (FLI instruction not included)
This implements experimental support for the RISCV Zfa extension as specified here: https://github.com/riscv/riscv-isa-manual/releases/download/draft-20221119-5234c63/riscv-spec.pdf, Ch. 25. This extension has not been ratified. Once ratified, it'll move out of experimental status.

This change adds assembly support for all instructions except load-immediate instructions (fli.s/fli.d/fli.h).  Assembly support for that instruction and codegen support will follow in separate patches.

Differential Revision: https://reviews.llvm.org/D141984
2023-02-16 08:08:52 -08:00
Philip Reames
80334ca1e2 Revert "Update: [RISCV][MC] Add support for experimental zfa extension(FLI instruction not included)"
This reverts commit 321cd52ba2647259f58b0d38cdb62528a9ded9a1. It was submitted without an appropriate patch description.  Will reapply shortly.
2023-02-16 07:49:44 -08:00
Craig Topper
43059255ce [RISCV] Make a const member function static. NFC
This function doesn't use any members from the class so it can be
static.
2023-02-15 19:29:09 -08:00
Jun Sha (Joshua)
321cd52ba2 Update: [RISCV][MC] Add support for experimental zfa extension(FLI instruction not included) 2023-02-16 09:54:40 +08:00
Fangrui Song
7d3a181c8c [MC] Simplify code with parseComma 2023-02-01 18:41:02 -08:00
Fangrui Song
d1ebd352b0 [RISCV][MC] Simplify .option and make error messages more conventional
and add line/column information to tests.
2023-02-01 17:58:23 -08:00
Craig Topper
84b6d074d7 [RISCV] Move the even register check for rv32zdinx later in the matching process.
And remove the IsRV64 checks for isGPRAsFPR and isGPRPF64AsFPR.

Overall I think this results in a better diagnostic experience. We
now do a better job of matching Zdinx instructions even if the registers
aren't correct and report an error for missing features like RV64.

Unfortunately, this makes it difficult to recover the error location
for the invalid odd register when we do report it. But to make up
for it, I gave a more specific error message.

It doesn't look like binutils gives any warning or error for odd registers.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D142997
2023-02-01 11:15:06 -08:00
Craig Topper
6a1b2d0428 [RISCV] Handle FRMArg as an optional operand instead of using InstAliases.
Instead of having InstAliases without operand. Use the optional
operand infrastructure.

Still use the PrintAliases/NoAlias controls to determine if we
print "dyn" or not.

Differential Revision: https://reviews.llvm.org/D142959
2023-01-31 09:08:13 -08:00
Craig Topper
d558a70abf [RISCV] Use custom operand parsing for FenceArg.
Rather than parsing a symbol and checking its name, look for an
identifier during parsing.

I've also handled the 0 immediate during parsing, though we could
let that go through the normal immediate parsing if we need to support
expressions that evaluate to 0. We don't have tests for that currently.

Reviewed By: asb, frasercrmck

Differential Revision: https://reviews.llvm.org/D142865
2023-01-30 12:31:00 -08:00
Craig Topper
d178bd2caf [RISCV] Move IsRV64 field of RISCVOperand into RegOp and ImmOp sub-structs.
We don't need this field for all operand types, so sync it into the
ones that do need it. Then remove it from the create* functions that
don't need it.
2023-01-29 18:46:39 -08:00
Craig Topper
13e3bdef3b [RISCV] Correct end pointer in RISCVAsmParser::parseGPRAsFPR.
Instead of using start pointer - 1, use start pointer + length of
the name string.
2023-01-29 18:46:39 -08:00
Craig Topper
e1872c5873 [RISCV] Make RISCVOperand struct final.
Allows the compiler to de-virtualize some calls.
2023-01-29 18:46:38 -08:00
Craig Topper
621360657b [RISCV] Move IsGPRAsFPR into RegOp struct in RISCVOperand. NFC
This field is only initialized for register operands, move it into
the struct to make that clear.

This also fixes a potential bug where the field wasn't copied by
the RISCVOperand copy constructor.
2023-01-29 12:41:01 -08:00
Craig Topper
2a45aa8dc2 [RISCV] Move FRM parsing in the assembler to a custom operand parser.
Previously we parsed it as a symbol, and then accessed the name.
This works, but seems like an unusual way to do it.

This adds a custom parser that looks for an Identifier token containing
one of the valid FRM strings.

Differential Revision: https://reviews.llvm.org/D142833
2023-01-29 12:25:00 -08:00
Craig Topper
0de61934a3 [RISCV] Simplify code slightly. NFC
These two pieces of code were using a switch with a single case and
a default that always returned.

Replace with an if statement that early returns.
2023-01-28 22:44:58 -08:00
WuXinlong
42c36da9c9 [RISCV] Add MC support of RISCV Zcb Extension
This patch add the instructions of Zcb extension.

Instructions in zcb extensions shorten part of bit manipulation instructions.

Co-authored-by: Craig Topper <craig.topper@sifive.com>

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D131141
2023-01-26 12:54:00 -08:00
wangpc
3f703b071e [RISCV][NFC] Move compressInst/uncompressInst to RISCVBaseInfo
We have several usages of compressInst/uncompressInst in different
files, which results in duplicated code. We move their implementations
to RISCVBaseInfo under namespace RISCVRVC to remove these duplications.

Reviewed By: craig.topper, asb

Differential Revision: https://reviews.llvm.org/D141897
2023-01-18 14:34:06 +08:00
Craig Topper
0b38636f77 [RISCV] Remove MCRegisterInfo dependency from compressInst/uncompresInst/isCompressibleInst.
This was being used to lookup the register class for a register number,
but those live in a tablegened array. We can index that array directly
just like RISCVAsmParser does.

Differential Revision: https://reviews.llvm.org/D141951
2023-01-17 11:56:43 -08:00
Sergei Barannikov
6ae84d668f [MC] Use MCRegister instead of unsigned in MCInstPrinter (NFC)
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140654
2023-01-17 22:39:39 +03:00
Sergei Barannikov
4d48ccfc88 [MC] Use MCRegister instead of unsigned in MCTargetAsmParser
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D140273
2022-12-18 12:12:05 -08:00
Craig Topper
f2ffdbeb9c [RISCV] Add accessors to RISCVMatInt::Inst.
Make fields private. This helps hide that the Imm field doesn't
store a full int64_t.
2022-12-07 19:02:01 -08:00
Yeting Kuo
3a88121732 [RISCV] Support .variant_cc directive for the assembler.
The patch is split from D103435. The patch supported a new directive .variant_cc
that annotates function with STO_RISCV_VARIANT_CC. Symbols marked with
STO_RISCV_VARIANT_CC do not use standard calling conversion or use parameter not
passed in GPR/FPR.

Related: https://github.com/riscv/riscv-elf-psabi-doc/pull/190

Initial authored by: HsiangKai

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D138352
2022-12-05 12:13:43 +08:00
Fangrui Song
74034588bd Support: Convert some Optional to std::optional 2022-12-02 08:02:19 +00:00
WuXinlong
219417b2c6 [RISCV] Add CodeGen support and MC testcase of RISCV Zca Extension
This patch add the support of RISCV Zca ext

`Zca` is a subset of C extension instructions that are compatible with the Zc extension.

So this patch implements Zca code generation with reference to the C extension and sets the 2-byte alignment for the Zca extension, just like C extension does.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D130483
2022-11-22 17:22:26 +08:00
Michael Maitland
30a4264f5f [RISCV][CodeGen] add assertion to RISCVTargetStreamer getTargetStreamer()
X86 and ARM AsmParsers have this same assertion. This assertion provides better reporting when the RISCVTargetStreamer is null and helps to prevent null pointer access.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D132863
2022-08-31 11:15:47 -07:00
Alex Bradbury
7bcfcabbd1 [RISCV] Implement support for the Zicbop extension
Implements the ratified RISC-V Base Cache Management Operation ISA
Extension: Zicbop, as described in
https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-v1.0.pdf.

This is implemented in a separate patch to Zicbom and Zicboz due to it
requiring a new ASM operand type to be defined.

Differential Revision: https://reviews.llvm.org/D117433
2022-06-28 12:43:26 +01:00
Shao-Ce SUN
529f05cdbb [RISCV][MC] Fold UIMM related code
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D128495
2022-06-25 10:50:50 +08:00
Kazu Hirata
7a47ee51a1 [llvm] Don't use Optional::getValue (NFC) 2022-06-20 22:45:45 -07:00
Kazu Hirata
e0e687a615 [llvm] Don't use Optional::hasValue (NFC) 2022-06-20 10:38:12 -07:00
Fangrui Song
77e300ffdf [MC] Change EndOfStatement "unexpected tokens in .xxx directive " to "expected newline" 2022-06-05 15:11:01 -07:00
Craig Topper
d2ee2c9c8d [RISCV] Add an operand kind to the opcode/imm returned from RISCVMatInt.
Instead of matching opcodes to know the format to emit, use an
enum value that we can get from the RISCVMatInt::Inst class.

Change the consumers to use fully covered switches so that we get
a compiler warning if a new kind is added. With the opcode checks
it was easier to forget to update one of the 3 consumers.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D126317
2022-05-24 14:56:29 -07:00
Craig Topper
057c063c9b [RISCV] Add a encodeLMUL function to RISCVVType. NFC
This moves the encoding handling out of the assembly parser.

Reviewed By: khchen, frasercrmck

Differential Revision: https://reviews.llvm.org/D123553
2022-04-12 13:39:47 -07:00
Fraser Cormack
a276d1f44b [RISCV][NFC] Fix formatting on one line 2022-03-31 13:17:37 +01:00
Dávid Bolvanský
9a738c477e [NFCI] Fix set-but-unused warning in RISCVAsmParser.cpp 2022-03-24 08:33:40 +01:00
luxufan
227496dc09 [RISCV] Generate correct ELF EFlags when .ll file has target-abi attribute
In the past, when construct RISCVAsmBackend, MCTargetOptions.ABIName would be passed and stored in RISCVAsmBackend.
But MCTargetOptions.ABIName can only be specified by -target-abi xxx in command line, if the .ll file has target-abi attribute, the codegen module will ignore it. And the generated object file would have incorrect EFlags value.

https://github.com/llvm/llvm-project/issues/50591 also caused by this problem.

This patch override the AsmPrinter::emitFunctionEntryLabel function and use it to set the target abi value that get from .ll file's target-abi attribute. And storing the target-abi in RISCVTargetStreamer instead of RISCVAsmBackend.

Differential Revision: https://reviews.llvm.org/D121183
2022-03-24 00:48:52 +08:00
Shao-Ce SUN
0e38b29543 [RISCV] add the MC layer support of Zfinx extension
This patch added the MC layer support of Zfinx extension.

Authored-by: StephenFan
Co-Authored-by: Shao-Ce Sun

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D93298
2022-03-02 14:25:19 +08:00
Eric Tang
cf80ef1393 [RISCV] Change GPRMemAtomic to GPRMemZeroOffset for general usage
Not only some AMO instructions but also other instructions need to
    process (${gpr}) or 0(${gpr}), where the 0 is be silently ignored.

    This patch does some changes for general usage.

Signed-off-by: Eric Tang <eric.tang@starfivetech.com>

Differential Revision: https://reviews.llvm.org/D120017
2022-02-28 14:02:43 +08:00