151 Commits

Author SHA1 Message Date
4vtomat
02f94a655f [RISCV] Bump vector crypto to v1.0.0-rc1
Differential Revision: https://reviews.llvm.org/D153836
2023-06-28 19:53:07 -07:00
Alex Bradbury
6101d720cb [RISCV] Relax rules for ordering s/z/x prefixed extensions in ISA naming strings
This was discussed somewhat in D148315. As it stands, we require in
RISCVISAInfo::parseArchString (used for e.g. -march parsing in Clang)
that extensions are given in the order of z, then s, then x prefixed
extensions (after the standard single-letter extensions). However, we
recently (in D148315) moved to that order from z/x/s as the canonical
ordering was changed in the spec. In addition, recent GCC seems to
require z* extensions before s*.

My recollection of the history here is that we thought keeping -march as
close to the rules for ISA naming strings as possible would simplify
things, as there's an existing spec to point to. My feeling is that now
we've had incompatible changes, and an incompatibility with GCC there's
no real benefit to sticking to this restriction, and it risks making it
much more painful than it needs to be to copy a -march= string between
GCC and Clang.

This patch removes all ordering restrictions so you can freely mix x/s/z
extensions.

To be very explicit, this doesn't change our behaviour when emitting a
canonically ordered extension string (e.g. in build attributes). We of
course sort according to the canonical order (as we understand it) in
that case.

Differential Revision: https://reviews.llvm.org/D149246
2023-06-27 13:32:11 +01:00
Garvit Gupta
4c37d30e22 [RISCV] Add support for custom instructions for Sifive S76.
Support for below instruction is added
1. CFLUSH.D.L1
2. CDISCARD.D.L1
3. CEASE

Additionally, Zihintpause extension is added to sifive s76 for pause
instruction.

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

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D153370
2023-06-26 11:36:00 -07:00
Craig Topper
f2d16b368f [RISCV] Use binary search on the extension tables in RISCVISAInfo.cpp. NFC
After D153170 the tables are now sorted by extension name so we can use that to
avoid a linear search.

Reviewed By: asb, MaskRay

Differential Revision: https://reviews.llvm.org/D153598
2023-06-23 17:23:12 -07:00
Craig Topper
076759f068 Revert "[RISCV] Implement support for bf16 truncate/extend on hard FP targets"
This was committed with D153598 merged into it. Reverting to recommit as separate patches.

This reverts commit 690b1c847f0b188202a86dc25a0a76fd8c4618f4.
2023-06-23 17:23:12 -07:00
Alex Bradbury
690b1c847f [RISCV] Implement support for bf16 truncate/extend on hard FP targets
For the same reasons as D151284, this requires custom lowering of the
truncate libcall on hard float ABIs (the normal libcall code path is
used on soft ABIs).

The extend operation is implemented by a shift just as in the standard
legalisation, but needs to be custom lowered because i32 isn't a legal
type on RV64.

This patch aims to make the minimal changes that result in correct
codegen for the bfloat.ll tests.

Differential Revision: https://reviews.llvm.org/D151663
2023-06-23 14:18:59 +01:00
Craig Topper
e4a93d80f4 [RISCV] Sort the extensions in SupportedExtensions and SupportedExperimentalExtensions.
As the extension list continues to grow it probably makes sense
to use a binary search rather than linear search. Sorting the strings
will make this possible.

This also avoids any question about where to add new strings in
the tables.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D153170
2023-06-22 11:25:47 -07: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
Craig Topper
61e91988bc [RISCV] Add errors for mixing Zcmp with C/Zcd and D.
We already had an error for Zcmt though it appears to be untested
Add similar one for Zcmp along with tests for both.

Factor the code to share the strings as much as possible.

Reviewed By: VincentWu

Differential Revision: https://reviews.llvm.org/D153159
2023-06-21 00:10:37 -07:00
Piyou Chen
fc4350cb43 [NFC][RISCV] rename findFirstNonVersionCharacter with findLastNonVersionCharacter
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D152506
2023-06-13 23:55:34 -07:00
Eric Gouriou
c5a88fe3d0 [RISC-V] Zvk update to 0.9.7, Zvknc/Zvksc
Update the RISC-V Zvk (vector cryptography) extension support from 0.5
to version 0.9.7 (2023-05-31), per
    <https://github.com/riscv/riscv-crypto/releases/download/v20230531/riscv-crypto-spec-vector.pdf>

Differences:
     - Zvbc is dropped from Zvkn and Zvks, and by extension
       from Zvkng and Zvksg;
     - new combo extensions Zvknc and Zvksc are introduced,
      adding Zvbc to Zvkn and Zvks;
     - the experimentatl extensions are tagged as "0.9",
       from the earlier "0.5".

Reviewed By: 4vtomat

Differential Revision: https://reviews.llvm.org/D152117
2023-06-12 15:43:08 -07:00
Piyou Chen
eabf1d367f [RISCV] check pointer before dereference
Encountered ASAN crash and found it dereference without check pointer.

Reviewed By: kito-cheng, eklepilkina

Differential Revision: https://reviews.llvm.org/D151716
2023-05-31 21:35:07 -07:00
Craig Topper
a5e5eea29c Revert "[RISCV] Add Zvfhmin extension for clang."
This reverts commit 35a0079238ce9fc36cdc8c6a2895eb5538bf7b4a.

The backend support is not present yet. The intrinsics will crash
the compiler if compiled to assembly or binary.
2023-05-31 10:17:11 -07:00
Jianjian GUAN
35a0079238 [RISCV] Add Zvfhmin extension for clang.
This patch adds the Zvfhmin extension for clang.

Reviewed By: craig.topper, michaelmaitland

Differential Revision: https://reviews.llvm.org/D150253
2023-05-31 14:31:11 +08:00
Alex Bradbury
033690fffe [RISCV] Make zfbfmin imply the F extension
Our current approach is that if one extension requires another, we make
LLVM treat it as implied. My initial zfbfmin patch failed to do this for
the F extension (documented as a requirement of zfbfmin). This patch
fixes that.

Differential Revision: https://reviews.llvm.org/D151096
2023-05-23 10:10:11 +01:00
Alex Bradbury
a1455de74d [RISCV][MC] Add support for experimental Zvfbfwma extension
Provides MC layer support for Zvfbfwma: vector BF16 widening mul-add.

As currently specified, Zvfbfwma does not appear to have a dependency on
Zvfbfmin or Zfbfmin.

Differential Revision: https://reviews.llvm.org/D147612
2023-05-19 15:37:26 +01:00
Alex Bradbury
b18a819664 [RISCV][MC] Add support for experimental Zvfbfmin extension
Provides MC layer support for Zfbfmin: vector BF16 conversions.

Zvfbfmin does not appear to have a dependency on Zfbfmin as currently
specified.

Differential Revision: https://reviews.llvm.org/D147611
2023-05-19 15:26:25 +01:00
Alex Bradbury
35ff5eba16 [RISCV][MC] Add support for experimental Zfbfmin extension
Provides MC layer support for Zfbfmin: scalar BF16 conversions.

As documented, this extension includes FLH, FSH, FMV.H.X, and FMH.X.H as
defined in Zfh/Zfhmin, but doesn't require either extension.

No Zfbfinxmin has been defined (though you would expect one in the
future, for symmetry with Zfhinxmin). See issue
https://github.com/riscv/riscv-bfloat16/issues/27.

Differential Revision: https://reviews.llvm.org/D147610
2023-05-19 15:17:56 +01:00
Craig Topper
57a9522f87 [RISCV] Remove redundant F and D extension implication from V. NFC
We recently added implications for F and D to Zve32f and Zve64d
which V implies. So these have become redundant.
2023-05-10 10:00:59 -07:00
Jianjian GUAN
7ab9478560 [RISCV] Make Zvfh depend on Zfhmin.
According to the v spec, the Zvfh extension depends on the Zve32f and Zfhmin extensions.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D150016
2023-05-10 09:46:19 +08: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
728b8a1398 [RISCV] Make zve32f imply F and zve64d imply D.
The 1.0 vector spec PDF has text that says that Zve32f is compatible
with F or Zfinx and that Zve64d is compatible with D and Zdinx.
The references to *inx were removed from the spec in the github repository in
October 2021. The 1.0 pdf was made in September 2021.

Relevant commit 6fedb869e2

Reviewed By: jacquesguan

Differential Revision: https://reviews.llvm.org/D150021
2023-05-06 23:17:16 -07:00
WuXinlong
9f0d725744 [RISCV] Add MC support of RISCV zcmt Extension
This patch add the instructions of zcmt extension.
[[ https://github.com/riscv/riscv-code-size-reduction/releases/tag/v1.0.0-RC5.7 | spac is here ]]
Which includes two instructions (cm.jt&cm.jalt) and a CSR Reg JVT

co-author: @Scott Egerton

Reviewed By: kito-cheng, craig.topper

Differential Revision: https://reviews.llvm.org/D133863
2023-05-03 22:06:37 +08:00
4vtomat
74c1fa60b5 [RISCV] Add Smaia and Ssaia extensions support
This patch implements 1.0-RC3:
https://github.com/riscv/riscv-aia/releases/download/1.0-RC3/riscv-interrupts-1.0-RC3.pdf

Differential Revision: https://reviews.llvm.org/D148066
2023-05-01 22:30:08 -07:00
Craig Topper
3ce3ee6169 [RISCV] Make Zicntr and Zihpm imply Zicsr.
Zicntr and Zihpm are names for groups of CSRs so they should imply
that CSRs exist.

Reviewed By: asb, kito-cheng

Differential Revision: https://reviews.llvm.org/D148962
2023-04-26 10:11:14 -07:00
Craig Topper
236898f619 [RISCV] Accept zicntr and zihpm command line options
This change adds the definition of the two extensions, but does not either a) make any register definitions conditional on them or b) enabled the extensions by default.

This is somewhat analogous to https://reviews.llvm.org/D143953, but with some key differences.  The best discussion I can find on status is here: https://github.com/riscv/riscv-profiles/issues/43.  These were removed between document version 2.1 and 2.2, but were not defined as new extensions in 2.2.  That addition came later - in March 2022.

According to https://drive.google.com/file/d/1qa57pePesOiDOrNzxuuGFhCL4Rbi9AYB/view these were ratified in March 2023.

Reviewed By: asb, reames

Differential Revision: https://reviews.llvm.org/D144215
2023-04-26 10:11:07 -07:00
Alex Bradbury
52b51ee0d4 [RISCV][NFC] Remove outdated TODOs about extension versions in RISCVISAInfo
As was documented in D147183, we don't currently intend to support
multiple versions of specifications simultaneously. While external
circumstances might mean exceptions to this are needed, the TODOs about
reflecting version numbers in the feature strings no longer make sense.
2023-04-26 09:58:57 +01:00
Eric Gouriou
ca554ad7c2 [RISCV] NFC tweaks in extension descriptions, sorting
NFC changes in RISCISAInfo and RISCFeatures, and matching updates to the
MC tests.

- Drop the '.' in the parentheses section of the Zvk extension
  descriptions. This is supported by
<https://www.masterclass.com/articles/period-inside-or-outside-parentheses#>,
- Remove an extraneous space in the description of Zvt,
- Reorder the ImpliedExts.* constant literals in RISCISAInfo.cpp, as
  suggested in <https://reviews.llvm.org/D148483>.

Differential Revision: https://reviews.llvm.org/D148857
2023-04-21 17:39:44 +01:00
Eric Gouriou
cb7dffdc9a [RISCV] Zvk (vector crypto) specification update to 0.5.1 (Zvbb/Zvbc/Zvkt/Zvkng/Zvksg)
Update the Zvk support from 0.3.x to 0.5.1, tracking the extension as
documented in
<https://github.com/riscv/riscv-crypto/releases/download/v20230407/riscv-crypto-spec-vector.pdf>.

- Zvkb is split into Zvbb and Zvbc
- Zvbc (vector carryless multiply) requires 64 bit elements (Zve64x)
- Use the extension descriptions from the specification for Zvbb/Zvbc
- Zvkt is introduced (no instructions, but adds an attribute and macro)
- Zvkn and Zvks both imply Zvkt
- Zvkng and Zvksg are introduced, adding Zvkg (GMAC) to Zvkn and Zvks
- In Zvbb, add vrev.v, vclz.v, vctz.v, vcpop.v, vwsll.{vv,vx,vi}

Differential Revision: https://reviews.llvm.org/D148483
2023-04-20 18:25:19 +01:00
Jun Sha (Joshua)
3f81d25cee [RISCV] Remove 'sx' when parsing arch string to match the latest ISA manual
In order to match the latest ISA manual, we need to remove sx prefix.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D148617
2023-04-20 10:32:24 +08:00
Jun Sha (Joshua)
914b38aa4b Revert '[RISCV] Remove 'sx' when parsing arch string to match the latest ISA manual'
This reverts commit fbc63e5658f67036d4ea57940459074d9ecdd2d8
2023-04-20 10:27:02 +08:00
Jun Sha (Joshua)
fbc63e5658 [RISCV] Remove 'sx' when parsing arch string to match the latest ISA manual 2023-04-20 10:19:14 +08:00
Alex Bradbury
c8318b973a [RISCV] Fix canonical ordering of s* vs z* extensions in RISCVISAInfo
As noted in https://reviews.llvm.org/D148315, the ordering logic for
OrderedExtensionMap currently puts s* before z* extensions, but per the
ISA manual the correct order should be z* and then s* (with the
exception of zxm*, which are ordered after s*).

This patch fixes the ordering and adds a TODO for zxm*. The changes are
visible in the test case added in
a35e67fc5be654a7efdfa6125343b90f8960a487 which also demonstrates an
issue with the ordering of single letter extensions (which isn't
addressed in this patch).

This ordering matches the one used by GCC/binutils as well.

Differential Revision: https://reviews.llvm.org/D148615
2023-04-19 07:04:48 +01:00
Alex Bradbury
2a5661c841 [RISCV] Bump Zfa version to 0.2 and correct RISCVUsage description
As of
1f03818281
in the riscv-isa-manual, Zfa is at version 0.2. Reviewing the commit
history for
zfa.tex
<https://github.com/riscv/riscv-isa-manual/commits/master/src/zfa.tex>
there are no relevant changes since 0.1. As such, we can simply
increment the version number.

This change also removes the claim in RISCVUsage that we implement a
"subset of" Zfa, as I believe this is no longer true. That sentence
previously incorrectly claimed we didn't implement fli.{h,s,d} (I
[corrected this a couple of weeks
ago](https://reviews.llvm.org/rG3d969191b277)) but I think should have
removed the "subset of" wording too.

As was noted during the review, we never added Zfa to the release notes.
This is corrected in this patch.

Differential Revision: https://reviews.llvm.org/D148634
2023-04-19 06:27:35 +01:00
Alex Bradbury
b582bfb60e [RISCV][NFC] Fix comment in RISCVISAInfo after f98ca363bed
My fault for missing this in initial review -
f98ca363bed7405a23ad4b77167e39505a1ca9dd didn't properly update the
comment to reflect the change.
2023-04-18 09:50:53 +01:00
Jun Sha (Joshua)
f98ca363be [RISCV] Modify arch string parsing order according to latest riscv spec
According to latest risc-v spec, the canonical order in which extension names must appear in the name string specified in Table 29.1 is different from before. In the latest table, non-standard extensions must be listed after all standard extensions. To keep consistent, we now change the parsing order in parseArchString().

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D148315
2023-04-18 16:20:08 +08: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
dc90af501f [RISCV] Bump I, F, D, and A extension versions to 20191214 spec version
New versions I2.1, F2.2, D2.2 A2.1

Make F and Zfinx imply Zicsr.
Make G imply Zifencei.

This should have no impact to generated code. We have no plans to require Zicsr/Zifencei extension to be explicitly enabled to use Zicsr/Zifencei instructions in assembly.

See https://reviews.llvm.org/D147183 for documentation regarding what version specification we implement.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D147179
2023-03-30 15:28:44 -07:00
Craig Topper
8c124e3c41 [RISCV] isDigit instead of isdigit for consistency. NFC
There are several other calls to isDigit in RISCVISAInfo.cpp
2023-03-30 00:11:12 -07:00
Craig Topper
24bc5f3f31 [RISCV] Replace std::string with StringRef in RISCVISAInfo. NFC
We're just slicing off part of an existing StringRef. No need to
allocate any new storage.
2023-03-29 22:24:08 -07:00
Craig Topper
e2630a5b4c [RISCV] Use StringRef(&C, 1) instead of std::string(1, C).
We're calling functions that take a StringRef. We can create one
from a single character variable without using std::string.
2023-03-29 21:51:24 -07:00
Alex Bradbury
d3291c692c [RISCV][MC] Add support for the experimental zicond extension
This patch adds the basic MC layer support for Zicond, based on
[1.0-rc1](https://github.com/riscv/riscv-zicond/releases/tag/v1.0-rc1).
As with other extensions, if there are additional changes between
release candidates without incrementing the version number we won't be
able to reflect that in the version number. I believe we've previously
decided this is not a problem for extensions still considered
experimental (i.e. not yet ratified).

Differential Revision: https://reviews.llvm.org/D146946
2023-03-29 12:17:50 +01: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
Alex Bradbury
062065888f [RISCV] Enable tools such as llvm-objdump to process objects with unrecognised base ISA versions
Tools such as llvm-objdump will currently inputs when the base ISA has
an unrecognised version. I addressed a similar issue in LLD in D144353,
introducing parseArchStringNormalized. While it would make sense to
migrate `llvm/lib/Object/ELFObjectFile.cpp` to using
`parseArchStringNormalized` as well, this patch takes a less ambitious
initial step. By tweaking the behaviour of `parseArchString` when
`IgnoreUnknown` is true (which only has one in-tree user), we use the
default supported ISA version when a base ISA with unrecognised version
is encountered.

This means that llvm-objdump and related tools will function better for
objects produced from a recent GCC. This isn't a full fix, as
IgnoreUnknown means that an imafd object with attributes specifying
newer A/F/D versions will have those extensions ignored.

Differential Revision: https://reviews.llvm.org/D146070
2023-03-27 04:32:58 +01:00
Alex Bradbury
af602edf0e [RISCV] Make RISCVISAInfo::toFeatureVector ignore unsupported extensions
parseNormalizedArchString adds a code path that creates a RISCVISAInfo
including extensions that may not be supported by LLVM (rather than
erroring or just ignoring them). Therefore, toFeatureVector needs to
check the extension is supported in order to avoid creating unrecognised
feature strings.

This change shouldn't impact any code paths used outside of test code,
but this will be relied upon by the next patch which moves llvm-objdump
and related tools over to using parseNormalizedArchString.

Differential Revision: https://reviews.llvm.org/D146113
2023-03-26 15:51:38 +01: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
Job Noorman
d25751779b Bump RV32E version to 2.0
RV32E was recently [ratified](afd613691c) so we should update the version as our MC-layer support is complete.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D144384
2023-03-23 18:12:26 +08:00
Craig Topper
37f3e53c5b [RISCV] Simplify RISCVISAInfo::compareExtension. NFCI
Instead of having a separate single letter and multiletter ranking
use a unified rank that assigns multiletter a larger value than
single letter.

Once we've ranked the extensions, then we compare using these ranks.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D146273
2023-03-20 22:25:11 -07:00
Craig Topper
91b3051ac8 [RISCV] Remove ExtName from RISCVExtensionInfo.
This field is never used in the compiler and was only used in
unit tests added recently.

It's only used as the value in a map where the extension name
is the key. If we need the string we can get it from the key.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D146197
2023-03-16 15:20:25 -07:00